tor-browser

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

bug301397_window.xhtml (9047B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 
      4 <window id="301397Test"
      5        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      6        width="600"
      7        height="600"
      8        onload="setTimeout(runTest, 0);"
      9        title="bug 301397 test">
     10 
     11  <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
     12  <script type="application/javascript" src="docshell_helpers.js" />
     13  <script type="application/javascript"><![CDATA[
     14    Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
     15  
     16    ////
     17    // Verifies that the given string exists in the innerHTML of the iframe
     18    // content.
     19    //
     20    async function verifyIframeInnerHtml(string) {
     21      var iframeInnerHtml = await SpecialPowers.spawn(document.getElementById("content"), [string], () =>
     22          content.document.getElementById("iframe").contentDocument.body.innerHTML);
     23      ok(iframeInnerHtml.includes(string),
     24         "iframe contains wrong document: " + iframeInnerHtml);
     25    }
     26 
     27    ////
     28    // Generator function for test steps for bug 301397:
     29    // The correct page should be displayed in an iframe when
     30    // navigating back and forwards, when the parent page
     31    // occupies multiple spots in the session history.
     32    //
     33    async function runTest()
     34    {
     35      // Make sure the bfcache is enabled.
     36      enableBFCache(8);
     37 
     38      // Load a dummy page.
     39      await promisePageNavigation({
     40        uri: getHttpUrl("generic.html"),
     41      });
     42 
     43      // Load a page containing an iframe.
     44      await promisePageNavigation({
     45        uri: getHttpUrl("bug301397_1.html"),
     46        eventsToListenFor: ["pageshow", "pagehide"],
     47        expectedEvents: [ { type: "pagehide",
     48                            title: "generic page",
     49                            persisted: true },
     50                          { type: "pageshow",
     51                            title: "iframe content #1",
     52                            persisted: false },   // false on initial load
     53                          { type: "pageshow",
     54                            title: "iframe parent",
     55                            persisted: false } ], // false on initial load
     56      });
     57 
     58      // Click a link in the iframe to cause the iframe to navigate
     59      // to a new page, and wait until the related pagehide/pageshow
     60      // events have occurred.
     61      let waitForLinkNavigation = promisePageEvents({
     62        eventsToListenFor: ["pageshow", "pagehide"],
     63        expectedEvents: [ { type: "pagehide",
     64                            title: "iframe content #1",
     65                            persisted: false },   // false, subframe nav
     66                          { type: "pageshow",
     67                            title: "iframe content #2",
     68                            persisted: false } ], // false on initial load
     69      });
     70      SpecialPowers.spawn(document.getElementById("content"), [], function() {
     71        let iframe = content.document.getElementById("iframe");
     72        let link = iframe.contentDocument.getElementById("link");
     73        let event = iframe.contentDocument.createEvent("MouseEvents");
     74        event.initMouseEvent("click", true, true, iframe.contentWindow,
     75          0, 0, 0, 0, 0,
     76          false, false, false, false,
     77          0, null);
     78        link.dispatchEvent(event);
     79      });
     80      await waitForLinkNavigation;
     81 
     82      // Load another dummy page.  Verify that both the outgoing parent and
     83      // iframe pages are stored in the bfcache.
     84      await promisePageNavigation({
     85        uri: getHttpUrl("bug301397_4.html"),
     86        eventsToListenFor: ["pageshow", "pagehide"],
     87        expectedEvents: [ { type: "pagehide",
     88                            title: "iframe parent",
     89                            persisted: true },
     90                          { type: "pagehide",
     91                            title: "iframe content #2",
     92                            persisted: true },
     93                          { type: "pageshow",
     94                            title: "dummy page, no iframe",
     95                            persisted: false } ],  // false on initial load
     96      });
     97 
     98      // Go back.  The iframe should show the second page loaded in it.
     99      // Both the parent and the iframe pages should be loaded from
    100      // the bfcache.
    101      await promisePageNavigation({
    102        back: true,
    103        eventsToListenFor: ["pageshow", "pagehide"],
    104        expectedEvents: [ { type: "pagehide",
    105                            title: "dummy page, no iframe",
    106                            persisted: true },
    107                          { type: "pageshow",
    108                            persisted: true,
    109                            title: "iframe content #2" },
    110                          { type: "pageshow",
    111                            persisted: true,
    112                            title: "iframe parent" } ],
    113      });
    114 
    115      verifyIframeInnerHtml("You made it");
    116      
    117      // Go gack again.  The iframe should show the first page loaded in it.
    118      await promisePageNavigation({
    119        back: true,
    120        eventsToListenFor: ["pageshow", "pagehide"],
    121        expectedEvents: [ { type: "pagehide",
    122                            title: "iframe content #2",
    123                            persisted: false },  // false, subframe nav
    124                          { type: "pageshow",
    125                            title: "iframe content #1",
    126                            // false since this page was never stored
    127                            // in the bfcache in the first place
    128                            persisted: false } ], 
    129      });
    130 
    131      verifyIframeInnerHtml("go to next page");
    132      
    133      // Go back to the generic page.  Now go forward to the last page,
    134      // again verifying that the iframe shows the first and second
    135      // pages in order.
    136      await promisePageNavigation({
    137        back: true,
    138        eventsToListenFor: ["pageshow", "pagehide"],
    139        expectedEvents: [ { type: "pagehide",
    140                            title: "iframe parent",
    141                            persisted: true },
    142                          { type: "pagehide",
    143                            title: "iframe content #1",
    144                            persisted: true },
    145                          { type: "pageshow",
    146                            title: "generic page",
    147                            persisted: true } ], 
    148      });
    149 
    150      await promisePageNavigation({
    151        forward: true,
    152        eventsToListenFor: ["pageshow"],
    153        expectedEvents: [ {type: "pageshow",
    154                           title: "iframe content #1",
    155                           persisted: true},
    156                          {type: "pageshow",
    157                           title: "iframe parent",
    158                           persisted: true} ],
    159      });
    160 
    161      verifyIframeInnerHtml("go to next page");
    162      
    163      await promisePageNavigation({
    164        forward: true,
    165        eventsToListenFor: ["pageshow", "pagehide"],
    166        expectedEvents: [ { type: "pagehide",
    167                            title: "iframe content #1",
    168                            persisted: false },   // false, subframe nav
    169                          { type: "pageshow",
    170                            title: "iframe content #2",
    171                            // false because the page wasn't stored in 
    172                            // bfcache last time it was unloaded
    173                            persisted: false } ], 
    174      });
    175 
    176      verifyIframeInnerHtml("You made it");
    177      
    178      await promisePageNavigation({
    179        forward: true,
    180        eventsToListenFor: ["pageshow", "pagehide"],
    181        expectedEvents: [ { type: "pagehide",
    182                            title: "iframe parent",
    183                            persisted: true },
    184                          { type: "pagehide",
    185                            title: "iframe content #2",
    186                            persisted: true },
    187                          { type: "pageshow",
    188                            title: "dummy page, no iframe",
    189                            persisted: true } ],
    190      });
    191 
    192      // Go back once more, and again verify that the iframe shows the
    193      // second page loaded in it.
    194      await promisePageNavigation({
    195        back: true,
    196        eventsToListenFor: ["pageshow", "pagehide"],
    197        expectedEvents: [ { type: "pagehide",
    198                            title: "dummy page, no iframe",
    199                            persisted: true },
    200                          { type: "pageshow",
    201                            persisted: true,
    202                            title: "iframe content #2" },
    203                          { type: "pageshow",
    204                            persisted: true,
    205                            title: "iframe parent" } ],
    206      });
    207 
    208      verifyIframeInnerHtml("You made it");
    209      
    210      Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
    211      // Tell the framework the test is finished.
    212      finish();
    213    }
    214    
    215  ]]></script>
    216 
    217  <browser type="content" primary="true" flex="1" id="content" messagemanagergroup="test" remote="true" maychangeremoteness="true" />
    218 </window>