Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=147777
5 -->
6 <head>
7 <title>Test for visited link coloring pref Bug 147777</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <style type="text/css">
13 :link { float: left; }
15 :visited { float: right; }
17 </style>
18 </head>
19 <body>
20 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
21 <iframe id="iframe" src="visited-pref-iframe.html" style="width: 10em; height: 5em"></iframe>
22 <pre id="test">
23 <script type="application/javascript">
25 /** Test for Bug 147777 **/
27 function reinsert_node(e) {
28 var sib = e.nextSibling;
29 var par = e.parentNode;
30 par.removeChild(e);
31 par.insertBefore(e, sib);
32 }
34 function get_pref()
35 {
36 return SpecialPowers.getBoolPref("layout.css.visited_links_enabled");
37 }
39 function set_pref(val)
40 {
41 SpecialPowers.setBoolPref("layout.css.visited_links_enabled", val);
42 }
44 function snapshotsEqual(snap1, snap2)
45 {
46 return compareSnapshots(snap1, snap2, true)[0];
47 }
49 SimpleTest.waitForExplicitFinish();
50 window.addEventListener("load", step1, false);
52 var iframe, subdoc, subwin;
53 var link;
54 var start;
55 var timeout;
57 var unvisref; // reference image for unvisited style
59 function step1()
60 {
61 is(get_pref(), true, "pref defaults to true");
63 iframe = document.getElementById("iframe");
64 subdoc = iframe.contentDocument;
65 subwin = iframe.contentWindow;
66 link = subdoc.getElementById("link");
68 unvisref = snapshotWindow(subwin, false);
70 // Now set the href of the link to a location that's actually visited.
71 link.href = window.location;
73 start = Date.now();
75 // And wait for the link to get restyled when the history lets us
76 // know it is (asynchronously).
77 setTimeout(poll_for_visited_style, 100);
78 }
80 function poll_for_visited_style()
81 {
82 var snapshot = snapshotWindow(subwin, false);
83 if (snapshotsEqual(unvisref, snapshot)) {
84 // hasn't been styled yet
85 setTimeout(poll_for_visited_style, 100);
87 // If it never gets styled correctly, this test will fail because
88 // this loop will never complete.
89 } else {
90 var end = Date.now();
91 timeout = 3 * Math.max(end - start, 300);
92 step2();
93 }
94 }
96 function step2()
97 {
98 set_pref(false);
100 // we don't handle dynamic changes of this pref; it only takes effect
101 // when a new page loads
102 reinsert_node(link);
104 setTimeout(step3, timeout);
105 }
107 function step3()
108 {
109 var snapshot = snapshotWindow(subwin, false);
110 ok(snapshotsEqual(unvisref, snapshot),
111 ":visited selector does not apply given false preference");
113 // Set the pref back for the rest of the tests.
114 set_pref(true);
116 SimpleTest.finish();
117 }
119 </script>
120 </pre>
121 </body>
122 </html>