Commit a6428237 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[Settings] Refactor: change createExceptionEntry(); set ids in tests

This CL is simply the analogous of crrev.com/c/2218055 for password
exceptions. This means it changes the signature of this helper function
to: a) make it easier to write tests in a multi-store scenario; b) allow
the deduplication functionality to be introduced without breaking the
existing tests.

Besides that, the CL fixes a comment typo in validatePasswordList() and
also exposes chrome.passwordsPrivate.removeExceptions() API in the
PasswordManagerProxy, so it can later be used at PasswordsSection when
exceptions are deduplicated.

TBR=fhorschig@chromium.org

Bug: 1049141
Change-Id: I3a501283c964904b981a6e2463336f4f147816bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2234755
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776221}
parent 34457ab2
...@@ -86,6 +86,13 @@ export class PasswordManagerProxy { ...@@ -86,6 +86,13 @@ export class PasswordManagerProxy {
*/ */
removeException(id) {} removeException(id) {}
/**
* Should remove the password exceptions and notify that the list has changed.
* @param {!Array<number>} ids The ids for the exception url entries being
* removed. Any |id| not in the list is ignored.
*/
removeExceptions(ids) {}
/** /**
* Should undo the last saved password or exception removal and notify that * Should undo the last saved password or exception removal and notify that
* the list has changed. * the list has changed.
...@@ -381,6 +388,11 @@ export class PasswordManagerImpl { ...@@ -381,6 +388,11 @@ export class PasswordManagerImpl {
chrome.passwordsPrivate.removePasswordException(id); chrome.passwordsPrivate.removePasswordException(id);
} }
/** @override */
removeExceptions(ids) {
chrome.passwordsPrivate.removePasswordExceptions(ids);
}
/** @override */ /** @override */
undoRemoveSavedPasswordOrException() { undoRemoveSavedPasswordOrException() {
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException(); chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
......
...@@ -207,7 +207,10 @@ suite('PasswordsAndForms', function() { ...@@ -207,7 +207,10 @@ suite('PasswordsAndForms', function() {
return createPrefs(true, true).then(function(prefs) { return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs); const element = createAutofillElement(prefs);
const list = [createExceptionEntry(), createExceptionEntry()]; const list = [
createExceptionEntry({url: 'one.com', id: 0}),
createExceptionEntry({url: 'two.com', id: 1})
];
passwordManager.lastCallback.addExceptionListChangedListener(list); passwordManager.lastCallback.addExceptionListChangedListener(list);
flush(); flush();
......
...@@ -11,9 +11,9 @@ import {createExceptionEntry} from 'chrome://test/settings/passwords_and_autofil ...@@ -11,9 +11,9 @@ import {createExceptionEntry} from 'chrome://test/settings/passwords_and_autofil
suite('MultiStoreExceptionEntry', function() { suite('MultiStoreExceptionEntry', function() {
test('verifyIds', function() { test('verifyIds', function() {
const deviceEntry = createExceptionEntry('g.com', 0); const deviceEntry = createExceptionEntry({url: 'g.com', id: 0});
deviceEntry.fromAccountStore = false; deviceEntry.fromAccountStore = false;
const accountEntry = createExceptionEntry('g.com', 1); const accountEntry = createExceptionEntry({url: 'g.com', id: 1});
accountEntry.fromAccountStore = true; accountEntry.fromAccountStore = true;
const multiStoreDeviceEntry = new MultiStoreExceptionEntry(deviceEntry); const multiStoreDeviceEntry = new MultiStoreExceptionEntry(deviceEntry);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import {assertNotReached} from 'chrome://resources/js/assert.m.js'; import {assertNotReached} from 'chrome://resources/js/assert.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {AutofillManager, PaymentsManager} from 'chrome://settings/lazy_load.js'; import {AutofillManager, PaymentsManager} from 'chrome://settings/lazy_load.js';
import {MultiStorePasswordUiEntry} from 'chrome://settings/settings.js'; import {MultiStoreExceptionEntry, MultiStorePasswordUiEntry} from 'chrome://settings/settings.js';
import {assertEquals} from '../chai_assert.js'; import {assertEquals} from '../chai_assert.js';
...@@ -18,7 +18,7 @@ import {TestPasswordManagerProxy} from './test_password_manager_proxy.js'; ...@@ -18,7 +18,7 @@ import {TestPasswordManagerProxy} from './test_password_manager_proxy.js';
* password manager native code. If no |id| is passed, it is set to a default, * password manager native code. If no |id| is passed, it is set to a default,
* value so this should probably not be done in tests with multiple entries * value so this should probably not be done in tests with multiple entries
* (|id| is unique). If no |frontendId| is passed, it is set to the same value * (|id| is unique). If no |frontendId| is passed, it is set to the same value
* as |id|. * set for |id|.
* @param {{ url: (string|undefined), * @param {{ url: (string|undefined),
* username: (string|undefined), * username: (string|undefined),
* federationText: (string|undefined), * federationText: (string|undefined),
...@@ -31,24 +31,23 @@ import {TestPasswordManagerProxy} from './test_password_manager_proxy.js'; ...@@ -31,24 +31,23 @@ import {TestPasswordManagerProxy} from './test_password_manager_proxy.js';
export function createPasswordEntry(params) { export function createPasswordEntry(params) {
// Generate fake data if param is undefined. // Generate fake data if param is undefined.
params = params || {}; params = params || {};
params.url = params.url !== undefined ? params.url : 'www.foo.com'; const url = params.url !== undefined ? params.url : 'www.foo.com';
params.username = params.username || 'user'; const username = params.username !== undefined ? params.username : 'user';
params.id = params.id !== undefined ? params.id : 42; const id = params.id !== undefined ? params.id : 42;
params.frontendId = const frontendId = params.frontendId !== undefined ? params.frontendId : id;
params.frontendId !== undefined ? params.frontendId : params.id; const fromAccountStore = params.fromAccountStore || false;
params.fromAccountStore = params.fromAccountStore || false;
return { return {
urls: { urls: {
origin: 'http://' + params.url + '/login', origin: 'http://' + url + '/login',
shown: params.url, shown: url,
link: 'http://' + params.url + '/login', link: 'http://' + url + '/login',
}, },
username: params.username, username: username,
federationText: params.federationText, federationText: params.federationText,
id: params.id, id: id,
frontendId: params.frontendId, frontendId: frontendId,
fromAccountStore: params.fromAccountStore, fromAccountStore: fromAccountStore,
}; };
} }
...@@ -100,14 +99,23 @@ export function createMultiStorePasswordEntry(params) { ...@@ -100,14 +99,23 @@ export function createMultiStorePasswordEntry(params) {
} }
/** /**
* Creates a single item for the list of password exceptions. * Creates a single item for the list of password exceptions. If no |id| is
* @param {string=} url * passed, it is set to a default, value so this should probably not be done in
* @param {number=} id * tests with multiple entries (|id| is unique). If no |frontendId| is passed,
* it is set to the same value set for |id|.
* @param {{ url: (string|undefined),
* id: (number|undefined),
* frontendId: (number|undefined),
* fromAccountStore: (boolean|undefined)
* }=} params
* @return {chrome.passwordsPrivate.ExceptionEntry} * @return {chrome.passwordsPrivate.ExceptionEntry}
*/ */
export function createExceptionEntry(url, id) { export function createExceptionEntry(params) {
url = url || patternMaker_('www.xxxxxx.com', 16); params = params || {};
id = id || 0; const url = params.url !== undefined ? params.url : 'www.foo.com';
const id = params.id !== undefined ? params.id : 42;
const frontendId = params.frontendId !== undefined ? params.frontendId : id;
const fromAccountStore = params.fromAccountStore || false;
return { return {
urls: { urls: {
origin: 'http://' + url + '/login', origin: 'http://' + url + '/login',
...@@ -115,8 +123,8 @@ export function createExceptionEntry(url, id) { ...@@ -115,8 +123,8 @@ export function createExceptionEntry(url, id) {
link: 'http://' + url + '/login', link: 'http://' + url + '/login',
}, },
id: id, id: id,
frontendId: id, frontendId: frontendId,
fromAccountStore: false, fromAccountStore: fromAccountStore,
}; };
} }
......
...@@ -46,7 +46,7 @@ function validateMultiStorePasswordList(passwordsSection, expectedPasswords) { ...@@ -46,7 +46,7 @@ function validateMultiStorePasswordList(passwordsSection, expectedPasswords) {
} }
/** /**
* Convenience version of validateMultiStorePasswordList for when store * Convenience version of validateMultiStorePasswordList() for when store
* duplicates don't exist. * duplicates don't exist.
* @param {!Element} passwordsSection The passwords section element that will * @param {!Element} passwordsSection The passwords section element that will
* be checked. * be checked.
...@@ -573,12 +573,12 @@ suite('PasswordsSection', function() { ...@@ -573,12 +573,12 @@ suite('PasswordsSection', function() {
test('verifyFilterPasswordExceptions', function() { test('verifyFilterPasswordExceptions', function() {
const exceptionList = [ const exceptionList = [
createExceptionEntry('docsshoW.google.com'), createExceptionEntry({url: 'docsshoW.google.com', id: 0}),
createExceptionEntry('showmail.com'), createExceptionEntry({url: 'showmail.com', id: 1}),
createExceptionEntry('google.com'), createExceptionEntry({url: 'google.com', id: 2}),
createExceptionEntry('inbox.google.com'), createExceptionEntry({url: 'inbox.google.com', id: 3}),
createExceptionEntry('mapsshow.google.com'), createExceptionEntry({url: 'mapsshow.google.com', id: 4}),
createExceptionEntry('plus.google.comshow'), createExceptionEntry({url: 'plus.google.comshow', id: 5}),
]; ];
const passwordsSection = elementFactory.createPasswordsSection( const passwordsSection = elementFactory.createPasswordsSection(
...@@ -587,10 +587,10 @@ suite('PasswordsSection', function() { ...@@ -587,10 +587,10 @@ suite('PasswordsSection', function() {
flush(); flush();
const expectedExceptionList = [ const expectedExceptionList = [
createExceptionEntry('docsshoW.google.com'), createExceptionEntry({url: 'docsshoW.google.com', id: 0}),
createExceptionEntry('showmail.com'), createExceptionEntry({url: 'showmail.com', id: 1}),
createExceptionEntry('mapsshow.google.com'), createExceptionEntry({url: 'mapsshow.google.com', id: 4}),
createExceptionEntry('plus.google.comshow'), createExceptionEntry({url: 'plus.google.comshow', id: 5}),
]; ];
validateExceptionList( validateExceptionList(
...@@ -610,12 +610,12 @@ suite('PasswordsSection', function() { ...@@ -610,12 +610,12 @@ suite('PasswordsSection', function() {
test('verifyPasswordExceptions', function() { test('verifyPasswordExceptions', function() {
const exceptionList = [ const exceptionList = [
createExceptionEntry('docs.google.com'), createExceptionEntry({url: 'docs.google.com', id: 0}),
createExceptionEntry('mail.com'), createExceptionEntry({url: 'mail.com', id: 1}),
createExceptionEntry('google.com'), createExceptionEntry({url: 'google.com', id: 2}),
createExceptionEntry('inbox.google.com'), createExceptionEntry({url: 'inbox.google.com', id: 3}),
createExceptionEntry('maps.google.com'), createExceptionEntry({url: 'maps.google.com', id: 4}),
createExceptionEntry('plus.google.com'), createExceptionEntry({url: 'plus.google.com', id: 5}),
]; ];
const passwordsSection = elementFactory.createPasswordsSection( const passwordsSection = elementFactory.createPasswordsSection(
...@@ -631,12 +631,12 @@ suite('PasswordsSection', function() { ...@@ -631,12 +631,12 @@ suite('PasswordsSection', function() {
// Test verifies that removing an exception will update the elements. // Test verifies that removing an exception will update the elements.
test('verifyPasswordExceptionRemove', function() { test('verifyPasswordExceptionRemove', function() {
const exceptionList = [ const exceptionList = [
createExceptionEntry('docs.google.com'), createExceptionEntry({url: 'docs.google.com', id: 0}),
createExceptionEntry('mail.com'), createExceptionEntry({url: 'mail.com', id: 1}),
createExceptionEntry('google.com'), createExceptionEntry({url: 'google.com', id: 2}),
createExceptionEntry('inbox.google.com'), createExceptionEntry({url: 'inbox.google.com', id: 3}),
createExceptionEntry('maps.google.com'), createExceptionEntry({url: 'maps.google.com', id: 4}),
createExceptionEntry('plus.google.com'), createExceptionEntry({url: 'plus.google.com', id: 5}),
]; ];
const passwordsSection = elementFactory.createPasswordsSection( const passwordsSection = elementFactory.createPasswordsSection(
...@@ -653,21 +653,28 @@ suite('PasswordsSection', function() { ...@@ -653,21 +653,28 @@ suite('PasswordsSection', function() {
assertFalse(exceptionsListContainsUrl(exceptionList, 'mail.com')); assertFalse(exceptionsListContainsUrl(exceptionList, 'mail.com'));
flush(); flush();
const expectedExceptionList = [
createExceptionEntry({url: 'docs.google.com', id: 0}),
createExceptionEntry({url: 'google.com', id: 2}),
createExceptionEntry({url: 'inbox.google.com', id: 3}),
createExceptionEntry({url: 'maps.google.com', id: 4}),
createExceptionEntry({url: 'plus.google.com', id: 5})
];
validateExceptionList( validateExceptionList(
getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), getDomRepeatChildren(passwordsSection.$.passwordExceptionsList),
exceptionList); expectedExceptionList);
}); });
// Test verifies that pressing the 'remove' button will trigger a remove // Test verifies that pressing the 'remove' button will trigger a remove
// event. Does not actually remove any exceptions. // event. Does not actually remove any exceptions.
test('verifyPasswordExceptionRemoveButton', function() { test('verifyPasswordExceptionRemoveButton', function() {
const exceptionList = [ const exceptionList = [
createExceptionEntry('docs.google.com'), createExceptionEntry({url: 'docs.google.com', id: 0}),
createExceptionEntry('mail.com'), createExceptionEntry({url: 'mail.com', id: 1}),
createExceptionEntry('google.com'), createExceptionEntry({url: 'google.com', id: 2}),
createExceptionEntry('inbox.google.com'), createExceptionEntry({url: 'inbox.google.com', id: 3}),
createExceptionEntry('maps.google.com'), createExceptionEntry({url: 'maps.google.com', id: 4}),
createExceptionEntry('plus.google.com'), createExceptionEntry({url: 'plus.google.com', id: 5}),
]; ];
const passwordsSection = elementFactory.createPasswordsSection( const passwordsSection = elementFactory.createPasswordsSection(
......
...@@ -56,6 +56,7 @@ export class TestPasswordManagerProxy extends TestBrowserProxy { ...@@ -56,6 +56,7 @@ export class TestPasswordManagerProxy extends TestBrowserProxy {
'removeSavedPassword', 'removeSavedPassword',
'removeSavedPasswords', 'removeSavedPasswords',
'removeException', 'removeException',
'removeExceptions',
]); ]);
/** @private {!PasswordManagerExpectations} */ /** @private {!PasswordManagerExpectations} */
...@@ -141,6 +142,12 @@ export class TestPasswordManagerProxy extends TestBrowserProxy { ...@@ -141,6 +142,12 @@ export class TestPasswordManagerProxy extends TestBrowserProxy {
this.methodCalled('removeException', id); this.methodCalled('removeException', id);
} }
/** @override */
removeExceptions(ids) {
this.actual_.removed.exceptions += ids.length;
this.methodCalled('removeExceptions', ids);
}
/** @override */ /** @override */
requestPlaintextPassword(id, reason) { requestPlaintextPassword(id, reason) {
this.methodCalled('requestPlaintextPassword', {id, reason}); this.methodCalled('requestPlaintextPassword', {id, reason});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment