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.

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

mercurial