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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 * expected data. | 53 * expected data. |
| 54 * @private | 54 * @private |
| 55 */ | 55 */ |
| 56 function validatePasswordList(listElement, passwordList) { | 56 function validatePasswordList(listElement, passwordList) { |
| 57 assertEquals(passwordList.length, listElement.items.length); | 57 assertEquals(passwordList.length, listElement.items.length); |
| 58 if (passwordList.length > 0) { | 58 if (passwordList.length > 0) { |
| 59 // The first child is a template, skip and get the real 'first child'. | 59 // The first child is a template, skip and get the real 'first child'. |
| 60 var node = Polymer.dom(listElement).children[1]; | 60 var node = Polymer.dom(listElement).children[1]; |
| 61 assert(node); | 61 assert(node); |
| 62 var passwordInfo = passwordList[0]; | 62 var passwordInfo = passwordList[0]; |
| 63 assertEquals(passwordInfo.loginPair.originUrl, | 63 assertEquals( |
|
hcarmona
2017/04/21 22:45:46
nit: keep on same line as assert for consistency w
jdoerrie
2017/04/24 08:35:59
Done.
| |
| 64 passwordInfo.loginPair.urls.shown, | |
| 64 node.querySelector('#originUrl').textContent.trim()); | 65 node.querySelector('#originUrl').textContent.trim()); |
| 65 assertEquals(passwordInfo.linkUrl, | 66 assertEquals( |
| 67 passwordInfo.loginPair.urls.link, | |
| 66 node.querySelector('#originUrl').href); | 68 node.querySelector('#originUrl').href); |
| 67 assertEquals(passwordInfo.loginPair.username, | 69 assertEquals(passwordInfo.loginPair.username, |
| 68 node.querySelector('#username').textContent); | 70 node.querySelector('#username').textContent); |
| 69 assertEquals(passwordInfo.numCharactersInPassword, | 71 assertEquals(passwordInfo.numCharactersInPassword, |
| 70 node.querySelector('#password').value.length); | 72 node.querySelector('#password').value.length); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 /** | 76 /** |
| 75 * Helper method that validates a that elements in the exception list match | 77 * Helper method that validates a that elements in the exception list match |
| 76 * the expected data. | 78 * the expected data. |
| 77 * @param {!Array<!Element>} nodes The nodes that will be checked. | 79 * @param {!Array<!Element>} nodes The nodes that will be checked. |
| 78 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList The | 80 * @param {!Array<!chrome.passwordsPrivate.ExceptionEntry>} exceptionList The |
| 79 * expected data. | 81 * expected data. |
| 80 * @private | 82 * @private |
| 81 */ | 83 */ |
| 82 function validateExceptionList(nodes, exceptionList) { | 84 function validateExceptionList(nodes, exceptionList) { |
| 83 assertEquals(exceptionList.length, nodes.length); | 85 assertEquals(exceptionList.length, nodes.length); |
| 84 for (var index = 0; index < exceptionList.length; ++index) { | 86 for (var index = 0; index < exceptionList.length; ++index) { |
| 85 var node = nodes[index]; | 87 var node = nodes[index]; |
| 86 var exception = exceptionList[index]; | 88 var exception = exceptionList[index]; |
| 87 assertEquals(exception.exceptionUrl, | 89 assertEquals( |
|
hcarmona
2017/04/21 22:45:46
nit: ditto
jdoerrie
2017/04/24 08:35:59
Done.
| |
| 88 node.querySelector('#exception').textContent); | 90 exception.urls.shown, node.querySelector('#exception').textContent); |
| 89 assertEquals(exception.linkUrl, | 91 assertEquals(exception.urls.link, node.querySelector('#exception').href); |
| 90 node.querySelector('#exception').href); | |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 /** | 95 /** |
| 95 * Returns all children of an element that has children added by a dom-repeat. | 96 * Returns all children of an element that has children added by a dom-repeat. |
| 96 * @param {!Element} element | 97 * @param {!Element} element |
| 97 * @return {!Array<!Element>} | 98 * @return {!Array<!Element>} |
| 98 * @private | 99 * @private |
| 99 */ | 100 */ |
| 100 function getDomRepeatChildren(element) { | 101 function getDomRepeatChildren(element) { |
| 101 var nodes = element.querySelectorAll('.list-item:not([id])'); | 102 var nodes = element.querySelectorAll('.list-item:not([id])'); |
| 102 return nodes; | 103 return nodes; |
| 103 } | 104 } |
| 104 | 105 |
| 105 /** | 106 /** |
| 106 * Allow the iron-list to be sized properly. | 107 * Allow the iron-list to be sized properly. |
| 107 * @param {!Object} passwordsSection | 108 * @param {!Object} passwordsSection |
| 108 * @private | 109 * @private |
| 109 */ | 110 */ |
| 110 function flushPasswordSection(passwordsSection) { | 111 function flushPasswordSection(passwordsSection) { |
| 111 passwordsSection.$.passwordList.notifyResize(); | 112 passwordsSection.$.passwordList.notifyResize(); |
| 112 Polymer.dom.flush(); | 113 Polymer.dom.flush(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 /** | 116 /** |
| 116 * Helper method used to create a password section for the given lists. | 117 * Helper method used to create a password section for the given lists. |
| 117 * @param {!PasswordManager} passwordManager | 118 * @param {!PasswordManager} passwordManager |
| 118 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 119 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
| 119 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | 120 * @param {!Array<!chrome.passwordsPrivate.ExceptionEntry>} exceptionList |
| 120 * @return {!Object} | 121 * @return {!Object} |
| 121 * @private | 122 * @private |
| 122 */ | 123 */ |
| 123 function createPasswordsSection(passwordManager, passwordList, | 124 function createPasswordsSection(passwordManager, passwordList, |
| 124 exceptionList) { | 125 exceptionList) { |
| 125 // Override the PasswordManager data for testing. | 126 // Override the PasswordManager data for testing. |
| 126 passwordManager.data.passwords = passwordList; | 127 passwordManager.data.passwords = passwordList; |
| 127 passwordManager.data.exceptions = exceptionList; | 128 passwordManager.data.exceptions = exceptionList; |
| 128 | 129 |
| 129 // Create a passwords-section to use for testing. | 130 // Create a passwords-section to use for testing. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 147 return passwordDialog; | 148 return passwordDialog; |
| 148 } | 149 } |
| 149 | 150 |
| 150 /** | 151 /** |
| 151 * Helper method used to test for a url in a list of passwords. | 152 * Helper method used to test for a url in a list of passwords. |
| 152 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 153 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
| 153 * @param {string} url The URL that is being searched for. | 154 * @param {string} url The URL that is being searched for. |
| 154 */ | 155 */ |
| 155 function listContainsUrl(passwordList, url) { | 156 function listContainsUrl(passwordList, url) { |
| 156 for (var i = 0; i < passwordList.length; ++i) { | 157 for (var i = 0; i < passwordList.length; ++i) { |
| 157 if (passwordList[i].loginPair.originUrl == url) | 158 if (passwordList[i].loginPair.urls.origin == url) |
| 158 return true; | 159 return true; |
| 159 } | 160 } |
| 160 return false; | 161 return false; |
| 161 } | 162 } |
| 162 | 163 |
| 163 /** | 164 /** |
| 164 * Helper method used to test for a url in a list of passwords. | 165 * Helper method used to test for a url in a list of passwords. |
| 165 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | 166 * @param {!Array<!chrome.passwordsPrivate.ExceptionEntry>} exceptionList |
| 166 * @param {string} url The URL that is being searched for. | 167 * @param {string} url The URL that is being searched for. |
| 167 */ | 168 */ |
| 168 function exceptionsListContainsUrl(exceptionList, url) { | 169 function exceptionsListContainsUrl(exceptionList, url) { |
| 169 for (var i = 0; i < exceptionList.length; ++i) { | 170 for (var i = 0; i < exceptionList.length; ++i) { |
| 170 if (exceptionList[i].exceptionUrl == url) | 171 if (exceptionList[i].urls.orginUrl == url) |
| 171 return true; | 172 return true; |
| 172 } | 173 } |
| 173 return false; | 174 return false; |
| 174 } | 175 } |
| 175 | 176 |
| 176 suite('PasswordsSection', function() { | 177 suite('PasswordsSection', function() { |
| 177 /** @type {TestPasswordManager} */ | 178 /** @type {TestPasswordManager} */ |
| 178 var passwordManager = null; | 179 var passwordManager = null; |
| 179 | 180 |
| 180 setup(function() { | 181 setup(function() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 var passwordsSection = createPasswordsSection( | 268 var passwordsSection = createPasswordsSection( |
| 268 passwordManager, passwordList, []); | 269 passwordManager, passwordList, []); |
| 269 | 270 |
| 270 // The first child is a template, skip and get the real 'first child'. | 271 // The first child is a template, skip and get the real 'first child'. |
| 271 var firstNode = Polymer.dom(passwordsSection.$.passwordList).children[1]; | 272 var firstNode = Polymer.dom(passwordsSection.$.passwordList).children[1]; |
| 272 assert(firstNode); | 273 assert(firstNode); |
| 273 var firstPassword = passwordList[0]; | 274 var firstPassword = passwordList[0]; |
| 274 | 275 |
| 275 passwordManager.onRemoveSavedPassword = function(detail) { | 276 passwordManager.onRemoveSavedPassword = function(detail) { |
| 276 // Verify that the event matches the expected value. | 277 // Verify that the event matches the expected value. |
| 277 assertEquals(firstPassword.loginPair.originUrl, detail.originUrl); | 278 assertEquals(firstPassword.loginPair.urls.origin, detail.urls.origin); |
| 278 assertEquals(firstPassword.loginPair.username, detail.username); | 279 assertEquals(firstPassword.loginPair.username, detail.username); |
| 279 | 280 |
| 280 // Clean up after self. | 281 // Clean up after self. |
| 281 passwordManager.onRemoveSavedPassword = null; | 282 passwordManager.onRemoveSavedPassword = null; |
| 282 | 283 |
| 283 done(); | 284 done(); |
| 284 }; | 285 }; |
| 285 | 286 |
| 286 // Click the remove button on the first password. | 287 // Click the remove button on the first password. |
| 287 MockInteractions.tap(firstNode.querySelector('#passwordMenu')); | 288 MockInteractions.tap(firstNode.querySelector('#passwordMenu')); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 assertEquals('text', | 462 assertEquals('text', |
| 462 passwordDialog.$.passwordInput.type); | 463 passwordDialog.$.passwordInput.type); |
| 463 }); | 464 }); |
| 464 | 465 |
| 465 // Test will timeout if event is not received. | 466 // Test will timeout if event is not received. |
| 466 test('onShowSavedPassword', function(done) { | 467 test('onShowSavedPassword', function(done) { |
| 467 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', 1); | 468 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', 1); |
| 468 var passwordDialog = createPasswordDialog(item); | 469 var passwordDialog = createPasswordDialog(item); |
| 469 | 470 |
| 470 passwordDialog.addEventListener('show-password', function(event) { | 471 passwordDialog.addEventListener('show-password', function(event) { |
| 471 assertEquals(item.loginPair.originUrl, event.detail.originUrl); | 472 assertEquals(item.loginPair.urls.origin, event.detail.urls.origin); |
| 472 assertEquals(item.loginPair.username, event.detail.username); | 473 assertEquals(item.loginPair.username, event.detail.username); |
| 473 done(); | 474 done(); |
| 474 }); | 475 }); |
| 475 | 476 |
| 476 MockInteractions.tap(passwordDialog.$.showPasswordButton); | 477 MockInteractions.tap(passwordDialog.$.showPasswordButton); |
| 477 }); | 478 }); |
| 478 }); | 479 }); |
| 479 | 480 |
| 480 mocha.run(); | 481 mocha.run(); |
| 481 }); | 482 }); |
| OLD | NEW |