docshell/test/chrome/bug293235_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug293235_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +
     1.7 +<window id="293235Test"
     1.8 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     1.9 +        width="600"
    1.10 +        height="600"
    1.11 +        onload="setTimeout(nextTest,0);"
    1.12 +        title="bug 293235 test">
    1.13 +
    1.14 +  <script type="text/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/>
    1.16 +  <script type="text/javascript"
    1.17 +          src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/>
    1.18 +  <script type="text/javascript"
    1.19 +          src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/>
    1.20 +  <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
    1.21 +  <script type="application/javascript" src="docshell_helpers.js" />
    1.22 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
    1.23 +
    1.24 +  <script type="application/javascript"><![CDATA[
    1.25 +    var Ci = Components.interfaces;
    1.26 +    var Cc = Components.classes;
    1.27 +    Components.utils.import("resource://gre/modules/NetUtil.jsm");
    1.28 +
    1.29 +    // Define the generator-iterator for the tests.
    1.30 +    var tests = testIterator();
    1.31 +
    1.32 +    ////
    1.33 +    // Execute the next test in the generator function.
    1.34 +    //
    1.35 +    function nextTest() {
    1.36 +      tests.next();
    1.37 +    }
    1.38 +
    1.39 +    // Return the Element object for the specified element id
    1.40 +    function $(id) { return TestWindow.getDocument().getElementById(id); }
    1.41 +
    1.42 +    ////
    1.43 +    // Generator function for test steps for bug 293235:
    1.44 +    // A visited link should have the :visited style applied
    1.45 +    // to it when displayed on a page which was fetched from
    1.46 +    // the bfcache.
    1.47 +    //
    1.48 +    function testIterator()
    1.49 +    {
    1.50 +      // Register our observer to know when the link lookup is complete.
    1.51 +      let testURI = NetUtil.newURI(getHttpUrl("bug293235_p2.html"));
    1.52 +      let os = Cc["@mozilla.org/observer-service;1"].
    1.53 +               getService(Ci.nsIObserverService);
    1.54 +      const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
    1.55 +      let observer = {
    1.56 +        notified: false,
    1.57 +        observe: function(aSubject, aTopic, aData)
    1.58 +        {
    1.59 +          if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
    1.60 +            return;
    1.61 +          }
    1.62 +          is(aTopic, URI_VISITED_RESOLUTION_TOPIC, "Unexpected topic");
    1.63 +          this.notified = true;
    1.64 +
    1.65 +          // Cleanup after ourselves...
    1.66 +          os.removeObserver(this, URI_VISITED_RESOLUTION_TOPIC);
    1.67 +        },
    1.68 +      };
    1.69 +      os.addObserver(observer, URI_VISITED_RESOLUTION_TOPIC, false);
    1.70 +      function notified() observer.notified;
    1.71 +
    1.72 +      // Load a test page containing a link that should be initially
    1.73 +      // blue, per the :link style.
    1.74 +      doPageNavigation({
    1.75 +        uri: getHttpUrl("bug293235.html"),
    1.76 +        onNavComplete: nextTest
    1.77 +      });
    1.78 +      yield undefined;
    1.79 +
    1.80 +      // Before we go any further, make sure our link has been notified.
    1.81 +      waitForTrue(notified, nextTest);
    1.82 +      yield undefined;
    1.83 +
    1.84 +      // Now that we've been notified, we can check our link color.
    1.85 +      // Since we can't use getComputedStyle() for this because
    1.86 +      // getComputedStyle lies about styles that result from :visited,
    1.87 +      // we have to take snapshots.
    1.88 +      // First, take two reference snapshots.
    1.89 +      var link1 = $("link1");
    1.90 +      link1.className = "forcelink";
    1.91 +      var refLink = snapshotWindow(TestWindow.getWindow());
    1.92 +      link1.className = "forcevisited";
    1.93 +      var refVisited = snapshotWindow(TestWindow.getWindow());
    1.94 +      link1.className = "";
    1.95 +      function snapshotsEqual(snap1, snap2) {
    1.96 +        return compareSnapshots(snap1, snap2, true)[0];
    1.97 +      }
    1.98 +      ok(!snapshotsEqual(refLink, refVisited), "references should not match");
    1.99 +      ok(snapshotsEqual(refLink, snapshotWindow(TestWindow.getWindow())),
   1.100 +         "link should initially be blue");
   1.101 +
   1.102 +      let observedVisit = false, observedPageShow = false;
   1.103 +      function maybeRunNextTest() {
   1.104 +        ok(true, "maybe run next test? visited: " + observedVisit + " pageShow: " + observedPageShow);
   1.105 +        if (observedVisit && observedPageShow)
   1.106 +          nextTest();
   1.107 +      }
   1.108 +
   1.109 +      // Because adding visits is async, we will not be notified imemdiately.
   1.110 +      let visitObserver = {
   1.111 +        observe: function(aSubject, aTopic, aData)
   1.112 +        {
   1.113 +          if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
   1.114 +            return;
   1.115 +          }
   1.116 +          os.removeObserver(this, aTopic);
   1.117 +          observedVisit = true;
   1.118 +          maybeRunNextTest();
   1.119 +        },
   1.120 +      };
   1.121 +      os.addObserver(visitObserver, "uri-visit-saved", false);
   1.122 +      // Load the page that the link on the previous page points to.
   1.123 +      doPageNavigation({
   1.124 +        uri: getHttpUrl("bug293235_p2.html"),
   1.125 +        onNavComplete: function() {
   1.126 +          observedPageShow = true;
   1.127 +          maybeRunNextTest();
   1.128 +        }
   1.129 +      });
   1.130 +      yield undefined;
   1.131 +
   1.132 +      // And the nodes get notified after the "link-visited" topic, so
   1.133 +      // we need to execute soon...
   1.134 +      SimpleTest.executeSoon(nextTest);
   1.135 +      yield undefined;
   1.136 +
   1.137 +      // Go back, verify the original page was loaded from the bfcache,
   1.138 +      // and verify that the link is now purple, per the
   1.139 +      // :visited style.
   1.140 +      doPageNavigation({
   1.141 +        back: true,
   1.142 +        eventsToListenFor: ["pageshow"],
   1.143 +        expectedEvents: [ { type: "pageshow",
   1.144 +                            persisted: true,
   1.145 +                            title: "Bug 293235 page1" } ],
   1.146 +        onNavComplete: nextTest
   1.147 +      });
   1.148 +      yield undefined;
   1.149 +
   1.150 +      // Now we can test the link color.
   1.151 +      ok(snapshotsEqual(refVisited, snapshotWindow(TestWindow.getWindow())),
   1.152 +         "visited link should be purple");
   1.153 +
   1.154 +      // Tell the framework the test is finished.  Include the final 'yield'
   1.155 +      // statement to prevent a StopIteration exception from being thrown.
   1.156 +      finish();
   1.157 +      yield undefined;
   1.158 +    }
   1.159 +
   1.160 +  ]]></script>
   1.161 +
   1.162 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.163 +</window>

mercurial