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

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

Powered by Google App Engine
This is Rietveld 408576698