Bug 1397653 - Update tests within docshell/ to comply with new toplevel data: URI navigation policy. r=smaug
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Sun, 10 Sep 2017 13:22:12 +0200
changeset 662200 2b64aee9198d90d181d6b6d5870f57762d47f76f
parent 662105 9b2a93197d2ba3a04d05644c55f3432c2dba5866
child 662201 e7ce80185031ac5c037bbcbca3ff6566ef9e0718
child 663015 e1b0fa042239778856fa221c02de20a26cd38323
push id78990
push userttung@mozilla.com
push dateMon, 11 Sep 2017 07:00:55 +0000
reviewerssmaug
bugs1397653
milestone57.0a1
Bug 1397653 - Update tests within docshell/ to comply with new toplevel data: URI navigation policy. r=smaug
docshell/base/crashtests/914521.html
docshell/test/chrome/test_bug364461.xul
docshell/test/file_bug598895_1.html
docshell/test/file_bug598895_2.html
docshell/test/file_bug637644_1.html
docshell/test/file_bug637644_2.html
docshell/test/mochitest.ini
docshell/test/navigation/NavigationUtils.js
docshell/test/navigation/file_scrollRestoration.html
docshell/test/navigation/mochitest.ini
docshell/test/navigation/navigation_target_popup_url.html
docshell/test/navigation/navigation_target_url.html
docshell/test/navigation/open.html
docshell/test/navigation/test_triggeringprincipal_window_open.html
docshell/test/test_bug598895.html
docshell/test/test_bug637644.html
--- a/docshell/base/crashtests/914521.html
+++ b/docshell/base/crashtests/914521.html
@@ -17,17 +17,20 @@ function f()
     window.addEventListener("popstate", spin);
     window.close();
     window.location = "#c";
     finish();
 }
 
 function init()
 {
-  SpecialPowers.pushPrefEnv({"set": [["security.data_uri.unique_opaque_origin", false]]}, start);
+  SpecialPowers.pushPrefEnv({"set": [
+    ["security.data_uri.unique_opaque_origin", false],
+    ["security.data_uri.block_toplevel_data_uri_navigations", false],
+  ]}, start);
 }
 
 function start()
 {
     var html = "<script>" + f + "<\/script><body onload=f()>";
     var win = window.open("data:text/html," + encodeURIComponent(html), null, "width=300,height=300");
     win.finish = function() {
       SpecialPowers.clearUserPref("security.data_uri.unique_opaque_origin");
--- a/docshell/test/chrome/test_bug364461.xul
+++ b/docshell/test/chrome/test_bug364461.xul
@@ -24,15 +24,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 </body>
 
 <script class="testbody" type="application/javascript">
 <![CDATA[
 
 /** Test for Bug 364461 **/
 
 SimpleTest.waitForExplicitFinish();
-window.open("bug364461_window.xul", "bug364461",
-            "chrome,width=600,height=600");
+
+SpecialPowers.pushPrefEnv({
+  "set":[["security.data_uri.block_toplevel_data_uri_navigations", false]]
+}, runTests);
 
+function runTests() {
+  window.open("bug364461_window.xul", "bug364461",
+              "chrome,width=600,height=600");
+}
 ]]>
 </script>
 
 </window>
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug598895_1.html
@@ -0,0 +1,1 @@
+<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body>Should show</body>
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug598895_2.html
@@ -0,0 +1,1 @@
+<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body></body>
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug637644_1.html
@@ -0,0 +1,1 @@
+<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body>Should show</body>
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug637644_2.html
@@ -0,0 +1,1 @@
+<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body></body>
--- a/docshell/test/mochitest.ini
+++ b/docshell/test/mochitest.ini
@@ -20,19 +20,23 @@ support-files =
   file_bug385434_1.html
   file_bug385434_2.html
   file_bug385434_3.html
   file_bug475636.sjs
   file_bug509055.html
   file_bug540462.html
   file_bug580069_1.html
   file_bug580069_2.sjs
+  file_bug598895_1.html
+  file_bug598895_2.html
   file_bug590573_1.html
   file_bug590573_2.html
   file_bug634834.html
+  file_bug637644_1.html
+  file_bug637644_2.html
   file_bug640387.html
   file_bug653741.html
   file_bug660404
   file_bug660404^headers^
   file_bug660404-1.html
   file_bug662170.html
   file_bug669671.sjs
   file_bug680257.html
--- a/docshell/test/navigation/NavigationUtils.js
+++ b/docshell/test/navigation/NavigationUtils.js
@@ -4,20 +4,20 @@
 
 ///////////////////////////////////////////////////////////////////////////
 //
 // Utilities for navigation tests
 // 
 ///////////////////////////////////////////////////////////////////////////
 
 var body = "This frame was navigated.";
-var target_url = "data:text/html,<html><body>" + body + "</body></html>";
+var target_url = "navigation_target_url.html"
 
 var popup_body = "This is a popup";
-var target_popup_url = "data:text/html,<html><body>" + popup_body + "</body></html>";
+var target_popup_url = "navigation_target_popup_url.html";
 
 ///////////////////////////////////////////////////////////////////////////
 // Functions that navigate frames
 ///////////////////////////////////////////////////////////////////////////
 
 function navigateByLocation(wnd) {
   try {
     wnd.location = target_url;
@@ -53,27 +53,27 @@ function navigateByHyperlink(name) {
 
 ///////////////////////////////////////////////////////////////////////////
 // Functions that call into Mochitest framework
 ///////////////////////////////////////////////////////////////////////////
 
 function isNavigated(wnd, message) {
   var result = null;
   try {
-    result = SpecialPowers.wrap(wnd).document.body.innerHTML;
+    result = SpecialPowers.wrap(wnd).document.body.innerHTML.trim();
   } catch(ex) {
     result = ex;
   }
   is(result, body, message);
 }
 
 function isBlank(wnd, message) {
   var result = null;
   try {
-    result = wnd.document.body.innerHTML;
+    result = wnd.document.body.innerHTML.trim();
   } catch(ex) {
     result = ex;
   }
   is(result, "This is a blank document.", message);
 }
 
 function isAccessible(wnd, message) {
   try {
@@ -141,18 +141,21 @@ function xpcGetFramesByName(name) {
       results.push(win);
   });
 
   return results;
 }
 
 function xpcCleanupWindows() {
   xpcEnumerateContentWindows(function(win) {
-    if (win.location && win.location.protocol == "data:")
+    if (win.location &&
+        (win.location.href.endsWith(target_url) ||
+         win.location.href.endsWith(target_popup_url))) {
       win.close();
+    }
   });
 }
 
 function xpcWaitForFinishedFrames(callback, numFrames) {
   var finishedFrameCount = 0;
   function frameFinished() {
     finishedFrameCount++;
 
@@ -172,22 +175,22 @@ function xpcWaitForFinishedFrames(callba
     for (var i = 0; i < arr.length; i++) {
       if (obj === arr[i])
         return true;
     }
     return false;
   }
 
   function searchForFinishedFrames(win) {
-    if ((escape(unescape(win.location)) == escape(target_url) ||
-         escape(unescape(win.location)) == escape(target_popup_url)) && 
+    if ((win.location.href.endsWith(target_url) ||
+         win.location.href.endsWith(target_popup_url)) &&
         win.document && 
         win.document.body && 
-        (win.document.body.textContent == body ||
-         win.document.body.textContent == popup_body) && 
+        (win.document.body.textContent.trim() == body ||
+         win.document.body.textContent.trim() == popup_body) && 
         win.document.readyState == "complete") {
 
       var util = win.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
                     .getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
       var windowId = util.outerWindowID;
       if (!contains(windowId, finishedWindows)) {
         finishedWindows.push(windowId);
         frameFinished();
--- a/docshell/test/navigation/file_scrollRestoration.html
+++ b/docshell/test/navigation/file_scrollRestoration.html
@@ -35,34 +35,34 @@
           }
           case 3: {
             opener.is(event.persisted, false, "Shouldn't have persisted session history entry.");
             opener.is(window.scrollY, 0, "Should not have restored scrolling.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration as before reload.");
             document.getElementById("bottom").scrollIntoView();
             window.onunload = null; // Should get bfcache behavior.
             opener.setTimeout("SpecialPowers.wrap(testWindow).history.back();", 250);
-            window.location.href = 'data:text/html,';
+            window.location.href = 'about:blank';
             break;
           }
           case 4: {
             opener.is(event.persisted, true, "Should have persisted session history entry.");
             opener.isnot(Math.round(window.scrollY), 0, "Should have kept the old scroll position.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration as before reload.");
             window.scrollTo(0, 0);
             window.location.hash = "hash";
             requestAnimationFrame(test);
             break;
           }
           case 5: {
             opener.isnot(Math.round(window.scrollY), 0, "Should have scrolled to #hash.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation.");
             window.onunload = function() {} // Disable bfcache.
             opener.setTimeout("is(SpecialPowers.wrap(testWindow).history.scrollRestoration, 'auto'); SpecialPowers.wrap(testWindow).history.back();", 250);
-            window.location.href = 'data:text/html,';
+            window.location.href = 'about:blank';
             break;
           }
           case 6: {
             opener.is(event.persisted, false, "Shouldn't have persisted session history entry.");
             opener.is(window.scrollY, 0, "Shouldn't have kept the old scroll position.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation.");
             history.scrollRestoration = "auto";
             document.getElementById("bottom").scrollIntoView();
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -1,11 +1,13 @@
 [DEFAULT]
 support-files =
   NavigationUtils.js
+  navigation_target_url.html
+  navigation_target_popup_url.html
   blank.html
   file_bug386782_contenteditable.html
   file_bug386782_designmode.html
   redbox_bug430723.html
   bluebox_bug430723.html
   file_bug462076_1.html
   file_bug462076_2.html
   file_bug462076_3.html
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/navigation_target_popup_url.html
@@ -0,0 +1,1 @@
+<html><body>This is a popup</body></html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/navigation_target_url.html
@@ -0,0 +1,1 @@
+<html><body>This frame was navigated.</body></html>
--- a/docshell/test/navigation/open.html
+++ b/docshell/test/navigation/open.html
@@ -1,9 +1,9 @@
 <html>
 <body>
 <script>
 var target = window.location.hash.substring(1);
 document.write("target=" + target);
-window.open("data:text/html,<html><body>This is a popup</body></html>", target, "width=10,height=10");
+window.open("navigation_target_popup_url.html", target, "width=10,height=10");
 </script>
 </body>
 </html>
--- a/docshell/test/navigation/test_triggeringprincipal_window_open.html
+++ b/docshell/test/navigation/test_triggeringprincipal_window_open.html
@@ -8,26 +8,25 @@
 </head>
 <body>
 
 <script type="text/javascript">
 
 /* We call window.open() using different URIs and make sure the triggeringPrincipal
  * loadingPrincipal are correct.
  * Test1: window.open(http:)
- * Test2: window.open(data:)
- * Test3: window.open(javascript:)
+ * Test2: window.open(javascript:)
  */
 
 const TRIGGERING_PRINCIPAL_URI =
   "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_window_open.html";
 
 SimpleTest.waitForExplicitFinish();
 
-const NUM_TESTS = 3;
+const NUM_TESTS = 2;
 var test_counter = 0;
 
 function checkFinish() {
   test_counter++;
   if (test_counter === NUM_TESTS) {
     SimpleTest.finish();
   }
 }
@@ -49,41 +48,17 @@ httpWin.onload = function() {
   is(httpLoadingPrincipal, null,
      "LoadingPrincipal for window.open(http:) should be null");
 
   httpWin.close();
   checkFinish();
 }
 
 // ----------------------------------------------------------------------------
-// Test 2: window.open(data:)
-var dataWin = window.open("data:text/html,<html><script>opener.postMessage('loaded','*');<\/script></html>", "_blank", "width=10,height=10");
-window.onmessage = function (evt) {
-  is(evt.data, "loaded", "message should be loaded");
-
-  var doc = SpecialPowers.wrap(dataWin).document;
-  var dataChannel = doc.docShell.currentDocumentChannel;
-  var dataTriggeringPrincipal = dataChannel.loadInfo.triggeringPrincipal.URI.asciiSpec;
-  var dataLoadingPrincipal = dataChannel.loadInfo.loadingPrincipal;
-
-  is(dataTriggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
-     "TriggeringPrincipal for window.open(data:) should be the principal of the document");
-
-  is(doc.referrer, "",
-     "Referrer for window.open(data:) should be empty");
-
-  is(dataLoadingPrincipal, null,
-     "LoadingPrincipal for window.open(data:) should be null");
-
-  dataWin.close();
-  checkFinish();
-}
-
-// ----------------------------------------------------------------------------
-// Test 3: window.open(javascript:)
+// Test 2: window.open(javascript:)
 var jsWin = window.open("javascript:'<html><body>js</body></html>';", "_blank", "width=10,height=10");
 jsWin.onload = function() {
   var jsChannel = SpecialPowers.wrap(jsWin.document).docShell.currentDocumentChannel;
   var jsTriggeringPrincipal = jsChannel.loadInfo.triggeringPrincipal.URI.asciiSpec;
   var jsLoadingPrincipal = jsChannel.loadInfo.loadingPrincipal;
 
   is(jsTriggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
      "TriggeringPrincipal for window.open(javascript:) should be the principal of the document");
--- a/docshell/test/test_bug598895.html
+++ b/docshell/test/test_bug598895.html
@@ -38,16 +38,15 @@ window.onmessage = function (ev) {
     win3.close();
     ok(compareSnapshots(one, two, true)[0], "Popups should look identical");
     ok(compareSnapshots(one, three, false)[0], "Popups should not look identical");
 
     SimpleTest.finish();
   }
 }
 
-var win2 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body>Should show</body>");
-
-var win3 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body></body>");
+var win2 = window.open("file_bug598895_1.html");
+var win3 = window.open("file_bug598895_2.html");
 });
 </script>
 </pre>
 </body>
 </html>
--- a/docshell/test/test_bug637644.html
+++ b/docshell/test/test_bug637644.html
@@ -38,16 +38,15 @@ window.onmessage = function (ev) {
     win3.close();
     ok(compareSnapshots(one, two, true)[0], "Popups should look identical");
     ok(compareSnapshots(one, three, false)[0], "Popups should not look identical");
 
     SimpleTest.finish();
   }
 }
 
-var win2 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body>Should show</body>", "", "height=500,width=500");
-
-var win3 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body></body>", "", "height=500,width=500");
+var win2 = window.open("file_bug637644_1.html", "", "height=500,width=500");
+var win3 = window.open("file_bug637644_2.html", "", "height=500,width=500");
 });
 </script>
 </pre>
 </body>
 </html>