Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Used to create fake data for both passwords and autofill. | 6 * Used to create fake data for both passwords and autofill. |
| 7 * These sections are related, so it made sense to share this. | 7 * These sections are related, so it made sense to share this. |
| 8 */ | 8 */ |
| 9 | |
| 9 function FakeDataMaker() {} | 10 function FakeDataMaker() {} |
| 10 /** | 11 /** |
| 11 * Creates a single item for the list of passwords. | 12 * Creates a single item for the list of passwords. |
| 12 * @param {string|undefined} url | 13 * @param {string|undefined} url |
| 13 * @param {string|undefined} username | 14 * @param {string|undefined} username |
| 14 * @param {number|undefined} passwordLength | 15 * @param {number|undefined} passwordLength |
| 15 * @return {chrome.passwordsPrivate.PasswordUiEntry} | 16 * @return {chrome.passwordsPrivate.PasswordUiEntry} |
| 16 */ | 17 */ |
| 17 FakeDataMaker.passwordEntry = function(url, username, passwordLength) { | 18 FakeDataMaker.passwordEntry = function(url, username, passwordLength) { |
| 18 // Generate fake data if param is undefined. | 19 // Generate fake data if param is undefined. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 * @param {string} pattern The pattern that should be used as an input. | 121 * @param {string} pattern The pattern that should be used as an input. |
| 121 * @param {number} base The number base. ie: 16 for hex or 10 for decimal. | 122 * @param {number} base The number base. ie: 16 for hex or 10 for decimal. |
| 122 * @return {string} | 123 * @return {string} |
| 123 * @private | 124 * @private |
| 124 */ | 125 */ |
| 125 FakeDataMaker.patternMaker_ = function(pattern, base) { | 126 FakeDataMaker.patternMaker_ = function(pattern, base) { |
| 126 return pattern.replace(/x/g, function() { | 127 return pattern.replace(/x/g, function() { |
| 127 return Math.floor(Math.random() * base).toString(base); | 128 return Math.floor(Math.random() * base).toString(base); |
| 128 }); | 129 }); |
| 129 }; | 130 }; |
| 131 | |
| 132 function PasswordManagerExpectations() {}; | |
|
Dan Beam
2017/01/26 19:10:44
don't put a ; after function Delcarations() {}
hcarmona
2017/01/26 21:34:47
Done.
| |
| 133 PasswordManagerExpectations.prototype = { | |
| 134 requested: { | |
| 135 passwords: 0, | |
| 136 exceptions: 0, | |
| 137 plaintextPassword: 0, | |
| 138 }, | |
| 139 | |
| 140 removed: { | |
| 141 passwords: 0, | |
| 142 exceptions: 0, | |
| 143 }, | |
| 144 | |
| 145 listening: { | |
| 146 passwords: 0, | |
| 147 exceptions: 0, | |
| 148 }, | |
| 149 }; | |
| 150 | |
| 151 /** | |
| 152 * Test implementation | |
| 153 * @implements {PasswordManager} | |
| 154 * @constructor | |
| 155 */ | |
| 156 function TestPasswordManager() { | |
| 157 this.actual_ = new PasswordManagerExpectations(); | |
| 158 }; | |
|
Dan Beam
2017/01/26 19:10:44
no ;
hcarmona
2017/01/26 21:34:47
Done.
| |
| 159 TestPasswordManager.prototype = { | |
| 160 /** @override */ | |
| 161 addSavedPasswordListChangedListener: function(listener) { | |
| 162 this.actual_.listening.passwords++; | |
| 163 this.lastCallback.addSavedPasswordListChangedListener = listener; | |
| 164 }, | |
| 165 | |
| 166 /** @override */ | |
| 167 removeSavedPasswordListChangedListener: function(listener) { | |
| 168 this.actual_.listening.passwords--; | |
| 169 }, | |
| 170 | |
| 171 /** @override */ | |
| 172 getSavedPasswordList: function(callback) { | |
| 173 this.actual_.requested.passwords++; | |
| 174 callback(this.data.passwords); | |
| 175 }, | |
| 176 | |
| 177 /** @override */ | |
| 178 removeSavedPassword: function(loginPair) { | |
| 179 this.actual_.removed.passwords++; | |
| 180 }, | |
| 181 | |
| 182 /** @override */ | |
| 183 addExceptionListChangedListener: function(listener) { | |
| 184 this.actual_.listening.exceptions++; | |
| 185 this.lastCallback.addExceptionListChangedListener = listener; | |
| 186 }, | |
| 187 | |
| 188 /** @override */ | |
| 189 removeExceptionListChangedListener: function(listener) { | |
| 190 this.actual_.listening.exceptions--; | |
| 191 }, | |
| 192 | |
| 193 /** @override */ | |
| 194 getExceptionList: function(callback) { | |
| 195 this.actual_.requested.exceptions++; | |
| 196 callback(this.data.exceptions); | |
| 197 }, | |
| 198 | |
| 199 /** @override */ | |
| 200 removeException: function(exception) { | |
| 201 this.actual_.removed.exceptions++; | |
| 202 }, | |
| 203 | |
| 204 /** @override */ | |
| 205 getPlaintextPassword: function(loginPair, callback) { | |
| 206 this.actual_.requested.plaintextPassword++; | |
| 207 this.lastCallback.getPlaintextPassword = callback; | |
| 208 }, | |
| 209 | |
| 210 /** | |
| 211 * Verifies expectations. | |
| 212 * @param {!PasswordManagerExpectations} expected | |
| 213 */ | |
| 214 assertExpectations: function(expected) { | |
| 215 var actual = this.actual_; | |
| 216 | |
| 217 assertEquals(expected.requested.passwords, actual.requested.passwords); | |
| 218 assertEquals(expected.requested.exceptions, actual.requested.exceptions); | |
| 219 assertEquals(expected.requested.plaintextPassword, | |
| 220 actual.requested.plaintextPassword); | |
| 221 | |
| 222 assertEquals(expected.removed.passwords, actual.removed.passwords); | |
| 223 assertEquals(expected.removed.exceptions, actual.removed.exceptions); | |
| 224 | |
| 225 assertEquals(expected.listening.passwords, actual.listening.passwords); | |
| 226 assertEquals(expected.listening.exceptions, actual.listening.exceptions); | |
| 227 }, | |
| 228 | |
| 229 // Set these to have non-empty data. | |
| 230 data: { | |
| 231 passwords: [], | |
| 232 exceptions: [], | |
| 233 }, | |
| 234 | |
| 235 // Holds the last callbacks so they can be called when needed/ | |
| 236 lastCallback: { | |
| 237 addSavedPasswordListChangedListener: null, | |
| 238 addExceptionListChangedListener: null, | |
| 239 getPlaintextPassword: null, | |
| 240 }, | |
| 241 }; | |
| 242 | |
| 243 function AutofillManagerExpectations() {}; | |
|
Dan Beam
2017/01/26 19:10:44
^
hcarmona
2017/01/26 21:34:47
Done.
| |
| 244 AutofillManagerExpectations.prototype = { | |
| 245 requested: { | |
| 246 addresses: 0, | |
| 247 creditCards: 0, | |
| 248 }, | |
| 249 | |
| 250 listening: { | |
| 251 addresses: 0, | |
| 252 creditCards: 0, | |
| 253 }, | |
| 254 }; | |
| 255 | |
| 256 /** | |
| 257 * Test implementation | |
| 258 * @implements {AutofillManager} | |
| 259 * @constructor | |
| 260 */ | |
| 261 function TestAutofillManager() { | |
| 262 this.actual_ = new AutofillManagerExpectations(); | |
| 263 }; | |
|
Dan Beam
2017/01/26 19:10:44
^
hcarmona
2017/01/26 21:34:47
Done.
| |
| 264 TestAutofillManager.prototype = { | |
| 265 /** @override */ | |
| 266 addAddressListChangedListener: function(listener) { | |
| 267 this.actual_.listening.addresses++; | |
| 268 this.lastCallback.addAddressListChangedListener = listener; | |
| 269 }, | |
| 270 | |
| 271 /** @override */ | |
| 272 removeAddressListChangedListener: function(listener) { | |
| 273 this.actual_.listening.addresses--; | |
| 274 }, | |
| 275 | |
| 276 /** @override */ | |
| 277 getAddressList: function(callback) { | |
| 278 this.actual_.requested.addresses++; | |
| 279 callback(this.data.addresses); | |
| 280 }, | |
| 281 | |
| 282 /** @override */ | |
| 283 addCreditCardListChangedListener: function(listener) { | |
| 284 this.actual_.listening.creditCards++; | |
| 285 this.lastCallback.addCreditCardListChangedListener = listener; | |
| 286 }, | |
| 287 | |
| 288 /** @override */ | |
| 289 removeCreditCardListChangedListener: function(listener) { | |
| 290 this.actual_.listening.creditCards--; | |
| 291 }, | |
| 292 | |
| 293 /** @override */ | |
| 294 getCreditCardList: function(callback) { | |
| 295 this.actual_.requested.creditCards++; | |
| 296 callback(this.data.creditCards); | |
| 297 }, | |
| 298 | |
| 299 /** | |
| 300 * Verifies expectations. | |
| 301 * @param {!AutofillManagerExpectations} expected | |
| 302 */ | |
| 303 assertExpectations: function(expected) { | |
| 304 var actual = this.actual_; | |
| 305 | |
| 306 assertEquals(expected.requested.addresses, actual.requested.addresses); | |
| 307 assertEquals(expected.requested.creditCards, actual.requested.creditCards); | |
| 308 | |
| 309 assertEquals(expected.listening.addresses, actual.listening.addresses); | |
| 310 assertEquals(expected.listening.creditCards, actual.listening.creditCards); | |
| 311 }, | |
| 312 | |
| 313 // Set these to have non-empty data. | |
| 314 data: { | |
| 315 addresses: [], | |
| 316 creditCards: [], | |
| 317 }, | |
| 318 | |
| 319 // Holds the last callbacks so they can be called when needed. | |
| 320 lastCallback: { | |
| 321 addAddressListChangedListener: null, | |
| 322 addCreditCardListChangedListener: null, | |
| 323 }, | |
| 324 }; | |
| OLD | NEW |