tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_triggeringprincipal_parent_iframe_window_open.html (2606B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src="/tests/SimpleTest/SimpleTest.js"></script>        
      5  <script src="/tests/SimpleTest/EventUtils.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7  <script type="text/javascript" src="NavigationUtils.js"></script>        
      8 </head>
      9 <body>
     10 
     11 <iframe name="testframe" id="testframe" src="file_triggeringprincipal_iframe_iframe_window_open_base.html"></iframe>
     12 
     13 <script type="text/javascript">
     14 
     15 /* We load an iframe which then gets navigated by the iframe's parent by calling
     16 *  window.open("http://", iframe) later in the test. We then verify the
     17 * TriggeringPrincipal and LoadingPrincipal of the navigated iframe.
     18 *
     19 * +------------------------------------------+
     20 * |                                          |
     21 * |  +------------------+                    |
     22 * |  | testframe        |                    |
     23 * |  +------------------+                    |
     24 * |                                          |
     25 * | window.open("http://", "testframe");     |
     26 * |                                          |
     27 * +------------------------------------------+
     28 */
     29 
     30 const TRIGGERING_PRINCIPAL_URI =
     31  "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_parent_iframe_window_open.html";
     32 
     33 const LOADING_PRINCIPAL_URI = TRIGGERING_PRINCIPAL_URI;
     34 
     35 var testframe = document.getElementById("testframe");
     36 
     37 function checkResults() {
     38  testframe.removeEventListener("load", checkResults);
     39 
     40  var channel = SpecialPowers.wrap(testframe.contentWindow).docShell.currentDocumentChannel;
     41  var triggeringPrincipal = channel.loadInfo.triggeringPrincipal.asciiSpec.split("?")[0];
     42  var loadingPrincipal = channel.loadInfo.loadingPrincipal.asciiSpec.split("?")[0];
     43 
     44  is(triggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
     45    "TriggeringPrincipal for targeted window.open() should be the principal of the document");
     46 
     47  is(testframe.contentDocument.referrer.split("?")[0], TRIGGERING_PRINCIPAL_URI,
     48    "Referrer for targeted window.open() should be the principal of the document");
     49 
     50  is(loadingPrincipal, LOADING_PRINCIPAL_URI,
     51    "LoadingPrincipal for targeted window.open() should be the <iframe>.ownerDocument");
     52 
     53  SimpleTest.finish();
     54 }
     55 
     56 function performNavigation() {
     57  testframe.removeEventListener("load", performNavigation);
     58  testframe.addEventListener("load", checkResults);
     59  window.open("file_triggeringprincipal_parent_iframe_window_open_nav.html", "testframe");
     60 }
     61 
     62 // start the test
     63 SimpleTest.waitForExplicitFinish();
     64 
     65 testframe.addEventListener("load", performNavigation);
     66 
     67 </script>
     68 </pre>
     69 </body>
     70 </html>