Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 Password Settings tests. */ | 5 /** @fileoverview Runs the Polymer Password Settings 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 * @param {!Array<!string>} exceptionList | 105 * @param {!Array<!string>} exceptionList |
| 106 * @return {!Object} | 106 * @return {!Object} |
| 107 * @private | 107 * @private |
| 108 */ | 108 */ |
| 109 createPasswordsSection_: function(passwordList, exceptionList) { | 109 createPasswordsSection_: function(passwordList, exceptionList) { |
| 110 // Create a passwords-section to use for testing. | 110 // Create a passwords-section to use for testing. |
| 111 var passwordsSection = document.createElement('passwords-section'); | 111 var passwordsSection = document.createElement('passwords-section'); |
| 112 passwordsSection.savedPasswords = passwordList; | 112 passwordsSection.savedPasswords = passwordList; |
| 113 passwordsSection.passwordExceptions = exceptionList; | 113 passwordsSection.passwordExceptions = exceptionList; |
| 114 document.body.appendChild(passwordsSection); | 114 document.body.appendChild(passwordsSection); |
| 115 this.flush_(passwordsSection); | 115 this.flushPasswordSection_(passwordsSection); |
| 116 return passwordsSection; | 116 return passwordsSection; |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * Helper method used to create a password editing dialog. | |
| 121 * @param {!chrome.passwordsPrivate.PasswordUiEntry} passwordItem | |
| 122 * @return {!Object} | |
| 123 * @private | |
| 124 */ | |
| 125 createPasswordDialog_: function(passwordItem) { | |
| 126 var passwordDialog = document.createElement('password-edit-dialog'); | |
| 127 passwordDialog.item = passwordItem; | |
| 128 document.body.appendChild(passwordDialog); | |
| 129 this.flushPolymer_(); | |
| 130 return passwordDialog; | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 120 * Helper method used to test for a url in a list of passwords. | 134 * Helper method used to test for a url in a list of passwords. |
| 121 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 135 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
| 122 * @param {!String} url The URL that is being searched for. | 136 * @param {!string} url The URL that is being searched for. |
| 123 */ | 137 */ |
| 124 listContainsUrl(passwordList, url) { | 138 listContainsUrl(passwordList, url) { |
| 125 for (var i = 0; i < passwordList.length; ++i) { | 139 for (var i = 0; i < passwordList.length; ++i) { |
| 126 if (passwordList[i].loginPair.originUrl == url) | 140 if (passwordList[i].loginPair.originUrl == url) |
| 127 return true; | 141 return true; |
| 128 } | 142 } |
| 129 return false; | 143 return false; |
| 130 }, | 144 }, |
| 131 | 145 |
| 132 /** | 146 /** |
| 133 * Allow the iron-list to be sized properly. | 147 * Allow the iron-list to be sized properly. |
| 134 * @param {!Object} passwordsSection | 148 * @param {!Object} passwordsSection |
| 135 * @private | 149 * @private |
| 136 */ | 150 */ |
| 137 flush_: function(passwordsSection) { | 151 flushPasswordSection_: function(passwordsSection) { |
| 138 passwordsSection.$.passwordList.notifyResize(); | 152 passwordsSection.$.passwordList.notifyResize(); |
| 139 passwordsSection.$.passwordExceptionsList.notifyResize(); | 153 passwordsSection.$.passwordExceptionsList.notifyResize(); |
| 140 Polymer.dom.flush(); | 154 Polymer.dom.flush(); |
| 141 }, | 155 }, |
| 156 | |
| 157 /** | |
| 158 * Flush any pending polymer updates. | |
| 159 * @private | |
| 160 */ | |
| 161 flushPolymer_: function() { | |
| 162 Polymer.dom.flush(); | |
| 163 }, | |
|
Dan Beam
2016/03/25 03:12:55
i don't think this is better than just calling Pol
hcarmona
2016/03/25 19:08:20
Sounds good. Removed.
| |
| 142 }; | 164 }; |
| 143 | 165 |
| 144 /** | 166 /** |
| 145 * This test will validate that the section is loaded with data. | 167 * This test will validate that the section is loaded with data. |
| 146 */ | 168 */ |
| 147 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { | 169 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { |
| 148 var self = this; | 170 var self = this; |
| 149 | 171 |
| 150 suite('PasswordsSection', function() { | 172 suite('PasswordsSection', function() { |
| 151 test('verifySavedPasswordLength', function() { | 173 test('verifySavedPasswordLength', function() { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 179 self.createPasswordItem_('website.com', 'mario', 70) | 201 self.createPasswordItem_('website.com', 'mario', 70) |
| 180 ]; | 202 ]; |
| 181 | 203 |
| 182 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 204 var passwordsSection = self.createPasswordsSection_(passwordList, []); |
| 183 | 205 |
| 184 self.validatePasswordList( | 206 self.validatePasswordList( |
| 185 self.getIronListChildren_(passwordsSection.$.passwordList), | 207 self.getIronListChildren_(passwordsSection.$.passwordList), |
| 186 passwordList); | 208 passwordList); |
| 187 // Simulate 'longwebsite.com' being removed from the list. | 209 // Simulate 'longwebsite.com' being removed from the list. |
| 188 passwordsSection.splice('savedPasswords', 1, 1); | 210 passwordsSection.splice('savedPasswords', 1, 1); |
| 189 self.flush_(passwordsSection); | 211 self.flushPasswordSection_(passwordsSection); |
| 190 | 212 |
| 191 assertFalse(self.listContainsUrl(passwordsSection.savedPasswords, | 213 assertFalse(self.listContainsUrl(passwordsSection.savedPasswords, |
| 192 'longwebsite.com')); | 214 'longwebsite.com')); |
| 193 assertFalse(self.listContainsUrl(passwordList, 'longwebsite.com')); | 215 assertFalse(self.listContainsUrl(passwordList, 'longwebsite.com')); |
| 194 | 216 |
| 195 self.validatePasswordList( | 217 self.validatePasswordList( |
| 196 self.getIronListChildren_(passwordsSection.$.passwordList), | 218 self.getIronListChildren_(passwordsSection.$.passwordList), |
| 197 passwordList); | 219 passwordList); |
| 198 }); | 220 }); |
| 199 | 221 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 303 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 282 | 304 |
| 283 self.validateExceptionList_( | 305 self.validateExceptionList_( |
| 284 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 306 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 285 exceptionList); | 307 exceptionList); |
| 286 | 308 |
| 287 // Simulate 'mail.com' being removed from the list. | 309 // Simulate 'mail.com' being removed from the list. |
| 288 passwordsSection.splice('passwordExceptions', 1, 1); | 310 passwordsSection.splice('passwordExceptions', 1, 1); |
| 289 assertEquals(-1, passwordsSection.passwordExceptions.indexOf('mail.com')); | 311 assertEquals(-1, passwordsSection.passwordExceptions.indexOf('mail.com')); |
| 290 assertEquals(-1, exceptionList.indexOf('mail.com')); | 312 assertEquals(-1, exceptionList.indexOf('mail.com')); |
| 291 self.flush_(passwordsSection); | 313 self.flushPasswordSection_(passwordsSection); |
| 292 | 314 |
| 293 self.validateExceptionList_( | 315 self.validateExceptionList_( |
| 294 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 316 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 295 exceptionList); | 317 exceptionList); |
| 296 }); | 318 }); |
| 297 | 319 |
| 298 // Test verifies that pressing the 'remove' button will trigger a remove | 320 // Test verifies that pressing the 'remove' button will trigger a remove |
| 299 // event. Does not actually remove any exceptions. | 321 // event. Does not actually remove any exceptions. |
| 300 test('verifyPasswordExceptionRemoveButton', function(done) { | 322 test('verifyPasswordExceptionRemoveButton', function(done) { |
| 301 var exceptionList = [ | 323 var exceptionList = [ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 329 | 351 |
| 330 if (++index < exceptionList.length) | 352 if (++index < exceptionList.length) |
| 331 clickRemoveButton(); // Click 'remove' on all passwords, one by one. | 353 clickRemoveButton(); // Click 'remove' on all passwords, one by one. |
| 332 else | 354 else |
| 333 done(); | 355 done(); |
| 334 }); | 356 }); |
| 335 | 357 |
| 336 // Start removing. | 358 // Start removing. |
| 337 clickRemoveButton(); | 359 clickRemoveButton(); |
| 338 }); | 360 }); |
| 361 | |
| 362 test('usePasswordDialogTwice', function() { | |
| 363 var blankPassword = ' '.repeat(7); | |
|
Dan Beam
2016/03/25 03:12:55
nit: BLANK_PASSWORD
Dan Beam
2016/03/25 03:12:55
nit: why 7?
Dan Beam
2016/03/25 03:12:55
nit: put closer to use
hcarmona
2016/03/25 19:08:20
Done.
hcarmona
2016/03/25 19:08:20
Arbitrary. I replaced it with ' ' for simpli
hcarmona
2016/03/25 19:08:20
Used on next line.
| |
| 364 var item = self.createPasswordItem_('google.com', 'homer', | |
| 365 blankPassword.length); | |
| 366 var passwordDialog = self.createPasswordDialog_(item); | |
| 367 | |
| 368 passwordDialog.open(); | |
| 369 self.flushPolymer_(); | |
| 370 | |
| 371 assertEquals(item.loginPair.originUrl, | |
| 372 passwordDialog.$.websiteInput.value); | |
| 373 assertEquals(item.loginPair.username, | |
| 374 passwordDialog.$.usernameInput.value); | |
| 375 assertEquals(blankPassword, | |
| 376 passwordDialog.$.passwordInput.value); | |
| 377 // Password should NOT be visible. | |
| 378 assertEquals('password', | |
| 379 passwordDialog.$.passwordInput.type); | |
| 380 | |
| 381 passwordDialog.close(); | |
| 382 self.flushPolymer_(); | |
| 383 | |
| 384 var blankPassword2 = ' '.repeat(17); | |
| 385 var item2 = self.createPasswordItem_('drive.google.com', 'marge', | |
| 386 blankPassword2.length); | |
| 387 | |
| 388 passwordDialog.item = item2; | |
| 389 passwordDialog.open(); | |
| 390 self.flushPolymer_(); | |
| 391 | |
| 392 assertEquals(item2.loginPair.originUrl, | |
| 393 passwordDialog.$.websiteInput.value); | |
| 394 assertEquals(item2.loginPair.username, | |
| 395 passwordDialog.$.usernameInput.value); | |
| 396 assertEquals(blankPassword2, | |
| 397 passwordDialog.$.passwordInput.value); | |
| 398 // Password should NOT be visible. | |
| 399 assertEquals('password', | |
| 400 passwordDialog.$.passwordInput.type); | |
| 401 }); | |
| 402 | |
| 403 test('showSavedPassword', function() { | |
| 404 var password = 'bAn@n@5'; | |
|
Dan Beam
2016/03/25 03:12:55
nit: put closer to use
hcarmona
2016/03/25 19:08:20
Used on next line.
| |
| 405 var item = self.createPasswordItem_('goo.gl', 'bart', password.length); | |
| 406 var passwordDialog = self.createPasswordDialog_(item); | |
| 407 | |
| 408 passwordDialog.open(); | |
| 409 self.flushPolymer_(); | |
| 410 | |
| 411 passwordDialog.password = password; | |
| 412 passwordDialog.showPassword = true; | |
| 413 | |
| 414 self.flushPolymer_(); | |
| 415 | |
| 416 assertEquals(password, | |
| 417 passwordDialog.$.passwordInput.value); | |
| 418 // Password should be visible. | |
| 419 assertEquals('text', | |
| 420 passwordDialog.$.passwordInput.type); | |
| 421 }); | |
| 422 | |
| 423 // Test will timeout if event is not received. | |
| 424 test('onShowSavedPassword', function(done) { | |
| 425 var item = self.createPasswordItem_('goo.gl', 'bart', 1); | |
| 426 var passwordDialog = self.createPasswordDialog_(item); | |
| 427 | |
| 428 passwordDialog.open(); | |
| 429 self.flushPolymer_(); | |
| 430 | |
| 431 passwordDialog.addEventListener('show-password', | |
| 432 function(event) { | |
|
Dan Beam
2016/03/25 03:12:55
nit: doesn't this fit on one line?
hcarmona
2016/03/25 19:08:20
Done.
| |
| 433 assertEquals(item.loginPair.originUrl, event.detail.originUrl); | |
| 434 assertEquals(item.loginPair.username, event.detail.username); | |
| 435 done(); | |
| 436 }); | |
| 437 | |
| 438 passwordDialog.$.showPasswordButton.click(); | |
|
Dan Beam
2016/03/25 03:12:55
can you use MockInteractions.tap() instead?
hcarmona
2016/03/25 19:08:20
Yes! Replaced all |click| calls.
| |
| 439 }); | |
| 339 }); | 440 }); |
| 340 | 441 |
| 341 mocha.run(); | 442 mocha.run(); |
| 342 }); | 443 }); |
| OLD | NEW |