tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_visited_pref.html (2749B)


      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 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  <style type="text/css">
     12 
     13  :link { float: left; }
     14 
     15  :visited { float: right; }
     16 
     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">
     24 /** Test for Bug 147777 */
     25 
     26 function reinsert_node(e) {
     27  var sib = e.nextSibling;
     28  var par = e.parentNode;
     29  par.removeChild(e);
     30  par.insertBefore(e, sib);
     31 }
     32 
     33 function get_pref()
     34 {
     35    return SpecialPowers.getBoolPref("layout.css.visited_links_enabled");
     36 }
     37 
     38 function snapshotsEqual(snap1, snap2)
     39 {
     40  return compareSnapshots(snap1, snap2, true)[0];
     41 }
     42 
     43 SimpleTest.waitForExplicitFinish();
     44 SimpleTest.requestFlakyTimeout("untriaged");
     45 window.addEventListener("load", step1);
     46 
     47 var iframe, subdoc, subwin;
     48 var link;
     49 var start;
     50 var timeout;
     51 
     52 var unvisref; // reference image for unvisited style
     53 
     54 function step1()
     55 {
     56  is(get_pref(), true, "pref defaults to true");
     57 
     58  iframe = document.getElementById("iframe");
     59  subdoc = iframe.contentDocument;
     60  subwin = iframe.contentWindow;
     61  link = subdoc.getElementById("link");
     62 
     63  unvisref = snapshotWindow(subwin, false);
     64 
     65  // Now set the href of the link to a location that's actually visited.
     66  link.href = top.location;
     67 
     68  start = Date.now();
     69 
     70  // And wait for the link to get restyled when the history lets us
     71  // know it is (asynchronously).
     72  setTimeout(poll_for_visited_style, 100);
     73 }
     74 
     75 function poll_for_visited_style()
     76 {
     77  var snapshot = snapshotWindow(subwin, false);
     78  if (snapshotsEqual(unvisref, snapshot)) {
     79    // hasn't been styled yet
     80    setTimeout(poll_for_visited_style, 100);
     81 
     82    // If it never gets styled correctly, this test will fail because
     83    // this loop will never complete.
     84  } else {
     85    var end = Date.now();
     86    timeout = 3 * Math.max(end - start, 300);
     87    SpecialPowers.pushPrefEnv({"set":[["layout.css.visited_links_enabled", false]]}, step2);
     88  }
     89 }
     90 
     91 function step2()
     92 {
     93  // we don't handle dynamic changes of this pref; it only takes effect
     94  // when a new page loads
     95  reinsert_node(link);
     96 
     97  setTimeout(step3, timeout);
     98 }
     99 
    100 function step3()
    101 {
    102  var snapshot = snapshotWindow(subwin, false);
    103  ok(snapshotsEqual(unvisref, snapshot),
    104     ":visited selector does not apply given false preference");
    105 
    106  SimpleTest.finish();
    107 }
    108 
    109 </script>
    110 </pre>
    111 </body>
    112 </html>