tor-browser

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

test_triggeringprincipal_iframe_iframe_window_open.html (3285B)


      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="framea" id="framea" src="file_triggeringprincipal_iframe_iframe_window_open_frame_a.html"></iframe>
     12 <iframe name="frameb" id="frameb"></iframe>
     13 
     14 <script type="text/javascript">
     15 
     16 /* We load an iframe (Frame A) which then gets navigated by another iframe (Frame B)
     17 * by calling window.open("http://", "Frame A") later in the test. We then verify the
     18 * TriggeringPrincipal and LoadingPrincipal of the navigated iframe (Frame A).
     19 *
     20 * +---------------------------------------+
     21 * |   Parent                              |
     22 * |                                       |
     23 * |  +----------------------------+       |
     24 * |  | Frame A                    |       |
     25 * |  |                            |       |
     26 * |  |                            |       |
     27 * |  +----------------------------+       |
     28 * |                                       |
     29 * |  +----------------------------+       |
     30 * |  | Frame B                    |       |
     31 * |  |                            |       |
     32 * |  | win.open("http://", "A")   |       |
     33 * |  +----------------------------+       |
     34 * |                                       |
     35 * +---------------------------------------+
     36 *
     37 * Sequence of the test:
     38 *   [1] load Frame A
     39 *   [2] load Frame B which navigates A
     40 *   [3] load navigated Frame A and check triggeringPrincipal and loadingPrincipal
     41 */
     42 
     43 const TRIGGERING_PRINCIPAL_URI =
     44  "http://mochi.test:8888/tests/docshell/test/navigation/file_triggeringprincipal_iframe_iframe_window_open_frame_b.html";
     45 
     46 const LOADING_PRINCIPAL_URI =
     47  "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_iframe_iframe_window_open.html";
     48 
     49 var frameA = document.getElementById("framea");
     50 
     51 function checkResults() {
     52  frameA.removeEventListener("load", checkResults);
     53 
     54  var channel = SpecialPowers.wrap(frameA.contentWindow).docShell.currentDocumentChannel;
     55  var triggeringPrincipal = channel.loadInfo.triggeringPrincipal.asciiSpec;
     56  var loadingPrincipal = channel.loadInfo.loadingPrincipal.asciiSpec;
     57 
     58  is(triggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
     59    "TriggeringPrincipal for targeted window.open() should be the iframe triggering the load");
     60 
     61  is(frameA.contentDocument.referrer, TRIGGERING_PRINCIPAL_URI,
     62    "Referrer for targeted window.open() should be the principal of the iframe triggering the load");
     63 
     64  is(loadingPrincipal.split("?")[0], LOADING_PRINCIPAL_URI,
     65    "LoadingPrincipal for targeted window.open() should be the containing document");
     66 
     67  SimpleTest.finish();
     68 }
     69 
     70 function performNavigation() {
     71  frameA.removeEventListener("load", performNavigation);
     72  frameA.addEventListener("load", checkResults);
     73 
     74  // load Frame B which then navigates Frame A
     75  var frameB = document.getElementById("frameb");
     76  frameB.src = "file_triggeringprincipal_iframe_iframe_window_open_frame_b.html";
     77 }
     78 
     79 // start the test
     80 SimpleTest.waitForExplicitFinish();
     81 
     82 frameA.addEventListener("load", performNavigation);
     83 
     84 </script>
     85 </pre>
     86 </body>
     87 </html>