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