OLD | NEW |
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. |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 function PasswordsAndFormsBrowserTest() {} | 216 function PasswordsAndFormsBrowserTest() {} |
217 | 217 |
218 PasswordsAndFormsBrowserTest.prototype = { | 218 PasswordsAndFormsBrowserTest.prototype = { |
219 __proto__: PolymerTest.prototype, | 219 __proto__: PolymerTest.prototype, |
220 | 220 |
221 /** @override */ | 221 /** @override */ |
222 browsePreload: 'chrome://md-settings/passwords_and_forms_page/' + | 222 browsePreload: 'chrome://md-settings/passwords_and_forms_page/' + |
223 'passwords_and_forms_page.html', | 223 'passwords_and_forms_page.html', |
224 | 224 |
225 /** @override */ | 225 /** @override */ |
226 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 226 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ |
| 227 '../fake_chrome_event.js', |
| 228 'fake_settings_private.js', |
| 229 ]), |
227 | 230 |
228 /** @override */ | 231 /** @override */ |
229 setUp: function() { | 232 setUp: function() { |
230 PolymerTest.prototype.setUp.call(this); | 233 PolymerTest.prototype.setUp.call(this); |
231 | 234 |
232 // Test is run on an individual element that won't have a page language. | 235 // Test is run on an individual element that won't have a page language. |
233 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 236 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
234 | 237 |
235 // Override the PasswordManagerImpl for testing. | 238 // Override the PasswordManagerImpl for testing. |
236 this.passwordManager = new TestPasswordManager(); | 239 this.passwordManager = new TestPasswordManager(); |
237 PasswordManagerImpl.instance_ = this.passwordManager; | 240 PasswordManagerImpl.instance_ = this.passwordManager; |
238 | 241 |
239 // Override the AutofillManagerImpl for testing. | 242 // Override the AutofillManagerImpl for testing. |
240 this.autofillManager = new TestAutofillManager(); | 243 this.autofillManager = new TestAutofillManager(); |
241 AutofillManagerImpl.instance_ = this.autofillManager; | 244 AutofillManagerImpl.instance_ = this.autofillManager; |
242 }, | 245 }, |
243 | 246 |
| 247 /** @override */ |
| 248 tearDown: function() { |
| 249 PolymerTest.clearBody(); |
| 250 }, |
| 251 |
244 /** | 252 /** |
245 * Creates a new passwords and forms element. | 253 * Creates a new passwords and forms element. |
246 * @return {!Object} | 254 * @return {!Object} |
247 */ | 255 */ |
248 createPasswordsAndFormsElement: function() { | 256 createPasswordsAndFormsElement: function() { |
249 var element = document.createElement('settings-passwords-and-forms-page'); | 257 var element = document.createElement('settings-passwords-and-forms-page'); |
250 document.body.appendChild(element); | 258 document.body.appendChild(element); |
251 Polymer.dom.flush(); | 259 Polymer.dom.flush(); |
252 return element; | 260 return element; |
253 }, | 261 }, |
254 | 262 |
255 /** | 263 /** |
| 264 * @pram {boolean} autofill Whether autofill is enabled or not. |
| 265 * @param {boolean} passwords Whether passwords are enabled or not. |
| 266 * @return {!Promise<!Element>} The |prefs| object. |
| 267 */ |
| 268 createPrefs: function(autofill, passwords) { |
| 269 return new Promise(function(resolve) { |
| 270 CrSettingsPrefs.deferInitialization = true; |
| 271 var prefs = document.createElement('settings-prefs'); |
| 272 document.body.appendChild(prefs); |
| 273 prefs.initializeForTesting(new settings.FakeSettingsPrivate([ |
| 274 { |
| 275 key: 'autofill.enabled', |
| 276 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 277 value: autofill, |
| 278 }, |
| 279 { |
| 280 key: 'profile.password_manager_enabled', |
| 281 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 282 value: passwords, |
| 283 }, |
| 284 ])); |
| 285 |
| 286 CrSettingsPrefs.initialized.then(function() { |
| 287 resolve(prefs); |
| 288 }); |
| 289 }); |
| 290 }, |
| 291 |
| 292 /** |
| 293 * Cleans up prefs so tests can continue to run. |
| 294 * @param {!Element} prefs The prefs element. |
| 295 */ |
| 296 destroyPrefs: function(prefs) { |
| 297 CrSettingsPrefs.resetForTesting(); |
| 298 CrSettingsPrefs.deferInitialization = false; |
| 299 prefs.resetForTesting(); |
| 300 }, |
| 301 |
| 302 /** |
256 * Creates PasswordManagerExpectations with the values expected after first | 303 * Creates PasswordManagerExpectations with the values expected after first |
257 * creating the element. | 304 * creating the element. |
258 * @return {!PasswordManagerExpectations} | 305 * @return {!PasswordManagerExpectations} |
259 */ | 306 */ |
260 basePasswordExpectations: function() { | 307 basePasswordExpectations: function() { |
261 var expected = new PasswordManagerExpectations(); | 308 var expected = new PasswordManagerExpectations(); |
262 expected.requested.passwords = 1; | 309 expected.requested.passwords = 1; |
263 expected.requested.exceptions = 1; | 310 expected.requested.exceptions = 1; |
264 expected.listening.passwords = 1; | 311 expected.listening.passwords = 1; |
265 expected.listening.exceptions = 1; | 312 expected.listening.exceptions = 1; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 self.autofillManager.lastCallback.addCreditCardListChangedListener(list); | 412 self.autofillManager.lastCallback.addCreditCardListChangedListener(list); |
366 Polymer.dom.flush(); | 413 Polymer.dom.flush(); |
367 | 414 |
368 assertEquals(list, element.creditCards); | 415 assertEquals(list, element.creditCards); |
369 | 416 |
370 // The callback is coming from the manager, so the element shouldn't have | 417 // The callback is coming from the manager, so the element shouldn't have |
371 // additional calls to the manager after the base expectations. | 418 // additional calls to the manager after the base expectations. |
372 self.passwordManager.assertExpectations(self.basePasswordExpectations()); | 419 self.passwordManager.assertExpectations(self.basePasswordExpectations()); |
373 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); | 420 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); |
374 }); | 421 }); |
| 422 |
| 423 test('testActionabilityNope', function() { |
| 424 return self.createPrefs(false, false).then(function(prefs) { |
| 425 var element = self.createPasswordsAndFormsElement(); |
| 426 element.prefs = prefs.prefs; |
| 427 Polymer.dom.flush(); |
| 428 |
| 429 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable')); |
| 430 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable')); |
| 431 |
| 432 self.destroyPrefs(prefs); |
| 433 }); |
| 434 }); |
| 435 |
| 436 test('testActionabilityYes', function() { |
| 437 return self.createPrefs(true, true).then(function(prefs) { |
| 438 var element = self.createPasswordsAndFormsElement(); |
| 439 element.prefs = prefs.prefs; |
| 440 Polymer.dom.flush(); |
| 441 |
| 442 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable')); |
| 443 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable')); |
| 444 |
| 445 self.destroyPrefs(prefs); |
| 446 }); |
| 447 }); |
375 }); | 448 }); |
376 | 449 |
377 mocha.run(); | 450 mocha.run(); |
378 }); | 451 }); |
OLD | NEW |