tor-browser

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

test_bug481335.xhtml (3466B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=481335
      4 -->
      5 <head>
      6  <title>Test for Bug 481335</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      9  <style type="text/css">
     10    a { color:blue; }
     11    a:visited { color:red; }
     12  </style>
     13  <base href="https://example.com/" />
     14 </head>
     15 <body>
     16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=481335">Mozilla Bug 481335</a>
     17 <p id="display">
     18  <a id="t">A link</a>
     19  <iframe id="i"></iframe>
     20 </p>
     21 <p id="newparent"></p>
     22 <div id="content" style="display: none"></div>
     23 <pre id="test">
     24 <script type="application/javascript">
     25 <![CDATA[
     26 
     27 /** Test for Bug 481335 */
     28 SimpleTest.waitForExplicitFinish();
     29 var rand = Date.now() + "-" + Math.random();
     30 
     31 is($("t").href, "",
     32   "Unexpected href before set");
     33 is($("t").href, "",
     34   "Unexpected cached href before set");
     35 
     36 $("t").setAttribute("href", rand);
     37 is($("t").href, "https://example.com/" + rand,
     38   "Unexpected href after set");
     39 is($("t").href, "https://example.com/" + rand,
     40   "Unexpected cached href after set");
     41 const unvisitedColor = "rgb(0, 0, 255)";
     42 const visitedColor = "rgb(255, 0, 0)";
     43 
     44 let tests = testIterator();
     45 function continueTest() {
     46  tests.next();
     47 }
     48 
     49 function checkLinkColor(aElmId, aExpectedColor, aMessage) {
     50  // Because link coloring is asynchronous, we wait until we get the right
     51  // result, or we will time out (resulting in a failure).
     52  function getColor() {
     53    var utils = SpecialPowers.getDOMWindowUtils(window);
     54    return utils.getVisitedDependentComputedStyle($(aElmId), "", "color");
     55  }
     56  while (getColor() != aExpectedColor) {
     57    requestIdleCallback(continueTest);
     58    return false;
     59  }
     60  is(getColor(), aExpectedColor, aMessage);
     61  return true;
     62 }
     63 
     64 let win;
     65 
     66 function* testIterator() {
     67  // After first load
     68  $("newparent").appendChild($("t"));
     69  is($("t").href, "https://example.com/" + rand,
     70     "Unexpected href after move");
     71  is($("t").href, "https://example.com/" + rand,
     72     "Unexpected cached href after move");
     73  while (!checkLinkColor("t", unvisitedColor, "Should be unvisited now"))
     74    yield undefined;
     75 
     76  win.close();
     77  win = window.open($("t").href, "_blank");
     78 
     79  // After second load
     80  while (!checkLinkColor("t", visitedColor, "Should be visited now"))
     81    yield undefined;
     82  $("t").pathname = rand;
     83  while (!checkLinkColor("t", visitedColor,
     84            "Should still be visited after setting pathname to its existing value")) {
     85    yield undefined;
     86  }
     87 
     88  /* TODO uncomment this test with the landing of bug 534526.  See
     89   * https://bugzilla.mozilla.org/show_bug.cgi?id=461199#c167
     90  $("t").pathname += "x";
     91  while (!checkLinkColor("t", unvisitedColor,
     92            "Should not be visited after changing pathname")) {
     93    yield undefined;
     94  }
     95  $("t").pathname = $("t").pathname;
     96  while (!checkLinkColor("t", unvisitedColor,
     97            "Should not be visited after setting unvisited pathname to existing value")) {
     98    yield undefined;
     99  }
    100  */
    101 
    102  win.close();
    103  win = window.open($("t").href, "_blank");
    104 
    105  // After third load
    106  while (!checkLinkColor("t", visitedColor,
    107                         "Should be visited now after third load")) {
    108    yield undefined;
    109  }
    110  win.close();
    111  SimpleTest.finish();
    112 }
    113 
    114 addLoadEvent(function() {
    115  win = window.open($("t").href, "_blank");
    116  requestIdleCallback(continueTest);
    117 });
    118 ]]>
    119 </script>
    120 </pre>
    121 </body>
    122 </html>