Chromium Code Reviews| Index: chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js |
| diff --git a/chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js b/chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js |
| index 18c5d33ed033b493453ababc9f4b18153b0c18ce..9cae255eed4df4b5abc4f466627272230e07fb44 100644 |
| --- a/chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js |
| +++ b/chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js |
| @@ -6,6 +6,7 @@ |
| * Used to create fake data for both passwords and autofill. |
| * These sections are related, so it made sense to share this. |
| */ |
| + |
| function FakeDataMaker() {} |
| /** |
| * Creates a single item for the list of passwords. |
| @@ -127,3 +128,197 @@ FakeDataMaker.patternMaker_ = function(pattern, base) { |
| return Math.floor(Math.random() * base).toString(base); |
| }); |
| }; |
| + |
| +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.
|
| +PasswordManagerExpectations.prototype = { |
| + requested: { |
| + passwords: 0, |
| + exceptions: 0, |
| + plaintextPassword: 0, |
| + }, |
| + |
| + removed: { |
| + passwords: 0, |
| + exceptions: 0, |
| + }, |
| + |
| + listening: { |
| + passwords: 0, |
| + exceptions: 0, |
| + }, |
| +}; |
| + |
| +/** |
| + * Test implementation |
| + * @implements {PasswordManager} |
| + * @constructor |
| + */ |
| +function TestPasswordManager() { |
| + this.actual_ = new PasswordManagerExpectations(); |
| +}; |
|
Dan Beam
2017/01/26 19:10:44
no ;
hcarmona
2017/01/26 21:34:47
Done.
|
| +TestPasswordManager.prototype = { |
| + /** @override */ |
| + addSavedPasswordListChangedListener: function(listener) { |
| + this.actual_.listening.passwords++; |
| + this.lastCallback.addSavedPasswordListChangedListener = listener; |
| + }, |
| + |
| + /** @override */ |
| + removeSavedPasswordListChangedListener: function(listener) { |
| + this.actual_.listening.passwords--; |
| + }, |
| + |
| + /** @override */ |
| + getSavedPasswordList: function(callback) { |
| + this.actual_.requested.passwords++; |
| + callback(this.data.passwords); |
| + }, |
| + |
| + /** @override */ |
| + removeSavedPassword: function(loginPair) { |
| + this.actual_.removed.passwords++; |
| + }, |
| + |
| + /** @override */ |
| + addExceptionListChangedListener: function(listener) { |
| + this.actual_.listening.exceptions++; |
| + this.lastCallback.addExceptionListChangedListener = listener; |
| + }, |
| + |
| + /** @override */ |
| + removeExceptionListChangedListener: function(listener) { |
| + this.actual_.listening.exceptions--; |
| + }, |
| + |
| + /** @override */ |
| + getExceptionList: function(callback) { |
| + this.actual_.requested.exceptions++; |
| + callback(this.data.exceptions); |
| + }, |
| + |
| + /** @override */ |
| + removeException: function(exception) { |
| + this.actual_.removed.exceptions++; |
| + }, |
| + |
| + /** @override */ |
| + getPlaintextPassword: function(loginPair, callback) { |
| + this.actual_.requested.plaintextPassword++; |
| + this.lastCallback.getPlaintextPassword = callback; |
| + }, |
| + |
| + /** |
| + * Verifies expectations. |
| + * @param {!PasswordManagerExpectations} expected |
| + */ |
| + assertExpectations: function(expected) { |
| + var actual = this.actual_; |
| + |
| + assertEquals(expected.requested.passwords, actual.requested.passwords); |
| + assertEquals(expected.requested.exceptions, actual.requested.exceptions); |
| + assertEquals(expected.requested.plaintextPassword, |
| + actual.requested.plaintextPassword); |
| + |
| + assertEquals(expected.removed.passwords, actual.removed.passwords); |
| + assertEquals(expected.removed.exceptions, actual.removed.exceptions); |
| + |
| + assertEquals(expected.listening.passwords, actual.listening.passwords); |
| + assertEquals(expected.listening.exceptions, actual.listening.exceptions); |
| + }, |
| + |
| + // Set these to have non-empty data. |
| + data: { |
| + passwords: [], |
| + exceptions: [], |
| + }, |
| + |
| + // Holds the last callbacks so they can be called when needed/ |
| + lastCallback: { |
| + addSavedPasswordListChangedListener: null, |
| + addExceptionListChangedListener: null, |
| + getPlaintextPassword: null, |
| + }, |
| +}; |
| + |
| +function AutofillManagerExpectations() {}; |
|
Dan Beam
2017/01/26 19:10:44
^
hcarmona
2017/01/26 21:34:47
Done.
|
| +AutofillManagerExpectations.prototype = { |
| + requested: { |
| + addresses: 0, |
| + creditCards: 0, |
| + }, |
| + |
| + listening: { |
| + addresses: 0, |
| + creditCards: 0, |
| + }, |
| +}; |
| + |
| +/** |
| + * Test implementation |
| + * @implements {AutofillManager} |
| + * @constructor |
| + */ |
| +function TestAutofillManager() { |
| + this.actual_ = new AutofillManagerExpectations(); |
| +}; |
|
Dan Beam
2017/01/26 19:10:44
^
hcarmona
2017/01/26 21:34:47
Done.
|
| +TestAutofillManager.prototype = { |
| + /** @override */ |
| + addAddressListChangedListener: function(listener) { |
| + this.actual_.listening.addresses++; |
| + this.lastCallback.addAddressListChangedListener = listener; |
| + }, |
| + |
| + /** @override */ |
| + removeAddressListChangedListener: function(listener) { |
| + this.actual_.listening.addresses--; |
| + }, |
| + |
| + /** @override */ |
| + getAddressList: function(callback) { |
| + this.actual_.requested.addresses++; |
| + callback(this.data.addresses); |
| + }, |
| + |
| + /** @override */ |
| + addCreditCardListChangedListener: function(listener) { |
| + this.actual_.listening.creditCards++; |
| + this.lastCallback.addCreditCardListChangedListener = listener; |
| + }, |
| + |
| + /** @override */ |
| + removeCreditCardListChangedListener: function(listener) { |
| + this.actual_.listening.creditCards--; |
| + }, |
| + |
| + /** @override */ |
| + getCreditCardList: function(callback) { |
| + this.actual_.requested.creditCards++; |
| + callback(this.data.creditCards); |
| + }, |
| + |
| + /** |
| + * Verifies expectations. |
| + * @param {!AutofillManagerExpectations} expected |
| + */ |
| + assertExpectations: function(expected) { |
| + var actual = this.actual_; |
| + |
| + assertEquals(expected.requested.addresses, actual.requested.addresses); |
| + assertEquals(expected.requested.creditCards, actual.requested.creditCards); |
| + |
| + assertEquals(expected.listening.addresses, actual.listening.addresses); |
| + assertEquals(expected.listening.creditCards, actual.listening.creditCards); |
| + }, |
| + |
| + // Set these to have non-empty data. |
| + data: { |
| + addresses: [], |
| + creditCards: [], |
| + }, |
| + |
| + // Holds the last callbacks so they can be called when needed. |
| + lastCallback: { |
| + addAddressListChangedListener: null, |
| + addCreditCardListChangedListener: null, |
| + }, |
| +}; |