toolkit/components/passwordmgr/test/test_notifications.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 <head>
     4   <title>Test for Login Manager</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>  
     6   <script type="text/javascript" src="pwmgr_common.js"></script>
     7   <script type="text/javascript" src="notification_common.js"></script>
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     9 </head>
    10 <body>
    11 Login Manager test: notifications
    12 <p id="display"></p>
    14 <div id="content" style="display: none">
    15   <iframe id="iframe"></iframe>
    16 </div>
    18 <pre id="test">
    19 <script class="testbody" type="text/javascript">
    21 SimpleTest.expectAssertions(23);
    23 /** Test for Login Manager: notifications. **/
    25 // Set testpath to the directory where we live. Used to load tests from
    26 // alternate Mochitest servers (different hostnames, same content).
    27 var testpath = document.location.pathname + "/../";
    29 var subtests = [
    30                    "subtst_notifications_1.html", // 1
    31                    "subtst_notifications_1.html", // 2
    32                    "subtst_notifications_1.html", // 3
    33                    "subtst_notifications_1.html", // 4
    34                    "subtst_notifications_1.html", // 5
    35                    "subtst_notifications_1.html", // 6
    36                    "subtst_notifications_1.html", // 7
    37                    "subtst_notifications_1.html", // 8
    38                    "subtst_notifications_2.html", // 9
    39                    "subtst_notifications_3.html", // 10
    40                    "subtst_notifications_4.html", // 11
    41                    "subtst_notifications_5.html", // 12
    42                    "subtst_notifications_1.html", // 13
    43                    "subtst_notifications_6.html", // 14
    44                    "subtst_notifications_1.html", // 15
    45                    "subtst_notifications_6.html", // 16
    46                    "subtst_notifications_8.html", // 17
    47                    "subtst_notifications_8.html", // 18
    48                    "subtst_notifications_9.html", // 19
    49                    "subtst_notifications_10.html",  // 20
    50                    "http://test1.example.org:80" + testpath + "subtst_notifications_1.html", // 21
    51                    "http://test1.example.org:80" + testpath + "subtst_notifications_7.html", // 22
    52                    "http://test1.example.org:80" + testpath + "subtst_notifications_6.html", // 23
    53                ];
    56 var ignoreLoad = false;
    57 function handleLoad(aEvent) {
    58     // ignore every other load event ... We get one for loading the subtest (which
    59     // we want to ignore), and another when the subtest's form submits itself
    60     // (which we want to handle, to start the next test).
    61     ignoreLoad = !ignoreLoad;
    62     if (ignoreLoad) {
    63         ok(true, "Ignoring load of subtest #" + testNum);
    64         return;
    65     }
    66     ok(true, "Processing submission of subtest #" + testNum);
    68     checkTest();
    70     testNum++;
    72     if (testNum <= subtests.length) {
    73         ok(true, "Starting test #" + testNum);
    74         iframe.src = subtests[testNum-1];
    75     } else {
    76         ok(true, "notification tests finished.");
    77         SimpleTest.finish();
    78     }
    79 }
    82 // Remember, Never for This Site, Not Now
    83 function checkTest() {
    84     var popup, notificationText, expectedText;
    86     // The document generated from formsubmit.sjs contains the user/pass it
    87     // received inside <span id="blah">value</span>
    88     var gotUser = SpecialPowers.wrap(iframe).contentDocument.getElementById("user").textContent;
    89     var gotPass = SpecialPowers.wrap(iframe).contentDocument.getElementById("pass").textContent;
    92     switch(testNum) {
    94       /* Basic Yes/No/Never tests... */
    96       case 1:
    97         is(gotUser, "notifyu1", "Checking submitted username");
    98         is(gotPass, "notifyp1", "Checking submitted password");
    99         popup = getPopup(popupNotifications, "password-save");
   100         ok(popup, "got notification popup");
   101         popup.remove();
   102         break;
   104       case 2:
   105         // Same subtest, this time click Never
   106         is(gotUser, "notifyu1", "Checking submitted username");
   107         is(gotPass, "notifyp1", "Checking submitted password");
   108         popup = getPopup(popupNotifications, "password-save");
   109         ok(popup, "got notification popup");
   110         is(true, pwmgr.getLoginSavingEnabled("http://mochi.test:8888"),
   111            "Checking for login saving enabled");
   112         clickPopupButton(popup, kNeverButton);
   113         break;
   115       case 3:
   116         // Same subtest, make sure Never took effect
   117         is(gotUser, "notifyu1", "Checking submitted username");
   118         is(gotPass, "notifyp1", "Checking submitted password");
   119         popup = getPopup(popupNotifications, "password-save");
   120         ok(!popup, "checking for no notification popup");
   121         is(false, pwmgr.getLoginSavingEnabled("http://mochi.test:8888"),
   122            "Checking for login saving disabled");
   123         // reenable login saving.
   124         pwmgr.setLoginSavingEnabled("http://mochi.test:8888", true);
   125         break;
   127       case 4:
   128         // Same subtest, this time click Remember
   129         is(gotUser, "notifyu1", "Checking submitted username");
   130         is(gotPass, "notifyp1", "Checking submitted password");
   131         popup = getPopup(popupNotifications, "password-save");
   132         ok(popup, "got notification popup");
   134         // Sanity check, no logins should exist yet.
   135         var logins = pwmgr.getAllLogins();
   136         is(logins.length, 0, "Should not have any logins yet");
   138         clickPopupButton(popup, kRememberButton);
   139         break;
   141       case 5:
   142         // Same subtest, make sure we didn't prompt for an existing login.
   143         is(gotUser, "notifyu1", "Checking submitted username");
   144         is(gotPass, "notifyp1", "Checking submitted password");
   145         popup = getPopup(popupNotifications, "password-save");
   146         ok(!popup, "checking for no notification popup");
   148         // Check to make sure we updated the timestamps and use count on the
   149         // existing loging that was submitted for this form.
   150         var logins = pwmgr.getAllLogins();
   151         is(logins.length, 1, "Should only have 1 login");
   152         ok(SpecialPowers.call_Instanceof(logins[0], Ci.nsILoginMetaInfo), "metainfo QI");
   153         is(logins[0].timesUsed, 2, "check .timesUsed for existing login submission");
   154         ok(logins[0].timeLastUsed > logins[0].timeCreated, "timeLastUsed bumped");
   155         ok(logins[0].timeCreated == logins[0].timePasswordChanged, "timeChanged not updated");
   157         // remove that login
   158         pwmgr.removeLogin(login1);
   159         break;
   161       /* signons.rememberSignons pref tests... */
   163       case 6:
   164         // Same subtest, make sure we're getting the popup again.
   165         is(gotUser, "notifyu1", "Checking submitted username");
   166         is(gotPass, "notifyp1", "Checking submitted password");
   167         popup = getPopup(popupNotifications, "password-save");
   168         ok(popup, "got notification popup");
   169         popup.remove();
   170         // Change prefs to no longer remember signons
   171         prefs.setBoolPref("rememberSignons", false);
   172         break;
   174       case 7:
   175         // Same subtest, make sure we're not prompting.
   176         is(gotUser, "notifyu1", "Checking submitted username");
   177         is(gotPass, "notifyp1", "Checking submitted password");
   178         popup = getPopup(popupNotifications, "password-save");
   179         ok(!popup, "checking for no notification popup");
   180         // Change prefs to remember signons again
   181         prefs.setBoolPref("rememberSignons", true);
   182         break;
   184       case 8:
   185         // Same subtest, make sure we're getting the popup again.
   186         is(gotUser, "notifyu1", "Checking submitted username");
   187         is(gotPass, "notifyp1", "Checking submitted password");
   188         popup = getPopup(popupNotifications, "password-save");
   189         ok(popup, "got notification popup");
   190         popup.remove();
   191         break;
   193       /* autocomplete=off tests... */
   195       case 9:
   196         // Check for notification popup when autocomplete=off present
   197         is(gotUser, "notifyu1", "Checking submitted username");
   198         is(gotPass, "notifyp1", "Checking submitted password");
   199         popup = getPopup(popupNotifications, "password-save");
   200         ok(popup, "checking for notification popup");
   201         popup.remove();
   202         break;
   204       case 10:
   205         // Check for notification popup when autocomplete=off present
   206         is(gotUser, "notifyu1", "Checking submitted username");
   207         is(gotPass, "notifyp1", "Checking submitted password");
   208         popup = getPopup(popupNotifications, "password-save");
   209         ok(popup, "checking for notification popup");
   210         popup.remove();
   211         break;
   213       case 11:
   214         // Check for notification popup when autocomplete=off present
   215         is(gotUser, "notifyu1", "Checking submitted username");
   216         is(gotPass, "notifyp1", "Checking submitted password");
   217         popup = getPopup(popupNotifications, "password-save");
   218         ok(popup, "checking for notification popup");
   219         popup.remove();
   220         break;
   222       /* no password field test... */
   224       case 12:
   225         // Check for no notification popup when no password field present
   226         is(gotUser, "notifyu1", "Checking submitted username");
   227         is(gotPass, "null",     "Checking submitted password");
   228         popup = getPopup(popupNotifications, "password-save");
   229         ok(!popup, "checking for no notification popup");
   231         // Add login for the next test.
   232         pwmgr.addLogin(login2);
   233         break;
   235       case 13:
   236         // Check for no notification popup when existing pw-only login matches form.
   237         is(gotUser, "notifyu1", "Checking submitted username");
   238         is(gotPass, "notifyp1", "Checking submitted password");
   239         popup = getPopup(popupNotifications, "password-save");
   240         ok(!popup, "checking for no notification popup");
   241         pwmgr.removeLogin(login2);
   243         // Add login for the next test
   244         pwmgr.addLogin(login1);
   245         break;
   247       case 14:
   248         // Check for no notification popup when pw-only form matches existing login.
   249         is(gotUser, "null",     "Checking submitted username");
   250         is(gotPass, "notifyp1", "Checking submitted password");
   251         popup = getPopup(popupNotifications, "password-save");
   252         ok(!popup, "checking for no notification popup");
   253         pwmgr.removeLogin(login1);
   255         // Add login for the next test
   256         pwmgr.addLogin(login2B);
   257         break;
   259       case 15:
   260         // Check for notification popup when existing pw-only login doesn't match form.
   261         is(gotUser, "notifyu1", "Checking submitted username");
   262         is(gotPass, "notifyp1", "Checking submitted password");
   263         popup = getPopup(popupNotifications, "password-save");
   264         ok(popup, "got notification popup");
   265         pwmgr.removeLogin(login2B);
   266         popup.remove();
   268         // Add login for the next test
   269         pwmgr.addLogin(login1B);
   270         break;
   272       case 16:
   273         // Check for notification popup when pw-only form doesn't match existing login.
   274         is(gotUser, "null",     "Checking submitted username");
   275         is(gotPass, "notifyp1", "Checking submitted password");
   276         popup = getPopup(popupNotifications, "password-save");
   277         ok(popup, "got notification popup");
   278         pwmgr.removeLogin(login1B);
   279         popup.remove();
   281         // Add login for the next tests
   282         pwmgr.addLogin(login1);
   283         break;
   285       case 17:
   286         // Check for change-password popup, u+p login on u+p form. (not changed)
   287         is(gotUser, "notifyu1", "Checking submitted username");
   288         is(gotPass, "pass2",    "Checking submitted password");
   289         popup = getPopup(popupNotifications, "password-change");
   290         ok(popup, "got notification popup");
   291         clickPopupButton(popup, kDontChangeButton);
   292         break;
   294       case 18:
   295         // Check for change-password popup, u+p login on u+p form.
   296         is(gotUser, "notifyu1", "Checking submitted username");
   297         is(gotPass, "pass2",    "Checking submitted password");
   298         popup = getPopup(popupNotifications, "password-change");
   299         ok(popup, "got notification popup");
   300         clickPopupButton(popup, kChangeButton);
   302         // Check to make sure we updated the timestamps and use count for
   303         // the login being changed with this form.
   304         var logins = pwmgr.getAllLogins();
   305         is(logins.length, 1, "Should only have 1 login");
   306         ok(SpecialPowers.call_Instanceof(logins[0], Ci.nsILoginMetaInfo), "metainfo QI");
   307         is(logins[0].timesUsed, 2, "check .timesUsed incremented on change");
   308         ok(logins[0].timeCreated < logins[0].timeLastUsed, "timeLastUsed bumped");
   309         ok(logins[0].timeLastUsed == logins[0].timePasswordChanged, "timeUsed == timeChanged");
   311         // cleanup
   312         login1.password = "pass2";
   313         pwmgr.removeLogin(login1);
   314         login1.password = "notifyp1";
   316         // Add login for the next test
   317         pwmgr.addLogin(login2);
   318         break;
   320       // ...can't change a u+p login on a p-only form...
   322       case 19:
   323         // Check for change-password popup, p-only login on u+p form.
   324         // (needed a different subtest for this because the login created in
   325         // test_0init was interfering)
   326         is(gotUser, "",         "Checking submitted username");
   327         is(gotPass, "pass2",    "Checking submitted password");
   328         popup = getPopup(popupNotifications, "password-change");
   329         ok(popup, "got notification popup");
   330         clickPopupButton(popup, kChangeButton);
   331         break;
   333       case 20:
   334         // Check for change-password popup, p-only login on p-only form.
   335         is(gotUser, "null",     "Checking submitted username");
   336         is(gotPass, "notifyp1", "Checking submitted password");
   337         popup = getPopup(popupNotifications, "password-change");
   338         ok(popup, "got notification popup");
   339         clickPopupButton(popup, kChangeButton);
   341         pwmgr.removeLogin(login2);
   342         break;
   344       case 21:
   345         // Check text on a user+pass notification popup
   346         is(gotUser, "notifyu1", "Checking submitted username");
   347         is(gotPass, "notifyp1", "Checking submitted password");
   348         popup = getPopup(popupNotifications, "password-save");
   349         ok(popup, "got notification popup");
   350         // Check the text, which comes from the localized saveLoginText string.
   351         notificationText = popup.message;
   352         expectedText = /^Would you like to remember the password for \"notifyu1\" on example.org\?$/;
   353         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
   354         popup.remove();
   355         break;
   357       case 22:
   358         // Check text on a user+pass notification popup, username is really long
   359         is(gotUser, "nowisthetimeforallgoodmentocometotheaidoftheircountry", "Checking submitted username");
   360         is(gotPass, "notifyp1", "Checking submitted password");
   361         popup = getPopup(popupNotifications, "password-save");
   362         ok(popup, "got notification popup");
   363         // Check the text, which comes from the localized saveLoginText string.
   364         notificationText = popup.message;
   365         expectedText = /^Would you like to remember the password for \"nowisthetimeforallgoodmentocom[^e]\" on example.org\?$/;
   366         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
   367         popup.remove();
   368         break;
   370       case 23:
   371         // Check text on a pass-only notification popup
   372         is(gotUser, "null",     "Checking submitted username");
   373         is(gotPass, "notifyp1", "Checking submitted password");
   374         popup = getPopup(popupNotifications, "password-save");
   375         ok(popup, "got notification popup");
   376         // Check the text, which comes from the localized saveLoginTextNoUser string.
   377         notificationText = popup.message;
   378         expectedText = /^Would you like to remember the password on example.org\?$/;
   379         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
   380         popup.remove();
   381         break;
   383       default:
   384         ok(false, "Unexpected call to checkTest for test #" + testNum);
   386     }
   388     // TODO:
   389     // * existing login test, form has different password --> change password, no save prompt
   390 }
   392 const Ci = SpecialPowers.Ci;
   393 const Cc = SpecialPowers.Cc;
   394 ok(Ci != null, "Access Ci");
   395 ok(Cc != null, "Access Cc");
   397 var pwmgr = Cc["@mozilla.org/login-manager;1"].
   398             getService(Ci.nsILoginManager);
   399 ok(pwmgr != null, "Access pwmgr");
   401 pwmgr.removeAllLogins();
   403 var prefs = Cc["@mozilla.org/preferences-service;1"].
   404             getService(Ci.nsIPrefService);
   405 ok(prefs != null, "Access prefs");
   406 prefs = prefs.getBranch("signon.");
   407 ok(prefs != null, "Access pref branch");
   409 var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
   410                                              Ci.nsILoginInfo, "init");
   411 var login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   412                              "notifyu1", "notifyp1", "user", "pass");
   413 var login2 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   414                              "", "notifyp1", "", "pass");
   415 var login1B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   416                               "notifyu1B", "notifyp1B", "user", "pass");
   417 var login2B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   418                               "", "notifyp1B", "", "pass");
   420 var iframe = document.getElementById("iframe");
   421 iframe.onload = handleLoad;
   423 // popupNotifications (not *popup*) is a constant, per-tab container. So, we
   424 // only need to fetch it once.
   425 var popupNotifications = getPopupNotifications(window.top);
   426 ok(popupNotifications, "Got popupNotifications");
   428 var testNum = 1;
   429 ok(true, "Starting test #" + testNum);
   430 iframe.src = subtests[testNum-1];
   432 SimpleTest.waitForExplicitFinish();
   433 </script>
   434 </pre>
   435 </body>
   436 </html>

mercurial