Bug 1218474 - Improve the referrer checks in worker mochitests, r=bkelly
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 18 Nov 2015 22:13:28 +0000
changeset 273185 bc5aaa4b23f26a844a4d5946583dc02d0af2132a
parent 273184 b6c8ce8730d72856699345a4d3c52781e5a84fa7
child 273186 044b9ffab63cd806448941e71437735a4daca630
push id29696
push usercbook@mozilla.com
push dateThu, 19 Nov 2015 13:45:03 +0000
treeherdermozilla-central@a523d4c7efe2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1218474
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1218474 - Improve the referrer checks in worker mochitests, r=bkelly
dom/workers/test/mochitest.ini
dom/workers/test/referrer.sjs
dom/workers/test/test_referrer.html
dom/workers/test/worker_referrer.js
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -107,16 +107,17 @@ support-files =
   empty.html
   worker_performance_user_timing.js
   worker_performance_observer.js
   sharedworker_performance_user_timing.js
   referrer.sjs
   performance_observer.html
   sharedWorker_ports.js
   sharedWorker_lifetime.js
+  worker_referrer.js
 
 [test_404.html]
 [test_atob.html]
 [test_blobConstructor.html]
 [test_blobWorkers.html]
 [test_bug949946.html]
 [test_bug978260.html]
 [test_bug998474.html]
--- a/dom/workers/test/referrer.sjs
+++ b/dom/workers/test/referrer.sjs
@@ -1,11 +1,15 @@
 function handleRequest(request, response)
 {
   if (request.queryString == "result") {
     response.write(getState("referer"));
-  } else {
+    setState("referer", "INVALID");
+  } else if (request.queryString == "worker") {
     response.setHeader("Content-Type", "text/javascript", false);
     response.write("onmessage = function() { postMessage(42); }");
     setState("referer", request.getHeader("referer"));
+  } else if (request.queryString == 'import') {
+    setState("referer", request.getHeader("referer"));
+    response.write("'hello world'");
   }
 }
 
--- a/dom/workers/test/test_referrer.html
+++ b/dom/workers/test/test_referrer.html
@@ -10,26 +10,49 @@
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test"></pre>
 <script class="testbody" type="text/javascript">
 
-  var worker = new Worker("referrer.sjs");
-  worker.onmessage = function() {
-    var xhr = new XMLHttpRequest();
-    xhr.open('GET', 'referrer.sjs?result', true);
-    xhr.onload = function() {
-      is(xhr.responseText, location.href, "The referrer has been sent.");
+  function test_mainScript() {
+    var worker = new Worker("referrer.sjs?worker");
+    worker.onmessage = function() {
+      var xhr = new XMLHttpRequest();
+      xhr.open('GET', 'referrer.sjs?result', true);
+      xhr.onload = function() {
+        is(xhr.responseText, location.href, "The referrer has been sent.");
+        next();
+      }
+      xhr.send();
+    }
+    worker.postMessage(42);
+  }
+
+  function test_importScript() {
+    var worker = new Worker("worker_referrer.js");
+    worker.onmessage = function(e) {
+      is(e.data, location.href.replace("test_referrer.html", "worker_referrer.js"), "The referrer has been sent.");
+      next();
+    }
+    worker.postMessage(42);
+  }
+
+  var tests = [ test_mainScript, test_importScript ];
+  function next() {
+    if (!tests.length) {
       SimpleTest.finish();
+      return;
     }
-    xhr.send();
+
+    var test = tests.shift();
+    test();
   }
-  worker.postMessage(42);
 
   SimpleTest.waitForExplicitFinish();
+  next();
 
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/worker_referrer.js
@@ -0,0 +1,9 @@
+onmessage = function() {
+  importScripts(['referrer.sjs?import']);
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', 'referrer.sjs?result', true);
+  xhr.onload = function() {
+    postMessage(xhr.responseText);
+  }
+  xhr.send();
+}