| 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 Polymer.dom.flush(); |
| 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 }, |
| 142 }; | 156 }; |
| 143 | 157 |
| 144 /** | 158 /** |
| 145 * This test will validate that the section is loaded with data. | 159 * This test will validate that the section is loaded with data. |
| 146 */ | 160 */ |
| 147 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { | 161 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 self.createPasswordItem_('website.com', 'mario', 70) | 193 self.createPasswordItem_('website.com', 'mario', 70) |
| 180 ]; | 194 ]; |
| 181 | 195 |
| 182 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 196 var passwordsSection = self.createPasswordsSection_(passwordList, []); |
| 183 | 197 |
| 184 self.validatePasswordList( | 198 self.validatePasswordList( |
| 185 self.getIronListChildren_(passwordsSection.$.passwordList), | 199 self.getIronListChildren_(passwordsSection.$.passwordList), |
| 186 passwordList); | 200 passwordList); |
| 187 // Simulate 'longwebsite.com' being removed from the list. | 201 // Simulate 'longwebsite.com' being removed from the list. |
| 188 passwordsSection.splice('savedPasswords', 1, 1); | 202 passwordsSection.splice('savedPasswords', 1, 1); |
| 189 self.flush_(passwordsSection); | 203 self.flushPasswordSection_(passwordsSection); |
| 190 | 204 |
| 191 assertFalse(self.listContainsUrl(passwordsSection.savedPasswords, | 205 assertFalse(self.listContainsUrl(passwordsSection.savedPasswords, |
| 192 'longwebsite.com')); | 206 'longwebsite.com')); |
| 193 assertFalse(self.listContainsUrl(passwordList, 'longwebsite.com')); | 207 assertFalse(self.listContainsUrl(passwordList, 'longwebsite.com')); |
| 194 | 208 |
| 195 self.validatePasswordList( | 209 self.validatePasswordList( |
| 196 self.getIronListChildren_(passwordsSection.$.passwordList), | 210 self.getIronListChildren_(passwordsSection.$.passwordList), |
| 197 passwordList); | 211 passwordList); |
| 198 }); | 212 }); |
| 199 | 213 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 211 | 225 |
| 212 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 226 var passwordsSection = self.createPasswordsSection_(passwordList, []); |
| 213 | 227 |
| 214 var passwords = | 228 var passwords = |
| 215 self.getIronListChildren_(passwordsSection.$.passwordList); | 229 self.getIronListChildren_(passwordsSection.$.passwordList); |
| 216 | 230 |
| 217 // The index of the button currently being checked. | 231 // The index of the button currently being checked. |
| 218 var index = 0; | 232 var index = 0; |
| 219 | 233 |
| 220 var clickRemoveButton = function() { | 234 var clickRemoveButton = function() { |
| 221 passwords[index].querySelector('#passwordMenu').click(); | 235 MockInteractions.tap(passwords[index].querySelector('#passwordMenu')); |
| 222 passwordsSection.$.menuRemovePassword.click(); | 236 MockInteractions.tap(passwordsSection.$.menuRemovePassword); |
| 223 }; | 237 }; |
| 224 | 238 |
| 225 // Listen for the remove event. If this event isn't received, the test | 239 // Listen for the remove event. If this event isn't received, the test |
| 226 // will time out and fail. | 240 // will time out and fail. |
| 227 passwordsSection.addEventListener('remove-saved-password', | 241 passwordsSection.addEventListener('remove-saved-password', |
| 228 function(event) { | 242 function(event) { |
| 229 // Verify that the event matches the expected value. | 243 // Verify that the event matches the expected value. |
| 230 assertTrue(index < passwordList.length); | 244 assertTrue(index < passwordList.length); |
| 231 assertEquals(passwordList[index].loginPair.originUrl, | 245 assertEquals(passwordList[index].loginPair.originUrl, |
| 232 event.detail.originUrl); | 246 event.detail.originUrl); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 295 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 282 | 296 |
| 283 self.validateExceptionList_( | 297 self.validateExceptionList_( |
| 284 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 298 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 285 exceptionList); | 299 exceptionList); |
| 286 | 300 |
| 287 // Simulate 'mail.com' being removed from the list. | 301 // Simulate 'mail.com' being removed from the list. |
| 288 passwordsSection.splice('passwordExceptions', 1, 1); | 302 passwordsSection.splice('passwordExceptions', 1, 1); |
| 289 assertEquals(-1, passwordsSection.passwordExceptions.indexOf('mail.com')); | 303 assertEquals(-1, passwordsSection.passwordExceptions.indexOf('mail.com')); |
| 290 assertEquals(-1, exceptionList.indexOf('mail.com')); | 304 assertEquals(-1, exceptionList.indexOf('mail.com')); |
| 291 self.flush_(passwordsSection); | 305 self.flushPasswordSection_(passwordsSection); |
| 292 | 306 |
| 293 self.validateExceptionList_( | 307 self.validateExceptionList_( |
| 294 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 308 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 295 exceptionList); | 309 exceptionList); |
| 296 }); | 310 }); |
| 297 | 311 |
| 298 // Test verifies that pressing the 'remove' button will trigger a remove | 312 // Test verifies that pressing the 'remove' button will trigger a remove |
| 299 // event. Does not actually remove any exceptions. | 313 // event. Does not actually remove any exceptions. |
| 300 test('verifyPasswordExceptionRemoveButton', function(done) { | 314 test('verifyPasswordExceptionRemoveButton', function(done) { |
| 301 var exceptionList = [ | 315 var exceptionList = [ |
| 302 'docs.google.com', | 316 'docs.google.com', |
| 303 'mail.com', | 317 'mail.com', |
| 304 'google.com', | 318 'google.com', |
| 305 'inbox.google.com', | 319 'inbox.google.com', |
| 306 'maps.google.com', | 320 'maps.google.com', |
| 307 'plus.google.com', | 321 'plus.google.com', |
| 308 ]; | 322 ]; |
| 309 | 323 |
| 310 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 324 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 311 | 325 |
| 312 var exceptions = | 326 var exceptions = |
| 313 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList); | 327 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList); |
| 314 | 328 |
| 315 // The index of the button currently being checked. | 329 // The index of the button currently being checked. |
| 316 var index = 0; | 330 var index = 0; |
| 317 | 331 |
| 318 var clickRemoveButton = function() { | 332 var clickRemoveButton = function() { |
| 319 exceptions[index].querySelector('#removeExceptionButton').click(); | 333 MockInteractions.tap( |
| 334 exceptions[index].querySelector('#removeExceptionButton')); |
| 320 }; | 335 }; |
| 321 | 336 |
| 322 // Listen for the remove event. If this event isn't received, the test | 337 // Listen for the remove event. If this event isn't received, the test |
| 323 // will time out and fail. | 338 // will time out and fail. |
| 324 passwordsSection.addEventListener('remove-password-exception', | 339 passwordsSection.addEventListener('remove-password-exception', |
| 325 function(event) { | 340 function(event) { |
| 326 // Verify that the event matches the expected value. | 341 // Verify that the event matches the expected value. |
| 327 assertTrue(index < exceptionList.length); | 342 assertTrue(index < exceptionList.length); |
| 328 assertEquals(exceptionList[index], event.detail); | 343 assertEquals(exceptionList[index], event.detail); |
| 329 | 344 |
| 330 if (++index < exceptionList.length) | 345 if (++index < exceptionList.length) |
| 331 clickRemoveButton(); // Click 'remove' on all passwords, one by one. | 346 clickRemoveButton(); // Click 'remove' on all passwords, one by one. |
| 332 else | 347 else |
| 333 done(); | 348 done(); |
| 334 }); | 349 }); |
| 335 | 350 |
| 336 // Start removing. | 351 // Start removing. |
| 337 clickRemoveButton(); | 352 clickRemoveButton(); |
| 338 }); | 353 }); |
| 354 |
| 355 test('usePasswordDialogTwice', function() { |
| 356 var BLANK_PASSWORD = ' '; |
| 357 var item = self.createPasswordItem_('google.com', 'homer', |
| 358 BLANK_PASSWORD.length); |
| 359 var passwordDialog = self.createPasswordDialog_(item); |
| 360 |
| 361 passwordDialog.open(); |
| 362 Polymer.dom.flush(); |
| 363 |
| 364 assertEquals(item.loginPair.originUrl, |
| 365 passwordDialog.$.websiteInput.value); |
| 366 assertEquals(item.loginPair.username, |
| 367 passwordDialog.$.usernameInput.value); |
| 368 assertEquals(BLANK_PASSWORD, |
| 369 passwordDialog.$.passwordInput.value); |
| 370 // Password should NOT be visible. |
| 371 assertEquals('password', |
| 372 passwordDialog.$.passwordInput.type); |
| 373 |
| 374 passwordDialog.close(); |
| 375 Polymer.dom.flush(); |
| 376 |
| 377 var blankPassword2 = ' '.repeat(17); |
| 378 var item2 = self.createPasswordItem_('drive.google.com', 'marge', |
| 379 blankPassword2.length); |
| 380 |
| 381 passwordDialog.item = item2; |
| 382 passwordDialog.open(); |
| 383 Polymer.dom.flush(); |
| 384 |
| 385 assertEquals(item2.loginPair.originUrl, |
| 386 passwordDialog.$.websiteInput.value); |
| 387 assertEquals(item2.loginPair.username, |
| 388 passwordDialog.$.usernameInput.value); |
| 389 assertEquals(blankPassword2, |
| 390 passwordDialog.$.passwordInput.value); |
| 391 // Password should NOT be visible. |
| 392 assertEquals('password', |
| 393 passwordDialog.$.passwordInput.type); |
| 394 }); |
| 395 |
| 396 test('showSavedPassword', function() { |
| 397 var PASSWORD = 'bAn@n@5'; |
| 398 var item = self.createPasswordItem_('goo.gl', 'bart', PASSWORD.length); |
| 399 var passwordDialog = self.createPasswordDialog_(item); |
| 400 |
| 401 passwordDialog.open(); |
| 402 Polymer.dom.flush(); |
| 403 |
| 404 passwordDialog.password = PASSWORD; |
| 405 passwordDialog.showPassword = true; |
| 406 |
| 407 Polymer.dom.flush(); |
| 408 |
| 409 assertEquals(PASSWORD, |
| 410 passwordDialog.$.passwordInput.value); |
| 411 // Password should be visible. |
| 412 assertEquals('text', |
| 413 passwordDialog.$.passwordInput.type); |
| 414 }); |
| 415 |
| 416 // Test will timeout if event is not received. |
| 417 test('onShowSavedPassword', function(done) { |
| 418 var item = self.createPasswordItem_('goo.gl', 'bart', 1); |
| 419 var passwordDialog = self.createPasswordDialog_(item); |
| 420 |
| 421 passwordDialog.open(); |
| 422 Polymer.dom.flush(); |
| 423 |
| 424 passwordDialog.addEventListener('show-password', function(event) { |
| 425 assertEquals(item.loginPair.originUrl, event.detail.originUrl); |
| 426 assertEquals(item.loginPair.username, event.detail.username); |
| 427 done(); |
| 428 }); |
| 429 |
| 430 MockInteractions.tap(passwordDialog.$.showPasswordButton); |
| 431 }); |
| 339 }); | 432 }); |
| 340 | 433 |
| 341 mocha.run(); | 434 mocha.run(); |
| 342 }); | 435 }); |
| OLD | NEW |