Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/test/data/webui/settings/settings_passwords_section_browsertest.js

Issue 1591053002: Add a password handler to get the list of passwords in md-settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome.passwordsPrivate Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
Dan Beam 2016/01/27 00:17:45 needs a @return, might also want to @typedef this
hcarmona 2016/01/27 02:46:18 Done.
43 */
44 createPasswordItem(url, username, passwordLength) {
Dan Beam 2016/01/27 00:17:45 can this be private?
Dan Beam 2016/01/27 00:17:45 createPasswordItem: function(url, username, passwo
hcarmona 2016/01/27 02:46:18 Done.
hcarmona 2016/01/27 02:46:18 Done.
45 return {
46 loginPair: {originUrl: url, username: username},
47 numCharactersInPassword: passwordLength
48 };
49 },
50
51 /**
52 * Helper method that validates a node matches the data for an index.
53 * @param {Array<Element>} nodes The nodes that will be checked.
Dan Beam 2016/01/27 00:17:45 nit: this should probably be !Array<!Element>
hcarmona 2016/01/27 02:46:18 Done.
54 * @param {Array<Object>} passwordList The expected data.
Dan Beam 2016/01/27 00:17:45 and !Array<!Object>
hcarmona 2016/01/27 02:46:18 Done.
55 * @param {number} index The index that should match the node and data.
56 */
57 validate(nodes, passwordList, index) {
58 var node = nodes[index];
59 var passwordInfo = passwordList[index];
60 assertTrue(!!node, 'Failed to get nodes[' + index + ']');
61 assertTrue(!!passwordInfo, 'Failed to get passwordList[' + index + ']');
62 assertEquals(
63 passwordInfo.loginPair.originUrl,
64 node.querySelector('#shownUrl').textContent,
65 'shownUrl mismatch in nodes[' + index + ']');
66 assertEquals(
67 passwordInfo.loginPair.username,
68 node.querySelector('#username').textContent,
69 'username mismatch in nodes[' + index + ']');
70 assertEquals(
71 passwordInfo.numCharactersInPassword,
72 node.querySelector('#password').value.length,
73 'password size mismatch in nodes[' + index + ']');
74 },
29 }; 75 };
30 76
31 /** 77 /**
32 * This test will validate that the section is loaded with data. 78 * This test will validate that the section is loaded with data.
33 */ 79 */
34 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { 80 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() {
35 var self = this; 81 var self = this;
36 82
37 suite('PasswordsSection', function() { 83 suite('PasswordsSection', function() {
38 test('doWork', function(done) { 84 test('doWork', function(done) {
39 assertEquals(self.browsePreload, document.location.href, 85 assertEquals(self.browsePreload, document.location.href,
40 'Unexpected URL loaded'); 86 'Unexpected URL loaded');
41 87
42 var passwordList = [{origin: 'anotherwebsite.com', 88 var passwordList = [
43 username: 'luigi', 89 self.createPasswordItem('anotherwebsite.com', 'luigi', 7),
44 password: '*******'}, 90 self.createPasswordItem('longwebsite.com', 'peach', 7),
45 {origin: 'longwebsite.com', 91 self.createPasswordItem('website.com', 'mario', 7)
46 username: 'peach', 92 ];
47 password: '***'},
48 {origin: 'website.com',
49 username: 'mario',
50 password: '*******'}];
51 93
52 // Create a passwords-section to use for testing. 94 // Create a passwords-section to use for testing.
53 var passwordsSection = document.createElement('passwords-section'); 95 var passwordsSection = document.createElement('passwords-section');
54 passwordsSection.savedPasswords = passwordList; 96 passwordsSection.savedPasswords = passwordList;
55 document.body.appendChild(passwordsSection); 97 document.body.appendChild(passwordsSection);
56 98
57 // TODO(hcarmona): use an event listener rather than a setTimeout(0). 99 // TODO(hcarmona): use an event listener rather than a setTimeout(0).
58 window.setTimeout(function() { 100 window.setTimeout(function() {
59 // Assert that the data is passed into the iron list. If this fails, 101 // Assert that the data is passed into the iron list. If this fails,
60 // then other expectations will also fail. 102 // then other expectations will also fail.
61 assertEquals(passwordList, passwordsSection.$.passwordList.items, 103 assertEquals(passwordList, passwordsSection.$.passwordList.items,
62 'Failed to pass list of passwords to iron-list'); 104 'Failed to pass list of passwords to iron-list');
63 105
64 var list = Polymer.dom(passwordsSection.$.passwordList); 106 var list = Polymer.dom(passwordsSection.$.passwordList);
65 assertTrue(!!list, "Failed to get the password list"); 107 assertTrue(!!list, 'Failed to get the password list');
66 // Skip the first child because it's the template. 108 // Skip the first child because it's the template.
67 var listChildren = list.children.slice(1); 109 var listChildren = list.children.slice(1);
68 110
69 var validate = function(nodes, passwordList, index) { 111 self.validate(listChildren, passwordList, 0);
70 assertTrue(!!nodes[index], 'Failed to get nodes[' + index + ']'); 112 self.validate(listChildren, passwordList, 1);
71 assertEquals(passwordList[index].origin, 113 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(); 114 done();
86 }, 0); 115 }, 0);
87 }); 116 });
88 }); 117 });
89 118
90 mocha.run(); 119 mocha.run();
91 }); 120 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698