Bug 1386644 - Enable test for bug 1053321 on Android, r=bkelly
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 11 Jan 2018 07:19:00 +0200
changeset 453434 7fba47d2119beacfa6484afef20d1da5cc349f71
parent 453360 792b172327f28a7d90aa51c38c26dff23cc06032
child 453435 8e08a2cf1b2d3e509d971d52e65377fd6290e3f5
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1386644, 1053321
milestone59.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 1386644 - Enable test for bug 1053321 on Android, r=bkelly
dom/tests/mochitest/script/file_blocked_script.sjs
dom/tests/mochitest/script/mochitest.ini
dom/tests/mochitest/script/test_bug1053321.html
--- a/dom/tests/mochitest/script/file_blocked_script.sjs
+++ b/dom/tests/mochitest/script/file_blocked_script.sjs
@@ -20,47 +20,49 @@ function getGlobalState(key)
   return data;
 }
 
 function finishBlockedRequest(request, response, query)
 {
   response.setStatusLine(request.httpVersion, 200, "OK");
   response.setHeader("Cache-Control", "no-cache", false);
   response.setHeader("Content-Type", "application/javascript", false);
-  response.write("window.script_executed_" + query[1] + " = true; ok(true, 'Script " + query[1] + " executed');");
+  response.write("scriptLoaded('" + query[1] + "');");
   response.finish();
+
+  setGlobalState(undefined, query[1]);
 }
 
 function handleRequest(request, response)
 {
   var query = request.queryString.split('&');
   switch (query[0]) {
     case "blocked":
       var alreadyUnblocked = getGlobalState(query[1]);
 
       response.processAsync();
-      if (alreadyUnblocked) {
+      if (alreadyUnblocked === true) {
         // the unblock request came before the blocked request, just go on and finish synchronously
         finishBlockedRequest(request, response, query);
       } else {
         setGlobalState(response, query[1]);
       }
       break;
 
     case "unblock":
       response.setStatusLine(request.httpVersion, 200, "OK");
       response.setHeader("Cache-Control", "no-cache", false);
       response.setHeader("Content-Type", "image/png", false);
       response.write("\x89PNG"); // just a broken image is enough for our purpose
 
       var blockedResponse = getGlobalState(query[1]);
-      if (!blockedResponse) {
+      if (blockedResponse === undefined) {
         // the unblock request came before the blocked request, remember to not block it
         setGlobalState(true, query[1]);
-      } else {
+      } else if (typeof blockedResponse == "object") {
         finishBlockedRequest(request, blockedResponse, query);
       }
       break;
 
     default:
       response.setStatusLine(request.httpVersion, 400, "Bad request");
       break;
   }
--- a/dom/tests/mochitest/script/mochitest.ini
+++ b/dom/tests/mochitest/script/mochitest.ini
@@ -1,7 +1,6 @@
 [DEFAULT]
 support-files =
   file_blocked_script.sjs
 
 [test_bug1053321.html]
-skip-if = os == 'android' # bug 1386644
 [test_whitespace.html]
--- a/dom/tests/mochitest/script/test_bug1053321.html
+++ b/dom/tests/mochitest/script/test_bug1053321.html
@@ -5,37 +5,46 @@ This test confirms we don't block body r
 If this test times out, the two image requests, that unblock the two script requests, never happen, hence
 are unexpectedly blocked.
 -->
 
 <head>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
+  <script>
+    // The two scripts below are expected to load and call scriptLoaded().
+    SimpleTest.waitForExplicitFinish();
+
+    window.expected_scripts = {
+      "defer": true,
+      "async": true,
+    };
+
+    function scriptLoaded(script)
+    {
+      ok(true, 'Script ' + script + ' executed');
+      delete window.expected_scripts[script];
+
+      let expecting = Object.keys(window.expected_scripts).length;
+      info("Expecting " + expecting + " more script(s) to execute");
+
+      if (expecting == 0) {
+        SimpleTest.finish();
+      }
+    }
+  </script>
+
   <!-- this script is not loaded until file_blocked_script.sjs?unblock&defer request is made,
-       when this script is executed, it sets window.script_executed_defer to true
+       when this script is executed, it calls SimpleTest.finish().
    -->
   <script defer src="file_blocked_script.sjs?blocked&defer"></script>
 
   <!-- this script is not loaded until file_blocked_script.sjs?unblock&async request is made,
-       when this script is executed, it sets window.script_executed_async to true
+       when this script is executed, it calls SimpleTest.finish().
    -->
   <script async src="file_blocked_script.sjs?blocked&async"></script>
 </head>
 
 <body>
-  <script>
-    SimpleTest.waitForExplicitFinish();
-
-    // We can't test whether the two scripts have not been executed here, since
-    // preloads of the two images below (that unblock the two tested <head>
-    // scripts) may happen sooner than this script executes.
-    document.addEventListener("DOMContentLoaded", function() {
-      ok(window.script_executed_defer, "Deferred script executed before DOMContentLoaded");
-    });
-    window.addEventListener("load", function() {
-      ok(window.script_executed_async, "Async script executed before onload");
-      SimpleTest.finish();
-    }, true);
-  </script>
   <img src="file_blocked_script.sjs?unblock&defer"/>
   <img src="file_blocked_script.sjs?unblock&async"/>
 </body>