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

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: Undo indent for better diff Created 3 years, 11 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 40
235 // Test is run on an individual element that won't have a page language. 41 // Test is run on an individual element that won't have a page language.
236 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); 42 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
237 43
238 // Override the PasswordManagerImpl for testing. 44 // Override the PasswordManagerImpl for testing.
239 this.passwordManager = new TestPasswordManager(); 45 this.passwordManager = new TestPasswordManager();
240 PasswordManagerImpl.instance_ = this.passwordManager; 46 PasswordManagerImpl.instance_ = this.passwordManager;
241 47
242 // Override the AutofillManagerImpl for testing. 48 // Override the AutofillManagerImpl for testing.
243 this.autofillManager = new TestAutofillManager(); 49 this.autofillManager = new TestAutofillManager();
244 AutofillManagerImpl.instance_ = this.autofillManager; 50 AutofillManagerImpl.instance_ = this.autofillManager;
245 }, 51 },
246 52
247 /** @override */ 53 /** @override */
248 tearDown: function() { 54 tearDown: function() {
249 PolymerTest.clearBody(); 55 PolymerTest.clearBody();
250 }, 56 },
251 57
252 /** 58 /**
253 * Creates a new passwords and forms element. 59 * Creates a new passwords and forms element.
254 * @return {!Object} 60 * @return {!Object}
255 */ 61 */
256 createPasswordsAndFormsElement: function() { 62 createPasswordsAndFormsElement: function(prefsElement) {
257 var element = document.createElement('settings-passwords-and-forms-page'); 63 var element = document.createElement('settings-passwords-and-forms-page');
64 element.prefs = prefsElement.prefs;
258 document.body.appendChild(element); 65 document.body.appendChild(element);
66 element.$$('template[route-path="/passwords"').if = true;
Dan Beam 2017/01/26 19:10:44 did you run this? there should be a ] at the end
hcarmona 2017/01/26 21:34:47 Fixed... but it finds the right element, you can a
Dan Beam 2017/01/27 01:11:32 well, there's no difference, because returning nul
hcarmona 2017/01/27 18:28:16 Removed asserts to keep cleaner.
67 element.$$('template[route-path="/autofill"').if = true;
259 Polymer.dom.flush(); 68 Polymer.dom.flush();
260 return element; 69 return element;
261 }, 70 },
262 71
263 /** 72 /**
264 * @pram {boolean} autofill Whether autofill is enabled or not. 73 * @pram {boolean} autofill Whether autofill is enabled or not.
265 * @param {boolean} passwords Whether passwords are enabled or not. 74 * @param {boolean} passwords Whether passwords are enabled or not.
266 * @return {!Promise<!Element>} The |prefs| object. 75 * @return {!Promise<!Element>} The |prefs| element.
267 */ 76 */
268 createPrefs: function(autofill, passwords) { 77 createPrefs: function(autofill, passwords) {
269 return new Promise(function(resolve) { 78 return new Promise(function(resolve) {
270 CrSettingsPrefs.deferInitialization = true; 79 CrSettingsPrefs.deferInitialization = true;
271 var prefs = document.createElement('settings-prefs'); 80 var prefs = document.createElement('settings-prefs');
272 prefs.initialize(new settings.FakeSettingsPrivate([ 81 prefs.initialize(new settings.FakeSettingsPrivate([
273 { 82 {
274 key: 'autofill.enabled', 83 key: 'autofill.enabled',
275 type: chrome.settingsPrivate.PrefType.BOOLEAN, 84 type: chrome.settingsPrivate.PrefType.BOOLEAN,
276 value: autofill, 85 value: autofill,
277 }, 86 },
278 { 87 {
279 key: 'profile.password_manager_enabled', 88 key: 'credentials_enable_autosignin',
280 type: chrome.settingsPrivate.PrefType.BOOLEAN, 89 type: chrome.settingsPrivate.PrefType.BOOLEAN,
281 value: passwords, 90 value: true,
282 }, 91 },
92 {
93 key: 'profile.password_manager_enabled',
94 type: chrome.settingsPrivate.PrefType.BOOLEAN,
95 value: passwords,
96 },
283 ])); 97 ]));
284 98
285 CrSettingsPrefs.initialized.then(function() { 99 CrSettingsPrefs.initialized.then(function() {
286 resolve(prefs); 100 resolve(prefs);
287 }); 101 });
288 }); 102 });
289 }, 103 },
290 104
291 /** 105 /**
292 * Cleans up prefs so tests can continue to run. 106 * Cleans up prefs so tests can continue to run.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return expected; 140 return expected;
327 }, 141 },
328 }; 142 };
329 143
330 /** This test will validate that the section is loaded with data. */ 144 /** This test will validate that the section is loaded with data. */
331 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() { 145 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() {
332 var self = this; 146 var self = this;
333 147
334 suite('PasswordsAndForms', function() { 148 suite('PasswordsAndForms', function() {
335 test('baseLoadAndRemove', function() { 149 test('baseLoadAndRemove', function() {
336 var element = self.createPasswordsAndFormsElement(); 150 return self.createPrefs(true, true).then(function(prefs) {
151 var element = self.createPasswordsAndFormsElement(prefs);
337 152
338 var passwordsExpectations = self.basePasswordExpectations(); 153 var passwordsExpectations = self.basePasswordExpectations();
339 self.passwordManager.assertExpectations(passwordsExpectations); 154 self.passwordManager.assertExpectations(passwordsExpectations);
340 155
341 var autofillExpectations = self.baseAutofillExpectations(); 156 var autofillExpectations = self.baseAutofillExpectations();
342 self.autofillManager.assertExpectations(autofillExpectations); 157 self.autofillManager.assertExpectations(autofillExpectations);
343 158
344 element.remove(); 159 element.remove();
345 Polymer.dom.flush(); 160 Polymer.dom.flush();
346 161
347 passwordsExpectations.listening.passwords = 0; 162 passwordsExpectations.listening.passwords = 0;
348 passwordsExpectations.listening.exceptions = 0; 163 passwordsExpectations.listening.exceptions = 0;
349 self.passwordManager.assertExpectations(passwordsExpectations); 164 self.passwordManager.assertExpectations(passwordsExpectations);
350 165
351 autofillExpectations.listening.addresses = 0; 166 autofillExpectations.listening.addresses = 0;
352 autofillExpectations.listening.creditCards = 0; 167 autofillExpectations.listening.creditCards = 0;
353 self.autofillManager.assertExpectations(autofillExpectations); 168 self.autofillManager.assertExpectations(autofillExpectations);
169
170 self.destroyPrefs(prefs);
171 });
354 }); 172 });
355 173
356 test('loadPasswordsAsync', function() { 174 test('loadPasswordsAsync', function() {
357 var element = self.createPasswordsAndFormsElement(); 175 return self.createPrefs(true, true).then(function(prefs) {
176 var element = self.createPasswordsAndFormsElement(prefs);
358 177
359 var list = [FakeDataMaker.passwordEntry(), FakeDataMaker.passwordEntry()]; 178 var list = [
360 self.passwordManager.lastCallback.addSavedPasswordListChangedListener( 179 FakeDataMaker.passwordEntry(),
361 list); 180 FakeDataMaker.passwordEntry()
362 Polymer.dom.flush(); 181 ];
363 182
364 assertEquals(list, element.savedPasswords); 183 self.passwordManager.lastCallback.addSavedPasswordListChangedListener(
184 list);
185 Polymer.dom.flush();
365 186
366 // The callback is coming from the manager, so the element shouldn't have 187 assertEquals(list, element.$$('#passwordSection').savedPasswords);
367 // additional calls to the manager after the base expectations. 188
368 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 189 // The callback is coming from the manager, so the element shouldn't
369 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 190 // have additional calls to the manager after the base expectations.
191 self.passwordManager.assertExpectations(
192 self.basePasswordExpectations());
193 self.autofillManager.assertExpectations(
194 self.baseAutofillExpectations());
195
196 self.destroyPrefs(prefs);
197 });
370 }); 198 });
371 199
372 test('loadExceptionsAsync', function() { 200 test('loadExceptionsAsync', function() {
373 var element = self.createPasswordsAndFormsElement(); 201 return self.createPrefs(true, true).then(function(prefs) {
202 var element = self.createPasswordsAndFormsElement(prefs);
374 203
375 var list = [FakeDataMaker.exceptionEntry(), 204 var list = [FakeDataMaker.exceptionEntry(),
376 FakeDataMaker.exceptionEntry()]; 205 FakeDataMaker.exceptionEntry()];
377 self.passwordManager.lastCallback.addExceptionListChangedListener( 206 self.passwordManager.lastCallback.addExceptionListChangedListener(
378 list); 207 list);
379 Polymer.dom.flush(); 208 Polymer.dom.flush();
380 209
381 assertEquals(list, element.passwordExceptions); 210 assertEquals(list, element.$$('#passwordSection').passwordExceptions);
382 211
383 // The callback is coming from the manager, so the element shouldn't have 212 // The callback is coming from the manager, so the element shouldn't
384 // additional calls to the manager after the base expectations. 213 // have additional calls to the manager after the base expectations.
385 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 214 self.passwordManager.assertExpectations(
386 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 215 self.basePasswordExpectations());
216 self.autofillManager.assertExpectations(
217 self.baseAutofillExpectations());
218
219 self.destroyPrefs(prefs);
220 });
387 }); 221 });
388 222
389 test('loadAddressesAsync', function() { 223 test('loadAddressesAsync', function() {
390 var element = self.createPasswordsAndFormsElement(); 224 return self.createPrefs(true, true).then(function(prefs) {
225 var element = self.createPasswordsAndFormsElement(prefs);
391 226
392 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()]; 227 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
393 self.autofillManager.lastCallback.addAddressListChangedListener(list); 228 self.autofillManager.lastCallback.addAddressListChangedListener(list);
394 Polymer.dom.flush(); 229 Polymer.dom.flush();
395 230
396 assertEquals(list, element.addresses); 231 assertEquals(list, element.$$('#autofillSection').addresses);
397 232
398 // The callback is coming from the manager, so the element shouldn't have 233 // The callback is coming from the manager, so the element shouldn't
399 // additional calls to the manager after the base expectations. 234 // have additional calls to the manager after the base expectations.
400 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 235 self.passwordManager.assertExpectations(
401 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 236 self.basePasswordExpectations());
237 self.autofillManager.assertExpectations(
238 self.baseAutofillExpectations());
239
240 self.destroyPrefs(prefs);
241 });
402 }); 242 });
403 243
404 test('loadCreditCardsAsync', function() { 244 test('loadCreditCardsAsync', function() {
405 var element = self.createPasswordsAndFormsElement(); 245 return self.createPrefs(true, true).then(function(prefs) {
246 var element = self.createPasswordsAndFormsElement(prefs);
406 247
407 var list = [FakeDataMaker.creditCardEntry(), 248 var list = [FakeDataMaker.creditCardEntry(),
408 FakeDataMaker.creditCardEntry()]; 249 FakeDataMaker.creditCardEntry()];
409 self.autofillManager.lastCallback.addCreditCardListChangedListener(list); 250 self.autofillManager.lastCallback.addCreditCardListChangedListener(
410 Polymer.dom.flush(); 251 list);
252 Polymer.dom.flush();
411 253
412 assertEquals(list, element.creditCards); 254 assertEquals(list, element.$$('#autofillSection').creditCards);
413 255
414 // The callback is coming from the manager, so the element shouldn't have 256 // The callback is coming from the manager, so the element shouldn't
415 // additional calls to the manager after the base expectations. 257 // have additional calls to the manager after the base expectations.
416 self.passwordManager.assertExpectations(self.basePasswordExpectations()); 258 self.passwordManager.assertExpectations(
417 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); 259 self.basePasswordExpectations());
260 self.autofillManager.assertExpectations(
261 self.baseAutofillExpectations());
262
263 self.destroyPrefs(prefs);
264 });
418 }); 265 });
419 266
420 test('testActionabilityNope', function() { 267 test('testActionabilityNope', function() {
421 return self.createPrefs(false, false).then(function(prefs) { 268 return self.createPrefs(false, false).then(function(prefs) {
422 var element = self.createPasswordsAndFormsElement(); 269
423 element.prefs = prefs.prefs; 270 var element = self.createPasswordsAndFormsElement(prefs);
424 Polymer.dom.flush();
425 271
426 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable')); 272 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable'));
427 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable')); 273 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable'));
428 274
429 self.destroyPrefs(prefs); 275 self.destroyPrefs(prefs);
430 }); 276 });
431 }); 277 });
432 278
433 test('testActionabilityYes', function() { 279 test('testActionabilityYes', function() {
434 return self.createPrefs(true, true).then(function(prefs) { 280 return self.createPrefs(true, true).then(function(prefs) {
435 var element = self.createPasswordsAndFormsElement(); 281 var element = self.createPasswordsAndFormsElement(prefs);
436 element.prefs = prefs.prefs;
437 Polymer.dom.flush();
438 282
439 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable')); 283 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable'));
440 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable')); 284 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable'));
441 285
442 self.destroyPrefs(prefs); 286 self.destroyPrefs(prefs);
443 }); 287 });
444 }); 288 });
445 }); 289 });
446 290
447 mocha.run(); 291 mocha.run();
448 }); 292 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698