summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js')
-rw-r--r--toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js
new file mode 100644
index 000000000..1dc7076aa
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_observers.js
@@ -0,0 +1,129 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+ waitForExplicitFinish();
+
+ const LOGIN_HOST = "http://example.com";
+ const LOGIN_COUNT = 5;
+
+ let nsLoginInfo = new Components.Constructor(
+ "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init");
+ let pmDialog = window.openDialog(
+ "chrome://passwordmgr/content/passwordManager.xul",
+ "Toolkit:PasswordManager", "");
+
+ let logins = [];
+ let loginCounter = 0;
+ let loginOrder = null;
+ let modifiedLogin;
+ let testNumber = 0;
+ let testObserver = {
+ observe: function (subject, topic, data) {
+ if (topic == "passwordmgr-dialog-updated") {
+ switch (testNumber) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ is(countLogins(), loginCounter, "Verify login added");
+ ok(getLoginOrder().startsWith(loginOrder), "Verify login order");
+ runNextTest();
+ break;
+ case 6:
+ is(countLogins(), loginCounter, "Verify login count");
+ is(getLoginOrder(), loginOrder, "Verify login order");
+ is(getLoginPassword(), "newpassword0", "Verify login modified");
+ runNextTest();
+ break;
+ case 7:
+ is(countLogins(), loginCounter, "Verify login removed");
+ ok(loginOrder.endsWith(getLoginOrder()), "Verify login order");
+ runNextTest();
+ break;
+ case 8:
+ is(countLogins(), 0, "Verify all logins removed");
+ runNextTest();
+ break;
+ }
+ }
+ }
+ };
+
+ SimpleTest.waitForFocus(startTest, pmDialog);
+
+ function createLogins() {
+ let login;
+ for (let i = 0; i < LOGIN_COUNT; i++) {
+ login = new nsLoginInfo(LOGIN_HOST + "?n=" + i, LOGIN_HOST + "?n=" + i,
+ null, "user" + i, "password" + i, "u" + i, "p" + i);
+ logins.push(login);
+ }
+ modifiedLogin = new nsLoginInfo(LOGIN_HOST + "?n=0", LOGIN_HOST + "?n=0",
+ null, "user0", "newpassword0", "u0", "p0");
+ is(logins.length, LOGIN_COUNT, "Verify logins created");
+ }
+
+ function countLogins() {
+ let doc = pmDialog.document;
+ let signonsTree = doc.getElementById("signonsTree");
+ return signonsTree.view.rowCount;
+ }
+
+ function getLoginOrder() {
+ let doc = pmDialog.document;
+ let signonsTree = doc.getElementById("signonsTree");
+ let column = signonsTree.columns[0]; // host column
+ let order = [];
+ for (let i = 0; i < signonsTree.view.rowCount; i++) {
+ order.push(signonsTree.view.getCellText(i, column));
+ }
+ return order.join(',');
+ }
+
+ function getLoginPassword() {
+ let doc = pmDialog.document;
+ let loginsTree = doc.getElementById("signonsTree");
+ let column = loginsTree.columns[2]; // password column
+ return loginsTree.view.getCellText(0, column);
+ }
+
+ function startTest() {
+ Services.obs.addObserver(
+ testObserver, "passwordmgr-dialog-updated", false);
+ is(countLogins(), 0, "Verify starts with 0 logins");
+ createLogins();
+ runNextTest();
+ }
+
+ function runNextTest() {
+ switch (++testNumber) {
+ case 1: // add the logins
+ for (let i = 0; i < logins.length; i++) {
+ loginCounter++;
+ loginOrder = getLoginOrder();
+ Services.logins.addLogin(logins[i]);
+ }
+ break;
+ case 6: // modify a login
+ loginOrder = getLoginOrder();
+ Services.logins.modifyLogin(logins[0], modifiedLogin);
+ break;
+ case 7: // remove a login
+ loginCounter--;
+ loginOrder = getLoginOrder();
+ Services.logins.removeLogin(modifiedLogin);
+ break;
+ case 8: // remove all logins
+ Services.logins.removeAllLogins();
+ break;
+ case 9: // finish
+ Services.obs.removeObserver(
+ testObserver, "passwordmgr-dialog-updated", false);
+ pmDialog.close();
+ finish();
+ break;
+ }
+ }
+}