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

[Settings] Refactor: change createPasswordEntry(); set id's in tests

With the addition of new fields to the PasswordUiEntry type over time,
this helper function (used to create mock data for tests) was modified
to set default values to these fields, since they were not relevant for
most tests. Once deduplication happens in passwords_section though,
only duplicates will be allowed to share the value of frontendId, which
is problematic.

In order to avoid having several optional parameters in an fixed order,
this CL changes the signature to receive them in a key/value manner.
When no frontendId is passed, it assumes the value of the id. This
allows tests that do not care about duplicate entries to simply set the
id value.

Besides that, the CL also touches existing tests that did not set id
values (which was inconsistent with the production code anyway). This
will allow adding the deduplication functionality in crrev.com/c/2219503
without touching these tests, but rather focusing on adding tests for
the new behavior.

Bug: 1049141
Change-Id: If773b2684eda844dc025fea6255288215cd66bdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218055
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773095}
parent e4cb2d91
......@@ -46,7 +46,7 @@ document.body.appendChild(settingsUi);
whenReady.then(() => {
const fakePasswords = [];
for (let i = 0; i < 10; i++) {
fakePasswords.push(createPasswordEntry());
fakePasswords.push(createPasswordEntry({id: i, user: i.toString()}));
}
// Set list of passwords.
passwordManager.lastCallback.addSavedPasswordListChangedListener(
......
......@@ -181,7 +181,10 @@ suite('PasswordsAndForms', function() {
return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs);
const list = [createPasswordEntry(), createPasswordEntry()];
const list = [
createPasswordEntry({url: 'one.com', username: 'user1', id: 0}),
createPasswordEntry({url: 'two.com', username: 'user1', id: 1})
];
passwordManager.lastCallback.addSavedPasswordListChangedListener(list);
flush();
......
......@@ -11,10 +11,10 @@ import {createPasswordEntry} from 'chrome://test/settings/passwords_and_autofill
suite('MultiStorePasswordUiEntry', function() {
test('verifyIds', function() {
const deviceEntry = createPasswordEntry('g.com', 'user', 0);
deviceEntry.fromAccountStore = false;
const accountEntry = createPasswordEntry('g.com', 'user', 1);
accountEntry.fromAccountStore = true;
const deviceEntry = createPasswordEntry(
{url: 'g.com', username: 'user', id: 0, fromAccountStore: false});
const accountEntry = createPasswordEntry(
{url: 'g.com', username: 'user', id: 1, fromAccountStore: true});
const multiStoreDeviceEntry = new MultiStorePasswordUiEntry(deviceEntry);
expectTrue(multiStoreDeviceEntry.isPresentOnDevice());
......
......@@ -13,28 +13,41 @@ import {TestPasswordManagerProxy} from './test_password_manager_proxy.js';
// clang-format on
/**
* Creates a single item for the list of passwords.
* @param {string=} url
* @param {string=} username
* @param {number=} id
* Creates a single item for the list of passwords, in the format sent by the
* 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
* (|id| is unique). If no |frontendId| is passed, it is set to the same value
* as |id|.
* @param {{ url: (string|undefined),
* username: (string|undefined),
* federationText: (string|undefined),
* id: (number|undefined),
* frontendId: (number|undefined),
* fromAccountStore: (boolean|undefined)
* }=} params
* @return {chrome.passwordsPrivate.PasswordUiEntry}
*/
export function createPasswordEntry(url, username, id) {
export function createPasswordEntry(params) {
// Generate fake data if param is undefined.
url = url || patternMaker_('www.xxxxxx.com', 16);
username = username || patternMaker_('user_xxxxx', 16);
id = id || 0;
params = params || {};
params.url = params.url !== undefined ? params.url : 'www.foo.com';
params.username = params.username || 'user';
params.id = params.id !== undefined ? params.id : 42;
params.frontendId =
params.frontendId !== undefined ? params.frontendId : params.id;
params.fromAccountStore = params.fromAccountStore || false;
return {
urls: {
origin: 'http://' + url + '/login',
shown: url,
link: 'http://' + url + '/login',
origin: 'http://' + params.url + '/login',
shown: params.url,
link: 'http://' + params.url + '/login',
},
username: username,
id: id,
frontendId: id,
fromAccountStore: false,
username: params.username,
federationText: params.federationText,
id: params.id,
frontendId: params.frontendId,
fromAccountStore: params.fromAccountStore,
};
}
......
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