layout/style/test/test_visited_pref.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial