summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_fields.js
blob: 95bcee9ed2866e25a4da444ea892a6eba21d8ba1 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

function test() {
  waitForExplicitFinish();

  let pwmgr = Cc["@mozilla.org/login-manager;1"].
                getService(Ci.nsILoginManager);
  pwmgr.removeAllLogins();

  // add login data
  let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                                 Ci.nsILoginInfo, "init");
  let login = new nsLoginInfo("http://example.com/", "http://example.com/", null,
                              "user", "password", "u1", "p1");
  pwmgr.addLogin(login);

  // Open the password manager dialog
  const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
  let pwmgrdlg = window.openDialog(PWMGR_DLG, "Toolkit:PasswordManager", "");
  SimpleTest.waitForFocus(doTest, pwmgrdlg);

  function doTest() {
    let doc = pwmgrdlg.document;

    let signonsTree = doc.querySelector("#signonsTree");
    is(signonsTree.view.rowCount, 1, "One entry in the passwords list");

    is(signonsTree.view.getCellText(0, signonsTree.columns.getNamedColumn("siteCol")),
       "http://example.com/",
       "Correct website saved");

    is(signonsTree.view.getCellText(0, signonsTree.columns.getNamedColumn("userCol")),
       "user",
       "Correct user saved");

    let timeCreatedCol = doc.getElementById("timeCreatedCol");
    is(timeCreatedCol.getAttribute("hidden"), "true",
       "Time created column is not displayed");


    let timeLastUsedCol = doc.getElementById("timeLastUsedCol");
    is(timeLastUsedCol.getAttribute("hidden"), "true",
       "Last Used column is not displayed");

    let timePasswordChangedCol = doc.getElementById("timePasswordChangedCol");
    is(timePasswordChangedCol.getAttribute("hidden"), "",
       "Last Changed column is displayed");

    // cleanup
    Services.ww.registerNotification(function (aSubject, aTopic, aData) {
      if (aSubject.location == pwmgrdlg.location && aTopic == "domwindowclosed") {
        // unregister ourself
        Services.ww.unregisterNotification(arguments.callee);

        pwmgr.removeAllLogins();

        finish();
      }
    });

    pwmgrdlg.close();
  }
}