Bug 1403814 - Update tests for toplevel data URI blocking because we know block after we have received the response. r=smaug
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Fri, 03 Nov 2017 13:22:57 +0100
changeset 443314 5d25efb36d34042e37075af204e109d29bc9bded
parent 443313 acbbffb64a063475792c693b61c20f62af203ead
child 443315 0c4ecb84046395afd7c5ed4a250b64991c9b0da7
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1403814
milestone58.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 1403814 - Update tests for toplevel data URI blocking because we know block after we have received the response. r=smaug
dom/security/test/general/test_block_toplevel_data_img_navigation.html
dom/security/test/general/test_block_toplevel_data_navigation.html
--- a/dom/security/test/general/test_block_toplevel_data_img_navigation.html
+++ b/dom/security/test/general/test_block_toplevel_data_img_navigation.html
@@ -29,23 +29,25 @@ function test_toplevel_data_image() {
     test_toplevel_data_image_svg();
   }, 1000);
 }
 
 function test_toplevel_data_image_svg() {
   const DATA_SVG =
     "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2Ij4KICA8cGF0aCBkPSJNOCwxMkwzLDcsNCw2bDQsNCw0LTQsMSwxWiIgZmlsbD0iIzZBNkE2QSIgLz4KPC9zdmc+Cg==";
   let win2 = window.open(DATA_SVG);
-  let wrappedWin2 = SpecialPowers.wrap(win2);
-  setTimeout(function () {
-    isnot(wrappedWin2.document.documentElement.localName, "svg",
-          "Loading data:image/svg+xml should be blocked");
-    wrappedWin2.close();
-    SimpleTest.finish();
-  }, 1000);
+  // Unfortunately we can't detect whether the window was closed using some event,
+  // hence we are constantly polling till we see that win == null.
+  // Test times out on failure.
+  var win2Closed = setInterval(function() {
+    if (win2 == null || win2.closed) {
+      clearInterval(win2Closed);
+      ok(true, "Loading data:image/svg+xml should be blocked");
+      SimpleTest.finish();
+    }
+  }, 200);
 }
-
 // fire up the tests
 test_toplevel_data_image();
 
 </script>
 </body>
 </html>
--- a/dom/security/test/general/test_block_toplevel_data_navigation.html
+++ b/dom/security/test/general/test_block_toplevel_data_navigation.html
@@ -16,26 +16,22 @@ SimpleTest.registerCleanupFunction(() =>
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("have to test that top level data: URI navgiation is blocked");
 
 function test1() {
   // simple data: URI click navigation should be prevented
   let TEST_FILE = "file_block_toplevel_data_navigation.html";
   let win1 = window.open(TEST_FILE);
-  var readyStateCheckInterval = setInterval(function() {
-    let state = win1.document.readyState;
-    if (state === "interactive" || state === "complete") {
-      clearInterval(readyStateCheckInterval);
-      ok(win1.document.body.innerHTML.indexOf("test1:") !== -1,
-         "toplevel data: URI navigation through click() should be blocked");
-      win1.close();
-      test2();
-    }
-  }, 200);
+  setTimeout(function () {
+    ok(SpecialPowers.wrap(win1).document.body.innerHTML.indexOf("test1:") !== -1,
+      "toplevel data: URI navigation through click() should be blocked");
+    win1.close();
+    test2();
+  }, 1000);
 }
 
 function test2() {
   // data: URI in iframe which opens data: URI in _blank should be blocked 
   let win2 = window.open("file_block_toplevel_data_navigation2.html");
   window.addEventListener("message", receiveMessage);
   function receiveMessage(event) {
     window.removeEventListener("message", receiveMessage);