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 (5b81998bb7ab)

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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Login Manager</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>  
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <script type="text/javascript" src="notification_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: notifications
<p id="display"></p>

<div id="content" style="display: none">
  <iframe id="iframe"></iframe>
</div>

<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.expectAssertions(23);

/** Test for Login Manager: notifications. **/

// Set testpath to the directory where we live. Used to load tests from
// alternate Mochitest servers (different hostnames, same content).
var testpath = document.location.pathname + "/../";

var subtests = [
                   "subtst_notifications_1.html", // 1
                   "subtst_notifications_1.html", // 2
                   "subtst_notifications_1.html", // 3
                   "subtst_notifications_1.html", // 4
                   "subtst_notifications_1.html", // 5
                   "subtst_notifications_1.html", // 6
                   "subtst_notifications_1.html", // 7
                   "subtst_notifications_1.html", // 8
                   "subtst_notifications_2.html", // 9
                   "subtst_notifications_3.html", // 10
                   "subtst_notifications_4.html", // 11
                   "subtst_notifications_5.html", // 12
                   "subtst_notifications_1.html", // 13
                   "subtst_notifications_6.html", // 14
                   "subtst_notifications_1.html", // 15
                   "subtst_notifications_6.html", // 16
                   "subtst_notifications_8.html", // 17
                   "subtst_notifications_8.html", // 18
                   "subtst_notifications_9.html", // 19
                   "subtst_notifications_10.html",  // 20
                   "http://test1.example.org:80" + testpath + "subtst_notifications_1.html", // 21
                   "http://test1.example.org:80" + testpath + "subtst_notifications_7.html", // 22
                   "http://test1.example.org:80" + testpath + "subtst_notifications_6.html", // 23
               ];


var ignoreLoad = false;
function handleLoad(aEvent) {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

    // ignore every other load event ... We get one for loading the subtest (which
    // we want to ignore), and another when the subtest's form submits itself
    // (which we want to handle, to start the next test).
    ignoreLoad = !ignoreLoad;
    if (ignoreLoad) {
        ok(true, "Ignoring load of subtest #" + testNum);
        return;
    }
    ok(true, "Processing submission of subtest #" + testNum);

    checkTest();

    testNum++;

    if (testNum <= subtests.length) {
        ok(true, "Starting test #" + testNum);
        iframe.src = subtests[testNum-1];
    } else {
        ok(true, "notification tests finished.");
        SimpleTest.finish();
    }
}


