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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Test for Login Manager in popup Windows</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 in popup windows
<p id="display"></p>

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

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

/** Test for Login Manager: notifications in popup windows.

Test flow:
  1) runNextTest starts the sub-tests by loading them into the iframe.
  2) The subtests trigger a PopupNotification which trigger checkTest (from the
     panel event listener).
  3) An action is taken on the notification which triggers the
     passwordmgr-storage-changed observer that calls runNextTest (from step 1).
**/


var subtests = [
                // query arguments are: username, password, features, auto-close (delimited by '|')
                "subtst_notifications_11.html?notifyu1|notifyp1|menubar=no,toolbar=no,location=no|autoclose",  // 1
                "subtst_notifications_11.html?notifyu1|pass2|menubar=no,toolbar=no,location=no|autoclose",     // 2
                "subtst_notifications_11.html?notifyu2|notifyp2||",  // 3
                "subtst_notifications_11.html?notifyu2|pass2||",     // 4
               ];

function runNextTest() {
    testNum++;
    ok(true, "Starting test #" + testNum);
    if (testNum <= subtests.length) {
        iframe.src = subtests[testNum-1];
    } else {
        // final check which will call finish
        checkTest();
    }
}

PasswordMgrObserver = {
  observe: function passwordMgrObserver_observe(subject, topic, data) {
      // Only run the next test for actions triggered from a doorhanger (rather
      // than cleanup with removeLogin)
      if (data == "removeLogin")
          return;
      runNextTest();
  },
};

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

    switch(testNum) {

      case 1:
        popup = getPopup(popupNotifications, "password-save");
        ok(popup, "got notification popup");
        // Sanity check, no logins should exist yet.
        logins = pwmgr.getAllLogins();
        is(logins.length, 0, "Should not have any logins yet");

        // password-save with chrome hidden
        clickPopupButton(popup, kRememberButton);
        break;

      case 2:
        // Check result of clicking kRememberButton
        logins = pwmgr.getAllLogins();
        is(logins.length, 1, "Should only have 1 login");
        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
        ok(login.timesUsed, 1, "Check times used on new entry");

        // password-change with chrome hidden
        popup = getPopup(popupNotifications, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kChangeButton);
        break;

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

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

        // password-save with chrome visible
        var popupWin = iframe.contentWindow.popupWin;
        ok(popupWin, "Check popupWin is accessible");
        var popupNotificationsInPopup = getPopupNotifications(popupWin);
        ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
        popup = getPopup(popupNotificationsInPopup, "password-save");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kRememberButton);
        popupWin.close();
        break;

      case 4:
        // Check result of clicking kRememberButton
        logins = pwmgr.getAllLogins();
        is(logins.length, 1, "Should only have 1 login now");
        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
        ok(login.timesUsed, 1, "Check times used on new entry");

        // password-change with chrome visible
        var popupWin = iframe.contentWindow.popupWin;
        ok(popupWin, "Check popupWin is accessible");
        var popupNotificationsInPopup = getPopupNotifications(popupWin);
        ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
        popup = getPopup(popupNotificationsInPopup, "password-change");
        ok(popup, "got notification popup");
        clickPopupButton(popup, kChangeButton);
        popupWin.close();
        break;

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

        // cleanup
        SpecialPowers.removeObserver(PasswordMgrObserver, "passwordmgr-storage-changed");
        popupNotifications.panel.removeEventListener("popupshown", checkTest, false);

        login2.password = "pass2";
        pwmgr.removeLogin(login2);
        login2.password = "notifyp2";

        ok(true, "notification tests finished.");
        SimpleTest.finish();

        break;

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

    }
}

const Ci = SpecialPowers.Ci;
const Cc = SpecialPowers.Cc;
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 nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.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,
                             "notifyu2", "notifyp2", "user", "pass");

SpecialPowers.addObserver(PasswordMgrObserver, "passwordmgr-storage-changed", false);

// 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");

popupNotifications.panel.addEventListener("popupshown", checkTest, false);

var iframe = document.getElementById("iframe");
var testNum = 0;

SimpleTest.waitForFocus(runNextTest);

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