toolkit/components/places/tests/test_bug_461710_perwindowpb.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=461710
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 461710</title>
michael@0 8 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=461710">Mozilla Bug 461710</a>
michael@0 13 <p id="display"></p>
michael@0 14 <pre id="test">
michael@0 15 <script class="testbody" type="text/javascript">
michael@0 16
michael@0 17 /** Test for Bug 461710 **/
michael@0 18
michael@0 19 SimpleTest.waitForExplicitFinish();
michael@0 20
michael@0 21 const Ci = SpecialPowers.Ci;
michael@0 22 const Cc = SpecialPowers.Cc;
michael@0 23 const Cr = SpecialPowers.Cr;
michael@0 24
michael@0 25 SpecialPowers.Cu.import("resource://gre/modules/NetUtil.jsm", window);
michael@0 26 var Services = SpecialPowers.Services;
michael@0 27
michael@0 28 var gIframe;
michael@0 29
michael@0 30 /**
michael@0 31 * Helper function which waits until another function returns true, and
michael@0 32 * then notifies a callback.
michael@0 33 *
michael@0 34 * Original function stolen from docshell/test/chrome/docshell_helpers.js.
michael@0 35 *
michael@0 36 * Parameters:
michael@0 37 *
michael@0 38 * fn: a function which is evaluated repeatedly, and when it turns true,
michael@0 39 * the onWaitComplete callback is notified.
michael@0 40 *
michael@0 41 * onWaitComplete: a callback which will be notified when fn() returns
michael@0 42 * true.
michael@0 43 */
michael@0 44 function waitForTrue(fn, onWaitComplete) {
michael@0 45 var start = new Date().valueOf();
michael@0 46
michael@0 47 // Loop until the test function returns true, or until a timeout occurs,
michael@0 48 // if a timeout is defined.
michael@0 49 var intervalid =
michael@0 50 setInterval(
michael@0 51 function() {
michael@0 52 if (fn.call()) {
michael@0 53 // Stop calling the test function and notify the callback.
michael@0 54 clearInterval(intervalid);
michael@0 55 onWaitComplete.call();
michael@0 56 }
michael@0 57 }, 20);
michael@0 58 }
michael@0 59
michael@0 60 const kRed = "rgb(255, 0, 0)";
michael@0 61 const kBlue = "rgb(0, 0, 255)";
michael@0 62
michael@0 63 var testpath = "/tests/toolkit/components/places/tests/mochitest/bug_461710/";
michael@0 64 var prefix = "http://mochi.test:8888" + testpath;
michael@0 65 var subtests = [
michael@0 66 "visited_page.html", // 1
michael@0 67 "link_page.html", // 2
michael@0 68 "link_page-2.html", // 3
michael@0 69 "link_page-3.html" // 4
michael@0 70 ];
michael@0 71
michael@0 72 var testNum = 0;
michael@0 73 function loadNextTest() {
michael@0 74 // run the initialization code for each test
michael@0 75 switch (++testNum) {
michael@0 76 case 1:
michael@0 77 gIframe = normalWindowIframe;
michael@0 78 break;
michael@0 79
michael@0 80 case 2:
michael@0 81 break;
michael@0 82
michael@0 83 case 3:
michael@0 84 gIframe = privateWindowIframe;
michael@0 85 break;
michael@0 86
michael@0 87 case 4:
michael@0 88 gIframe = normalWindowIframe;
michael@0 89 break;
michael@0 90
michael@0 91 default:
michael@0 92 ok(false, "Unexpected call to loadNextTest for test #" + testNum);
michael@0 93 }
michael@0 94
michael@0 95 if (testNum == 1)
michael@0 96 observer.expectURL(prefix + subtests[0], "uri-visit-saved");
michael@0 97 else
michael@0 98 observer.expectURL(prefix + subtests[0]);
michael@0 99
michael@0 100 waitForTrue(function() observer.resolved, function() {
michael@0 101 // And the nodes get notified after the "link-visited" topic, so
michael@0 102 // we need to execute soon...
michael@0 103 SimpleTest.executeSoon(handleLoad);
michael@0 104 });
michael@0 105
michael@0 106 gIframe.src = prefix + subtests[testNum-1];
michael@0 107 }
michael@0 108
michael@0 109 function getColor(doc, win, id) {
michael@0 110 var elem = doc.getElementById(id);
michael@0 111 var utils = SpecialPowers.getDOMWindowUtils(win);
michael@0 112 return utils.getVisitedDependentComputedStyle(elem, "", "color");
michael@0 113 }
michael@0 114
michael@0 115 function checkTest() {
michael@0 116 switch (testNum) {
michael@0 117 case 1:
michael@0 118 // nothing to do here, we just want to mark the page as visited
michael@0 119 break;
michael@0 120
michael@0 121 case 2:
michael@0 122 // run outside of private mode, link should appear as visited
michael@0 123 var doc = gIframe.contentDocument;
michael@0 124 var win = doc.defaultView;
michael@0 125 is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
michael@0 126 break;
michael@0 127
michael@0 128 case 3:
michael@0 129 // run inside of private mode, link should appear as not visited
michael@0 130 var doc = gIframe.contentDocument;
michael@0 131 var win = doc.defaultView;
michael@0 132 is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
michael@0 133 break;
michael@0 134
michael@0 135 case 4:
michael@0 136 // run outside of private mode, link should appear as visited
michael@0 137 var doc = gIframe.contentDocument;
michael@0 138 var win = doc.defaultView;
michael@0 139 is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
michael@0 140 break;
michael@0 141
michael@0 142 default:
michael@0 143 ok(false, "Unexpected call to checkTest for test #" + testNum);
michael@0 144 }
michael@0 145 }
michael@0 146
michael@0 147 function handleLoad() {
michael@0 148 checkTest();
michael@0 149
michael@0 150 if (testNum < subtests.length) {
michael@0 151 loadNextTest();
michael@0 152 } else {
michael@0 153 normalWindow.close();
michael@0 154 privateWindow.close();
michael@0 155
michael@0 156 SimpleTest.finish();
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 161 .getInterface(Ci.nsIWebNavigation)
michael@0 162 .QueryInterface(Ci.nsIDocShellTreeItem)
michael@0 163 .rootTreeItem
michael@0 164 .QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 165 .getInterface(Ci.nsIDOMWindow);
michael@0 166 var contentPage = "http://mochi.test:8888/tests/toolkit/components/places/tests/mochitest/bug_461710/iframe.html";
michael@0 167
michael@0 168 function testOnWindow(aIsPrivate, aCallback) {
michael@0 169 var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
michael@0 170 win.addEventListener("load", function onLoad() {
michael@0 171 win.removeEventListener("load", onLoad, false);
michael@0 172 win.addEventListener("DOMContentLoaded", function onInnerLoad() {
michael@0 173 if (win.content.location.href != contentPage) {
michael@0 174 win.gBrowser.loadURI(contentPage);
michael@0 175 return;
michael@0 176 }
michael@0 177 win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
michael@0 178 win.gBrowser.selectedBrowser.focus();
michael@0 179 SimpleTest.executeSoon(function() { aCallback(win); });
michael@0 180 }, true);
michael@0 181 SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
michael@0 182 }, true);
michael@0 183 }
michael@0 184
michael@0 185 const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
michael@0 186 var observer = {
michael@0 187 uri: null,
michael@0 188 resolved: true,
michael@0 189 observe: function (aSubject, aTopic, aData) {
michael@0 190
michael@0 191 if (this.uri.equals(SpecialPowers.wrap(aSubject).QueryInterface(Ci.nsIURI))) {
michael@0 192 this.resolved = true;
michael@0 193
michael@0 194 Services.obs.removeObserver(this, aTopic);
michael@0 195 }
michael@0 196 },
michael@0 197 expectURL: function (url, aOverrideTopic) {
michael@0 198 ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
michael@0 199 this.resolved = false;
michael@0 200
michael@0 201 this.uri = SpecialPowers.wrap(NetUtil).newURI(url);
michael@0 202 var topic = aOverrideTopic || URI_VISITED_RESOLUTION_TOPIC;
michael@0 203 Services.obs.addObserver(this, topic, false);
michael@0 204 }
michael@0 205 };
michael@0 206
michael@0 207 var normalWindow;
michael@0 208 var privateWindow;
michael@0 209
michael@0 210 var normalWindowIframe;
michael@0 211 var privateWindowIframe;
michael@0 212
michael@0 213 testOnWindow(false, function(aWin) {
michael@0 214 var selectedBrowser = aWin.gBrowser.selectedBrowser;
michael@0 215
michael@0 216 normalWindow = aWin;
michael@0 217 normalWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
michael@0 218
michael@0 219 testOnWindow(true, function(aPrivateWin) {
michael@0 220 selectedBrowser = aPrivateWin.gBrowser.selectedBrowser;
michael@0 221
michael@0 222 privateWindow = aPrivateWin;
michael@0 223 privateWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
michael@0 224
michael@0 225 loadNextTest();
michael@0 226 });
michael@0 227 });
michael@0 228
michael@0 229 </script>
michael@0 230 </pre>
michael@0 231 </body>
michael@0 232 </html>

mercurial