Extra tests for bug 475634 - Login manager should send observer notifications on various events

This commit is contained in:
Justin Dolske 2009-03-29 15:29:21 -07:00
parent 5ce571ea26
commit 70fa670f43

View File

@ -11,24 +11,48 @@ const STORAGE_TYPE = "mozStorage";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var expectedNotification;
var expectedData;
var TestObserver = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
observe : function (subject, topic, data) {
do_check_eq(expectedNotification, data);
expectedNotification = null; // ensure a duplicate is flagged as unexpected.
do_check_eq(topic, "passwordmgr-storage-changed");
do_check_eq(data, expectedNotification);
switch (data) {
case "addLogin":
do_check_true(subject instanceof Ci.nsILoginInfo);
do_check_true(subject instanceof Ci.nsILoginMetaInfo);
do_check_true(expectedData.equals(subject)); // nsILoginInfo.equals()
break;
case "modifyLogin":
do_check_true(subject instanceof Ci.nsIArray);
do_check_eq(subject.length, 2);
var oldLogin = subject.queryElementAt(0, Ci.nsILoginInfo);
var newLogin = subject.queryElementAt(1, Ci.nsILoginInfo);
do_check_true(expectedData[0].equals(oldLogin)); // nsILoginInfo.equals()
do_check_true(expectedData[1].equals(newLogin));
break;
case "removeLogin":
do_check_true(subject instanceof Ci.nsILoginInfo);
do_check_true(subject instanceof Ci.nsILoginMetaInfo);
do_check_true(expectedData.equals(subject)); // nsILoginInfo.equals()
break;
case "removeAllLogins":
do_check_eq(subject, null);
break;
case "hostSavingEnabled":
case "hostSavingDisabled":
do_check_true(subject instanceof Ci.nsISupportsString);
do_check_eq(subject.data, expectedData);
break;
default:
do_throw("Unexpected observer topic: " + topic);
do_throw("Unhandled notification: " + data + " / " + topic);
}
expectedNotification = null; // ensure a duplicate is flagged as unexpected.
expectedData = null;
}
};
@ -79,6 +103,7 @@ testnum++;
testdesc = "addLogin";
expectedNotification = "addLogin";
expectedData = testuser1;
storage.addLogin(testuser1);
LoginTest.checkStorageData(storage, [], [testuser1]);
do_check_eq(expectedNotification, null); // check that observer got a notification
@ -88,6 +113,7 @@ testnum++;
testdesc = "modifyLogin";
expectedNotification = "modifyLogin";
expectedData=[testuser1, testuser2];
storage.modifyLogin(testuser1, testuser2);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], [testuser2]);
@ -97,6 +123,7 @@ testnum++;
testdesc = "removeLogin";
expectedNotification = "removeLogin";
expectedData = testuser2;
storage.removeLogin(testuser2);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], []);
@ -106,6 +133,7 @@ testnum++;
testdesc = "removeAllLogins";
expectedNotification = "removeAllLogins";
expectedData = null;
storage.removeAllLogins();
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], []);
@ -115,6 +143,7 @@ testnum++;
testdesc = "removeAllLogins (again)";
expectedNotification = "removeAllLogins";
expectedData = null;
storage.removeAllLogins();
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], []);
@ -124,6 +153,7 @@ testnum++;
testdesc = "setLoginSavingEnabled / false";
expectedNotification = "hostSavingDisabled";
expectedData = "http://site.com";
storage.setLoginSavingEnabled("http://site.com", false);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, ["http://site.com"], []);
@ -133,6 +163,7 @@ testnum++;
testdesc = "setLoginSavingEnabled / false (again)";
expectedNotification = "hostSavingDisabled";
expectedData = "http://site.com";
storage.setLoginSavingEnabled("http://site.com", false);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, ["http://site.com"], []);
@ -142,6 +173,7 @@ testnum++;
testdesc = "setLoginSavingEnabled / true";
expectedNotification = "hostSavingEnabled";
expectedData = "http://site.com";
storage.setLoginSavingEnabled("http://site.com", true);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], []);
@ -151,6 +183,7 @@ testnum++;
testdesc = "setLoginSavingEnabled / true (again)";
expectedNotification = "hostSavingEnabled";
expectedData = "http://site.com";
storage.setLoginSavingEnabled("http://site.com", true);
do_check_eq(expectedNotification, null);
LoginTest.checkStorageData(storage, [], []);