test_visited_lying.html (3188B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=147777 5 --> 6 <head> 7 <title>Test for Bug 147777</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/WindowSnapshot.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a> 14 <iframe id="iframe" src="visited-lying-inner.html" style="width: 20em; height: 5em"></iframe> 15 <pre id="test"> 16 <script type="application/javascript"> 17 18 /** Test for Bug 147777 */ 19 20 SimpleTest.waitForExplicitFinish(); 21 SimpleTest.requestFlakyTimeout("untriaged"); 22 window.addEventListener("load", start); 23 24 var iframe; 25 var visitedlink, unvisitedlink; 26 var snapshot1; 27 28 function start() 29 { 30 // Our load event has fired, so we know our iframe is loaded. 31 iframe = document.getElementById("iframe"); 32 visitedlink = iframe.contentDocument.getElementById("visitedlink"); 33 unvisitedlink = iframe.contentDocument.getElementById("unvisitedlink"); 34 35 // First, take a snapshot of it with both links unvisited. 36 snapshot1 = snapshotWindow(iframe.contentWindow, false); 37 38 // Then, change one of the links in the iframe to being visited. 39 visitedlink.href = top.location; 40 41 // Then, start polling to see when the history has updated the display. 42 setTimeout(poll_for_restyle, 100); 43 } 44 45 function poll_for_restyle() 46 { 47 var snapshot2 = snapshotWindow(iframe.contentWindow, false); 48 var equal = compareSnapshots(snapshot1, snapshot2, true)[0]; 49 if (equal) { 50 // keep polling 51 setTimeout(poll_for_restyle, 100); 52 } else { 53 // We now know that the link is visited, so we're ready to run 54 // tests. 55 run_tests(); 56 } 57 } 58 59 function run_tests() 60 { 61 // Test querySelector and querySelectorAll. 62 var subdoc = iframe.contentDocument; 63 is(subdoc.querySelector(":link"), unvisitedlink, 64 "first :link should be the unvisited link"); 65 is(subdoc.querySelector(":visited"), null, 66 "querySelector should not find anything :visited"); 67 var qsr = subdoc.querySelectorAll(":link"); 68 is(qsr.length, 2, "querySelectorAll(:link) should find 2 results"); 69 is(qsr[0], unvisitedlink, "querySelectorAll(:link)[0]"); 70 is(qsr[1], visitedlink, "querySelectorAll(:link)[1]"); 71 qsr = subdoc.querySelectorAll(":visited"); 72 is(qsr.length, 0, "querySelectorAll(:visited) should find 0 results"); 73 74 // Test getComputedStyle. 75 var subwin = iframe.contentWindow; 76 is(subwin.getComputedStyle(unvisitedlink).color, "rgb(0, 0, 255)", 77 "getComputedStyle on unvisited link should report color is blue"); 78 is(subwin.getComputedStyle(visitedlink).color, "rgb(0, 0, 255)", 79 "getComputedStyle on visited link should report color is blue"); 80 81 // Test matches. 82 is(unvisitedlink.matches(":link"), true, 83 "unvisited link matches :link"); 84 is(visitedlink.matches(":link"), true, 85 "visited link matches :link"); 86 is(unvisitedlink.matches(":visited"), false, 87 "unvisited link does not match :visited"); 88 is(visitedlink.matches(":visited"), false, 89 "visited link does not match :visited"); 90 91 SimpleTest.finish(); 92 } 93 94 </script> 95 </pre> 96 </body> 97 </html>