toolkit/components/passwordmgr/test/test_privbrowsing_perwindowpb.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=248970
     5 -->
     6 <head>
     7   <title>Test for Bug 248970</title>
     8   <script type="application/javascript"
     9           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    10   <script type="text/javascript" src="notification_common.js"></script>
    11   <link rel="stylesheet" type="text/css"
    12         href="chrome://mochikit/content/tests/SimpleTest/test.css">
    13 </head>
    14 <body>
    15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=248970">Mozilla Bug 248970</a>
    16 <p id="display"></p>
    17 <pre id="test">
    18 <script class="testbody" type="text/javascript">
    20 /** Test for Bug 248970 **/
    21 // based on test_notifications.html
    23 const Ci = SpecialPowers.Ci;
    24 const Cc = SpecialPowers.Cc;
    25 const Cr = SpecialPowers.Cr;
    27 Components.utils.import("resource://gre/modules/Services.jsm");
    29 var testpath = "/tests/toolkit/components/passwordmgr/test/";
    30 var prefix = "http://test2.example.com" + testpath;
    31 var subtests = [
    32                    "subtst_privbrowsing_1.html", // 1
    33                    "subtst_privbrowsing_1.html", // 2
    34                    "subtst_privbrowsing_1.html", // 3
    35                    "subtst_privbrowsing_2.html", // 4
    36                    "subtst_privbrowsing_2.html", // 5
    37                    "subtst_privbrowsing_2.html", // 6
    38                    "subtst_privbrowsing_3.html", // 7
    39                    "subtst_privbrowsing_3.html", // 8
    40                    "subtst_privbrowsing_4.html", // 9
    41                    "subtst_privbrowsing_3.html" // 10
    42                ];
    44 var testNum = 0;
    45 function loadNextTest() {
    46   // run the initialization code for each test
    47   switch (++ testNum) {
    48     case 1:
    49       popupNotifications = normalWindowPopupNotifications;
    50       iframe = normalWindowIframe;
    51       break;
    53     case 2:
    54       popupNotifications = privateWindowPopupNotifications;
    55       iframe = privateWindowIframe;
    56       break;
    58     case 3:
    59       popupNotifications = normalWindowPopupNotifications;
    60       iframe = normalWindowIframe;
    61       break;
    63     case 4:
    64       pwmgr.addLogin(login);
    65       break;
    67     case 5:
    68       popupNotifications = privateWindowPopupNotifications;
    69       iframe = privateWindowIframe;
    70       break;
    72     case 6:
    73       popupNotifications = normalWindowPopupNotifications;
    74       iframe = normalWindowIframe;
    75       break;
    77     case 7:
    78       pwmgr.addLogin(login);
    79       break;
    81     case 8:
    82       popupNotifications = privateWindowPopupNotifications;
    83       iframe = privateWindowIframe;
    84       break;
    86     case 9:
    87       break;
    89     case 10:
    90       popupNotifications = normalWindowPopupNotifications;
    91       iframe = normalWindowIframe;
    92       break;
    94     default:
    95       ok(false, "Unexpected call to loadNextTest for test #" + testNum);
    96   }
    98   ok(true, "Starting test #" + testNum);
    99   iframe.src = prefix + subtests[testNum-1];
   100 }
   103 function checkTest() {
   104   var popup;
   106   switch (testNum) {
   107     case 1:
   108       // run outside of private mode, popup notification should appear
   109       popup = getPopup(popupNotifications, "password-save");
   110       ok(popup, "got popup notification");
   111       popup.remove();
   112       break;
   114     case 2:
   115       // run inside of private mode, popup notification should not appear
   116       popup = getPopup(popupNotifications, "password-save");
   117       ok(!popup, "checking for no popup notification");
   118       break;
   120     case 3:
   121       // run outside of private mode, popup notification should appear
   122       popup = getPopup(popupNotifications, "password-save");
   123       ok(popup, "got popup notification");
   124       popup.remove();
   125       break;
   127     case 4:
   128       // run outside of private mode, popup notification should appear
   129       popup = getPopup(popupNotifications, "password-change");
   130       ok(popup, "got popup notification");
   131       popup.remove();
   132       break;
   134     case 5:
   135       // run inside of private mode, popup notification should not appear
   136       popup = getPopup(popupNotifications, "password-change");
   137       ok(!popup, "checking for no popup notification");
   138       break;
   140     case 6:
   141       // run outside of private mode, popup notification should appear
   142       popup = getPopup(popupNotifications, "password-change");
   143       ok(popup, "got popup notification");
   144       popup.remove();
   145       pwmgr.removeLogin(login);
   146       break;
   148     case 7:
   149       // verify that the user/pass pair was autofilled
   150       var gotUser = iframe.contentDocument.getElementById("user").textContent;
   151       var gotPass = iframe.contentDocument.getElementById("pass").textContent;
   152       is(gotUser, "notifyu1", "Checking submitted username");
   153       is(gotPass, "notifyp1", "Checking submitted password");
   154       break;
   156     case 8:
   157       // verify that the user/pass pair was not autofilled
   158       var gotUser = iframe.contentDocument.getElementById("user").textContent;
   159       var gotPass = iframe.contentDocument.getElementById("pass").textContent;
   160       is(gotUser, "", "Checking submitted username");
   161       is(gotPass, "", "Checking submitted password");
   162       break;
   164     case 9:
   165       // verify that the user/pass pair was available for autocomplete
   166       var gotUser = iframe.contentDocument.getElementById("user").textContent;
   167       var gotPass = iframe.contentDocument.getElementById("pass").textContent;
   168       is(gotUser, "notifyu1", "Checking submitted username");
   169       is(gotPass, "notifyp1", "Checking submitted password");
   170       break;
   172     case 10:
   173       // verify that the user/pass pair was autofilled
   174       var gotUser = iframe.contentDocument.getElementById("user").textContent;
   175       var gotPass = iframe.contentDocument.getElementById("pass").textContent;
   176       is(gotUser, "notifyu1", "Checking submitted username");
   177       is(gotPass, "notifyp1", "Checking submitted password");
   178       pwmgr.removeLogin(login);
   179       break;
   181     default:
   182       ok(false, "Unexpected call to checkTest for test #" + testNum);
   184   }
   185 }
   187 var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
   188                     .getInterface(Ci.nsIWebNavigation)
   189                     .QueryInterface(Ci.nsIDocShellTreeItem)
   190                     .rootTreeItem
   191                     .QueryInterface(Ci.nsIInterfaceRequestor)
   192                     .getInterface(Ci.nsIDOMWindow);
   193 var contentPage = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/test/privbrowsing_perwindowpb_iframe.html";
   194 var testWindows = [];
   196 function whenDelayedStartupFinished(aWindow, aCallback) {
   197   Services.obs.addObserver(function observer(aSubject, aTopic) {
   198     if (aWindow == aSubject) {
   199       Services.obs.removeObserver(observer, aTopic);
   200       setTimeout(aCallback, 0);
   201     }
   202   }, "browser-delayed-startup-finished", false);
   203 }
   205 function testOnWindow(aIsPrivate, aCallback) {
   206   var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
   207   win.addEventListener("load", function onLoad() {
   208     win.removeEventListener("load", onLoad, false);
   209     whenDelayedStartupFinished(win, function() {
   210       win.addEventListener("DOMContentLoaded", function onInnerLoad() {
   211         if (win.content.location.href != contentPage) {
   212           win.gBrowser.loadURI(contentPage);
   213           return;
   214         }
   215         win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
   217         win.content.addEventListener('load', function innerLoad2() {
   218           win.content.removeEventListener('load', innerLoad2, false);
   219           testWindows.push(win);
   220           SimpleTest.executeSoon(function() { aCallback(win); });
   221         }, false, true);
   222       }, true);
   223       SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
   224     });
   225   }, true);
   226 }
   228 var ignoreLoad = false;
   229 function handleLoad(aEvent) {
   230   // ignore every other load event ... We get one for loading the subtest (which
   231   // we want to ignore), and another when the subtest's form submits itself
   232   // (which we want to handle, to start the next test).
   233   ignoreLoad = !ignoreLoad;
   234   if (ignoreLoad) {
   235     ok(true, "Ignoring load of subtest #" + testNum);
   236     return;
   237   }
   238   ok(true, "Processing submission of subtest #" + testNum);
   240   checkTest();
   242   if (testNum < subtests.length) {
   243     loadNextTest();
   244   } else {
   245     ok(true, "private browsing notification tests finished.");
   247     testWindows.forEach(function(aWin) {
   248       aWin.close();
   249     });
   251     SimpleTest.finish();
   252   }
   253 }
   255 var pwmgr = Cc["@mozilla.org/login-manager;1"].
   256             getService(Ci.nsILoginManager);
   257 ok(pwmgr != null, "Access pwmgr");
   259 // We need to make sure no logins have been stored by previous tests
   260 // for forms in |url|, otherwise the change password notification
   261 // would turn into a prompt, and the test will fail.
   262 var url = "http://test2.example.com";
   263 is(pwmgr.countLogins(url, "", null), 0, "No logins should be stored for " + url);
   265 var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
   266                                              Ci.nsILoginInfo, "init");
   267 var login = new nsLoginInfo(url, url, null, "notifyu1", "notifyp1", "user", "pass");
   269 var normalWindow;
   270 var privateWindow;
   272 var iframe;
   273 var normalWindowIframe;
   274 var privateWindowIframe;
   276 var popupNotifications;
   277 var normalWindowPopupNotifications;
   278 var privateWindowPopupNotifications;
   280 testOnWindow(false, function(aWin) {
   281   var selectedBrowser = aWin.gBrowser.selectedBrowser;
   282   normalWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
   283   normalWindowIframe.onload = handleLoad;
   284   selectedBrowser.focus();
   286   normalWindowPopupNotifications = getPopupNotifications(selectedBrowser.contentWindow.top);
   287   ok(normalWindowPopupNotifications, "Got popupNotifications in normal window");
   288   // ignore the first load for this window;
   289   ignoreLoad = false;
   291   testOnWindow(true, function(aPrivateWin) {
   292     selectedBrowser = aPrivateWin.gBrowser.selectedBrowser;
   293     privateWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
   294     privateWindowIframe.onload = handleLoad;
   295     selectedBrowser.focus();
   297     privateWindowPopupNotifications = getPopupNotifications(selectedBrowser.contentWindow.top);
   298     ok(privateWindowPopupNotifications, "Got popupNotifications in private window");
   299     // ignore the first load for this window;
   300     ignoreLoad = false;
   302     SimpleTest.executeSoon(loadNextTest);
   303   });
   304 });
   306 SimpleTest.waitForExplicitFinish();
   307 </script>
   308 </pre>
   309 </body>
   310 </html>

mercurial