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

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: feedback + 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
Dan Beam 2017/02/14 06:18:06 nit: /** @constructor */
hcarmona 2017/02/14 18:38:44 Done.
132 function PasswordManagerExpectations() {}
Dan Beam 2017/02/14 06:18:06 nit: \n
hcarmona 2017/02/14 18:38:44 Done.
133 PasswordManagerExpectations.prototype = {
134 requested: {
135 passwords: 0,
136 exceptions: 0,
137 plaintextPassword: 0,
138 },
139
140 removed: {
141 passwords: 0,
142 exceptions: 0,
143 },
144
145 listening: {
146 passwords: 0,
147 exceptions: 0,
148 },
149 };
150
151 /**
152 * Test implementation
153 * @implements {PasswordManager}
154 * @constructor
155 */
156 function TestPasswordManager() {
157 this.actual_ = new PasswordManagerExpectations();
158 }
Dan Beam 2017/02/14 06:18:06 nit: \n
hcarmona 2017/02/14 18:38:44 Done.
159 TestPasswordManager.prototype = {
160 /** @override */
161 addSavedPasswordListChangedListener: function(listener) {
162 this.actual_.listening.passwords++;
163 this.lastCallback.addSavedPasswordListChangedListener = listener;
164 },
165
166 /** @override */
167 removeSavedPasswordListChangedListener: function(listener) {
168 this.actual_.listening.passwords--;
169 },
170
171 /** @override */
172 getSavedPasswordList: function(callback) {
173 this.actual_.requested.passwords++;
174 callback(this.data.passwords);
175 },
176
177 /** @override */
178 removeSavedPassword: function(loginPair) {
179 this.actual_.removed.passwords++;
180
181 if (this.onRemoveSavedPassword)
182 this.onRemoveSavedPassword(loginPair);
Dan Beam 2017/02/14 06:18:06 ok, if these only exist in tests, that's fine i gu
hcarmona 2017/02/14 18:38:44 Acknowledged.
183 },
184
185 /** @override */
186 addExceptionListChangedListener: function(listener) {
187 this.actual_.listening.exceptions++;
188 this.lastCallback.addExceptionListChangedListener = listener;
189 },
190
191 /** @override */
192 removeExceptionListChangedListener: function(listener) {
193 this.actual_.listening.exceptions--;
194 },
195
196 /** @override */
197 getExceptionList: function(callback) {
198 this.actual_.requested.exceptions++;
199 callback(this.data.exceptions);
200 },
201
202 /** @override */
203 removeException: function(exception) {
204 this.actual_.removed.exceptions++;
205
206 if (this.onRemoveException)
207 this.onRemoveException(exception);
208 },
209
210 /** @override */
211 getPlaintextPassword: function(loginPair, callback) {
212 this.actual_.requested.plaintextPassword++;
213 this.lastCallback.getPlaintextPassword = callback;
214 },
215
216 /**
217 * Verifies expectations.
218 * @param {!PasswordManagerExpectations} expected
219 */
220 assertExpectations: function(expected) {
221 var actual = this.actual_;
222
223 assertEquals(expected.requested.passwords, actual.requested.passwords);
224 assertEquals(expected.requested.exceptions, actual.requested.exceptions);
225 assertEquals(expected.requested.plaintextPassword,
226 actual.requested.plaintextPassword);
227
228 assertEquals(expected.removed.passwords, actual.removed.passwords);
229 assertEquals(expected.removed.exceptions, actual.removed.exceptions);
230
231 assertEquals(expected.listening.passwords, actual.listening.passwords);
232 assertEquals(expected.listening.exceptions, actual.listening.exceptions);
233 },
234
235 // Set these to have non-empty data.
236 data: {
237 passwords: [],
238 exceptions: [],
239 },
240
241 // Holds the last callbacks so they can be called when needed/
242 lastCallback: {
243 addSavedPasswordListChangedListener: null,
244 addExceptionListChangedListener: null,
245 getPlaintextPassword: null,
246 },
247 };
248
249 function AutofillManagerExpectations() {}
250 AutofillManagerExpectations.prototype = {
251 requested: {
252 addresses: 0,
253 creditCards: 0,
254 },
255
256 listening: {
257 addresses: 0,
258 creditCards: 0,
259 },
260 };
261
262 /**
263 * Test implementation
264 * @implements {AutofillManager}
265 * @constructor
266 */
267 function TestAutofillManager() {
268 this.actual_ = new AutofillManagerExpectations();
269 }
Dan Beam 2017/02/14 06:18:06 nit: \
hcarmona 2017/02/14 18:38:44 Done.
270 TestAutofillManager.prototype = {
271 /** @override */
272 addAddressListChangedListener: function(listener) {
273 this.actual_.listening.addresses++;
274 this.lastCallback.addAddressListChangedListener = listener;
275 },
276
277 /** @override */
278 removeAddressListChangedListener: function(listener) {
279 this.actual_.listening.addresses--;
280 },
281
282 /** @override */
283 getAddressList: function(callback) {
284 this.actual_.requested.addresses++;
285 callback(this.data.addresses);
286 },
287
288 /** @override */
289 addCreditCardListChangedListener: function(listener) {
290 this.actual_.listening.creditCards++;
291 this.lastCallback.addCreditCardListChangedListener = listener;
292 },
293
294 /** @override */
295 removeCreditCardListChangedListener: function(listener) {
296 this.actual_.listening.creditCards--;
297 },
298
299 /** @override */
300 getCreditCardList: function(callback) {
301 this.actual_.requested.creditCards++;
302 callback(this.data.creditCards);
303 },
304
305 /**
306 * Verifies expectations.
307 * @param {!AutofillManagerExpectations} expected
308 */
309 assertExpectations: function(expected) {
310 var actual = this.actual_;
311
312 assertEquals(expected.requested.addresses, actual.requested.addresses);
313 assertEquals(expected.requested.creditCards, actual.requested.creditCards);
314
315 assertEquals(expected.listening.addresses, actual.listening.addresses);
316 assertEquals(expected.listening.creditCards, actual.listening.creditCards);
317 },
318
319 // Set these to have non-empty data.
320 data: {
321 addresses: [],
322 creditCards: [],
323 },
324
325 // Holds the last callbacks so they can be called when needed.
326 lastCallback: {
327 addAddressListChangedListener: null,
328 addCreditCardListChangedListener: null,
329 },
330 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698