DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=461710
-->
<head>
  <title>Test for Bug 461710</title>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=461710">Mozilla Bug 461710</a>
<p id="display"></p>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 461710 **/

SimpleTest.waitForExplicitFinish();

const Ci = SpecialPowers.Ci;
const Cc = SpecialPowers.Cc;
const Cr = SpecialPowers.Cr;

SpecialPowers.Cu.import("resource://gre/modules/NetUtil.jsm", window);
var Services = SpecialPowers.Services;

var gIframe;

/**
 * Helper function which waits until another function returns true, and
 * then notifies a callback.
 *
 * Original function stolen from docshell/test/chrome/docshell_helpers.js.
 *
 * Parameters:
 *
 *    fn: a function which is evaluated repeatedly, and when it turns true,
 *        the onWaitComplete callback is notified.
 *
 *    onWaitComplete:  a callback which will be notified when fn() returns
 *        true.
 */
function waitForTrue(fn, onWaitComplete) {
  var start = new Date().valueOf();

  // Loop until the test function returns true, or until a timeout occurs,
  // if a timeout is defined.
  var intervalid =
    setInterval(
      function() {
        if (fn.call()) {
          // Stop calling the test function and notify the callback.
          clearInterval(intervalid);
          onWaitComplete.call();
        }
      }, 20);
}

const kRed = "rgb(255, 0, 0)";
const kBlue = "rgb(0, 0, 255)";

var testpath = "/tests/toolkit/components/places/tests/mochitest/bug_461710/";
var prefix = "http://mochi.test:8888" + testpath;
var subtests = [
                   "visited_page.html",   // 1
                   "link_page.html",      // 2
                   "link_page-2.html",    // 3
                   "link_page-3.html"     // 4
               ];

var testNum = 0;
function loadNextTest() {
  // run the initialization code for each test
  switch (++testNum) {
    case 1:
      gIframe = normalWindowIframe;
      break;

    case 2:
      break;

    case 3:
      gIframe = privateWindowIframe;
      break;

    case 4:
      gIframe = normalWindowIframe;
      break;

    default:
      ok(false, "Unexpected call to loadNextTest for test #" + testNum);
  }

  if (testNum == 1)
    observer.expectURL(prefix + subtests[0], "uri-visit-saved");
  else
    observer.expectURL(prefix + subtests[0]);

  waitForTrue(function() observer.resolved, function() {
    // And the nodes get notified after the "link-visited" topic, so
    // we need to execute soon...
    SimpleTest.executeSoon(handleLoad);
  });

  gIframe.src = prefix + subtests[testNum-1];
}

function getColor(doc, win, id) {
  var elem = doc.getElementById(id);
  var utils = SpecialPowers.getDOMWindowUtils(win);
  return utils.getVisitedDependentComputedStyle(elem, "", "color");
}

function checkTest() {
  switch (testNum) {
    case 1:
      // nothing to do here, we just want to mark the page as visited
      break;

    case 2:
      // run outside of private mode, link should appear as visited
      var doc = gIframe.contentDocument;
      var win = doc.defaultView;
      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
      break;

    case 3:
      // run inside of private mode, link should appear as not visited
      var doc = gIframe.contentDocument;
      var win = doc.defaultView;
      is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
      break;

    case 4:
      // run outside of private mode, link should appear as visited
      var doc = gIframe.contentDocument;
      var win = doc.defaultView;
      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
      break;

    default:
      ok(false, "Unexpected call to checkTest for test #" + testNum);
  }
}

function handleLoad() {
  checkTest();

  if (testNum < subtests.length) {
    loadNextTest();
  } else {
    normalWindow.close();
    privateWindow.close();

    SimpleTest.finish();
  }
}

var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIWebNavigation)
                    .QueryInterface(Ci.nsIDocShellTreeItem)
                    .rootTreeItem
                    .QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIDOMWindow);
var contentPage = "http://mochi.test:8888/tests/toolkit/components/places/tests/mochitest/bug_461710/iframe.html";

function testOnWindow(aIsPrivate, aCallback) {
  var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
  win.addEventListener("load", function onLoad() {
    win.removeEventListener("load", onLoad, false);
    win.addEventListener("DOMContentLoaded", function onInnerLoad() {
      if (win.content.location.href != contentPage) {
        win.gBrowser.loadURI(contentPage);
        return;
      }
      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
      win.gBrowser.selectedBrowser.focus();
      SimpleTest.executeSoon(function() { aCallback(win); });
    }, true);
    SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
  }, true);
}

const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
var observer = {
  uri: null,
  resolved: true,
  observe: function (aSubject, aTopic, aData) {

    if (this.uri.equals(SpecialPowers.wrap(aSubject).QueryInterface(Ci.nsIURI))) {
      this.resolved = true;

      Services.obs.removeObserver(this, aTopic);
    }
  },
  expectURL: function (url, aOverrideTopic) {
    ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
    this.resolved = false;

    this.uri = SpecialPowers.wrap(NetUtil).newURI(url);
    var topic = aOverrideTopic || URI_VISITED_RESOLUTION_TOPIC;
    Services.obs.addObserver(this, topic, false);
  }
};

var normalWindow;
var privateWindow;

var normalWindowIframe;
var privateWindowIframe;

testOnWindow(false, function(aWin) {
  var selectedBrowser = aWin.gBrowser.selectedBrowser;

   normalWindow = aWin;
   normalWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");

  testOnWindow(true, function(aPrivateWin) {
    selectedBrowser = aPrivateWin.gBrowser.selectedBrowser;

    privateWindow = aPrivateWin;
    privateWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");

    loadNextTest();
  });
});

</script>
</pre>
</body>
</html>