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