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

Side by Side Diff: chrome/test/data/webui/settings/passwords_and_forms_browsertest.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 /** @fileoverview Runs the Polymer Passwords and Forms tests. */ 5 /** @fileoverview Runs the Polymer Passwords and Forms tests. */
6 6
7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */
8 var ROOT_PATH = '../../../../../'; 8 var ROOT_PATH = '../../../../../';
9 9
10 // Polymer BrowserTest fixture. 10 // Polymer BrowserTest fixture.
11 GEN_INCLUDE( 11 GEN_INCLUDE(
12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); 12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
13 13
14 // Fake data generator. 14 // Fake data generator.
15 GEN_INCLUDE([ROOT_PATH + 15 GEN_INCLUDE([ROOT_PATH +
16 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']); 16 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']);
17 17
18 function PasswordManagerExpectations() {};
19 PasswordManagerExpectations.prototype = {
20 requested: {
21 passwords: 0,
22 exceptions: 0,
23 plaintextPassword: 0,
24 },
25
26 removed: {
27 passwords: 0,
28 exceptions: 0,
29 },
30
31 listening: {
32 passwords: 0,
33 exceptions: 0,
34 },
35 };
36
37 /**
38 * Test implementation
39 * @implements {PasswordManager}
40 * @constructor
41 */
42 function TestPasswordManager() {
43 this.actual_ = new PasswordManagerExpectations();
44 };
45 TestPasswordManager.prototype = {
46 /** @override */
47 addSavedPasswordListChangedListener: function(listener) {
48 this.actual_.listening.passwords++;
49 this.lastCallback.addSavedPasswordListChangedListener = listener;
50 },
51
52 /** @override */
53 removeSavedPasswordListChangedListener: function(listener) {
54 this.actual_.listening.passwords--;
55 },
56
57 /** @override */
58 getSavedPasswordList: function(callback) {
59 this.actual_.requested.passwords++;
60 callback(this.data.passwords);
61 },
62
63 /** @override */
64 removeSavedPassword: function(loginPair) {
65 this.actual_.removed.passwords++;
66 },
67
68 /** @override */
69 addExceptionListChangedListener: function(listener) {
70 this.actual_.listening.exceptions++;
71 this.lastCallback.addExceptionListChangedListener = listener;
72 },
73
74 /** @override */
75 removeExceptionListChangedListener: function(listener) {
76 this.actual_.listening.exceptions--;
77 },
78
79 /** @override */
80 getExceptionList: function(callback) {
81 this.actual_.requested.exceptions++;
82 callback(this.data.exceptions);
83 },
84
85 /** @override */
86 removeException: function(exception) {
87 this.actual_.removed.exceptions++;
88 },
89
90 /** @override */
91 getPlaintextPassword: function(loginPair, callback) {
92 this.actual_.requested.plaintextPassword++;
93 this.lastCallback.getPlaintextPassword = callback;
94 },
95
96 /**
97 * Verifies expectations.
98 * @param {!PasswordManagerExpectations} expected
99 */
100 assertExpectations: function(expected) {
101 var actual = this.actual_;
102
103 assertEquals(expected.requested.passwords, actual.requested.passwords);
104 assertEquals(expected.requested.exceptions, actual.requested.exceptions);
105 assertEquals(expected.requested.plaintextPassword,
106 actual.requested.plaintextPassword);
107
108 assertEquals(expected.removed.passwords, actual.removed.passwords);
109 assertEquals(expected.removed.exceptions, actual.removed.exceptions);
110
111 assertEquals(expected.listening.passwords, actual.listening.passwords);
112 assertEquals(expected.listening.exceptions, actual.listening.exceptions);
113 },
114
115 // Set these to have non-empty data.
116 data: {
117 passwords: [],
118 exceptions: [],
119 },
120
121 // Holds the last callbacks so they can be called when needed/
122 lastCallback: {
123 addSavedPasswordListChangedListener: null,
124 addExceptionListChangedListener: null,
125 getPlaintextPassword: null,
126 },
127 };
128
129 function AutofillManagerExpectations() {};
130 AutofillManagerExpectations.prototype = {
131 requested: {
132 addresses: 0,
133 creditCards: 0,
134 },
135
136 listening: {
137 addresses: 0,
138 creditCards: 0,
139 },
140 };
141
142 /**
143 * Test implementation
144 * @implements {AutofillManager}
145 * @constructor
146 */
147 function TestAutofillManager() {
148 this.actual_ = new AutofillManagerExpectations();
149 };
150 TestAutofillManager.prototype = {
151 /** @override */
152 addAddressListChangedListener: function(listener) {
153 this.actual_.listening.addresses++;
154 this.lastCallback.addAddressListChangedListener = listener;
155 },
156
157 /** @override */
158 removeAddressListChangedListener: function(listener) {
159 this.actual_.listening.addresses--;
160 },
161
162 /** @override */
163 getAddressList: function(callback) {
164 this.actual_.requested.addresses++;
165 callback(this.data.addresses);
166 },
167
168 /** @override */
169 addCreditCardListChangedListener: function(listener) {
170 this.actual_.listening.creditCards++;
171 this.lastCallback.addCreditCardListChangedListener = listener;
172 },
173
174 /** @override */
175 removeCreditCardListChangedListener: function(listener) {
176 this.actual_.listening.creditCards--;
177 },
178
179 /** @override */
180 getCreditCardList: function(callback) {
181 this.actual_.requested.creditCards++;
182 callback(this.data.creditCards);
183 },
184
185 /**
186 * Verifies expectations.
187 * @param {!AutofillManagerExpectations} expected
188 */
189 assertExpectations: function(expected) {
190 var actual = this.actual_;
191
192 assertEquals(expected.requested.addresses, actual.requested.addresses);
193 assertEquals(expected.requested.creditCards, actual.requested.creditCards);
194
195 assertEquals(expected.listening.addresses, actual.listening.addresses);
196 assertEquals(expected.listening.creditCards, actual.listening.creditCards);
197 },
198
199 // Set these to have non-empty data.
200 data: {
201 addresses: [],
202 creditCards: [],
203 },
204
205 // Holds the last callbacks so they can be called when needed/
206 lastCallback: {
207 addAddressListChangedListener: null,
208 addCreditCardListChangedListener: null,
209 },
210 };
211
212 /** 18 /**
213 * @constructor 19 * @constructor
214 * @extends {PolymerTest} 20 * @extends {PolymerTest}
215 */ 21 */
216 function PasswordsAndFormsBrowserTest() {} 22 function PasswordsAndFormsBrowserTest() {}
217 23
218 PasswordsAndFormsBrowserTest.prototype = { 24 PasswordsAndFormsBrowserTest.prototype = {
219 __proto__: PolymerTest.prototype, 25 __proto__: PolymerTest.prototype,
220 26
221 /** @override */ 27 /** @override */
222 browsePreload: 'chrome://md-settings/passwords_and_forms_page/' + 28 browsePreload: 'chrome://md-settings/passwords_and_forms_page/' +
223 'passwords_and_forms_page.html', 29 'passwords_and_forms_page.html',
224 30
225 /** @override */ 31 /** @override */
226 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ 32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
227 '../fake_chrome_event.js', 33 '../fake_chrome_event.js',
228 'fake_settings_private.js', 34 'fake_settings_private.js',
229 ]), 35 ]),
230 36
231 /** @override */ 37 /** @override */
232 setUp: function() { 38 setUp: function() {
233 PolymerTest.prototype.setUp.call(this); 39 PolymerTest.prototype.setUp.call(this);
234 PolymerTest.clearBody(); 40 PolymerTest.clearBody();
235 41
236 // Test is run on an individual element that won't have a page language. 42 // Test is run on an individual element that won't have a page language.
237 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); 43 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
238 44
239 // Override the PasswordManagerImpl for testing. 45 // Override the PasswordManagerImpl for testing.
240 this.passwordManager = new TestPasswordManager(); 46 this.passwordManager = new TestPasswordManager();
241 PasswordManagerImpl.instance_ = this.passwordManager; 47 PasswordManagerImpl.instance_ = this.passwordManager;
242 48
243 // Override the AutofillManagerImpl for testing. 49 // Override the AutofillManagerImpl for testing.
244 this.autofillManager = new TestAutofillManager(); 50 this.autofillManager = new TestAutofillManager();
245 AutofillManagerImpl.instance_ = this.autofillManager; 51 AutofillManagerImpl.instance_ = this.autofillManager;
246 }, 52 },
247 53
248 /** 54 /**
249 * Creates a new passwords and forms element. 55 * Creates a new passwords and forms element.
250 * @return {!Object} 56 * @return {!Object}
251 */ 57 */
252 createPasswordsAndFormsElement: function() { 58 createPasswordsAndFormsElement: function(prefsElement) {
253 var element = document.createElement('settings-passwords-and-forms-page'); 59 var element = document.createElement('settings-passwords-and-forms-page');
60 element.prefs = prefsElement.prefs;
254 document.body.appendChild(element); 61 document.body.appendChild(element);
62 element.$$('template[route-path="/passwords"]').if = true;
63 element.$$('template[route-path="/autofill"]').if = true;
255 Polymer.dom.flush(); 64 Polymer.dom.flush();
256 return element; 65 return element;
257 }, 66 },
258 67
259 /** 68 /**
260 * @pram {boolean} autofill Whether autofill is enabled or not. 69 * @pram {boolean} autofill Whether autofill is enabled or not.
261 * @param {boolean} passwords Whether passwords are enabled or not. 70 * @param {boolean} passwords Whether passwords are enabled or not.
262 * @return {!Promise<!Element>} The |prefs| object. 71 * @return {!Promise<!Element>} The |prefs| element.
263 */ 72 */
264 createPrefs: function(autofill, passwords) { 73 createPrefs: function(autofill, passwords) {
265 return new Promise(function(resolve) { 74 return new Promise(function(resolve) {
266 CrSettingsPrefs.deferInitialization = true; 75 CrSettingsPrefs.deferInitialization = true;
267 var prefs = document.createElement('settings-prefs'); 76 var prefs = document.createElement('settings-prefs');
268 prefs.initialize(new settings.FakeSettingsPrivate([ 77 prefs.initialize(new settings.FakeSettingsPrivate([
269 { 78 {
270 key: 'autofill.enabled', 79 key: 'autofill.enabled',
271 type: chrome.settingsPrivate.PrefType.BOOLEAN, 80 type: chrome.settingsPrivate.PrefType.BOOLEAN,
272 value: autofill, 81 value: autofill,
273 }, 82 },
274 { 83 {
275 key: 'credentials_enable_service', 84 key: 'credentials_enable_service',
276 type: chrome.settingsPrivate.PrefType.BOOLEAN, 85 type: chrome.settingsPrivate.PrefType.BOOLEAN,
277 value: passwords, 86 value: passwords,
278 }, 87 },
88 {
89 key: 'credentials_enable_autosignin',
90 type: chrome.settingsPrivate.PrefType.BOOLEAN,
91 value: true,
92 },
279 ])); 93 ]));
280 94
281 CrSettingsPrefs.initialized.then(function() { 95 CrSettingsPrefs.initialized.then(function() {
282 resolve(prefs); 96 resolve(prefs);
283 }); 97 });
284 }); 98 });
285 }, 99 },
286 100
287 /** 101 /**
288 * Cleans up prefs so tests can continue to run. 102 * Cleans up prefs so tests can continue to run.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return expected; 136 return expected;
323 }, 137 },
324 }; 138 };
325 139
326 /** This test will validate that the section is loaded with data. */ 140 /** This test will validate that the section is loaded with data. */
327 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() { 141 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() {
328 var self = this; 142 var self = this;
329 143
330 suite('PasswordsAndForms', function() { 144 suite('PasswordsAndForms', function() {
331 test('baseLoadAndRemove', function() { 145 test('baseLoadAndRemove', function() {
332 var element = self.createPasswordsAndFormsElement(); 146 return self.createPrefs(true, true).then(function(prefs) {
147 var element = self.createPasswordsAndFormsElement(prefs);
333 148
334 var passwordsExpectations = self.basePasswordExpectations(); 149 var passwordsExpectations = self.basePasswordExpectations();
335 self.passwordManager.assertExpectations(passwordsExpectations); 150 self.passwordManager.assertExpectations(passwordsExpectations);
336 151
337 var autofillExpectations = self.baseAutofillExpectations(); 152 var autofillExpectations = self.baseAutofillExpectations();
338 self.autofillManager.assertExpectations(autofillExpectations); 153 self.autofillManager.assertExpectations(autofillExpectations);
339 154
340 element.remove(); 155 element.remove();
341 Polymer.dom.flush(); 156 Polymer.dom.flush();
342 157
343 passwordsExpectations.listening.passwords = 0; 158 passwordsExpectations.listening.passwords = 0;
344 passwordsExpectations.listening.exceptions = 0; 159 passwordsExpectations.listening.exceptions = 0;
345 self.passwordManager.assertExpectations(passwordsExpectations); 160 self.passwordManager.assertExpectations(passwordsExpectations);
346 161
347 autofillExpectations.listening.addresses = 0; 162 autofillExpectations.listening.addresses = 0;
348 autofillExpectations.listening.creditCards = 0; 163 autofillExpectations.listening.creditCards = 0;
349 self.autofillManager.assertExpectations(autofillExpectations); 164 self.autofillManager.assertExpectations(autofillExpectations);
165
166 self.destroyPrefs(prefs);
167 });
350 }); 168 });
351 169
352 test('loadPasswordsAsync', function() { 170 test('loadPasswordsAsync', function() {
353 var element = self.createPasswordsAndFormsElement(); 171 return self.createPrefs(true, true).then(function(prefs) {
172 var element = self.createPasswordsAndFormsElement(prefs);
354 173
355 var list = [FakeDataMaker.passwordEntry(), FakeDataMaker.passwordEntry()]; 174 var list = [
356 self.passwordManager.lastCallback.addSavedPasswordListChangedListener( 175 FakeDataMaker.passwordEntry(),
357 list); 176 FakeDataMaker.passwordEntry()
358 Polymer.dom.flush(); 177 ];
359 178
360 assertEquals(list, element.savedPasswords); 179 self.passwordManager.lastCallback.addSavedPasswordListChangedListener(
180 list);
181 Polymer.dom.flush();
361 182
362 // The callback is coming from the manager, so the element shouldn't have 183 assertEquals(list, element.$$('#passwordSection').savedPasswords);
363 // additional calls to the manager after the base expectations. 184
364 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 185 // The callback is coming from the manager, so the element shouldn't
365 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 186 // have additional calls to the manager after the base expectations.
187 self.passwordManager.assertExpectations(
188 self.basePasswordExpectations());
189 self.autofillManager.assertExpectations(
190 self.baseAutofillExpectations());
191
192 self.destroyPrefs(prefs);
193 });
366 }); 194 });
367 195
368 test('loadExceptionsAsync', function() { 196 test('loadExceptionsAsync', function() {
369 var element = self.createPasswordsAndFormsElement(); 197 return self.createPrefs(true, true).then(function(prefs) {
198 var element = self.createPasswordsAndFormsElement(prefs);
370 199
371 var list = [FakeDataMaker.exceptionEntry(), 200 var list = [FakeDataMaker.exceptionEntry(),
372 FakeDataMaker.exceptionEntry()]; 201 FakeDataMaker.exceptionEntry()];
373 self.passwordManager.lastCallback.addExceptionListChangedListener( 202 self.passwordManager.lastCallback.addExceptionListChangedListener(
374 list); 203 list);
375 Polymer.dom.flush(); 204 Polymer.dom.flush();
376 205
377 assertEquals(list, element.passwordExceptions); 206 assertEquals(list, element.$$('#passwordSection').passwordExceptions);
378 207
379 // The callback is coming from the manager, so the element shouldn't have 208 // The callback is coming from the manager, so the element shouldn't
380 // additional calls to the manager after the base expectations. 209 // have additional calls to the manager after the base expectations.
381 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 210 self.passwordManager.assertExpectations(
382 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 211 self.basePasswordExpectations());
212 self.autofillManager.assertExpectations(
213 self.baseAutofillExpectations());
214
215 self.destroyPrefs(prefs);
216 });
383 }); 217 });
384 218
385 test('loadAddressesAsync', function() { 219 test('loadAddressesAsync', function() {
386 var element = self.createPasswordsAndFormsElement(); 220 return self.createPrefs(true, true).then(function(prefs) {
221 var element = self.createPasswordsAndFormsElement(prefs);
387 222
388 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()]; 223 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
389 self.autofillManager.lastCallback.addAddressListChangedListener(list); 224 self.autofillManager.lastCallback.addAddressListChangedListener(list);
390 Polymer.dom.flush(); 225 Polymer.dom.flush();
391 226
392 assertEquals(list, element.addresses); 227 assertEquals(list, element.$$('#autofillSection').addresses);
393 228
394 // The callback is coming from the manager, so the element shouldn't have 229 // The callback is coming from the manager, so the element shouldn't
395 // additional calls to the manager after the base expectations. 230 // have additional calls to the manager after the base expectations.
396 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 231 self.passwordManager.assertExpectations(
397 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 232 self.basePasswordExpectations());
233 self.autofillManager.assertExpectations(
234 self.baseAutofillExpectations());
235
236 self.destroyPrefs(prefs);
237 });
398 }); 238 });
399 239
400 test('loadCreditCardsAsync', function() { 240 test('loadCreditCardsAsync', function() {
401 var element = self.createPasswordsAndFormsElement(); 241 return self.createPrefs(true, true).then(function(prefs) {
242 var element = self.createPasswordsAndFormsElement(prefs);
402 243
403 var list = [FakeDataMaker.creditCardEntry(), 244 var list = [FakeDataMaker.creditCardEntry(),
404 FakeDataMaker.creditCardEntry()]; 245 FakeDataMaker.creditCardEntry()];
405 self.autofillManager.lastCallback.addCreditCardListChangedListener(list); 246 self.autofillManager.lastCallback.addCreditCardListChangedListener(
406 Polymer.dom.flush(); 247 list);
248 Polymer.dom.flush();
407 249
408 assertEquals(list, element.creditCards); 250 assertEquals(list, element.$$('#autofillSection').creditCards);
409 251
410 // The callback is coming from the manager, so the element shouldn't have 252 // The callback is coming from the manager, so the element shouldn't
411 // additional calls to the manager after the base expectations. 253 // have additional calls to the manager after the base expectations.
412 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 254 self.passwordManager.assertExpectations(
413 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 255 self.basePasswordExpectations());
256 self.autofillManager.assertExpectations(
257 self.baseAutofillExpectations());
258
259 self.destroyPrefs(prefs);
260 });
414 }); 261 });
415 262
416 test('testActionabilityNope', function() { 263 test('testActionabilityNope', function() {
417 return self.createPrefs(false, false).then(function(prefs) { 264 return self.createPrefs(false, false).then(function(prefs) {
418 var element = self.createPasswordsAndFormsElement(); 265
419 element.prefs = prefs.prefs; 266 var element = self.createPasswordsAndFormsElement(prefs);
420 Polymer.dom.flush();
421 267
422 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable')); 268 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable'));
423 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable')); 269 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable'));
424 270
425 self.destroyPrefs(prefs); 271 self.destroyPrefs(prefs);
426 }); 272 });
427 }); 273 });
428 274
429 test('testActionabilityYes', function() { 275 test('testActionabilityYes', function() {
430 return self.createPrefs(true, true).then(function(prefs) { 276 return self.createPrefs(true, true).then(function(prefs) {
431 var element = self.createPasswordsAndFormsElement(); 277 var element = self.createPasswordsAndFormsElement(prefs);
432 element.prefs = prefs.prefs;
433 Polymer.dom.flush();
434 278
435 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable')); 279 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable'));
436 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable')); 280 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable'));
437 281
438 self.destroyPrefs(prefs); 282 self.destroyPrefs(prefs);
439 }); 283 });
440 }); 284 });
441 }); 285 });
442 286
443 mocha.run(); 287 mocha.run();
444 }); 288 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698