// Remember, Never for This Site, Not Now
function checkTest() {
    var popup, notificationText, expectedText;

    // The document generated from formsubmit.sjs contains the user/pass it
    // received inside <span id="blah">value</span>
    var gotUser = SpecialPowers.wrap(iframe).contentDocument.getElementById("user").textContent;
    var gotPass = SpecialPowers.wrap(iframe).contentDocument.getElementById("pass").textContent;


    switch(testNum) {

      /* Basic Yes/No/Never tests... */

      case 1:
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        popup.remove();
        break;

      case 2:
        // Same subtest, this time click Never
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        is(true, pwmgr.getLoginSavingEnabled("http://mochi.test:8888"),
           "Checking for login saving enabled");
        clickPopupButton(popup, kNeverButton);
        break;

      case 3:
        // Same subtest, make sure Never took effect
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        is(false, pwmgr.getLoginSavingEnabled("http://mochi.test:8888"),
           "Checking for login saving disabled");
        // reenable login saving.
        pwmgr.setLoginSavingEnabled("http://mochi.test:8888", true);
        break;

      case 4:
        // Same subtest, this time click Remember
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");

        // Sanity check, no logins should exist yet.
        var logins = pwmgr.getAllLogins();
        is(logins.length, 0, "Should not have any logins yet");

        clickPopupButton(popup, kRememberButton);
        break;

      case 5:
        // Same subtest, make sure we didn't prompt for an existing login.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");

        // Check to make sure we updated the timestamps and use count on the
        // existing loging that was submitted for this form.
        var logins = pwmgr.getAllLogins();
        is(logins.length, 1, "Should only have 1 login");
        ok(logins[0] instanceof Ci.nsILoginMetaInfo, "metainfo QI");
        is(logins[0].timesUsed, 2, "check .timesUsed for existing login submission");
        ok(logins[0].timeLastUsed > logins[0].timeCreated, "timeLastUsed bumped");
        ok(logins[0].timeCreated == logins[0].timePasswordChanged, "timeChanged not updated");

        // remove that login
        pwmgr.removeLogin(login1);
        break;

      /* signons.rememberSignons pref tests... */

      case 6:
        // Same subtest, make sure we're getting the popup again.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        popup.remove();
        // Change prefs to no longer remember signons
        prefs.setBoolPref("rememberSignons", false);
        break;

      case 7:
        // Same subtest, make sure we're not prompting.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        // Change prefs to remember signons again
        prefs.setBoolPref("rememberSignons", true);
        break;

      case 8:
        // Same subtest, make sure we're getting the popup again.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        popup.remove();
        break;

      /* autocomplete=off tests... */

      case 9:
        // Check for no notification popup when autocomplete=off present
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        break;

      case 10:
        // Check for no notification popup when autocomplete=off present
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        break;

      case 11:
        // Check for no notification popup when autocomplete=off present
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        break;

      /* no password field test... */

      case 12:
        // Check for no notification popup when no password field present
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "null",     "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");

        // Add login for the next test.
        pwmgr.addLogin(login2);
        break;

      case 13:
        // Check for no notification popup when existing pw-only login matches form.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        pwmgr.removeLogin(login2);

        // Add login for the next test
        pwmgr.addLogin(login1);
        break;

      case 14:
        // Check for no notification popup when pw-only form matches existing login.
        is(gotUser, "null",     "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(!popup, "checking for no notification popup");
        pwmgr.removeLogin(login1);

        // Add login for the next test
        pwmgr.addLogin(login2B);
        break;

      case 15:
        // Check for notification popup when existing pw-only login doesn't match form.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        pwmgr.removeLogin(login2B);
        popup.remove();

        // Add login for the next test
        pwmgr.addLogin(login1B);
        break;

      case 16:
        // Check for notification popup when pw-only form doesn't match existing login.
        is(gotUser, "null",     "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        pwmgr.removeLogin(login1B);
        popup.remove();

        // Add login for the next tests
        pwmgr.addLogin(login1);
        break;

      case 17:
        // Check for change-password popup, u+p login on u+p form. (not changed)
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "pass2",    "Checking submitted password");
        popup = getPopup(popupNotifications, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kDontChangeButton);
        break;

      case 18:
        // Check for change-password popup, u+p login on u+p form.
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "pass2",    "Checking submitted password");
        popup = getPopup(popupNotifications, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kChangeButton);

        // Check to make sure we updated the timestamps and use count for
        // the login being changed with this form.
        var logins = pwmgr.getAllLogins();
        is(logins.length, 1, "Should only have 1 login");
        ok(logins[0] instanceof Ci.nsILoginMetaInfo, "metainfo QI");
        is(logins[0].timesUsed, 2, "check .timesUsed incremented on change");
        ok(logins[0].timeCreated < logins[0].timeLastUsed, "timeLastUsed bumped");
        ok(logins[0].timeLastUsed == logins[0].timePasswordChanged, "timeUsed == timeChanged");

        // cleanup
        login1.password = "pass2";
        pwmgr.removeLogin(login1);
        login1.password = "notifyp1";

        // Add login for the next test
        pwmgr.addLogin(login2);
        break;

      // ...can't change a u+p login on a p-only form...

      case 19:
        // Check for change-password popup, p-only login on u+p form.
        // (needed a different subtest for this because the login created in
        // test_0init was interfering)
        is(gotUser, "",         "Checking submitted username");
        is(gotPass, "pass2",    "Checking submitted password");
        popup = getPopup(popupNotifications, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kChangeButton);
        break;

      case 20:
        // Check for change-password popup, p-only login on p-only form.
        is(gotUser, "null",     "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kChangeButton);

        pwmgr.removeLogin(login2);
        break;

      case 21:
        // Check text on a user+pass notification popup
        is(gotUser, "notifyu1", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        // Check the text, which comes from the localized saveLoginText string.
        notificationText = popup.message;
        expectedText = /^Would you like to remember the password for \"notifyu1\" on example.org\?$/;
        ok(expectedText.test(notificationText), "Checking text: " + notificationText);
        popup.remove();
        break;

      case 22:
        // Check text on a user+pass notification popup, username is really long
        is(gotUser, "nowisthetimeforallgoodmentocometotheaidoftheircountry", "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        // Check the text, which comes from the localized saveLoginText string.
        notificationText = popup.message;
        expectedText = /^Would you like to remember the password for \"nowisthetimeforallgoodmentocom[^e]\" on example.org\?$/;
        ok(expectedText.test(notificationText), "Checking text: " + notificationText);
        popup.remove();
        break;

      case 23:
        // Check text on a pass-only notification popup
        is(gotUser, "null",     "Checking submitted username");
        is(gotPass, "notifyp1", "Checking submitted password");
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        // Check the text, which comes from the localized saveLoginTextNoUser string.
        notificationText = popup.message;
        expectedText = /^Would you like to remember the password on example.org\?$/;
        ok(expectedText.test(notificationText), "Checking text: " + notificationText);
        popup.remove();
        break;

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

    }

    // TODO:
    // * existing login test, form has different password --> change password, no save prompt
}


netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

const Ci = Components.interfaces;
const Cc = Components.classes;
ok(Ci != null, "Access Ci");
ok(Cc != null, "Access Cc");

var pwmgr = Cc["@mozilla.org/login-manager;1"].
            getService(Ci.nsILoginManager);
ok(pwmgr != null, "Access pwmgr");

pwmgr.removeAllLogins();

var prefs = Cc["@mozilla.org/preferences-service;1"].
            getService(Ci.nsIPrefService);
ok(prefs != null, "Access prefs");
prefs = prefs.getBranch("signon.");
ok(prefs != null, "Access pref branch");

var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                             Ci.nsILoginInfo, "init");
var login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
                             "notifyu1", "notifyp1", "user", "pass");
var login2 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
                             "", "notifyp1", "", "pass");
var login1B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
                              "notifyu1B", "notifyp1B", "user", "pass");
var login2B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
                              "", "notifyp1B", "", "pass");

var iframe = document.getElementById("iframe");
iframe.onload = handleLoad;

// popupNotifications (not *popup*) is a constant, per-tab container. So, we
// only need to fetch it once.
var popupNotifications = getPopupNotifications(window.top);
ok(popupNotifications, "Got popupNotifications");

var testNum = 1;
ok(true, "Starting test #" + testNum);
iframe.src = subtests[testNum-1];

SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>