| 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 21 matching lines...) Expand all Loading... |
| 32 * This test will validate that the section is loaded with data. | 32 * This test will validate that the section is loaded with data. |
| 33 */ | 33 */ |
| 34 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { | 34 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { |
| 35 var self = this; | 35 var self = this; |
| 36 | 36 |
| 37 suite('PasswordsSection', function() { | 37 suite('PasswordsSection', function() { |
| 38 test('doWork', function(done) { | 38 test('doWork', function(done) { |
| 39 assertEquals(self.browsePreload, document.location.href, | 39 assertEquals(self.browsePreload, document.location.href, |
| 40 'Unexpected URL loaded'); | 40 'Unexpected URL loaded'); |
| 41 | 41 |
| 42 var passwordList = [{origin: 'anotherwebsite.com', | 42 var passwordList = [{shownUrl: 'anotherwebsite.com', |
| 43 username: 'luigi', | 43 username: 'luigi', |
| 44 password: '*******'}, | 44 password: '*******'}, |
| 45 {origin: 'longwebsite.com', | 45 {shownUrl: 'longwebsite.com', |
| 46 username: 'peach', | 46 username: 'peach', |
| 47 password: '***'}, | 47 password: '***'}, |
| 48 {origin: 'website.com', | 48 {shownUrl: 'website.com', |
| 49 username: 'mario', | 49 username: 'mario', |
| 50 password: '*******'}]; | 50 password: '*******'}]; |
| 51 | 51 |
| 52 // Create a passwords-section to use for testing. | 52 // Create a passwords-section to use for testing. |
| 53 var passwordsSection = document.createElement('passwords-section'); | 53 var passwordsSection = document.createElement('passwords-section'); |
| 54 passwordsSection.savedPasswords = passwordList; | 54 passwordsSection.savedPasswords = passwordList; |
| 55 document.body.appendChild(passwordsSection); | 55 document.body.appendChild(passwordsSection); |
| 56 | 56 |
| 57 // TODO(hcarmona): use an event listener rather than a setTimeout(0). | 57 // TODO(hcarmona): use an event listener rather than a setTimeout(0). |
| 58 window.setTimeout(function() { | 58 window.setTimeout(function() { |
| 59 // Assert that the data is passed into the iron list. If this fails, | 59 // Assert that the data is passed into the iron list. If this fails, |
| 60 // then other expectations will also fail. | 60 // then other expectations will also fail. |
| 61 assertEquals(passwordList, passwordsSection.$.passwordList.items, | 61 assertEquals(passwordList, passwordsSection.$.passwordList.items, |
| 62 'Failed to pass list of passwords to iron-list'); | 62 'Failed to pass list of passwords to iron-list'); |
| 63 | 63 |
| 64 var list = Polymer.dom(passwordsSection.$.passwordList); | 64 var list = Polymer.dom(passwordsSection.$.passwordList); |
| 65 assertTrue(!!list, "Failed to get the password list"); | 65 assertTrue(!!list, 'Failed to get the password list'); |
| 66 // Skip the first child because it's the template. | 66 // Skip the first child because it's the template. |
| 67 var listChildren = list.children.slice(1); | 67 var listChildren = list.children.slice(1); |
| 68 | 68 |
| 69 /** |
| 70 * Helper method that validates a node matches the data for an index. |
| 71 * @param {Array<Element>} nodes The nodes that will be checked. |
| 72 * @param {Array<Object>} passwordList The expected data. |
| 73 * @param {number} index The index that should match the node and data. |
| 74 */ |
| 69 var validate = function(nodes, passwordList, index) { | 75 var validate = function(nodes, passwordList, index) { |
| 70 assertTrue(!!nodes[index], 'Failed to get nodes[' + index + ']'); | 76 var node = nodes[index]; |
| 71 assertEquals(passwordList[index].origin, | 77 var passwordInfo = passwordList[index]; |
| 72 nodes[index].querySelector('#origin').textContent, | 78 assertTrue(!!node, 'Failed to get nodes[' + index + ']'); |
| 73 'origin mismatch in nodes[' + index + ']'); | 79 assertTrue(!!passwordInfo, |
| 74 assertEquals(passwordList[index].username, | 80 'Failed to get passwordList[' + index + ']'); |
| 75 nodes[index].querySelector('#username').textContent, | 81 assertEquals(passwordInfo.shownUrl, |
| 82 node.querySelector('#shownUrl').textContent, |
| 83 'shownUrl mismatch in nodes[' + index + ']'); |
| 84 assertEquals(passwordInfo.username, |
| 85 node.querySelector('#username').textContent, |
| 76 'username mismatch in nodes[' + index + ']'); | 86 'username mismatch in nodes[' + index + ']'); |
| 77 assertEquals(passwordList[index].password, | 87 assertEquals(passwordInfo.password, |
| 78 nodes[index].querySelector('#password').textContent, | 88 node.querySelector('#password').value, |
| 79 'password mismatch in nodes[' + index + ']'); | 89 'password mismatch in nodes[' + index + ']'); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 validate(listChildren, passwordList, 0); | 92 validate(listChildren, passwordList, 0); |
| 83 validate(listChildren, passwordList, 1); | 93 validate(listChildren, passwordList, 1); |
| 84 validate(listChildren, passwordList, 2); | 94 validate(listChildren, passwordList, 2); |
| 85 done(); | 95 done(); |
| 86 }, 0); | 96 }, 0); |
| 87 }); | 97 }); |
| 88 }); | 98 }); |
| 89 | 99 |
| 90 mocha.run(); | 100 mocha.run(); |
| 91 }); | 101 }); |
| OLD | NEW |