Commit 3f2d86f2 authored by Jan Wilken Doerrie's avatar Jan Wilken Doerrie Committed by Commit Bot

[Pwd List] Fix Display Of Passwords

This change fixes a bug when re-rendering the list of passwords after a
password store mutation. This bug could give the impression that a wrong
password was deleted.

Bug: 862119
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I13f42a18567f84e191e99a2beb6d00ee7e82e682
Reviewed-on: https://chromium-review.googlesource.com/1138233Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575474}
parent 31d87170
...@@ -151,13 +151,14 @@ Polymer({ ...@@ -151,13 +151,14 @@ Polymer({
/** @override */ /** @override */
attached: function() { attached: function() {
// Create listener functions. // Create listener functions.
const setSavedPasswordsListener = list => this.updateList( const setSavedPasswordsListener = list =>
'savedPasswords', this.updateList('savedPasswords', item => {
item => `${item.entry.index}_${item.entry.loginPair.urls.shown}`, return item.entry.loginPair.urls.origin + '_' +
list.map(entry => ({ item.entry.loginPair.username;
entry: entry, }, list.map(entry => ({
password: '', entry: entry,
}))); password: '',
})));
const setPasswordExceptionsListener = list => { const setPasswordExceptionsListener = list => {
this.passwordExceptions = list; this.passwordExceptions = list;
......
...@@ -11,18 +11,18 @@ function FakeDataMaker() {} ...@@ -11,18 +11,18 @@ function FakeDataMaker() {}
/** /**
* Creates a single item for the list of passwords. * Creates a single item for the list of passwords.
* @param {string|undefined} url * @param {string=} url
* @param {string|undefined} username * @param {string=} username
* @param {number|undefined} passwordLength * @param {number=} passwordLength
* @param {number=} index
* @return {chrome.passwordsPrivate.PasswordUiEntry} * @return {chrome.passwordsPrivate.PasswordUiEntry}
*/ */
FakeDataMaker.passwordEntry = function(url, username, passwordLength) { FakeDataMaker.passwordEntry = function(url, username, passwordLength, index) {
// Generate fake data if param is undefined. // Generate fake data if param is undefined.
url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16); url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16);
username = username || FakeDataMaker.patternMaker_('user_xxxxx', 16); username = username || FakeDataMaker.patternMaker_('user_xxxxx', 16);
passwordLength = passwordLength || Math.floor(Math.random() * 15) + 3; passwordLength = passwordLength || Math.floor(Math.random() * 15) + 3;
entryIndex = -1; index = index || 0;
exceptionIndex = -1;
return { return {
loginPair: { loginPair: {
...@@ -34,24 +34,26 @@ FakeDataMaker.passwordEntry = function(url, username, passwordLength) { ...@@ -34,24 +34,26 @@ FakeDataMaker.passwordEntry = function(url, username, passwordLength) {
username: username, username: username,
}, },
numCharactersInPassword: passwordLength, numCharactersInPassword: passwordLength,
index: ++entryIndex, index: index,
}; };
}; };
/** /**
* Creates a single item for the list of password exceptions. * Creates a single item for the list of password exceptions.
* @param {string|undefined} url * @param {string=} url
* @param {number=} index
* @return {chrome.passwordsPrivate.ExceptionEntry} * @return {chrome.passwordsPrivate.ExceptionEntry}
*/ */
FakeDataMaker.exceptionEntry = function(url) { FakeDataMaker.exceptionEntry = function(url, index) {
url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16); url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16);
index = index || 0;
return { return {
urls: { urls: {
origin: 'http://' + url + '/login', origin: 'http://' + url + '/login',
shown: url, shown: url,
link: 'http://' + url + '/login', link: 'http://' + url + '/login',
}, },
index: ++exceptionIndex, index: index,
}; };
}; };
......
...@@ -59,11 +59,11 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { ...@@ -59,11 +59,11 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() {
*/ */
function validatePasswordList(listElement, passwordList) { function validatePasswordList(listElement, passwordList) {
assertEquals(passwordList.length, listElement.items.length); assertEquals(passwordList.length, listElement.items.length);
if (passwordList.length > 0) { for (let index = 0; index < passwordList.length; ++index) {
// The first child is a template, skip and get the real 'first child'. // The first child is a template, skip and get the real 'first child'.
const node = Polymer.dom(listElement).children[1]; const node = Polymer.dom(listElement).children[index + 1];
assert(node); assert(node);
const passwordInfo = passwordList[0]; const passwordInfo = passwordList[index];
assertEquals( assertEquals(
passwordInfo.loginPair.urls.shown, passwordInfo.loginPair.urls.shown,
node.$$('#originUrl').textContent.trim()); node.$$('#originUrl').textContent.trim());
...@@ -290,6 +290,32 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { ...@@ -290,6 +290,32 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() {
validatePasswordList(passwordsSection.$.passwordList, passwordList); validatePasswordList(passwordsSection.$.passwordList, passwordList);
}); });
// Test verifies that removing one out of two passwords for the same website
// will update the elements.
test('verifyPasswordListRemoveSameWebsite', function() {
const passwordsSection = createPasswordsSection(passwordManager, [], []);
// Set-up initial list.
let passwordList = [
FakeDataMaker.passwordEntry('website.com', 'mario', 1, 0),
FakeDataMaker.passwordEntry('website.com', 'luigi', 7, 1)
];
passwordManager.lastCallback.addSavedPasswordListChangedListener(
passwordList);
Polymer.dom.flush();
validatePasswordList(passwordsSection.$.passwordList, passwordList);
// Simulate '(website.com, mario)' being removed from the list.
passwordList =
[FakeDataMaker.passwordEntry('website.com', 'luigi', 7, 0)];
passwordManager.lastCallback.addSavedPasswordListChangedListener(
passwordList);
Polymer.dom.flush();
validatePasswordList(passwordsSection.$.passwordList, passwordList);
});
// 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 passwords. // event. Does not actually remove any passwords.
test('verifyPasswordItemRemoveButton', function(done) { test('verifyPasswordItemRemoveButton', function(done) {
......
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