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

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

Issue 1957043002: Separate the listeners and getters for the Autofill Private API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-lists.gitbr
Patch Set: update histogram.xml and test Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 Autofill Settings tests. */ 5 /** @fileoverview Runs the Polymer Autofill 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 // Fake data generator.
15 GEN_INCLUDE([ROOT_PATH +
16 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']);
17
14 /** 18 /**
15 * @constructor 19 * @constructor
16 * @extends {PolymerTest} 20 * @extends {PolymerTest}
17 */ 21 */
18 function SettingsAutofillSectionBrowserTest() {} 22 function SettingsAutofillSectionBrowserTest() {}
19 23
20 SettingsAutofillSectionBrowserTest.prototype = { 24 SettingsAutofillSectionBrowserTest.prototype = {
21 __proto__: PolymerTest.prototype, 25 __proto__: PolymerTest.prototype,
22 26
23 /** @override */ 27 /** @override */
24 browsePreload: 28 browsePreload:
25 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', 29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html',
26 30
27 /** @override */ 31 /** @override */
28 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), 32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
29 33
30 /** @override */ 34 /** @override */
31 setUp: function() { 35 setUp: function() {
32 PolymerTest.prototype.setUp.call(this); 36 PolymerTest.prototype.setUp.call(this);
33 37
34 // Test is run on an individual element that won't have a page language. 38 // Test is run on an individual element that won't have a page language.
35 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); 39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
36 }, 40 },
37 41
38 /** 42 /**
39 * Replaces any 'x' in a string with a random number of the base.
40 * @param {!string} pattern The pattern that should be used as an input.
41 * @param {!number} base The number base. ie: 16 for hex or 10 for decimal.
42 * @return {!string}
43 * @private
44 */
45 patternMaker_: function(pattern, base) {
46 return pattern.replace(/x/g, function() {
47 return Math.floor(Math.random() * base).toString(base);
48 });
49 },
50
51 /**
52 * Creates a new random GUID for testing.
53 * @return {!string}
54 * @private
55 */
56 makeGuid_: function() {
57 return this.patternMaker_('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16);
58 },
59
60 /**
61 * Creates a fake address entry for testing.
62 * @return {!chrome.autofillPrivate.AddressEntry}
63 * @private
64 */
65 createFakeAddressEntry_: function() {
66 var ret = {};
67 ret.guid = this.makeGuid_();
68 ret.fullNames = ['John', 'Doe'];
69 ret.companyName = 'Google';
70 ret.addressLines = this.patternMaker_('xxxx Main St', 10);
71 ret.addressLevel1 = "CA";
72 ret.addressLevel2 = "Venice";
73 ret.postalCode = this.patternMaker_('xxxxx', 10);
74 ret.countryCode = 'US';
75 ret.phoneNumbers = [this.patternMaker_('(xxx) xxx-xxxx', 10)];
76 ret.emailAddresses = [this.patternMaker_('userxxxx@gmail.com', 16)];
77 ret.languageCode = 'EN-US';
78 ret.metadata = {isLocal: true};
79 ret.metadata.summaryLabel = ret.fullNames[0];
80 ret.metadata.summarySublabel = ' ' + ret.addressLines;
81 return ret;
82 },
83
84 /**
85 * Creates a new random credit card entry for testing.
86 * @return {!chrome.autofillPrivate.CreditCardEntry}
87 * @private
88 */
89 createFakeCreditCardEntry_: function() {
90 var ret = {};
91 ret.guid = this.makeGuid_();
92 ret.name = 'Jane Doe';
93 ret.cardNumber = this.patternMaker_('xxxx xxxx xxxx xxxx', 10);
94 ret.expirationMonth = Math.ceil(Math.random() * 11).toString();
95 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString();
96 ret.metadata = {isLocal: true};
97 var cards = ['Visa', 'Mastercard', 'Discover', 'Card'];
98 var card = cards[Math.floor(Math.random() * cards.length)];
99 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4);
100 return ret;
101 },
102
103 /**
104 * Allow the iron-list to be sized properly. 43 * Allow the iron-list to be sized properly.
105 * @param {!Object} autofillSection 44 * @param {!Object} autofillSection
106 * @private 45 * @private
107 */ 46 */
108 flushAutofillSection_: function(autofillSection) { 47 flushAutofillSection_: function(autofillSection) {
109 autofillSection.$.addressList.notifyResize(); 48 autofillSection.$.addressList.notifyResize();
110 autofillSection.$.creditCardList.notifyResize(); 49 autofillSection.$.creditCardList.notifyResize();
111 Polymer.dom.flush(); 50 Polymer.dom.flush();
112 }, 51 },
113 /** 52 /**
(...skipping 16 matching lines...) Expand all
130 69
131 /** 70 /**
132 * This test will validate that the section is loaded with data. 71 * This test will validate that the section is loaded with data.
133 */ 72 */
134 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { 73 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() {
135 var self = this; 74 var self = this;
136 75
137 suite('AutofillSection', function() { 76 suite('AutofillSection', function() {
138 test('verifyCreditCardCount', function() { 77 test('verifyCreditCardCount', function() {
139 var creditCards = [ 78 var creditCards = [
140 self.createFakeCreditCardEntry_(), 79 FakeDataMaker.creditCardEntry(),
141 self.createFakeCreditCardEntry_(), 80 FakeDataMaker.creditCardEntry(),
142 self.createFakeCreditCardEntry_(), 81 FakeDataMaker.creditCardEntry(),
143 self.createFakeCreditCardEntry_(), 82 FakeDataMaker.creditCardEntry(),
144 self.createFakeCreditCardEntry_(), 83 FakeDataMaker.creditCardEntry(),
145 self.createFakeCreditCardEntry_(), 84 FakeDataMaker.creditCardEntry(),
146 ]; 85 ];
147 86
148 var section = self.createAutofillSection_([], creditCards); 87 var section = self.createAutofillSection_([], creditCards);
149 88
150 assertTrue(!!section); 89 assertTrue(!!section);
151 var creditCardList = section.$.creditCardList; 90 var creditCardList = section.$.creditCardList;
152 assertTrue(!!creditCardList); 91 assertTrue(!!creditCardList);
153 assertEquals(creditCards, creditCardList.items); 92 assertEquals(creditCards, creditCardList.items);
154 // +1 for the template element. 93 // +1 for the template element.
155 assertEquals(creditCards.length + 1, creditCardList.children.length); 94 assertEquals(creditCards.length + 1, creditCardList.children.length);
156 }); 95 });
157 96
158 test('verifyCreditCardFields', function() { 97 test('verifyCreditCardFields', function() {
159 var creditCard = self.createFakeCreditCardEntry_(); 98 var creditCard = FakeDataMaker.creditCardEntry();
160 var section = self.createAutofillSection_([], [creditCard]); 99 var section = self.createAutofillSection_([], [creditCard]);
161 var creditCardList = section.$.creditCardList; 100 var creditCardList = section.$.creditCardList;
162 var row = creditCardList.children[1]; // Skip over the template. 101 var row = creditCardList.children[1]; // Skip over the template.
163 assertTrue(!!row); 102 assertTrue(!!row);
164 103
165 assertEquals(creditCard.metadata.summaryLabel, 104 assertEquals(creditCard.metadata.summaryLabel,
166 row.querySelector('#creditCardLabel').textContent); 105 row.querySelector('#creditCardLabel').textContent);
167 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear, 106 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear,
168 row.querySelector('#creditCardExpiration').textContent); 107 row.querySelector('#creditCardExpiration').textContent);
169 }); 108 });
170 109
171 test('verifyAddressCount', function() { 110 test('verifyAddressCount', function() {
172 var addresses = [ 111 var addresses = [
173 self.createFakeAddressEntry_(), 112 FakeDataMaker.addressEntry(),
174 self.createFakeAddressEntry_(), 113 FakeDataMaker.addressEntry(),
175 self.createFakeAddressEntry_(), 114 FakeDataMaker.addressEntry(),
176 self.createFakeAddressEntry_(), 115 FakeDataMaker.addressEntry(),
177 self.createFakeAddressEntry_(), 116 FakeDataMaker.addressEntry(),
178 ]; 117 ];
179 118
180 var section = self.createAutofillSection_(addresses, []); 119 var section = self.createAutofillSection_(addresses, []);
181 120
182 assertTrue(!!section); 121 assertTrue(!!section);
183 var addressList = section.$.addressList; 122 var addressList = section.$.addressList;
184 assertTrue(!!addressList); 123 assertTrue(!!addressList);
185 assertEquals(addresses, addressList.items); 124 assertEquals(addresses, addressList.items);
186 // +1 for the template element. 125 // +1 for the template element.
187 assertEquals(addresses.length + 1, addressList.children.length); 126 assertEquals(addresses.length + 1, addressList.children.length);
188 }); 127 });
189 128
190 test('verifyAddressFields', function() { 129 test('verifyAddressFields', function() {
191 var address = self.createFakeAddressEntry_(); 130 var address = FakeDataMaker.addressEntry();
192 var section = self.createAutofillSection_([address], []); 131 var section = self.createAutofillSection_([address], []);
193 var addressList = section.$.addressList; 132 var addressList = section.$.addressList;
194 var row = addressList.children[1]; // Skip over the template. 133 var row = addressList.children[1]; // Skip over the template.
195 assertTrue(!!row); 134 assertTrue(!!row);
196 135
197 var addressSummary = address.metadata.summaryLabel + 136 var addressSummary = address.metadata.summaryLabel +
198 address.metadata.summarySublabel; 137 address.metadata.summarySublabel;
199 138
200 assertEquals(addressSummary, 139 assertEquals(addressSummary,
201 row.querySelector('#addressSummary').textContent); 140 row.querySelector('#addressSummary').textContent);
202 }); 141 });
203 }); 142 });
204 143
205 mocha.run(); 144 mocha.run();
206 }); 145 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698