tor-browser

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

bug293235_window.xhtml (4468B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 
      4 <window id="293235Test"
      5        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      6        width="600"
      7        height="600"
      8        onload="setTimeout(runTests, 0);"
      9        title="bug 293235 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 src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
     14 
     15  <script type="application/javascript"><![CDATA[
     16    var {NetUtil} = ChromeUtils.importESModule(
     17      "resource://gre/modules/NetUtil.sys.mjs"
     18    );
     19 
     20    // Return the Element object for the specified element id
     21    function $(id) { return TestWindow.getDocument().getElementById(id); }
     22 
     23    ////
     24    // Generator function for test steps for bug 293235:
     25    // A visited link should have the :visited style applied
     26    // to it when displayed on a page which was fetched from
     27    // the bfcache.
     28    //
     29    async function runTests() {
     30      // Register our observer to know when the link lookup is complete.
     31      let testURI = NetUtil.newURI(getHttpUrl("bug293235_p2.html"));
     32      let os = SpecialPowers.Services.obs;
     33      // Load a test page containing a link that should be initially
     34      // blue, per the :link style.
     35      await new Promise(resolve => {
     36        doPageNavigation({
     37          uri: getHttpUrl("bug293235.html"),
     38          onNavComplete: resolve,
     39        });
     40      });
     41 
     42      // Now that we've been notified, we can check our link color.
     43      // Since we can't use getComputedStyle() for this because
     44      // getComputedStyle lies about styles that result from :visited,
     45      // we have to take snapshots.
     46      // First, take two reference snapshots.
     47      var link1 = $("link1");
     48      link1.className = "forcelink";
     49      var refLink = await snapshotWindow(TestWindow.getWindow());
     50      link1.className = "forcevisited";
     51      var refVisited = await snapshotWindow(TestWindow.getWindow());
     52      link1.className = "";
     53      function snapshotsEqual(snap1, snap2) {
     54        return compareSnapshots(snap1, snap2, true)[0];
     55      }
     56      ok(!snapshotsEqual(refLink, refVisited), "references should not match");
     57      ok(snapshotsEqual(refLink, await snapshotWindow(TestWindow.getWindow())),
     58         "link should initially be blue");
     59 
     60      let observedVisit = false, observedPageShow = false;
     61      await new Promise(resolve => {
     62        function maybeResolve() {
     63          ok(true, "maybe run next test? visited: " + observedVisit + " pageShow: " + observedPageShow);
     64          if (observedVisit && observedPageShow)
     65            resolve();
     66        }
     67 
     68        // Because adding visits is async, we will not be notified immediately.
     69        let visitObserver = {
     70          observe(aSubject, aTopic)
     71          {
     72            if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
     73              return;
     74            }
     75            os.removeObserver(this, aTopic);
     76            observedVisit = true;
     77            maybeResolve();
     78          },
     79        };
     80        os.addObserver(visitObserver, "uri-visit-saved");
     81        // Load the page that the link on the previous page points to.
     82        doPageNavigation({
     83          uri: getHttpUrl("bug293235_p2.html"),
     84          onNavComplete() {
     85            observedPageShow = true;
     86            maybeResolve();
     87          }
     88        });
     89      })
     90 
     91      // And the nodes get notified after the "uri-visit-saved" topic, so
     92      // we need to execute soon...
     93      await new Promise(SimpleTest.executeSoon);
     94 
     95      // Go back, verify the original page was loaded from the bfcache,
     96      // and verify that the link is now purple, per the
     97      // :visited style.
     98      await new Promise(resolve => {
     99        doPageNavigation({
    100          back: true,
    101          eventsToListenFor: ["pageshow"],
    102          expectedEvents: [ { type: "pageshow",
    103                              persisted: true,
    104                              title: "Bug 293235 page1" } ],
    105          onNavComplete: resolve,
    106        });
    107      })
    108 
    109      // Now we can test the link color.
    110      ok(snapshotsEqual(refVisited, await snapshotWindow(TestWindow.getWindow())),
    111         "visited link should be purple");
    112 
    113      // Tell the framework the test is finished.
    114      finish();
    115    }
    116 
    117  ]]></script>
    118 
    119  <browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
    120 </window>