Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Unit tests for nsLoginManager.js |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | function run_test() { |
michael@0 | 7 | |
michael@0 | 8 | try { |
michael@0 | 9 | |
michael@0 | 10 | var testnum = 0; |
michael@0 | 11 | var testdesc = "Setup of nsLoginInfo test-users"; |
michael@0 | 12 | var nsLoginInfo = new Components.Constructor( |
michael@0 | 13 | "@mozilla.org/login-manager/loginInfo;1", |
michael@0 | 14 | Components.interfaces.nsILoginInfo); |
michael@0 | 15 | do_check_true(nsLoginInfo != null); |
michael@0 | 16 | |
michael@0 | 17 | var testuser1 = new nsLoginInfo; |
michael@0 | 18 | |
michael@0 | 19 | |
michael@0 | 20 | /* ========== 1 ========== */ |
michael@0 | 21 | var testnum = 1; |
michael@0 | 22 | var testdesc = "Initial connection to login manager" |
michael@0 | 23 | |
michael@0 | 24 | var loginmgr = Cc["@mozilla.org/login-manager;1"]. |
michael@0 | 25 | createInstance(Ci.nsILoginManager); |
michael@0 | 26 | if (!loginmgr) |
michael@0 | 27 | throw "Couldn't create loginmgr instance."; |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | /* ========== 2 ========== */ |
michael@0 | 31 | testnum++; |
michael@0 | 32 | testdesc = "Force lazy init, check to ensure there is no existing data."; |
michael@0 | 33 | loginmgr.removeAllLogins(); |
michael@0 | 34 | var hosts = loginmgr.getAllDisabledHosts(); |
michael@0 | 35 | hosts.forEach(function(h) loginmgr.setLoginSavingEnabled(h, true)); |
michael@0 | 36 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | /* ========== 3 ========== */ |
michael@0 | 40 | testnum++; |
michael@0 | 41 | testdesc = "Try adding invalid logins (host / user / pass checks)"; |
michael@0 | 42 | |
michael@0 | 43 | function tryAddUser(module, aUser, aExpectedError) { |
michael@0 | 44 | var err = null; |
michael@0 | 45 | try { |
michael@0 | 46 | module.addLogin(aUser); |
michael@0 | 47 | } catch (e) { |
michael@0 | 48 | err = e; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | LoginTest.checkExpectedError(aExpectedError, err); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | testuser1.init(null, null, "Some Realm", |
michael@0 | 55 | "dummydude", "itsasecret", "put_user_here", "put_pw_here"); |
michael@0 | 56 | // null hostname |
michael@0 | 57 | tryAddUser(loginmgr, testuser1, /null or empty hostname/); |
michael@0 | 58 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 59 | |
michael@0 | 60 | testuser1.hostname = ""; |
michael@0 | 61 | tryAddUser(loginmgr, testuser1, /null or empty hostname/); |
michael@0 | 62 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | testuser1.hostname = "http://dummyhost.mozilla.org"; |
michael@0 | 66 | testuser1.username = null; |
michael@0 | 67 | tryAddUser(loginmgr, testuser1, /null username/); |
michael@0 | 68 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 69 | |
michael@0 | 70 | testuser1.username = "dummydude"; |
michael@0 | 71 | testuser1.password = null; |
michael@0 | 72 | tryAddUser(loginmgr, testuser1, /null or empty password/); |
michael@0 | 73 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 74 | |
michael@0 | 75 | testuser1.password = ""; |
michael@0 | 76 | tryAddUser(loginmgr, testuser1, /null or empty password/); |
michael@0 | 77 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 78 | |
michael@0 | 79 | |
michael@0 | 80 | /* ========== 4 ========== */ |
michael@0 | 81 | testnum++; |
michael@0 | 82 | testdesc = "Try adding invalid logins (httpRealm / formSubmitURL checks)"; |
michael@0 | 83 | |
michael@0 | 84 | testuser1.init("http://dummyhost.mozilla.org", null, null, |
michael@0 | 85 | "dummydude", "itsasecret", "put_user_here", "put_pw_here"); |
michael@0 | 86 | // formSubmitURL == null, httpRealm == null |
michael@0 | 87 | tryAddUser(loginmgr, testuser1, /without a httpRealm or formSubmitURL/); |
michael@0 | 88 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 89 | |
michael@0 | 90 | testuser1.formSubmitURL = ""; |
michael@0 | 91 | testuser1.httpRealm = ""; |
michael@0 | 92 | tryAddUser(loginmgr, testuser1, /both a httpRealm and formSubmitURL/); |
michael@0 | 93 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 94 | |
michael@0 | 95 | testuser1.formSubmitURL = "foo"; |
michael@0 | 96 | testuser1.httpRealm = "foo"; |
michael@0 | 97 | tryAddUser(loginmgr, testuser1, /both a httpRealm and formSubmitURL/); |
michael@0 | 98 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | testuser1.formSubmitURL = ""; |
michael@0 | 102 | testuser1.httpRealm = "foo"; |
michael@0 | 103 | tryAddUser(loginmgr, testuser1, /both a httpRealm and formSubmitURL/); |
michael@0 | 104 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 105 | |
michael@0 | 106 | testuser1.formSubmitURL = "foo"; |
michael@0 | 107 | testuser1.httpRealm = ""; |
michael@0 | 108 | tryAddUser(loginmgr, testuser1, /both a httpRealm and formSubmitURL/); |
michael@0 | 109 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 110 | |
michael@0 | 111 | |
michael@0 | 112 | testuser1.formSubmitURL = null; |
michael@0 | 113 | testuser1.httpRealm = ""; |
michael@0 | 114 | tryAddUser(loginmgr, testuser1, /without a httpRealm or formSubmitURL/); |
michael@0 | 115 | LoginTest.checkStorageData(loginmgr, [], []); |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | /* ========== 5 ========== */ |
michael@0 | 119 | testnum++; |
michael@0 | 120 | testdesc = "Try adding valid logins (httpRealm / formSubmitURL checks)"; |
michael@0 | 121 | |
michael@0 | 122 | testuser1.formSubmitURL = null; |
michael@0 | 123 | testuser1.httpRealm = "foo"; |
michael@0 | 124 | testuser1.hostname ="http://dummyhost1"; |
michael@0 | 125 | tryAddUser(loginmgr, testuser1); |
michael@0 | 126 | |
michael@0 | 127 | testuser1.formSubmitURL = ""; |
michael@0 | 128 | testuser1.httpRealm = null; |
michael@0 | 129 | testuser1.hostname ="http://dummyhost2"; |
michael@0 | 130 | tryAddUser(loginmgr, testuser1); |
michael@0 | 131 | |
michael@0 | 132 | testuser1.formSubmitURL = "foo"; |
michael@0 | 133 | testuser1.httpRealm = null; |
michael@0 | 134 | testuser1.hostname ="http://dummyhost3"; |
michael@0 | 135 | tryAddUser(loginmgr, testuser1); |
michael@0 | 136 | |
michael@0 | 137 | |
michael@0 | 138 | } catch (e) { |
michael@0 | 139 | throw "FAILED in test #" + testnum + " -- " + testdesc + ": " + e; |
michael@0 | 140 | } |
michael@0 | 141 | }; |