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

Unified Diff: chrome/test/data/webui/settings/passwords_and_forms_browsertest.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_forms_browsertest.js
diff --git a/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js b/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
index ebfa056d981aa019747f9f439aaddad0d16ae614..330d831bf9644e507c65b428601b1ab9f1375cd9 100644
--- a/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
+++ b/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
@@ -15,200 +15,6 @@ GEN_INCLUDE(
GEN_INCLUDE([ROOT_PATH +
'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']);
-function PasswordManagerExpectations() {};
-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();
-};
-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() {};
-AutofillManagerExpectations.prototype = {
- requested: {
- addresses: 0,
- creditCards: 0,
- },
-
- listening: {
- addresses: 0,
- creditCards: 0,
- },
-};
-
-/**
- * Test implementation
- * @implements {AutofillManager}
- * @constructor
- */
-function TestAutofillManager() {
- this.actual_ = new AutofillManagerExpectations();
-};
-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,
- },
-};
-
/**
* @constructor
* @extends {PolymerTest}
@@ -220,222 +26,253 @@ PasswordsAndFormsBrowserTest.prototype = {
/** @override */
browsePreload: 'chrome://md-settings/passwords_and_forms_page/' +
- 'passwords_and_forms_page.html',
+ 'passwords_and_forms_page.html',
/** @override */
extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
- '../fake_chrome_event.js',
- 'fake_settings_private.js',
+ '../fake_chrome_event.js',
+ 'fake_settings_private.js',
]),
/** @override */
setUp: function() {
PolymerTest.prototype.setUp.call(this);
- PolymerTest.clearBody();
// Test is run on an individual element that won't have a page language.
this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
-
- // Override the PasswordManagerImpl for testing.
- this.passwordManager = new TestPasswordManager();
- PasswordManagerImpl.instance_ = this.passwordManager;
-
- // Override the AutofillManagerImpl for testing.
- this.autofillManager = new TestAutofillManager();
- AutofillManagerImpl.instance_ = this.autofillManager;
},
+};
+
+/** This test will validate that the section is loaded with data. */
+TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() {
+ var passwordManager;
+ var autofillManager;
/**
* Creates a new passwords and forms element.
* @return {!Object}
*/
- createPasswordsAndFormsElement: function() {
+ function createPasswordsAndFormsElement(prefsElement) {
var element = document.createElement('settings-passwords-and-forms-page');
+ element.prefs = prefsElement.prefs;
document.body.appendChild(element);
+ element.$$('template[route-path="/passwords"]').if = true;
+ element.$$('template[route-path="/autofill"]').if = true;
Polymer.dom.flush();
return element;
- },
+ }
/**
* @pram {boolean} autofill Whether autofill is enabled or not.
* @param {boolean} passwords Whether passwords are enabled or not.
- * @return {!Promise<!Element>} The |prefs| object.
+ * @return {!Promise<!Element>} The |prefs| element.
*/
- createPrefs: function(autofill, passwords) {
+ function createPrefs(autofill, passwords) {
return new Promise(function(resolve) {
CrSettingsPrefs.deferInitialization = true;
var prefs = document.createElement('settings-prefs');
prefs.initialize(new settings.FakeSettingsPrivate([
- {
- key: 'autofill.enabled',
- type: chrome.settingsPrivate.PrefType.BOOLEAN,
- value: autofill,
- },
- {
- key: 'credentials_enable_service',
- type: chrome.settingsPrivate.PrefType.BOOLEAN,
- value: passwords,
- },
+ {
+ key: 'autofill.enabled',
+ type: chrome.settingsPrivate.PrefType.BOOLEAN,
+ value: autofill,
+ },
+ {
+ key: 'credentials_enable_service',
+ type: chrome.settingsPrivate.PrefType.BOOLEAN,
+ value: passwords,
+ },
+ {
+ key: 'credentials_enable_autosignin',
+ type: chrome.settingsPrivate.PrefType.BOOLEAN,
+ value: true,
+ },
]));
CrSettingsPrefs.initialized.then(function() {
resolve(prefs);
});
});
- },
+ }
/**
* Cleans up prefs so tests can continue to run.
* @param {!Element} prefs The prefs element.
*/
- destroyPrefs: function(prefs) {
+ function destroyPrefs(prefs) {
CrSettingsPrefs.resetForTesting();
CrSettingsPrefs.deferInitialization = false;
prefs.resetForTesting();
- },
+ }
/**
* Creates PasswordManagerExpectations with the values expected after first
* creating the element.
* @return {!PasswordManagerExpectations}
*/
- basePasswordExpectations: function() {
+ function basePasswordExpectations() {
var expected = new PasswordManagerExpectations();
expected.requested.passwords = 1;
expected.requested.exceptions = 1;
expected.listening.passwords = 1;
expected.listening.exceptions = 1;
return expected;
- },
+ }
/**
* Creates AutofillManagerExpectations with the values expected after first
* creating the element.
* @return {!AutofillManagerExpectations}
*/
- baseAutofillExpectations: function() {
+ function baseAutofillExpectations() {
var expected = new AutofillManagerExpectations();
expected.requested.addresses = 1;
expected.requested.creditCards = 1;
expected.listening.addresses = 1;
expected.listening.creditCards = 1;
return expected;
- },
-};
+ }
-/** This test will validate that the section is loaded with data. */
-TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() {
- var self = this;
+ setup(function() {
+ PolymerTest.clearBody();
+
+ // Override the PasswordManagerImpl for testing.
+ passwordManager = new TestPasswordManager();
+ PasswordManagerImpl.instance_ = passwordManager;
+
+ // Override the AutofillManagerImpl for testing.
+ autofillManager = new TestAutofillManager();
+ AutofillManagerImpl.instance_ = autofillManager;
+ });
suite('PasswordsAndForms', function() {
test('baseLoadAndRemove', function() {
- var element = self.createPasswordsAndFormsElement();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
+
+ var passwordsExpectations = basePasswordExpectations();
+ passwordManager.assertExpectations(passwordsExpectations);
- var passwordsExpectations = self.basePasswordExpectations();
- self.passwordManager.assertExpectations(passwordsExpectations);
+ var autofillExpectations = baseAutofillExpectations();
+ autofillManager.assertExpectations(autofillExpectations);
- var autofillExpectations = self.baseAutofillExpectations();
- self.autofillManager.assertExpectations(autofillExpectations);
+ element.remove();
+ Polymer.dom.flush();
- element.remove();
- Polymer.dom.flush();
+ passwordsExpectations.listening.passwords = 0;
+ passwordsExpectations.listening.exceptions = 0;
+ passwordManager.assertExpectations(passwordsExpectations);
- passwordsExpectations.listening.passwords = 0;
- passwordsExpectations.listening.exceptions = 0;
- self.passwordManager.assertExpectations(passwordsExpectations);
+ autofillExpectations.listening.addresses = 0;
+ autofillExpectations.listening.creditCards = 0;
+ autofillManager.assertExpectations(autofillExpectations);
- autofillExpectations.listening.addresses = 0;
- autofillExpectations.listening.creditCards = 0;
- self.autofillManager.assertExpectations(autofillExpectations);
+ destroyPrefs(prefs);
+ });
});
test('loadPasswordsAsync', function() {
- var element = self.createPasswordsAndFormsElement();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
- var list = [FakeDataMaker.passwordEntry(), FakeDataMaker.passwordEntry()];
- self.passwordManager.lastCallback.addSavedPasswordListChangedListener(
- list);
- Polymer.dom.flush();
+ var list = [
+ FakeDataMaker.passwordEntry(),
+ FakeDataMaker.passwordEntry()
+ ];
- assertEquals(list, element.savedPasswords);
+ passwordManager.lastCallback.addSavedPasswordListChangedListener(list);
+ Polymer.dom.flush();
+
+ assertEquals(list, element.$$('#passwordSection').savedPasswords);
- // The callback is coming from the manager, so the element shouldn't have
- // additional calls to the manager after the base expectations.
- self.passwordManager.assertExpectations(self.basePasswordExpectations());
- self.autofillManager.assertExpectations(self.baseAutofillExpectations());
+ // The callback is coming from the manager, so the element shouldn't
+ // have additional calls to the manager after the base expectations.
+ passwordManager.assertExpectations(basePasswordExpectations());
+ autofillManager.assertExpectations(baseAutofillExpectations());
+
+ destroyPrefs(prefs);
+ });
});
test('loadExceptionsAsync', function() {
- var element = self.createPasswordsAndFormsElement();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
- var list = [FakeDataMaker.exceptionEntry(),
- FakeDataMaker.exceptionEntry()];
- self.passwordManager.lastCallback.addExceptionListChangedListener(
- list);
- Polymer.dom.flush();
+ var list = [FakeDataMaker.exceptionEntry(),
+ FakeDataMaker.exceptionEntry()];
+ passwordManager.lastCallback.addExceptionListChangedListener(list);
+ Polymer.dom.flush();
+
+ assertEquals(list, element.$$('#passwordSection').passwordExceptions);
- assertEquals(list, element.passwordExceptions);
+ // The callback is coming from the manager, so the element shouldn't
+ // have additional calls to the manager after the base expectations.
+ passwordManager.assertExpectations(basePasswordExpectations());
+ autofillManager.assertExpectations(baseAutofillExpectations());
- // The callback is coming from the manager, so the element shouldn't have
- // additional calls to the manager after the base expectations.
- self.passwordManager.assertExpectations(self.basePasswordExpectations());
- self.autofillManager.assertExpectations(self.baseAutofillExpectations());
+ destroyPrefs(prefs);
+ });
});
test('loadAddressesAsync', function() {
- var element = self.createPasswordsAndFormsElement();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
+
+ var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
+ autofillManager.lastCallback.addAddressListChangedListener(list);
+ Polymer.dom.flush();
- var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
- self.autofillManager.lastCallback.addAddressListChangedListener(list);
- Polymer.dom.flush();
+ assertEquals(list, element.$$('#autofillSection').addresses);
- assertEquals(list, element.addresses);
+ // The callback is coming from the manager, so the element shouldn't
+ // have additional calls to the manager after the base expectations.
+ passwordManager.assertExpectations(basePasswordExpectations());
+ autofillManager.assertExpectations(baseAutofillExpectations());
- // The callback is coming from the manager, so the element shouldn't have
- // additional calls to the manager after the base expectations.
- self.passwordManager.assertExpectations(self.basePasswordExpectations());
- self.autofillManager.assertExpectations(self.baseAutofillExpectations());
+ destroyPrefs(prefs);
+ });
});
test('loadCreditCardsAsync', function() {
- var element = self.createPasswordsAndFormsElement();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
+
+ var list = [FakeDataMaker.creditCardEntry(),
+ FakeDataMaker.creditCardEntry()];
+ autofillManager.lastCallback.addCreditCardListChangedListener(list);
+ Polymer.dom.flush();
- var list = [FakeDataMaker.creditCardEntry(),
- FakeDataMaker.creditCardEntry()];
- self.autofillManager.lastCallback.addCreditCardListChangedListener(list);
- Polymer.dom.flush();
+ assertEquals(list, element.$$('#autofillSection').creditCards);
- assertEquals(list, element.creditCards);
+ // The callback is coming from the manager, so the element shouldn't
+ // have additional calls to the manager after the base expectations.
+ passwordManager.assertExpectations(basePasswordExpectations());
+ autofillManager.assertExpectations(baseAutofillExpectations());
- // The callback is coming from the manager, so the element shouldn't have
- // additional calls to the manager after the base expectations.
- self.passwordManager.assertExpectations(self.basePasswordExpectations());
- self.autofillManager.assertExpectations(self.baseAutofillExpectations());
+ destroyPrefs(prefs);
+ });
});
test('testActionabilityNope', function() {
- return self.createPrefs(false, false).then(function(prefs) {
- var element = self.createPasswordsAndFormsElement();
- element.prefs = prefs.prefs;
- Polymer.dom.flush();
+ return createPrefs(false, false).then(function(prefs) {
+
+ var element = createPasswordsAndFormsElement(prefs);
assertFalse(element.$.autofillManagerButton.hasAttribute('actionable'));
assertFalse(element.$.passwordManagerButton.hasAttribute('actionable'));
- self.destroyPrefs(prefs);
+ destroyPrefs(prefs);
});
});
test('testActionabilityYes', function() {
- return self.createPrefs(true, true).then(function(prefs) {
- var element = self.createPasswordsAndFormsElement();
- element.prefs = prefs.prefs;
- Polymer.dom.flush();
+ return createPrefs(true, true).then(function(prefs) {
+ var element = createPasswordsAndFormsElement(prefs);
assertTrue(element.$.autofillManagerButton.hasAttribute('actionable'));
assertTrue(element.$.passwordManagerButton.hasAttribute('actionable'));
- self.destroyPrefs(prefs);
+ destroyPrefs(prefs);
});
});
});

Powered by Google App Engine
This is Rietveld 408576698