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

Side by Side Diff: chrome/test/data/webui/settings/passwords_and_autofill_fake_data.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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Used to create fake data for both passwords and autofill. 6 * Used to create fake data for both passwords and autofill.
7 * These sections are related, so it made sense to share this. 7 * These sections are related, so it made sense to share this.
8 */ 8 */
9
9 function FakeDataMaker() {} 10 function FakeDataMaker() {}
10 /** 11 /**
11 * Creates a single item for the list of passwords. 12 * Creates a single item for the list of passwords.
12 * @param {string|undefined} url 13 * @param {string|undefined} url
13 * @param {string|undefined} username 14 * @param {string|undefined} username
14 * @param {number|undefined} passwordLength 15 * @param {number|undefined} passwordLength
15 * @return {chrome.passwordsPrivate.PasswordUiEntry} 16 * @return {chrome.passwordsPrivate.PasswordUiEntry}
16 */ 17 */
17 FakeDataMaker.passwordEntry = function(url, username, passwordLength) { 18 FakeDataMaker.passwordEntry = function(url, username, passwordLength) {
18 // Generate fake data if param is undefined. 19 // Generate fake data if param is undefined.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 * @param {string} pattern The pattern that should be used as an input. 121 * @param {string} pattern The pattern that should be used as an input.
121 * @param {number} base The number base. ie: 16 for hex or 10 for decimal. 122 * @param {number} base The number base. ie: 16 for hex or 10 for decimal.
122 * @return {string} 123 * @return {string}
123 * @private 124 * @private
124 */ 125 */
125 FakeDataMaker.patternMaker_ = function(pattern, base) { 126 FakeDataMaker.patternMaker_ = function(pattern, base) {
126 return pattern.replace(/x/g, function() { 127 return pattern.replace(/x/g, function() {
127 return Math.floor(Math.random() * base).toString(base); 128 return Math.floor(Math.random() * base).toString(base);
128 }); 129 });
129 }; 130 };
131
132 /** @constructor */
133 function PasswordManagerExpectations() {}
134
135 PasswordManagerExpectations.prototype = {
136 requested: {
dpapad 2017/02/14 19:00:10 Why are those defined on the prototype? Can we mov
Dan Beam 2017/02/14 19:33:23 fwiw, this is saner and safer
hcarmona 2017/02/14 20:34:30 Done. Had to update |PasswordsAndFormsBrowserTest|
137 passwords: 0,
138 exceptions: 0,
139 plaintextPassword: 0,
140 },
141
142 removed: {
143 passwords: 0,
144 exceptions: 0,
145 },
146
147 listening: {
148 passwords: 0,
149 exceptions: 0,
150 },
151 };
152
153 /**
154 * Test implementation
155 * @implements {PasswordManager}
156 * @constructor
157 */
158 function TestPasswordManager() {
159 this.actual_ = new PasswordManagerExpectations();
160 }
161
162 TestPasswordManager.prototype = {
163 /** @override */
164 addSavedPasswordListChangedListener: function(listener) {
165 this.actual_.listening.passwords++;
166 this.lastCallback.addSavedPasswordListChangedListener = listener;
167 },
168
169 /** @override */
170 removeSavedPasswordListChangedListener: function(listener) {
171 this.actual_.listening.passwords--;
172 },
173
174 /** @override */
175 getSavedPasswordList: function(callback) {
176 this.actual_.requested.passwords++;
177 callback(this.data.passwords);
178 },
179
180 /** @override */
181 removeSavedPassword: function(loginPair) {
182 this.actual_.removed.passwords++;
183
184 if (this.onRemoveSavedPassword)
185 this.onRemoveSavedPassword(loginPair);
186 },
187
188 /** @override */
189 addExceptionListChangedListener: function(listener) {
190 this.actual_.listening.exceptions++;
191 this.lastCallback.addExceptionListChangedListener = listener;
192 },
193
194 /** @override */
195 removeExceptionListChangedListener: function(listener) {
196 this.actual_.listening.exceptions--;
197 },
198
199 /** @override */
200 getExceptionList: function(callback) {
201 this.actual_.requested.exceptions++;
202 callback(this.data.exceptions);
203 },
204
205 /** @override */
206 removeException: function(exception) {
207 this.actual_.removed.exceptions++;
208
209 if (this.onRemoveException)
210 this.onRemoveException(exception);
211 },
212
213 /** @override */
214 getPlaintextPassword: function(loginPair, callback) {
215 this.actual_.requested.plaintextPassword++;
216 this.lastCallback.getPlaintextPassword = callback;
217 },
218
219 /**
220 * Verifies expectations.
221 * @param {!PasswordManagerExpectations} expected
222 */
223 assertExpectations: function(expected) {
224 var actual = this.actual_;
225
226 assertEquals(expected.requested.passwords, actual.requested.passwords);
227 assertEquals(expected.requested.exceptions, actual.requested.exceptions);
228 assertEquals(expected.requested.plaintextPassword,
229 actual.requested.plaintextPassword);
230
231 assertEquals(expected.removed.passwords, actual.removed.passwords);
232 assertEquals(expected.removed.exceptions, actual.removed.exceptions);
233
234 assertEquals(expected.listening.passwords, actual.listening.passwords);
235 assertEquals(expected.listening.exceptions, actual.listening.exceptions);
236 },
237
238 // Set these to have non-empty data.
239 data: {
240 passwords: [],
241 exceptions: [],
242 },
243
244 // Holds the last callbacks so they can be called when needed/
245 lastCallback: {
dpapad 2017/02/14 19:00:10 Can |data| and |lastCallback| be declared in the c
hcarmona 2017/02/14 20:34:30 Done.
246 addSavedPasswordListChangedListener: null,
247 addExceptionListChangedListener: null,
248 getPlaintextPassword: null,
249 },
250 };
251
252 function AutofillManagerExpectations() {}
253 AutofillManagerExpectations.prototype = {
254 requested: {
dpapad 2017/02/14 19:00:10 Same here.
hcarmona 2017/02/14 20:34:30 Done.
255 addresses: 0,
256 creditCards: 0,
257 },
258
259 listening: {
260 addresses: 0,
261 creditCards: 0,
262 },
263 };
264
265 /**
266 * Test implementation
267 * @implements {AutofillManager}
268 * @constructor
269 */
270 function TestAutofillManager() {
271 this.actual_ = new AutofillManagerExpectations();
272 }
273
274 TestAutofillManager.prototype = {
275 /** @override */
276 addAddressListChangedListener: function(listener) {
277 this.actual_.listening.addresses++;
278 this.lastCallback.addAddressListChangedListener = listener;
279 },
280
281 /** @override */
282 removeAddressListChangedListener: function(listener) {
283 this.actual_.listening.addresses--;
284 },
285
286 /** @override */
287 getAddressList: function(callback) {
288 this.actual_.requested.addresses++;
289 callback(this.data.addresses);
290 },
291
292 /** @override */
293 addCreditCardListChangedListener: function(listener) {
294 this.actual_.listening.creditCards++;
295 this.lastCallback.addCreditCardListChangedListener = listener;
296 },
297
298 /** @override */
299 removeCreditCardListChangedListener: function(listener) {
300 this.actual_.listening.creditCards--;
301 },
302
303 /** @override */
304 getCreditCardList: function(callback) {
305 this.actual_.requested.creditCards++;
306 callback(this.data.creditCards);
307 },
308
309 /**
310 * Verifies expectations.
311 * @param {!AutofillManagerExpectations} expected
312 */
313 assertExpectations: function(expected) {
314 var actual = this.actual_;
315
316 assertEquals(expected.requested.addresses, actual.requested.addresses);
317 assertEquals(expected.requested.creditCards, actual.requested.creditCards);
318
319 assertEquals(expected.listening.addresses, actual.listening.addresses);
320 assertEquals(expected.listening.creditCards, actual.listening.creditCards);
321 },
322
323 // Set these to have non-empty data.
324 data: {
325 addresses: [],
326 creditCards: [],
327 },
328
329 // Holds the last callbacks so they can be called when needed.
330 lastCallback: {
331 addAddressListChangedListener: null,
332 addCreditCardListChangedListener: null,
333 },
334 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698