Commit 052f2656 authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

[Password Manager] Move PasswordManager proxy to a separate file

The new PasswordManagerProxy class is an abstraction over
chrome.passwordsPrivate, used to test the passsword settings page
bahaviour.

Bug: 802352
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I12fba7cfdb4405477adf49ccb64f64d4b30a3d93
Reviewed-on: https://chromium-review.googlesource.com/883621Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549259}
parent ca8ad983
......@@ -57,6 +57,14 @@
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'password_manager_proxy',
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(EXTERNS_GYP):passwords_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'passwords_section',
'dependencies': [
......@@ -69,6 +77,7 @@
'<(EXTERNS_GYP):passwords_private',
'password_edit_dialog',
'password_list_item',
'password_manager_proxy',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
......
<link rel="import" href="chrome://resources/html/polymer.html">
<script src="password_manager_proxy.js"></script>
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview PasswordManagerProxy is an abstraction over
* chrome.passwordsPrivate which facilitates testing.
*/
/**
* Interface for all callbacks to the password API.
* @interface
*/
class PasswordManagerProxy {
/**
* Add an observer to the list of saved passwords.
* @param {function(!Array<!PasswordManagerProxy.PasswordUiEntry>):void}
* listener
*/
addSavedPasswordListChangedListener(listener) {}
/**
* Remove an observer from the list of saved passwords.
* @param {function(!Array<!PasswordManagerProxy.PasswordUiEntry>):void}
* listener
*/
removeSavedPasswordListChangedListener(listener) {}
/**
* Request the list of saved passwords.
* @param {function(!Array<!PasswordManagerProxy.PasswordUiEntry>):void}
* callback
*/
getSavedPasswordList(callback) {}
/**
* Should remove the saved password and notify that the list has changed.
* @param {number} index The index for the password entry being removed.
* No-op if |index| is not in the list.
*/
removeSavedPassword(index) {}
/**
* Add an observer to the list of password exceptions.
* @param {function(!Array<!PasswordManagerProxy.ExceptionEntry>):void}
* listener
*/
addExceptionListChangedListener(listener) {}
/**
* Remove an observer from the list of password exceptions.
* @param {function(!Array<!PasswordManagerProxy.ExceptionEntry>):void}
* listener
*/
removeExceptionListChangedListener(listener) {}
/**
* Request the list of password exceptions.
* @param {function(!Array<!PasswordManagerProxy.ExceptionEntry>):void}
* callback
*/
getExceptionList(callback) {}
/**
* Should remove the password exception and notify that the list has changed.
* @param {number} index The index for the exception url entry being removed.
* No-op if |index| is not in the list.
*/
removeException(index) {}
/**
* Should undo the last saved password or exception removal and notify that
* the list has changed.
*/
undoRemoveSavedPasswordOrException() {}
/**
* Gets the saved password for a given login pair.
* @param {number} index The index for password entry that should be
* retrieved. No-op if |index| is not in the list.
* @param {function(!PasswordManagerProxy.PlaintextPasswordEvent):void}
* callback
*/
getPlaintextPassword(index, callback) {}
/**
* Triggers the dialogue for importing passwords.
*/
importPasswords() {}
/**
* Triggers the dialogue for exporting passwords.
* @param {function():void} callback
*/
exportPasswords(callback) {}
/**
* Queries the status of any ongoing export.
* @param {function(!PasswordManagerProxy.ExportProgressStatus):void}
* callback
*/
requestExportProgressStatus(callback) {}
/**
* Add an observer to the export progress.
* @param {function(!PasswordManagerProxy.PasswordExportProgress):void}
* listener
*/
addPasswordsFileExportProgressListener(listener) {}
/**
* Remove an observer from the export progress.
* @param {function(!PasswordManagerProxy.PasswordExportProgress):void}
* listener
*/
removePasswordsFileExportProgressListener(listener) {}
}
/** @typedef {chrome.passwordsPrivate.PasswordUiEntry} */
PasswordManagerProxy.PasswordUiEntry;
/** @typedef {chrome.passwordsPrivate.LoginPair} */
PasswordManagerProxy.LoginPair;
/** @typedef {chrome.passwordsPrivate.ExceptionEntry} */
PasswordManagerProxy.ExceptionEntry;
/** @typedef {chrome.passwordsPrivate.PlaintextPasswordEventParameters} */
PasswordManagerProxy.PlaintextPasswordEvent;
/**
* @typedef {{ entry: !PasswordManagerProxy.PasswordUiEntry, password: string }}
*/
PasswordManagerProxy.UiEntryWithPassword;
/** @typedef {chrome.passwordsPrivate.PasswordExportProgress} */
PasswordManagerProxy.PasswordExportProgress;
/** @typedef {chrome.passwordsPrivate.ExportProgressStatus} */
PasswordManagerProxy.ExportProgressStatus;
/**
* Implementation that accesses the private API.
* @implements {PasswordManagerProxy}
*/
class PasswordManagerImpl {
/** @override */
addSavedPasswordListChangedListener(listener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener);
}
/** @override */
removeSavedPasswordListChangedListener(listener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener(
listener);
}
/** @override */
getSavedPasswordList(callback) {
chrome.passwordsPrivate.getSavedPasswordList(callback);
}
/** @override */
removeSavedPassword(index) {
chrome.passwordsPrivate.removeSavedPassword(index);
}
/** @override */
addExceptionListChangedListener(listener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener(
listener);
}
/** @override */
removeExceptionListChangedListener(listener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener(
listener);
}
/** @override */
getExceptionList(callback) {
chrome.passwordsPrivate.getPasswordExceptionList(callback);
}
/** @override */
removeException(index) {
chrome.passwordsPrivate.removePasswordException(index);
}
/** @override */
undoRemoveSavedPasswordOrException() {
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
}
/** @override */
getPlaintextPassword(index, callback) {
const listener = function(reply) {
// Only handle the reply for our loginPair request.
if (reply.index == index) {
chrome.passwordsPrivate.onPlaintextPasswordRetrieved.removeListener(
listener);
callback(reply);
}
};
chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(listener);
chrome.passwordsPrivate.requestPlaintextPassword(index);
}
/** @override */
importPasswords() {
chrome.passwordsPrivate.importPasswords();
}
/** @override */
exportPasswords(callback) {
chrome.passwordsPrivate.exportPasswords(callback);
}
/** @override */
requestExportProgressStatus(callback) {
chrome.passwordsPrivate.requestExportProgressStatus(callback);
}
/** @override */
addPasswordsFileExportProgressListener(listener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.addListener(listener);
}
/** @override */
removePasswordsFileExportProgressListener(listener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.removeListener(
listener);
}
}
cr.addSingletonGetter(PasswordManagerImpl);
......@@ -50,12 +50,12 @@ Polymer({
/**
* The interface for callbacks to the browser.
* Defined in passwords_section.js
* @type {PasswordManager}
* @type {PasswordManagerProxy}
* @private
*/
passwordManager_: null,
/** @private {function(!PasswordManager.PasswordExportProgress):void} */
/** @private {function(!PasswordManagerProxy.PasswordExportProgress):void} */
onPasswordsFileExportProgressListener_: null,
/**
......@@ -77,7 +77,7 @@ Polymer({
/**
* We display the progress bar for at least |progressBarBlockMs|. If progress
* is achieved earlier, we store the update here and consume it later.
* @private {?PasswordManager.PasswordExportProgress}
* @private {?PasswordManagerProxy.PasswordExportProgress}
*/
delayedProgress_: null,
......@@ -104,7 +104,7 @@ Polymer({
/**
* Handles an export progress event by changing the visible dialog or caching
* the event for later consumption.
* @param {!PasswordManager.PasswordExportProgress} progress
* @param {!PasswordManagerProxy.PasswordExportProgress} progress
* @private
*/
onPasswordsFileExportProgress_(progress) {
......@@ -183,7 +183,7 @@ Polymer({
/**
* Prepares and displays the appropriate view (with delay, if necessary).
* @param {!PasswordManager.PasswordExportProgress} progress
* @param {!PasswordManagerProxy.PasswordExportProgress} progress
* @private
*/
processProgress_(progress) {
......
......@@ -18,6 +18,7 @@
<link rel="import" href="passwords_export_dialog.html">
<link rel="import" href="passwords_shared_css.html">
<link rel="import" href="password_list_item.html">
<link rel="import" href="password_manager_proxy.html">
<dom-module id="passwords-section">
<template>
......
......@@ -8,234 +8,6 @@
* save any passwords.
*/
/**
* Interface for all callbacks to the password API.
* TODO(crbug.com/802352) Move the PasswordManager proxy to a separate
* location.
* @interface
*/
class PasswordManager {
/**
* Add an observer to the list of saved passwords.
* @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener
*/
addSavedPasswordListChangedListener(listener) {}
/**
* Remove an observer from the list of saved passwords.
* @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener
*/
removeSavedPasswordListChangedListener(listener) {}
/**
* Request the list of saved passwords.
* @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} callback
*/
getSavedPasswordList(callback) {}
/**
* Should remove the saved password and notify that the list has changed.
* @param {number} index The index for the password entry being removed.
* No-op if |index| is not in the list.
*/
removeSavedPassword(index) {}
/**
* Add an observer to the list of password exceptions.
* @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener
*/
addExceptionListChangedListener(listener) {}
/**
* Remove an observer from the list of password exceptions.
* @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener
*/
removeExceptionListChangedListener(listener) {}
/**
* Request the list of password exceptions.
* @param {function(!Array<!PasswordManager.ExceptionEntry>):void} callback
*/
getExceptionList(callback) {}
/**
* Should remove the password exception and notify that the list has changed.
* @param {number} index The index for the exception url entry being removed.
* No-op if |index| is not in the list.
*/
removeException(index) {}
/**
* Should undo the last saved password or exception removal and notify that
* the list has changed.
*/
undoRemoveSavedPasswordOrException() {}
/**
* Gets the saved password for a given login pair.
* @param {number} index The index for password entry that should be
* retrieved. No-op if |index| is not in the list.
* @param {function(!PasswordManager.PlaintextPasswordEvent):void} callback
*/
getPlaintextPassword(index, callback) {}
/**
* Triggers the dialogue for importing passwords.
*/
importPasswords() {}
/**
* Triggers the dialogue for exporting passwords.
* @param {function():void} callback
*/
exportPasswords(callback) {}
/**
* Cancels the ongoing export of passwords.
*/
cancelExportPasswords(callback) {}
/**
* Queries the status of any ongoing export.
* @param {function(!PasswordManager.ExportProgressStatus):void} callback
*/
requestExportProgressStatus(callback) {}
/**
* Add an observer to the export progress.
* @param {function(!PasswordManager.PasswordExportProgress):void} listener
*/
addPasswordsFileExportProgressListener(listener) {}
/**
* Remove an observer from the export progress.
* @param {function(!PasswordManager.PasswordExportProgress):void} listener
*/
removePasswordsFileExportProgressListener(listener) {}
}
/** @typedef {chrome.passwordsPrivate.PasswordUiEntry} */
PasswordManager.PasswordUiEntry;
/** @typedef {chrome.passwordsPrivate.LoginPair} */
PasswordManager.LoginPair;
/** @typedef {chrome.passwordsPrivate.ExceptionEntry} */
PasswordManager.ExceptionEntry;
/** @typedef {chrome.passwordsPrivate.PlaintextPasswordEventParameters} */
PasswordManager.PlaintextPasswordEvent;
/** @typedef {{ entry: !PasswordManager.PasswordUiEntry, password: string }} */
PasswordManager.UiEntryWithPassword;
/** @typedef {chrome.passwordsPrivate.PasswordExportProgress} */
PasswordManager.PasswordExportProgress;
/** @typedef {chrome.passwordsPrivate.ExportProgressStatus} */
PasswordManager.ExportProgressStatus;
/**
* Implementation that accesses the private API.
* @implements {PasswordManager}
*/
class PasswordManagerImpl {
/** @override */
addSavedPasswordListChangedListener(listener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener);
}
/** @override */
removeSavedPasswordListChangedListener(listener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener(
listener);
}
/** @override */
getSavedPasswordList(callback) {
chrome.passwordsPrivate.getSavedPasswordList(callback);
}
/** @override */
removeSavedPassword(index) {
chrome.passwordsPrivate.removeSavedPassword(index);
}
/** @override */
addExceptionListChangedListener(listener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener(
listener);
}
/** @override */
removeExceptionListChangedListener(listener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener(
listener);
}
/** @override */
getExceptionList(callback) {
chrome.passwordsPrivate.getPasswordExceptionList(callback);
}
/** @override */
removeException(index) {
chrome.passwordsPrivate.removePasswordException(index);
}
/** @override */
undoRemoveSavedPasswordOrException() {
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
}
/** @override */
getPlaintextPassword(index, callback) {
const listener = function(reply) {
// Only handle the reply for our loginPair request.
if (reply.index == index) {
chrome.passwordsPrivate.onPlaintextPasswordRetrieved.removeListener(
listener);
callback(reply);
}
};
chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(listener);
chrome.passwordsPrivate.requestPlaintextPassword(index);
}
/** @override */
importPasswords() {
chrome.passwordsPrivate.importPasswords();
}
/** @override */
exportPasswords(callback) {
chrome.passwordsPrivate.exportPasswords(callback);
}
/** @override */
cancelExportPasswords() {
chrome.passwordsPrivate.cancelExportPasswords();
}
/** @override */
requestExportProgressStatus(callback) {
chrome.passwordsPrivate.requestExportProgressStatus(callback);
}
/** @override */
addPasswordsFileExportProgressListener(listener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.addListener(listener);
}
/** @override */
removePasswordsFileExportProgressListener(listener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.removeListener(
listener);
}
}
cr.addSingletonGetter(PasswordManagerImpl);
/** @typedef {!{model: !{item: !chrome.passwordsPrivate.PasswordUiEntry}}} */
let PasswordUiEntryEvent;
......@@ -263,13 +35,13 @@ Polymer({
/**
* An array of passwords to display.
* @type {!Array<!PasswordManager.PasswordUiEntry>}
* @type {!Array<!PasswordManagerProxy.PasswordUiEntry>}
*/
savedPasswords: Array,
/**
* An array of sites to display.
* @type {!Array<!PasswordManager.ExceptionEntry>}
* @type {!Array<!PasswordManagerProxy.ExceptionEntry>}
*/
passwordExceptions: Array,
......@@ -325,7 +97,7 @@ Polymer({
value: '',
},
/** @private {!PasswordManager.PasswordUiEntry} */
/** @private {!PasswordManagerProxy.PasswordUiEntry} */
lastFocused_: Object,
},
......@@ -352,19 +124,19 @@ Polymer({
activeDialogAnchor_: null,
/**
* @type {PasswordManager}
* @type {PasswordManagerProxy}
* @private
*/
passwordManager_: null,
/**
* @type {?function(!Array<PasswordManager.PasswordUiEntry>):void}
* @type {?function(!Array<PasswordManagerProxy.PasswordUiEntry>):void}
* @private
*/
setSavedPasswordsListener_: null,
/**
* @type {?function(!Array<PasswordManager.ExceptionEntry>):void}
* @type {?function(!Array<PasswordManagerProxy.ExceptionEntry>):void}
* @private
*/
setPasswordExceptionsListener_: null,
......@@ -409,11 +181,15 @@ Polymer({
/** @override */
detached: function() {
this.passwordManager_.removeSavedPasswordListChangedListener(
/** @type {function(!Array<PasswordManager.PasswordUiEntry>):void} */ (
this.setSavedPasswordsListener_));
/**
* @type {function(!Array<PasswordManagerProxy.PasswordUiEntry>):void}
*/
(this.setSavedPasswordsListener_));
this.passwordManager_.removeExceptionListChangedListener(
/** @type {function(!Array<PasswordManager.ExceptionEntry>):void} */ (
this.setPasswordExceptionsListener_));
/**
* @type {function(!Array<PasswordManagerProxy.ExceptionEntry>):void}
*/
(this.setPasswordExceptionsListener_));
if (this.$.undoToast.open)
this.$.undoToast.hide();
......@@ -442,9 +218,9 @@ Polymer({
},
/**
* @param {!Array<!PasswordManager.UiEntryWithPassword>} savedPasswords
* @param {!Array<!PasswordManagerProxy.UiEntryWithPassword>} savedPasswords
* @param {string} filter
* @return {!Array<!PasswordManager.UiEntryWithPassword>}
* @return {!Array<!PasswordManagerProxy.UiEntryWithPassword>}
* @private
*/
getFilteredPasswords_: function(savedPasswords, filter) {
......@@ -591,7 +367,7 @@ Polymer({
/**
* @private
* @param {!Array<!PasswordManager.PasswordUiEntry>} savedPasswords
* @param {!Array<!PasswordManagerProxy.PasswordUiEntry>} savedPasswords
*/
showExportPasswordsAndReady_: function(savedPasswords) {
return loadTimeData.valueExists('showExportPasswords') &&
......
......@@ -723,6 +723,12 @@
<structure name="IDR_SETTINGS_PASSWORD_LIST_ITEM_JS"
file="passwords_and_forms_page/password_list_item.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_PASSWORD_MANAGER_PROXY_HTML"
file="passwords_and_forms_page/password_manager_proxy.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_PASSWORD_MANAGER_PROXY_JS"
file="passwords_and_forms_page/password_manager_proxy.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_PASSWORDS_SECTION_HTML"
file="passwords_and_forms_page/passwords_section.html"
type="chrome_html" />
......
......@@ -120,7 +120,7 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() {
/**
* Helper method used to create a password section for the given lists.
* @param {!PasswordManager} passwordManager
* @param {!PasswordManagerProxy} passwordManager
* @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList
* @param {!Array<!chrome.passwordsPrivate.ExceptionEntry>} exceptionList
* @return {!Object}
......@@ -128,7 +128,7 @@ TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() {
*/
function createPasswordsSection(passwordManager, passwordList,
exceptionList) {
// Override the PasswordManager data for testing.
// Override the PasswordManagerProxy data for testing.
passwordManager.data.passwords = passwordList;
passwordManager.data.exceptions = exceptionList;
......
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