| 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. |
| 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(); | |
| 235 | 40 |
| 236 // 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. |
| 237 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 42 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
| 238 | |
| 239 // Override the PasswordManagerImpl for testing. | |
| 240 this.passwordManager = new TestPasswordManager(); | |
| 241 PasswordManagerImpl.instance_ = this.passwordManager; | |
| 242 | |
| 243 // Override the AutofillManagerImpl for testing. | |
| 244 this.autofillManager = new TestAutofillManager(); | |
| 245 AutofillManagerImpl.instance_ = this.autofillManager; | |
| 246 }, | 43 }, |
| 44 }; |
| 45 |
| 46 /** This test will validate that the section is loaded with data. */ |
| 47 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() { |
| 48 var passwordManager; |
| 49 var autofillManager; |
| 247 | 50 |
| 248 /** | 51 /** |
| 249 * Creates a new passwords and forms element. | 52 * Creates a new passwords and forms element. |
| 250 * @return {!Object} | 53 * @return {!Object} |
| 251 */ | 54 */ |
| 252 createPasswordsAndFormsElement: function() { | 55 function createPasswordsAndFormsElement(prefsElement) { |
| 253 var element = document.createElement('settings-passwords-and-forms-page'); | 56 var element = document.createElement('settings-passwords-and-forms-page'); |
| 57 element.prefs = prefsElement.prefs; |
| 254 document.body.appendChild(element); | 58 document.body.appendChild(element); |
| 59 element.$$('template[route-path="/passwords"]').if = true; |
| 60 element.$$('template[route-path="/autofill"]').if = true; |
| 255 Polymer.dom.flush(); | 61 Polymer.dom.flush(); |
| 256 return element; | 62 return element; |
| 257 }, | 63 } |
| 258 | 64 |
| 259 /** | 65 /** |
| 260 * @pram {boolean} autofill Whether autofill is enabled or not. | 66 * @pram {boolean} autofill Whether autofill is enabled or not. |
| 261 * @param {boolean} passwords Whether passwords are enabled or not. | 67 * @param {boolean} passwords Whether passwords are enabled or not. |
| 262 * @return {!Promise<!Element>} The |prefs| object. | 68 * @return {!Promise<!Element>} The |prefs| element. |
| 263 */ | 69 */ |
| 264 createPrefs: function(autofill, passwords) { | 70 function createPrefs(autofill, passwords) { |
| 265 return new Promise(function(resolve) { | 71 return new Promise(function(resolve) { |
| 266 CrSettingsPrefs.deferInitialization = true; | 72 CrSettingsPrefs.deferInitialization = true; |
| 267 var prefs = document.createElement('settings-prefs'); | 73 var prefs = document.createElement('settings-prefs'); |
| 268 prefs.initialize(new settings.FakeSettingsPrivate([ | 74 prefs.initialize(new settings.FakeSettingsPrivate([ |
| 269 { | 75 { |
| 270 key: 'autofill.enabled', | 76 key: 'autofill.enabled', |
| 271 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 77 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 272 value: autofill, | 78 value: autofill, |
| 273 }, | 79 }, |
| 274 { | 80 { |
| 275 key: 'credentials_enable_service', | 81 key: 'credentials_enable_service', |
| 276 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 82 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 277 value: passwords, | 83 value: passwords, |
| 278 }, | 84 }, |
| 85 { |
| 86 key: 'credentials_enable_autosignin', |
| 87 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 88 value: true, |
| 89 }, |
| 279 ])); | 90 ])); |
| 280 | 91 |
| 281 CrSettingsPrefs.initialized.then(function() { | 92 CrSettingsPrefs.initialized.then(function() { |
| 282 resolve(prefs); | 93 resolve(prefs); |
| 283 }); | 94 }); |
| 284 }); | 95 }); |
| 285 }, | 96 } |
| 286 | 97 |
| 287 /** | 98 /** |
| 288 * Cleans up prefs so tests can continue to run. | 99 * Cleans up prefs so tests can continue to run. |
| 289 * @param {!Element} prefs The prefs element. | 100 * @param {!Element} prefs The prefs element. |
| 290 */ | 101 */ |
| 291 destroyPrefs: function(prefs) { | 102 function destroyPrefs(prefs) { |
| 292 CrSettingsPrefs.resetForTesting(); | 103 CrSettingsPrefs.resetForTesting(); |
| 293 CrSettingsPrefs.deferInitialization = false; | 104 CrSettingsPrefs.deferInitialization = false; |
| 294 prefs.resetForTesting(); | 105 prefs.resetForTesting(); |
| 295 }, | 106 } |
| 296 | 107 |
| 297 /** | 108 /** |
| 298 * Creates PasswordManagerExpectations with the values expected after first | 109 * Creates PasswordManagerExpectations with the values expected after first |
| 299 * creating the element. | 110 * creating the element. |
| 300 * @return {!PasswordManagerExpectations} | 111 * @return {!PasswordManagerExpectations} |
| 301 */ | 112 */ |
| 302 basePasswordExpectations: function() { | 113 function basePasswordExpectations() { |
| 303 var expected = new PasswordManagerExpectations(); | 114 var expected = new PasswordManagerExpectations(); |
| 304 expected.requested.passwords = 1; | 115 expected.requested.passwords = 1; |
| 305 expected.requested.exceptions = 1; | 116 expected.requested.exceptions = 1; |
| 306 expected.listening.passwords = 1; | 117 expected.listening.passwords = 1; |
| 307 expected.listening.exceptions = 1; | 118 expected.listening.exceptions = 1; |
| 308 return expected; | 119 return expected; |
| 309 }, | 120 } |
| 310 | 121 |
| 311 /** | 122 /** |
| 312 * Creates AutofillManagerExpectations with the values expected after first | 123 * Creates AutofillManagerExpectations with the values expected after first |
| 313 * creating the element. | 124 * creating the element. |
| 314 * @return {!AutofillManagerExpectations} | 125 * @return {!AutofillManagerExpectations} |
| 315 */ | 126 */ |
| 316 baseAutofillExpectations: function() { | 127 function baseAutofillExpectations() { |
| 317 var expected = new AutofillManagerExpectations(); | 128 var expected = new AutofillManagerExpectations(); |
| 318 expected.requested.addresses = 1; | 129 expected.requested.addresses = 1; |
| 319 expected.requested.creditCards = 1; | 130 expected.requested.creditCards = 1; |
| 320 expected.listening.addresses = 1; | 131 expected.listening.addresses = 1; |
| 321 expected.listening.creditCards = 1; | 132 expected.listening.creditCards = 1; |
| 322 return expected; | 133 return expected; |
| 323 }, | 134 } |
| 324 }; | 135 |
| 325 | 136 setup(function() { |
| 326 /** This test will validate that the section is loaded with data. */ | 137 PolymerTest.clearBody(); |
| 327 TEST_F('PasswordsAndFormsBrowserTest', 'uiTests', function() { | 138 |
| 328 var self = this; | 139 // Override the PasswordManagerImpl for testing. |
| 140 passwordManager = new TestPasswordManager(); |
| 141 PasswordManagerImpl.instance_ = passwordManager; |
| 142 |
| 143 // Override the AutofillManagerImpl for testing. |
| 144 autofillManager = new TestAutofillManager(); |
| 145 AutofillManagerImpl.instance_ = autofillManager; |
| 146 }); |
| 329 | 147 |
| 330 suite('PasswordsAndForms', function() { | 148 suite('PasswordsAndForms', function() { |
| 331 test('baseLoadAndRemove', function() { | 149 test('baseLoadAndRemove', function() { |
| 332 var element = self.createPasswordsAndFormsElement(); | 150 return createPrefs(true, true).then(function(prefs) { |
| 333 | 151 var element = createPasswordsAndFormsElement(prefs); |
| 334 var passwordsExpectations = self.basePasswordExpectations(); | 152 |
| 335 self.passwordManager.assertExpectations(passwordsExpectations); | 153 var passwordsExpectations = basePasswordExpectations(); |
| 336 | 154 passwordManager.assertExpectations(passwordsExpectations); |
| 337 var autofillExpectations = self.baseAutofillExpectations(); | 155 |
| 338 self.autofillManager.assertExpectations(autofillExpectations); | 156 var autofillExpectations = baseAutofillExpectations(); |
| 339 | 157 autofillManager.assertExpectations(autofillExpectations); |
| 340 element.remove(); | 158 |
| 341 Polymer.dom.flush(); | 159 element.remove(); |
| 342 | 160 Polymer.dom.flush(); |
| 343 passwordsExpectations.listening.passwords = 0; | 161 |
| 344 passwordsExpectations.listening.exceptions = 0; | 162 passwordsExpectations.listening.passwords = 0; |
| 345 self.passwordManager.assertExpectations(passwordsExpectations); | 163 passwordsExpectations.listening.exceptions = 0; |
| 346 | 164 passwordManager.assertExpectations(passwordsExpectations); |
| 347 autofillExpectations.listening.addresses = 0; | 165 |
| 348 autofillExpectations.listening.creditCards = 0; | 166 autofillExpectations.listening.addresses = 0; |
| 349 self.autofillManager.assertExpectations(autofillExpectations); | 167 autofillExpectations.listening.creditCards = 0; |
| 168 autofillManager.assertExpectations(autofillExpectations); |
| 169 |
| 170 destroyPrefs(prefs); |
| 171 }); |
| 350 }); | 172 }); |
| 351 | 173 |
| 352 test('loadPasswordsAsync', function() { | 174 test('loadPasswordsAsync', function() { |
| 353 var element = self.createPasswordsAndFormsElement(); | 175 return createPrefs(true, true).then(function(prefs) { |
| 354 | 176 var element = createPasswordsAndFormsElement(prefs); |
| 355 var list = [FakeDataMaker.passwordEntry(), FakeDataMaker.passwordEntry()]; | 177 |
| 356 self.passwordManager.lastCallback.addSavedPasswordListChangedListener( | 178 var list = [ |
| 357 list); | 179 FakeDataMaker.passwordEntry(), |
| 358 Polymer.dom.flush(); | 180 FakeDataMaker.passwordEntry() |
| 359 | 181 ]; |
| 360 assertEquals(list, element.savedPasswords); | 182 |
| 361 | 183 passwordManager.lastCallback.addSavedPasswordListChangedListener(list); |
| 362 // The callback is coming from the manager, so the element shouldn't have | 184 Polymer.dom.flush(); |
| 363 // additional calls to the manager after the base expectations. | 185 |
| 364 self.passwordManager.assertExpectations(self.basePasswordExpectations()); | 186 assertEquals(list, element.$$('#passwordSection').savedPasswords); |
| 365 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); | 187 |
| 188 // The callback is coming from the manager, so the element shouldn't |
| 189 // have additional calls to the manager after the base expectations. |
| 190 passwordManager.assertExpectations(basePasswordExpectations()); |
| 191 autofillManager.assertExpectations(baseAutofillExpectations()); |
| 192 |
| 193 destroyPrefs(prefs); |
| 194 }); |
| 366 }); | 195 }); |
| 367 | 196 |
| 368 test('loadExceptionsAsync', function() { | 197 test('loadExceptionsAsync', function() { |
| 369 var element = self.createPasswordsAndFormsElement(); | 198 return createPrefs(true, true).then(function(prefs) { |
| 370 | 199 var element = createPasswordsAndFormsElement(prefs); |
| 371 var list = [FakeDataMaker.exceptionEntry(), | 200 |
| 372 FakeDataMaker.exceptionEntry()]; | 201 var list = [FakeDataMaker.exceptionEntry(), |
| 373 self.passwordManager.lastCallback.addExceptionListChangedListener( | 202 FakeDataMaker.exceptionEntry()]; |
| 374 list); | 203 passwordManager.lastCallback.addExceptionListChangedListener(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 passwordManager.assertExpectations(basePasswordExpectations()); |
| 382 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); | 211 autofillManager.assertExpectations(baseAutofillExpectations()); |
| 212 |
| 213 destroyPrefs(prefs); |
| 214 }); |
| 383 }); | 215 }); |
| 384 | 216 |
| 385 test('loadAddressesAsync', function() { | 217 test('loadAddressesAsync', function() { |
| 386 var element = self.createPasswordsAndFormsElement(); | 218 return createPrefs(true, true).then(function(prefs) { |
| 387 | 219 var element = createPasswordsAndFormsElement(prefs); |
| 388 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()]; | 220 |
| 389 self.autofillManager.lastCallback.addAddressListChangedListener(list); | 221 var list = [FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()]; |
| 390 Polymer.dom.flush(); | 222 autofillManager.lastCallback.addAddressListChangedListener(list); |
| 391 | 223 Polymer.dom.flush(); |
| 392 assertEquals(list, element.addresses); | 224 |
| 393 | 225 assertEquals(list, element.$$('#autofillSection').addresses); |
| 394 // The callback is coming from the manager, so the element shouldn't have | 226 |
| 395 // additional calls to the manager after the base expectations. | 227 // The callback is coming from the manager, so the element shouldn't |
| 396 self.passwordManager.assertExpectations(self.basePasswordExpectations()); | 228 // have additional calls to the manager after the base expectations. |
| 397 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); | 229 passwordManager.assertExpectations(basePasswordExpectations()); |
| 230 autofillManager.assertExpectations(baseAutofillExpectations()); |
| 231 |
| 232 destroyPrefs(prefs); |
| 233 }); |
| 398 }); | 234 }); |
| 399 | 235 |
| 400 test('loadCreditCardsAsync', function() { | 236 test('loadCreditCardsAsync', function() { |
| 401 var element = self.createPasswordsAndFormsElement(); | 237 return createPrefs(true, true).then(function(prefs) { |
| 402 | 238 var element = createPasswordsAndFormsElement(prefs); |
| 403 var list = [FakeDataMaker.creditCardEntry(), | 239 |
| 404 FakeDataMaker.creditCardEntry()]; | 240 var list = [FakeDataMaker.creditCardEntry(), |
| 405 self.autofillManager.lastCallback.addCreditCardListChangedListener(list); | 241 FakeDataMaker.creditCardEntry()]; |
| 406 Polymer.dom.flush(); | 242 autofillManager.lastCallback.addCreditCardListChangedListener(list); |
| 407 | 243 Polymer.dom.flush(); |
| 408 assertEquals(list, element.creditCards); | 244 |
| 409 | 245 assertEquals(list, element.$$('#autofillSection').creditCards); |
| 410 // The callback is coming from the manager, so the element shouldn't have | 246 |
| 411 // additional calls to the manager after the base expectations. | 247 // The callback is coming from the manager, so the element shouldn't |
| 412 self.passwordManager.assertExpectations(self.basePasswordExpectations()); | 248 // have additional calls to the manager after the base expectations. |
| 413 self.autofillManager.assertExpectations(self.baseAutofillExpectations()); | 249 passwordManager.assertExpectations(basePasswordExpectations()); |
| 250 autofillManager.assertExpectations(baseAutofillExpectations()); |
| 251 |
| 252 destroyPrefs(prefs); |
| 253 }); |
| 414 }); | 254 }); |
| 415 | 255 |
| 416 test('testActionabilityNope', function() { | 256 test('testActionabilityNope', function() { |
| 417 return self.createPrefs(false, false).then(function(prefs) { | 257 return createPrefs(false, false).then(function(prefs) { |
| 418 var element = self.createPasswordsAndFormsElement(); | 258 |
| 419 element.prefs = prefs.prefs; | 259 var element = createPasswordsAndFormsElement(prefs); |
| 420 Polymer.dom.flush(); | |
| 421 | 260 |
| 422 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable')); | 261 assertFalse(element.$.autofillManagerButton.hasAttribute('actionable')); |
| 423 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable')); | 262 assertFalse(element.$.passwordManagerButton.hasAttribute('actionable')); |
| 424 | 263 |
| 425 self.destroyPrefs(prefs); | 264 destroyPrefs(prefs); |
| 426 }); | 265 }); |
| 427 }); | 266 }); |
| 428 | 267 |
| 429 test('testActionabilityYes', function() { | 268 test('testActionabilityYes', function() { |
| 430 return self.createPrefs(true, true).then(function(prefs) { | 269 return createPrefs(true, true).then(function(prefs) { |
| 431 var element = self.createPasswordsAndFormsElement(); | 270 var element = createPasswordsAndFormsElement(prefs); |
| 432 element.prefs = prefs.prefs; | |
| 433 Polymer.dom.flush(); | |
| 434 | 271 |
| 435 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable')); | 272 assertTrue(element.$.autofillManagerButton.hasAttribute('actionable')); |
| 436 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable')); | 273 assertTrue(element.$.passwordManagerButton.hasAttribute('actionable')); |
| 437 | 274 |
| 438 self.destroyPrefs(prefs); | 275 destroyPrefs(prefs); |
| 439 }); | 276 }); |
| 440 }); | 277 }); |
| 441 }); | 278 }); |
| 442 | 279 |
| 443 mocha.run(); | 280 mocha.run(); |
| 444 }); | 281 }); |
| OLD | NEW |