Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10926)

Unified Diff: chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js

Issue 2627123002: Load Passwords and Autofill in the corresponding sub page. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..88395291057383da4f4d92f73ad9b08922a0043e 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,7 +6,9 @@
* 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.
* @param {string|undefined} url
@@ -127,3 +129,205 @@ FakeDataMaker.patternMaker_ = function(pattern, base) {
return Math.floor(Math.random() * base).toString(base);
});
};
+
+/** @constructor */
+function PasswordManagerExpectations() {
+ this.requested = {
+ passwords: 0,
+ exceptions: 0,
+ plaintextPassword: 0,
+ };
+
+ this.removed = {
+ passwords: 0,
+ exceptions: 0,
+ };
+
+ this.listening = {
+ passwords: 0,
+ exceptions: 0,
+ };
+}
+
+/**
+ * Test implementation
+ * @implements {PasswordManager}
+ * @constructor
+ */
+function TestPasswordManager() {
+ this.actual_ = new PasswordManagerExpectations();
+
+ // Set these to have non-empty data.
+ this.data = {
+ passwords: [],
+ exceptions: [],
+ };
+
+ // Holds the last callbacks so they can be called when needed/
+ this.lastCallback = {
+ addSavedPasswordListChangedListener: null,
+ addExceptionListChangedListener: null,
+ getPlaintextPassword: null,
+ };
+}
+
+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++;
+
+ if (this.onRemoveSavedPassword)
+ this.onRemoveSavedPassword(loginPair);
+ },
+
+ /** @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++;
+
+ if (this.onRemoveException)
+ this.onRemoveException(exception);
+ },
+
+ /** @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);
+ },
+};
+
+/** @constructor */
+function AutofillManagerExpectations() {
+ this.requested = {
+ addresses: 0,
+ creditCards: 0,
+ };
+
+ this.listening = {
+ addresses: 0,
+ creditCards: 0,
+ };
+}
+
+/**
+ * Test implementation
+ * @implements {AutofillManager}
+ * @constructor
+ */
+function TestAutofillManager() {
+ this.actual_ = new AutofillManagerExpectations();
+
+ // Set these to have non-empty data.
+ this.data = {
+ addresses: [],
+ creditCards: [],
+ };
+
+ // Holds the last callbacks so they can be called when needed.
+ this.lastCallback = {
+ addAddressListChangedListener: null,
+ addCreditCardListChangedListener: null,
+ };
+}
+
+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);
+ },
+};

Powered by Google App Engine
This is Rietveld 408576698