Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | |
michael@0 | 4 | <window id="293235Test" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 6 | width="600" |
michael@0 | 7 | height="600" |
michael@0 | 8 | onload="setTimeout(nextTest,0);" |
michael@0 | 9 | title="bug 293235 test"> |
michael@0 | 10 | |
michael@0 | 11 | <script type="text/javascript" |
michael@0 | 12 | src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> |
michael@0 | 13 | <script type="text/javascript" |
michael@0 | 14 | src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> |
michael@0 | 15 | <script type="text/javascript" |
michael@0 | 16 | src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> |
michael@0 | 17 | <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> |
michael@0 | 18 | <script type="application/javascript" src="docshell_helpers.js" /> |
michael@0 | 19 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 20 | |
michael@0 | 21 | <script type="application/javascript"><![CDATA[ |
michael@0 | 22 | var Ci = Components.interfaces; |
michael@0 | 23 | var Cc = Components.classes; |
michael@0 | 24 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 25 | |
michael@0 | 26 | // Define the generator-iterator for the tests. |
michael@0 | 27 | var tests = testIterator(); |
michael@0 | 28 | |
michael@0 | 29 | //// |
michael@0 | 30 | // Execute the next test in the generator function. |
michael@0 | 31 | // |
michael@0 | 32 | function nextTest() { |
michael@0 | 33 | tests.next(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // Return the Element object for the specified element id |
michael@0 | 37 | function $(id) { return TestWindow.getDocument().getElementById(id); } |
michael@0 | 38 | |
michael@0 | 39 | //// |
michael@0 | 40 | // Generator function for test steps for bug 293235: |
michael@0 | 41 | // A visited link should have the :visited style applied |
michael@0 | 42 | // to it when displayed on a page which was fetched from |
michael@0 | 43 | // the bfcache. |
michael@0 | 44 | // |
michael@0 | 45 | function testIterator() |
michael@0 | 46 | { |
michael@0 | 47 | // Register our observer to know when the link lookup is complete. |
michael@0 | 48 | let testURI = NetUtil.newURI(getHttpUrl("bug293235_p2.html")); |
michael@0 | 49 | let os = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 50 | getService(Ci.nsIObserverService); |
michael@0 | 51 | const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution"; |
michael@0 | 52 | let observer = { |
michael@0 | 53 | notified: false, |
michael@0 | 54 | observe: function(aSubject, aTopic, aData) |
michael@0 | 55 | { |
michael@0 | 56 | if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) { |
michael@0 | 57 | return; |
michael@0 | 58 | } |
michael@0 | 59 | is(aTopic, URI_VISITED_RESOLUTION_TOPIC, "Unexpected topic"); |
michael@0 | 60 | this.notified = true; |
michael@0 | 61 | |
michael@0 | 62 | // Cleanup after ourselves... |
michael@0 | 63 | os.removeObserver(this, URI_VISITED_RESOLUTION_TOPIC); |
michael@0 | 64 | }, |
michael@0 | 65 | }; |
michael@0 | 66 | os.addObserver(observer, URI_VISITED_RESOLUTION_TOPIC, false); |
michael@0 | 67 | function notified() observer.notified; |
michael@0 | 68 | |
michael@0 | 69 | // Load a test page containing a link that should be initially |
michael@0 | 70 | // blue, per the :link style. |
michael@0 | 71 | doPageNavigation({ |
michael@0 | 72 | uri: getHttpUrl("bug293235.html"), |
michael@0 | 73 | onNavComplete: nextTest |
michael@0 | 74 | }); |
michael@0 | 75 | yield undefined; |
michael@0 | 76 | |
michael@0 | 77 | // Before we go any further, make sure our link has been notified. |
michael@0 | 78 | waitForTrue(notified, nextTest); |
michael@0 | 79 | yield undefined; |
michael@0 | 80 | |
michael@0 | 81 | // Now that we've been notified, we can check our link color. |
michael@0 | 82 | // Since we can't use getComputedStyle() for this because |
michael@0 | 83 | // getComputedStyle lies about styles that result from :visited, |
michael@0 | 84 | // we have to take snapshots. |
michael@0 | 85 | // First, take two reference snapshots. |
michael@0 | 86 | var link1 = $("link1"); |
michael@0 | 87 | link1.className = "forcelink"; |
michael@0 | 88 | var refLink = snapshotWindow(TestWindow.getWindow()); |
michael@0 | 89 | link1.className = "forcevisited"; |
michael@0 | 90 | var refVisited = snapshotWindow(TestWindow.getWindow()); |
michael@0 | 91 | link1.className = ""; |
michael@0 | 92 | function snapshotsEqual(snap1, snap2) { |
michael@0 | 93 | return compareSnapshots(snap1, snap2, true)[0]; |
michael@0 | 94 | } |
michael@0 | 95 | ok(!snapshotsEqual(refLink, refVisited), "references should not match"); |
michael@0 | 96 | ok(snapshotsEqual(refLink, snapshotWindow(TestWindow.getWindow())), |
michael@0 | 97 | "link should initially be blue"); |
michael@0 | 98 | |
michael@0 | 99 | let observedVisit = false, observedPageShow = false; |
michael@0 | 100 | function maybeRunNextTest() { |
michael@0 | 101 | ok(true, "maybe run next test? visited: " + observedVisit + " pageShow: " + observedPageShow); |
michael@0 | 102 | if (observedVisit && observedPageShow) |
michael@0 | 103 | nextTest(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | // Because adding visits is async, we will not be notified imemdiately. |
michael@0 | 107 | let visitObserver = { |
michael@0 | 108 | observe: function(aSubject, aTopic, aData) |
michael@0 | 109 | { |
michael@0 | 110 | if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) { |
michael@0 | 111 | return; |
michael@0 | 112 | } |
michael@0 | 113 | os.removeObserver(this, aTopic); |
michael@0 | 114 | observedVisit = true; |
michael@0 | 115 | maybeRunNextTest(); |
michael@0 | 116 | }, |
michael@0 | 117 | }; |
michael@0 | 118 | os.addObserver(visitObserver, "uri-visit-saved", false); |
michael@0 | 119 | // Load the page that the link on the previous page points to. |
michael@0 | 120 | doPageNavigation({ |
michael@0 | 121 | uri: getHttpUrl("bug293235_p2.html"), |
michael@0 | 122 | onNavComplete: function() { |
michael@0 | 123 | observedPageShow = true; |
michael@0 | 124 | maybeRunNextTest(); |
michael@0 | 125 | } |
michael@0 | 126 | }); |
michael@0 | 127 | yield undefined; |
michael@0 | 128 | |
michael@0 | 129 | // And the nodes get notified after the "link-visited" topic, so |
michael@0 | 130 | // we need to execute soon... |
michael@0 | 131 | SimpleTest.executeSoon(nextTest); |
michael@0 | 132 | yield undefined; |
michael@0 | 133 | |
michael@0 | 134 | // Go back, verify the original page was loaded from the bfcache, |
michael@0 | 135 | // and verify that the link is now purple, per the |
michael@0 | 136 | // :visited style. |
michael@0 | 137 | doPageNavigation({ |
michael@0 | 138 | back: true, |
michael@0 | 139 | eventsToListenFor: ["pageshow"], |
michael@0 | 140 | expectedEvents: [ { type: "pageshow", |
michael@0 | 141 | persisted: true, |
michael@0 | 142 | title: "Bug 293235 page1" } ], |
michael@0 | 143 | onNavComplete: nextTest |
michael@0 | 144 | }); |
michael@0 | 145 | yield undefined; |
michael@0 | 146 | |
michael@0 | 147 | // Now we can test the link color. |
michael@0 | 148 | ok(snapshotsEqual(refVisited, snapshotWindow(TestWindow.getWindow())), |
michael@0 | 149 | "visited link should be purple"); |
michael@0 | 150 | |
michael@0 | 151 | // Tell the framework the test is finished. Include the final 'yield' |
michael@0 | 152 | // statement to prevent a StopIteration exception from being thrown. |
michael@0 | 153 | finish(); |
michael@0 | 154 | yield undefined; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | ]]></script> |
michael@0 | 158 | |
michael@0 | 159 | <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
michael@0 | 160 | </window> |