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

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

Issue 2015463003: Add dialog to edit and save credit cards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 ROOT_PATH +
14 // Fake data generator. 14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js',
15 GEN_INCLUDE([ROOT_PATH + 15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js',
16 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']); 16 ]);
17 17
18 /** 18 /**
19 * @constructor 19 * @constructor
20 * @extends {PolymerTest} 20 * @extends {PolymerTest}
21 */ 21 */
22 function SettingsAutofillSectionBrowserTest() {} 22 function SettingsAutofillSectionBrowserTest() {}
23 23
24 SettingsAutofillSectionBrowserTest.prototype = { 24 SettingsAutofillSectionBrowserTest.prototype = {
25 __proto__: PolymerTest.prototype, 25 __proto__: PolymerTest.prototype,
26 26
27 /** @override */ 27 /** @override */
28 browsePreload: 28 browsePreload:
29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', 29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html',
30 30
31 /** @override */ 31 /** @override */
32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), 32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
33 33
34 /** @override */ 34 /** @override */
35 setUp: function() { 35 setUp: function() {
36 PolymerTest.prototype.setUp.call(this); 36 PolymerTest.prototype.setUp.call(this);
37 37
38 // 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.
39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); 39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
40
41 // Faking 'strings.js' for this test.
42 loadTimeData.data = {
43 editCreditCardTitle: 'edit-title',
44 addCreditCardTitle: 'add-title'
45 };
Dan Beam 2016/06/04 01:00:26 this seems fine to me
hcarmona 2016/06/04 01:19:10 Acknowledged.
40 }, 46 },
41 47
42 /** 48 /**
43 * Allow the iron-list to be sized properly. 49 * Allow the iron-list to be sized properly.
44 * @param {!Object} autofillSection 50 * @param {!Object} autofillSection
45 * @private 51 * @private
46 */ 52 */
47 flushAutofillSection_: function(autofillSection) { 53 flushAutofillSection_: function(autofillSection) {
48 autofillSection.$.addressList.notifyResize(); 54 autofillSection.$.addressList.notifyResize();
49 autofillSection.$.creditCardList.notifyResize(); 55 autofillSection.$.creditCardList.notifyResize();
50 Polymer.dom.flush(); 56 Polymer.dom.flush();
51 }, 57 },
58
52 /** 59 /**
53 * Creates the autofill section for the given lists. 60 * Creates the autofill section for the given lists.
54 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList 61 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList
55 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList 62 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList
56 * @return {!Object} 63 * @return {!Object}
57 * @private 64 * @private
58 */ 65 */
59 createAutofillSection_: function(addresses, creditCards) { 66 createAutofillSection_: function(addresses, creditCards) {
60 // Create a passwords-section to use for testing.
61 var section = document.createElement('settings-autofill-section'); 67 var section = document.createElement('settings-autofill-section');
62 section.addresses = addresses; 68 section.addresses = addresses;
63 section.creditCards = creditCards; 69 section.creditCards = creditCards;
64 document.body.appendChild(section); 70 document.body.appendChild(section);
65 this.flushAutofillSection_(section); 71 this.flushAutofillSection_(section);
66 return section; 72 return section;
67 }, 73 },
74
75 /**
76 * Creates the Edit Credit Card dialog.
77 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem
78 * @return {!Object}
79 */
80 createCreditCardDialog_: function(creditCardItem) {
81 var section = document.createElement('settings-credit-card-edit-dialog');
82 document.body.appendChild(section);
83 section.open(creditCardItem); // Opening the dialog will add the item.
84 Polymer.dom.flush();
85 return section;
86 },
68 }; 87 };
69 88
70 /** 89 /**
71 * This test will validate that the section is loaded with data. 90 * This test will validate that the section is loaded with data.
72 */ 91 */
73 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { 92 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() {
74 var self = this; 93 var self = this;
75 94
76 suite('AutofillSection', function() { 95 suite('AutofillSection', function() {
77 test('verifyCreditCardCount', function() { 96 test('verifyCreditCardCount', function() {
(...skipping 22 matching lines...) Expand all
100 var creditCardList = section.$.creditCardList; 119 var creditCardList = section.$.creditCardList;
101 var row = creditCardList.children[1]; // Skip over the template. 120 var row = creditCardList.children[1]; // Skip over the template.
102 assertTrue(!!row); 121 assertTrue(!!row);
103 122
104 assertEquals(creditCard.metadata.summaryLabel, 123 assertEquals(creditCard.metadata.summaryLabel,
105 row.querySelector('#creditCardLabel').textContent); 124 row.querySelector('#creditCardLabel').textContent);
106 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear, 125 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear,
107 row.querySelector('#creditCardExpiration').textContent); 126 row.querySelector('#creditCardExpiration').textContent);
108 }); 127 });
109 128
129 test('verifyAddVsEditCreditCardTitle', function() {
130 var newCreditCard = FakeDataMaker.emptyCreditCardEntry();
131 var newCreditCardDialog = self.createCreditCardDialog_(newCreditCard);
132 var oldCreditCard = FakeDataMaker.creditCardEntry();
133 var oldCreditCardDialog = self.createCreditCardDialog_(oldCreditCard);
134
135 assertNotEquals(oldCreditCardDialog.title_, newCreditCardDialog.title_);
136 assertNotEquals('', newCreditCardDialog.title_);
137 assertNotEquals('', oldCreditCardDialog.title_);
138 }),
139
140 test('verifyExpiredCreditCardYear', function() {
141 var creditCard = FakeDataMaker.creditCardEntry();
142
143 // 2015 is over unless time goes wobbly.
144 var twentyFifteen = 2015;
145 creditCard.expirationYear = twentyFifteen.toString();
146
147 var creditCardDialog = self.createCreditCardDialog_(creditCard);
148 var selectableYears = creditCardDialog.$.yearList.items;
149 var firstSelectableYear = selectableYears[0];
150 var lastSelectableYear = selectableYears[selectableYears.length - 1];
151
152 var now = new Date();
153 var maxYear = now.getFullYear() + 9;
154
155 assertEquals('2015', firstSelectableYear.textContent);
156 assertEquals(maxYear.toString(), lastSelectableYear.textContent);
157 }),
158
159 test('verifyVeryFutureCreditCardYear', function() {
160 var creditCard = FakeDataMaker.creditCardEntry();
161
162 // Expiring 20 years from now is unusual.
163 var now = new Date();
164 var farFutureYear = now.getFullYear() + 20;
165 creditCard.expirationYear = farFutureYear.toString();
166
167 var creditCardDialog = self.createCreditCardDialog_(creditCard);
168 var selectableYears = creditCardDialog.$.yearList.items;
169 var firstSelectableYear = selectableYears[0];
170 var lastSelectableYear = selectableYears[selectableYears.length - 1];
171
172 assertEquals(now.getFullYear().toString(),
173 firstSelectableYear.textContent);
174 assertEquals(farFutureYear.toString(), lastSelectableYear.textContent);
175 }),
176
177 test('verifyVeryNormalCreditCardYear', function() {
178 var creditCard = FakeDataMaker.creditCardEntry();
179
180 // Expiring 2 years from now is not unusual.
181 var now = new Date();
182 var nearFutureYear = now.getFullYear() + 2;
183 creditCard.expirationYear = nearFutureYear.toString();
184 var maxYear = now.getFullYear() + 9;
185
186 var creditCardDialog = self.createCreditCardDialog_(creditCard);
187 var selectableYears = creditCardDialog.$.yearList.items;
188 var firstSelectableYear = selectableYears[0];
189 var lastSelectableYear = selectableYears[selectableYears.length - 1];
190
191 assertEquals(now.getFullYear().toString(),
192 firstSelectableYear.textContent);
193 assertEquals(maxYear.toString(), lastSelectableYear.textContent);
194 }),
195
196 // Test will timeout if event is not received.
197 test('verifySaveCreditCardEdit', function(done) {
198 var creditCard = FakeDataMaker.emptyCreditCardEntry();
199 var creditCardDialog = self.createCreditCardDialog_(creditCard);
200
201 creditCardDialog.addEventListener('save-credit-card', function(event) {
202 assertEquals(creditCard.guid, event.detail.guid);
203 done();
204 });
205
206 creditCardDialog.$.saveButton.click();
207 }),
208
209 test('verifyCancelCreditCardEdit', function(done) {
210 var creditCard = FakeDataMaker.emptyCreditCardEntry();
211 var creditCardDialog = self.createCreditCardDialog_(creditCard);
212
213 creditCardDialog.addEventListener('save-credit-card', function(event) {
214 // Fail the test because the save event should not be called when cancel
215 // is clicked.
216 assertTrue(false);
217 done();
218 });
219
220 creditCardDialog.addEventListener('iron-overlay-closed', function(event) {
221 // Finish test if dialog is closed.
222 done();
223 });
224
225 creditCardDialog.$.cancelButton.click();
226 }),
227
110 test('verifyAddressCount', function() { 228 test('verifyAddressCount', function() {
111 var addresses = [ 229 var addresses = [
112 FakeDataMaker.addressEntry(), 230 FakeDataMaker.addressEntry(),
113 FakeDataMaker.addressEntry(), 231 FakeDataMaker.addressEntry(),
114 FakeDataMaker.addressEntry(), 232 FakeDataMaker.addressEntry(),
115 FakeDataMaker.addressEntry(), 233 FakeDataMaker.addressEntry(),
116 FakeDataMaker.addressEntry(), 234 FakeDataMaker.addressEntry(),
117 ]; 235 ];
118 236
119 var section = self.createAutofillSection_(addresses, []); 237 var section = self.createAutofillSection_(addresses, []);
(...skipping 16 matching lines...) Expand all
136 var addressSummary = address.metadata.summaryLabel + 254 var addressSummary = address.metadata.summaryLabel +
137 address.metadata.summarySublabel; 255 address.metadata.summarySublabel;
138 256
139 assertEquals(addressSummary, 257 assertEquals(addressSummary,
140 row.querySelector('#addressSummary').textContent); 258 row.querySelector('#addressSummary').textContent);
141 }); 259 });
142 }); 260 });
143 261
144 mocha.run(); 262 mocha.run();
145 }); 263 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698