Bug 1639195 - Part 2: Add a test. r=ckerschb
authorTim Huang <tihuang@mozilla.com>
Tue, 19 May 2020 18:59:36 +0000
changeset 530951 55ff7a761ebbc488561e2b4b9e4061a540d7e55d
parent 530950 5cf6e62ea26befe090114c51306f69a7fbb56a14
child 530952 005ef1c2599217538ed001683d210bd4f2776311
push id37434
push userabutkovits@mozilla.com
push dateWed, 20 May 2020 10:05:10 +0000
treeherdermozilla-central@005ef1c25992 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1639195
milestone78.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 1639195 - Part 2: Add a test. r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D75966
docshell/test/navigation/file_triggeringprincipal_subframe_same_origin_nav.html
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_triggeringprincipal_frame_same_origin_nav.html
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_triggeringprincipal_subframe_same_origin_nav.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head><meta charset="utf-8"></head>
+<body onload="checkResults()">
+<b>SubFrame Same-Origin Navigated</b><br/>
+
+<script type='application/javascript'>
+  function checkResults() {
+    // query the uri of the loadingPrincipal and the TriggeringPrincipal and pass
+    // that information on to the parent for verification.
+    var channel = SpecialPowers.wrap(window).docShell.currentDocumentChannel;
+    var triggeringPrincipalURI = channel.loadInfo.triggeringPrincipal.URI.asciiSpec;
+    var loadingPrincipalURI = channel.loadInfo.loadingPrincipal.URI.asciiSpec;
+
+    window.parent.postMessage({triggeringPrincipalURI,
+                               loadingPrincipalURI}, "*");
+  }
+</script>
+</body>
+</html>
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -31,16 +31,17 @@ support-files =
   iframe_static.html
   navigate.html
   open.html
   parent.html
   file_triggeringprincipal_frame_1.html
   file_triggeringprincipal_frame_2.html
   file_triggeringprincipal_subframe.html
   file_triggeringprincipal_subframe_nav.html
+  file_triggeringprincipal_subframe_same_origin_nav.html
   file_triggeringprincipal_window_open.html
   file_triggeringprincipal_parent_iframe_window_open_base.html
   file_triggeringprincipal_parent_iframe_window_open_nav.html
   file_triggeringprincipal_iframe_iframe_window_open_frame_a.html
   file_triggeringprincipal_iframe_iframe_window_open_frame_b.html
   file_triggeringprincipal_iframe_iframe_window_open_frame_a_nav.html
   file_load_history_entry_page_with_one_link.html
   file_load_history_entry_page_with_two_links.html
@@ -86,13 +87,14 @@ skip-if =
   (os == 'mac' && os_version == '10.14') # Bug 1548821
 [test_performance_navigation.html]
 [test_sessionhistory.html]
 skip-if = toolkit == 'android' # RANDOM on android
 support-files = file_bug1379762-1.html
 [test_sibling-matching-parent.html]
 [test_sibling-off-domain.html]
 [test_triggeringprincipal_frame_nav.html]
+[test_triggeringprincipal_frame_same_origin_nav.html]
 [test_triggeringprincipal_window_open.html]
 [test_triggeringprincipal_parent_iframe_window_open.html]
 [test_triggeringprincipal_iframe_iframe_window_open.html]
 skip-if = fission && os == 'linux' && debug && webrender #Bug 1586686
 [test_contentpolicy_block_window.html]
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/test_triggeringprincipal_frame_same_origin_nav.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Bug 1639195 - Test triggeringPrincipal for iframe same-origin navigations</title>
+  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<iframe style="width:100%;" id="testframe" src="http://example.com/"></iframe>
+
+<script type="text/javascript">
+/* We load an third-party iframe which then gets navigated by the iframe's
+ * parent by calling iframe.setAttribute("src", same-origin url) later in the
+ * test. We then verify the TriggeringPrincipal and LoadingPrincipal of the
+ * navigated iframe.
+ *
+ * +------------------------------------------+
+ * |                                          |
+ * |  +------------------+                    |
+ * |  | testframe        |                    |
+ * |  +------------------+                    |
+ * |                                          |
+ * | iframe.setAttribute("src",               |
+ * |                     same-origin url)     |
+ * |                                          |
+ * +------------------------------------------+
+ */
+
+var testframe = document.getElementById("testframe");
+
+window.addEventListener("message", receiveMessage);
+
+const TRIGGERING_PRINCIPAL_URI =
+  "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_frame_same_origin_nav.html";
+
+const LOADING_PRINCIPAL_URI = TRIGGERING_PRINCIPAL_URI;
+
+function receiveMessage(event) {
+  is(event.data.triggeringPrincipalURI, TRIGGERING_PRINCIPAL_URI,
+     "TriggeringPrincipal should be the parent iframe");
+  is(event.data.loadingPrincipalURI, TRIGGERING_PRINCIPAL_URI,
+     "LoadingPrincipal should be the parent iframe");
+
+  window.removeEventListener("message", receiveMessage);
+  SimpleTest.finish();
+}
+
+function performNavigation() {
+  testframe.removeEventListener("load", performNavigation);
+  testframe.setAttribute("src", "http://example.com/tests/docshell/test/navigation/file_triggeringprincipal_subframe_same_origin_nav.html");
+}
+
+// start the test
+SimpleTest.waitForExplicitFinish();
+
+testframe.addEventListener("load", performNavigation);
+</script>
+
+</body>
+</html>