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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 * @private | 44 * @private |
| 45 */ | 45 */ |
| 46 createPasswordItem_: function(url, username, passwordLength) { | 46 createPasswordItem_: function(url, username, passwordLength) { |
| 47 return { | 47 return { |
| 48 loginPair: {originUrl: url, username: username}, | 48 loginPair: {originUrl: url, username: username}, |
| 49 numCharactersInPassword: passwordLength | 49 numCharactersInPassword: passwordLength |
| 50 }; | 50 }; |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Creates a single item for the list of password exceptions. | |
| 55 * @param {string} url | |
| 56 * @return {chrome.passwordsPrivate.ExceptionPair} | |
| 57 * @private | |
| 58 */ | |
| 59 createExceptionItem_: function(url) { | |
| 60 return { | |
| 61 exceptionUrl: url, | |
| 62 linkUrl: url, | |
|
stevenjb
2016/04/22 16:11:20
Test with different values, e.g. append "/login"
hcarmona
2016/04/23 01:46:08
Done.
| |
| 63 }; | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 54 * Helper method that validates a that elements in the password list match | 67 * Helper method that validates a that elements in the password list match |
| 55 * the expected data. | 68 * the expected data. |
| 56 * @param {!Array<!Element>} nodes The nodes that will be checked. | 69 * @param {!Array<!Element>} nodes The nodes that will be checked. |
| 57 * @param {!Array<!Object>} passwordList The expected data. | 70 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList The |
| 71 * expected data. | |
| 58 * @private | 72 * @private |
| 59 */ | 73 */ |
| 60 validatePasswordList: function(nodes, passwordList) { | 74 validatePasswordList: function(nodes, passwordList) { |
| 61 assertEquals(passwordList.length, nodes.length); | 75 assertEquals(passwordList.length, nodes.length); |
| 62 for (var index = 0; index < passwordList.length; ++index) { | 76 for (var index = 0; index < passwordList.length; ++index) { |
| 63 var node = nodes[index]; | 77 var node = nodes[index]; |
| 64 var passwordInfo = passwordList[index]; | 78 var passwordInfo = passwordList[index]; |
| 65 assertEquals(passwordInfo.loginPair.originUrl, | 79 assertEquals(passwordInfo.loginPair.originUrl, |
| 66 node.querySelector('#originUrl').textContent); | 80 node.querySelector('#originUrl').textContent); |
| 67 assertEquals(passwordInfo.loginPair.username, | 81 assertEquals(passwordInfo.loginPair.username, |
| 68 node.querySelector('#username').textContent); | 82 node.querySelector('#username').textContent); |
| 69 assertEquals(passwordInfo.numCharactersInPassword, | 83 assertEquals(passwordInfo.numCharactersInPassword, |
| 70 node.querySelector('#password').value.length); | 84 node.querySelector('#password').value.length); |
| 71 } | 85 } |
| 72 }, | 86 }, |
| 73 | 87 |
| 74 /** | 88 /** |
| 75 * Helper method that validates a that elements in the exception list match | 89 * Helper method that validates a that elements in the exception list match |
| 76 * the expected data. | 90 * the expected data. |
| 77 * @param {!Array<!Element>} nodes The nodes that will be checked. | 91 * @param {!Array<!Element>} nodes The nodes that will be checked. |
| 78 * @param {!Array<!Object>} exceptionList The expected data. | 92 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList The |
| 93 * expected data. | |
| 79 * @private | 94 * @private |
| 80 */ | 95 */ |
| 81 validateExceptionList_: function(nodes, exceptionList) { | 96 validateExceptionList_: function(nodes, exceptionList) { |
| 82 assertEquals(exceptionList.length, nodes.length); | 97 assertEquals(exceptionList.length, nodes.length); |
| 83 for (var index = 0; index < exceptionList.length; ++index) { | 98 for (var index = 0; index < exceptionList.length; ++index) { |
| 84 var node = nodes[index]; | 99 var node = nodes[index]; |
| 85 var exception = exceptionList[index]; | 100 var exception = exceptionList[index]; |
| 86 assertEquals(exception, node.querySelector('#exception').textContent); | 101 assertEquals(exception.exceptionUrl, |
| 102 node.querySelector('#exception').textContent); | |
|
stevenjb
2016/04/22 16:11:20
Test the link url also
hcarmona
2016/04/23 01:46:08
Done.
| |
| 87 } | 103 } |
| 88 }, | 104 }, |
| 89 | 105 |
| 90 /** | 106 /** |
| 91 * Skips over the template and returns all visible children of an iron-list. | 107 * Skips over the template and returns all visible children of an iron-list. |
| 92 * @param {!Element} ironList | 108 * @param {!Element} ironList |
| 93 * @return {!Array<!Element>} | 109 * @return {!Array<!Element>} |
| 94 * @private | 110 * @private |
| 95 */ | 111 */ |
| 96 getIronListChildren_: function(ironList) { | 112 getIronListChildren_: function(ironList) { |
| 97 return Polymer.dom(ironList).children.filter(function(child, i) { | 113 return Polymer.dom(ironList).children.filter(function(child, i) { |
| 98 return i != 0 && !child.hidden; | 114 return i != 0 && !child.hidden; |
| 99 }); | 115 }); |
| 100 }, | 116 }, |
| 101 | 117 |
| 102 /** | 118 /** |
| 103 * Helper method used to create a password section for the given lists. | 119 * Helper method used to create a password section for the given lists. |
| 104 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 120 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
| 105 * @param {!Array<!string>} exceptionList | 121 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList |
| 106 * @return {!Object} | 122 * @return {!Object} |
| 107 * @private | 123 * @private |
| 108 */ | 124 */ |
| 109 createPasswordsSection_: function(passwordList, exceptionList) { | 125 createPasswordsSection_: function(passwordList, exceptionList) { |
| 110 // Create a passwords-section to use for testing. | 126 // Create a passwords-section to use for testing. |
| 111 var passwordsSection = document.createElement('passwords-section'); | 127 var passwordsSection = document.createElement('passwords-section'); |
| 112 passwordsSection.savedPasswords = passwordList; | 128 passwordsSection.savedPasswords = passwordList; |
| 113 passwordsSection.passwordExceptions = exceptionList; | 129 passwordsSection.passwordExceptions = exceptionList; |
| 114 document.body.appendChild(passwordsSection); | 130 document.body.appendChild(passwordsSection); |
| 115 this.flushPasswordSection_(passwordsSection); | 131 this.flushPasswordSection_(passwordsSection); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 137 */ | 153 */ |
| 138 listContainsUrl(passwordList, url) { | 154 listContainsUrl(passwordList, url) { |
| 139 for (var i = 0; i < passwordList.length; ++i) { | 155 for (var i = 0; i < passwordList.length; ++i) { |
| 140 if (passwordList[i].loginPair.originUrl == url) | 156 if (passwordList[i].loginPair.originUrl == url) |
| 141 return true; | 157 return true; |
| 142 } | 158 } |
| 143 return false; | 159 return false; |
| 144 }, | 160 }, |
| 145 | 161 |
| 146 /** | 162 /** |
| 163 * Helper method used to test for a url in a list of passwords. | |
| 164 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | |
| 165 * @param {!string} url The URL that is being searched for. | |
| 166 */ | |
| 167 exceptionsListContainsUrl(exceptionList, url) { | |
| 168 for (var i = 0; i < exceptionList.length; ++i) { | |
| 169 if (exceptionList[i].exceptionUrl == url) | |
| 170 return true; | |
| 171 } | |
| 172 return false; | |
| 173 }, | |
| 174 | |
| 175 /** | |
| 147 * Allow the iron-list to be sized properly. | 176 * Allow the iron-list to be sized properly. |
| 148 * @param {!Object} passwordsSection | 177 * @param {!Object} passwordsSection |
| 149 * @private | 178 * @private |
| 150 */ | 179 */ |
| 151 flushPasswordSection_: function(passwordsSection) { | 180 flushPasswordSection_: function(passwordsSection) { |
| 152 passwordsSection.$.passwordList.notifyResize(); | 181 passwordsSection.$.passwordList.notifyResize(); |
| 153 passwordsSection.$.passwordExceptionsList.notifyResize(); | 182 passwordsSection.$.passwordExceptionsList.notifyResize(); |
| 154 Polymer.dom.flush(); | 183 Polymer.dom.flush(); |
| 155 }, | 184 }, |
| 156 }; | 185 }; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 done(); | 283 done(); |
| 255 } | 284 } |
| 256 }); | 285 }); |
| 257 | 286 |
| 258 // Start removing. | 287 // Start removing. |
| 259 clickRemoveButton(); | 288 clickRemoveButton(); |
| 260 }); | 289 }); |
| 261 | 290 |
| 262 test('verifyPasswordExceptions', function() { | 291 test('verifyPasswordExceptions', function() { |
| 263 var exceptionList = [ | 292 var exceptionList = [ |
| 264 'docs.google.com', | 293 self.createExceptionItem_('docs.google.com'), |
| 265 'mail.com', | 294 self.createExceptionItem_('mail.com'), |
| 266 'google.com', | 295 self.createExceptionItem_('google.com'), |
| 267 'inbox.google.com', | 296 self.createExceptionItem_('inbox.google.com'), |
| 268 'maps.google.com', | 297 self.createExceptionItem_('maps.google.com'), |
| 269 'plus.google.com', | 298 self.createExceptionItem_('plus.google.com'), |
| 270 ]; | 299 ]; |
| 271 | 300 |
| 272 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 301 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 273 | 302 |
| 274 // Assert that the data is passed into the iron list. If this fails, | 303 // Assert that the data is passed into the iron list. If this fails, |
| 275 // then other expectations will also fail. | 304 // then other expectations will also fail. |
| 276 assertEquals(exceptionList, | 305 assertEquals(exceptionList, |
| 277 passwordsSection.$.passwordExceptionsList.items); | 306 passwordsSection.$.passwordExceptionsList.items); |
| 278 | 307 |
| 279 self.validateExceptionList_( | 308 self.validateExceptionList_( |
| 280 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 309 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 281 exceptionList); | 310 exceptionList); |
| 282 }); | 311 }); |
| 283 | 312 |
| 284 // Test verifies that removing an exception will update the elements. | 313 // Test verifies that removing an exception will update the elements. |
| 285 test('verifyPasswordExceptionRemove', function() { | 314 test('verifyPasswordExceptionRemove', function() { |
| 286 var exceptionList = [ | 315 var exceptionList = [ |
| 287 'docs.google.com', | 316 self.createExceptionItem_('docs.google.com'), |
| 288 'mail.com', | 317 self.createExceptionItem_('mail.com'), |
| 289 'google.com', | 318 self.createExceptionItem_('google.com'), |
| 290 'inbox.google.com', | 319 self.createExceptionItem_('inbox.google.com'), |
| 291 'maps.google.com', | 320 self.createExceptionItem_('maps.google.com'), |
| 292 'plus.google.com', | 321 self.createExceptionItem_('plus.google.com'), |
| 293 ]; | 322 ]; |
| 294 | 323 |
| 295 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 324 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 296 | 325 |
| 297 self.validateExceptionList_( | 326 self.validateExceptionList_( |
| 298 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 327 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 299 exceptionList); | 328 exceptionList); |
| 300 | 329 |
| 301 // Simulate 'mail.com' being removed from the list. | 330 // Simulate 'mail.com' being removed from the list. |
| 302 passwordsSection.splice('passwordExceptions', 1, 1); | 331 passwordsSection.splice('passwordExceptions', 1, 1); |
| 303 assertEquals(-1, passwordsSection.passwordExceptions.indexOf('mail.com')); | 332 assertFalse(self.exceptionsListContainsUrl( |
| 304 assertEquals(-1, exceptionList.indexOf('mail.com')); | 333 passwordsSection.passwordExceptions, 'mail.com')); |
| 334 assertFalse(self.exceptionsListContainsUrl(exceptionList, 'mail.com')); | |
| 305 self.flushPasswordSection_(passwordsSection); | 335 self.flushPasswordSection_(passwordsSection); |
| 306 | 336 |
| 307 self.validateExceptionList_( | 337 self.validateExceptionList_( |
| 308 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), | 338 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList), |
| 309 exceptionList); | 339 exceptionList); |
| 310 }); | 340 }); |
| 311 | 341 |
| 312 // Test verifies that pressing the 'remove' button will trigger a remove | 342 // Test verifies that pressing the 'remove' button will trigger a remove |
| 313 // event. Does not actually remove any exceptions. | 343 // event. Does not actually remove any exceptions. |
| 314 test('verifyPasswordExceptionRemoveButton', function(done) { | 344 test('verifyPasswordExceptionRemoveButton', function(done) { |
| 315 var exceptionList = [ | 345 var exceptionList = [ |
| 316 'docs.google.com', | 346 self.createExceptionItem_('docs.google.com'), |
| 317 'mail.com', | 347 self.createExceptionItem_('mail.com'), |
| 318 'google.com', | 348 self.createExceptionItem_('google.com'), |
| 319 'inbox.google.com', | 349 self.createExceptionItem_('inbox.google.com'), |
| 320 'maps.google.com', | 350 self.createExceptionItem_('maps.google.com'), |
| 321 'plus.google.com', | 351 self.createExceptionItem_('plus.google.com'), |
| 322 ]; | 352 ]; |
| 323 | 353 |
| 324 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 354 var passwordsSection = self.createPasswordsSection_([], exceptionList); |
| 325 | 355 |
| 326 var exceptions = | 356 var exceptions = |
| 327 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList); | 357 self.getIronListChildren_(passwordsSection.$.passwordExceptionsList); |
| 328 | 358 |
| 329 // The index of the button currently being checked. | 359 // The index of the button currently being checked. |
| 330 var index = 0; | 360 var index = 0; |
| 331 | 361 |
| 332 var clickRemoveButton = function() { | 362 var clickRemoveButton = function() { |
| 333 MockInteractions.tap( | 363 MockInteractions.tap( |
| 334 exceptions[index].querySelector('#removeExceptionButton')); | 364 exceptions[index].querySelector('#removeExceptionButton')); |
| 335 }; | 365 }; |
| 336 | 366 |
| 337 // Listen for the remove event. If this event isn't received, the test | 367 // Listen for the remove event. If this event isn't received, the test |
| 338 // will time out and fail. | 368 // will time out and fail. |
| 339 passwordsSection.addEventListener('remove-password-exception', | 369 passwordsSection.addEventListener('remove-password-exception', |
| 340 function(event) { | 370 function(event) { |
| 341 // Verify that the event matches the expected value. | 371 // Verify that the event matches the expected value. |
| 342 assertTrue(index < exceptionList.length); | 372 assertTrue(index < exceptionList.length); |
| 343 assertEquals(exceptionList[index], event.detail); | 373 assertEquals(exceptionList[index].exceptionUrl, event.detail); |
| 344 | 374 |
| 345 if (++index < exceptionList.length) | 375 if (++index < exceptionList.length) |
| 346 clickRemoveButton(); // Click 'remove' on all passwords, one by one. | 376 clickRemoveButton(); // Click 'remove' on all passwords, one by one. |
| 347 else | 377 else |
| 348 done(); | 378 done(); |
| 349 }); | 379 }); |
| 350 | 380 |
| 351 // Start removing. | 381 // Start removing. |
| 352 clickRemoveButton(); | 382 clickRemoveButton(); |
| 353 }); | 383 }); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 assertEquals(item.loginPair.username, event.detail.username); | 456 assertEquals(item.loginPair.username, event.detail.username); |
| 427 done(); | 457 done(); |
| 428 }); | 458 }); |
| 429 | 459 |
| 430 MockInteractions.tap(passwordDialog.$.showPasswordButton); | 460 MockInteractions.tap(passwordDialog.$.showPasswordButton); |
| 431 }); | 461 }); |
| 432 }); | 462 }); |
| 433 | 463 |
| 434 mocha.run(); | 464 mocha.run(); |
| 435 }); | 465 }); |
| OLD | NEW |