| 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. |
| 11 GEN_INCLUDE( | 11 GEN_INCLUDE( |
| 12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); | 12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * @constructor | 15 * @constructor |
| 16 * @extends {PolymerTest} | 16 * @extends {PolymerTest} |
| 17 */ | 17 */ |
| 18 function SettingsPasswordSectionBrowserTest() {} | 18 function SettingsPasswordSectionBrowserTest() {} |
| 19 | 19 |
| 20 SettingsPasswordSectionBrowserTest.prototype = { | 20 SettingsPasswordSectionBrowserTest.prototype = { |
| 21 __proto__: PolymerTest.prototype, | 21 __proto__: PolymerTest.prototype, |
| 22 | 22 |
| 23 /** @override */ | 23 /** @override */ |
| 24 browsePreload: | 24 browsePreload: |
| 25 'chrome://md-settings/passwords_and_forms_page/passwords_section.html', | 25 'chrome://md-settings/passwords_and_forms_page/passwords_section.html', |
| 26 | 26 |
| 27 /** @override */ | 27 /** @override */ |
| 28 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 28 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
| 29 |
| 30 /** @override */ |
| 31 setUp: function() { |
| 32 PolymerTest.prototype.setUp.call(this); |
| 33 |
| 34 // Test is run on an individual element that won't have a page language. |
| 35 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
| 36 }, |
| 37 |
| 38 /** |
| 39 * Creates a single item for the list of passwords. |
| 40 * @param {string} url |
| 41 * @param {string} username |
| 42 * @param {number} passwordLength |
| 43 * @return {chrome.passwordsPrivate.PasswordUiEntry} |
| 44 * @private |
| 45 */ |
| 46 createPasswordItem_: function(url, username, passwordLength) { |
| 47 return { |
| 48 loginPair: {originUrl: url, username: username}, |
| 49 numCharactersInPassword: passwordLength |
| 50 }; |
| 51 }, |
| 52 |
| 53 /** |
| 54 * Helper method that validates a node matches the data for an index. |
| 55 * @param {!Array<!Element>} nodes The nodes that will be checked. |
| 56 * @param {!Array<!Object>} passwordList The expected data. |
| 57 * @param {number} index The index that should match the node and data. |
| 58 * @private |
| 59 */ |
| 60 validate_: function(nodes, passwordList, index) { |
| 61 var node = nodes[index]; |
| 62 var passwordInfo = passwordList[index]; |
| 63 assertTrue(!!node, 'Failed to get nodes[' + index + ']'); |
| 64 assertTrue(!!passwordInfo, 'Failed to get passwordList[' + index + ']'); |
| 65 assertEquals( |
| 66 passwordInfo.loginPair.originUrl, |
| 67 node.querySelector('#originUrl').textContent, |
| 68 'originUrl mismatch in nodes[' + index + ']'); |
| 69 assertEquals( |
| 70 passwordInfo.loginPair.username, |
| 71 node.querySelector('#username').textContent, |
| 72 'username mismatch in nodes[' + index + ']'); |
| 73 assertEquals( |
| 74 passwordInfo.numCharactersInPassword, |
| 75 node.querySelector('#password').value.length, |
| 76 'password size mismatch in nodes[' + index + ']'); |
| 77 }, |
| 29 }; | 78 }; |
| 30 | 79 |
| 31 /** | 80 /** |
| 32 * This test will validate that the section is loaded with data. | 81 * This test will validate that the section is loaded with data. |
| 33 */ | 82 */ |
| 34 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { | 83 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { |
| 35 var self = this; | 84 var self = this; |
| 36 | 85 |
| 37 suite('PasswordsSection', function() { | 86 suite('PasswordsSection', function() { |
| 38 test('doWork', function(done) { | 87 test('doWork', function(done) { |
| 39 assertEquals(self.browsePreload, document.location.href, | 88 assertEquals(self.browsePreload, document.location.href, |
| 40 'Unexpected URL loaded'); | 89 'Unexpected URL loaded'); |
| 41 | 90 |
| 42 var passwordList = [{origin: 'anotherwebsite.com', | 91 var passwordList = [ |
| 43 username: 'luigi', | 92 self.createPasswordItem_('anotherwebsite.com', 'luigi', 1), |
| 44 password: '*******'}, | 93 self.createPasswordItem_('longwebsite.com', 'peach', 7), |
| 45 {origin: 'longwebsite.com', | 94 self.createPasswordItem_('website.com', 'mario', 70) |
| 46 username: 'peach', | 95 ]; |
| 47 password: '***'}, | |
| 48 {origin: 'website.com', | |
| 49 username: 'mario', | |
| 50 password: '*******'}]; | |
| 51 | 96 |
| 52 // Create a passwords-section to use for testing. | 97 // Create a passwords-section to use for testing. |
| 53 var passwordsSection = document.createElement('passwords-section'); | 98 var passwordsSection = document.createElement('passwords-section'); |
| 54 passwordsSection.savedPasswords = passwordList; | 99 passwordsSection.savedPasswords = passwordList; |
| 55 document.body.appendChild(passwordsSection); | 100 document.body.appendChild(passwordsSection); |
| 56 | 101 |
| 57 // TODO(hcarmona): use an event listener rather than a setTimeout(0). | 102 // TODO(hcarmona): use an event listener rather than a setTimeout(0). |
| 58 window.setTimeout(function() { | 103 window.setTimeout(function() { |
| 59 // Assert that the data is passed into the iron list. If this fails, | 104 // Assert that the data is passed into the iron list. If this fails, |
| 60 // then other expectations will also fail. | 105 // then other expectations will also fail. |
| 61 assertEquals(passwordList, passwordsSection.$.passwordList.items, | 106 assertEquals(passwordList, passwordsSection.$.passwordList.items, |
| 62 'Failed to pass list of passwords to iron-list'); | 107 'Failed to pass list of passwords to iron-list'); |
| 63 | 108 |
| 64 var list = Polymer.dom(passwordsSection.$.passwordList); | 109 var list = Polymer.dom(passwordsSection.$.passwordList); |
| 65 assertTrue(!!list, "Failed to get the password list"); | 110 assertTrue(!!list, 'Failed to get the password list'); |
| 66 // Skip the first child because it's the template. | 111 // Skip the first child because it's the template. |
| 67 var listChildren = list.children.slice(1); | 112 var listChildren = list.children.slice(1); |
| 68 | 113 |
| 69 var validate = function(nodes, passwordList, index) { | 114 self.validate_(listChildren, passwordList, 0); |
| 70 assertTrue(!!nodes[index], 'Failed to get nodes[' + index + ']'); | 115 self.validate_(listChildren, passwordList, 1); |
| 71 assertEquals(passwordList[index].origin, | 116 self.validate_(listChildren, passwordList, 2); |
| 72 nodes[index].querySelector('#origin').textContent, | |
| 73 'origin mismatch in nodes[' + index + ']'); | |
| 74 assertEquals(passwordList[index].username, | |
| 75 nodes[index].querySelector('#username').textContent, | |
| 76 'username mismatch in nodes[' + index + ']'); | |
| 77 assertEquals(passwordList[index].password, | |
| 78 nodes[index].querySelector('#password').textContent, | |
| 79 'password mismatch in nodes[' + index + ']'); | |
| 80 }; | |
| 81 | |
| 82 validate(listChildren, passwordList, 0); | |
| 83 validate(listChildren, passwordList, 1); | |
| 84 validate(listChildren, passwordList, 2); | |
| 85 done(); | 117 done(); |
| 86 }, 0); | 118 }, 0); |
| 87 }); | 119 }); |
| 88 }); | 120 }); |
| 89 | 121 |
| 90 mocha.run(); | 122 mocha.run(); |
| 91 }); | 123 }); |
| OLD | NEW |