1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 report: function(msg
) {
7 domAutomationController
.setAutomationId(0);
8 // The automation controller seems to choke on Objects, so turn them into
10 domAutomationController
.send(JSON
.stringify(msg
));
13 log: function(message
) {
14 load_util
.report({type
: "Log", message
: message
});
17 shutdown: function(message
, passed
) {
18 load_util
.report({type
: "Shutdown", message
: message
, passed
: passed
});
21 embed: function(manifest_url
) {
22 var embed
= document
.createElement("embed");
23 embed
.src
= manifest_url
;
24 embed
.type
= "application/x-nacl";
28 // Use the DOM to determine the absolute URL.
29 absoluteURL: function(url
) {
30 var a
= document
.createElement("a");
35 crossOriginURL: function(manifest_url
) {
36 manifest_url
= load_util
.absoluteURL(manifest_url
);
37 // The test server is only listening on a specific random port
38 // at 127.0.0.1. So, to inspect a cross-origin request from within
39 // the server code, we load from "localhost" which is a different origin,
40 // yet still served by the server. Otherwise, if we choose a host
41 // other than localhost we would need to modify the DNS/host resolver
42 // to point that host at 127.0.0.1.
43 var cross_url
= manifest_url
.replace("127.0.0.1", "localhost");
44 if (cross_url
== manifest_url
) {
45 load_util
.shutdown("Could not create a cross-origin URL.", false);
51 crossOriginEmbed: function(manifest_url
) {
52 return load_util
.embed(load_util
.crossOriginURL(manifest_url
));
55 expectLoadFailure: function(embed
, message
) {
56 embed
.addEventListener("load", function(event
) {
57 load_util
.log("Load succeeded when it should have failed.");
58 load_util
.shutdown("1 test failed.", false);
61 embed
.addEventListener("error", function(event
) {
62 if (embed
.lastError
!= "NaCl module load failed: " + message
) {
63 load_util
.log("Unexpected load error: " + embed
.lastError
);
64 load_util
.shutdown("1 test failed.", false);
66 load_util
.shutdown("1 test passed.", true);