OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 GEN_INCLUDE(['options_browsertest_base.js']); | |
6 | |
7 /** | |
8 * Returns the HTML element for the |field|. | |
9 * @param {string} field The field name for the element. | |
10 * @return {HTMLElement} The HTML element. | |
11 */ | |
12 function getField(field) { | |
13 return document.querySelector( | |
14 '#autofill-edit-address-overlay [field=' + field + ']'); | |
15 } | |
16 | |
17 /** | |
18 * Returns the size of the |list|. | |
19 * @param {HTMLElement} list The list to check. | |
20 * @return {number} The size of the list. | |
21 */ | |
22 function getListSize(list) { | |
23 // Remove 1 for placeholder input field. | |
24 return list.items.length - 1; | |
25 } | |
26 | |
27 /** | |
28 * TestFixture for autofill options WebUI testing. | |
29 * @extends {testing.Test} | |
30 * @constructor | |
31 */ | |
32 function AutofillOptionsWebUITest() {} | |
33 | |
34 AutofillOptionsWebUITest.prototype = { | |
35 __proto__: OptionsBrowsertestBase.prototype, | |
36 | |
37 /** | |
38 * Browse to autofill options. | |
39 * @override | |
40 */ | |
41 browsePreload: 'chrome://settings-frame/autofill', | |
42 }; | |
43 | |
44 // TODO(crbug.com/617066) Flakes on Win. | |
45 GEN('#if defined(OS_WIN)'); | |
46 GEN('#define MAYBE_testOpenAutofillOptions ' + | |
47 'DISABLED_testOpenAutofillOptions'); | |
48 GEN('#else'); | |
49 GEN('#define MAYBE_testOpenAutofillOptions testOpenAutofillOptions'); | |
50 GEN('#endif'); | |
51 // Test opening the autofill options has correct location. | |
52 TEST_F('AutofillOptionsWebUITest', 'MAYBE_testOpenAutofillOptions', | |
53 function() { | |
54 assertEquals(this.browsePreload, document.location.href); | |
55 }); | |
56 | |
57 /** | |
58 * TestFixture for autofill edit address overlay WebUI testing. | |
59 * @extends {testing.Test} | |
60 * @constructor | |
61 */ | |
62 function AutofillEditAddressWebUITest() {} | |
63 | |
64 AutofillEditAddressWebUITest.prototype = { | |
65 __proto__: OptionsBrowsertestBase.prototype, | |
66 | |
67 /** @override */ | |
68 browsePreload: 'chrome://settings-frame/autofillEditAddress', | |
69 }; | |
70 | |
71 TEST_F('AutofillEditAddressWebUITest', 'testInitialFormLayout', function() { | |
72 assertEquals(this.browsePreload, document.location.href); | |
73 | |
74 var fields = ['country', 'phone', 'email', 'fullName', 'city']; | |
75 for (field in fields) { | |
76 assertEquals('', getField(fields[field]).value, 'Field: ' + fields[field]); | |
77 } | |
78 | |
79 testDone(); | |
80 }); | |
81 | |
82 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() { | |
83 // http://crbug.com/434502 | |
84 // Accessibility failure was originally (and consistently) seen on Mac OS and | |
85 // Chromium OS. Disabling for all OSs because of a flake in Windows. There is | |
86 // a possibility for flake in linux too. | |
87 this.disableAccessibilityChecks(); | |
88 | |
89 assertEquals(this.browsePreload, document.location.href); | |
90 | |
91 var testAddress = { | |
92 guid: 'GUID Value', | |
93 fullName: 'Full Name 1', | |
94 companyName: 'Company Name Value', | |
95 addrLines: 'First Line Value\nSecond Line Value', | |
96 dependentLocality: 'Dependent Locality Value', | |
97 city: 'City Value', | |
98 state: 'State Value', | |
99 postalCode: 'Postal Code Value', | |
100 sortingCode: 'Sorting Code Value', | |
101 country: 'CH', | |
102 phone: '123', | |
103 email: 'a@b.c', | |
104 languageCode: 'de', | |
105 components: [[ | |
106 {field: 'postalCode', length: 'short'}, | |
107 {field: 'sortingCode', length: 'short'}, | |
108 {field: 'dependentLocality', length: 'short'}, | |
109 {field: 'city', length: 'short'}, | |
110 {field: 'state', length: 'short'}, | |
111 {field: 'addrLines', length: 'long'}, | |
112 {field: 'companyName', length: 'long'}, | |
113 {field: 'country', length: 'long'}, | |
114 {field: 'fullName', length: 'long', placeholder: 'Add name'} | |
115 ]] | |
116 }; | |
117 AutofillEditAddressOverlay.loadAddress(testAddress); | |
118 | |
119 var overlay = AutofillEditAddressOverlay.getInstance(); | |
120 assertEquals(testAddress.guid, overlay.guid_); | |
121 assertEquals(testAddress.languageCode, overlay.languageCode_); | |
122 | |
123 var inputs = ['companyName', 'dependentLocality', 'city', 'state', | |
124 'postalCode', 'sortingCode', 'fullName', 'email', 'phone']; | |
125 for (var i in inputs) { | |
126 var field = getField(inputs[i]); | |
127 assertEquals(testAddress[inputs[i]], field.value); | |
128 assertTrue(field instanceof HTMLInputElement); | |
129 } | |
130 | |
131 var addrLines = getField('addrLines'); | |
132 assertEquals(testAddress.addrLines, addrLines.value); | |
133 assertTrue(addrLines instanceof HTMLTextAreaElement); | |
134 | |
135 var country = getField('country'); | |
136 assertEquals(testAddress.country, country.value); | |
137 assertTrue(country instanceof HTMLSelectElement); | |
138 }); | |
139 | |
140 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddressComponents', function() { | |
141 assertEquals(this.browsePreload, document.location.href); | |
142 | |
143 var testInput = { | |
144 languageCode: 'fr', | |
145 components: [[{field: 'city'}], | |
146 [{field: 'state'}]] | |
147 }; | |
148 AutofillEditAddressOverlay.loadAddressComponents(testInput); | |
149 | |
150 assertEquals('fr', AutofillEditAddressOverlay.getInstance().languageCode_); | |
151 expectEquals(2, $('autofill-edit-address-fields').children.length); | |
152 }); | |
153 | |
154 TEST_F('AutofillEditAddressWebUITest', 'testFieldValuesSaved', function() { | |
155 assertEquals(this.browsePreload, document.location.href); | |
156 | |
157 AutofillEditAddressOverlay.loadAddressComponents({ | |
158 languageCode: 'en', | |
159 components: [[{field: 'city'}]] | |
160 }); | |
161 getField('city').value = 'New York'; | |
162 | |
163 AutofillEditAddressOverlay.loadAddressComponents({ | |
164 languageCode: 'en', | |
165 components: [[{field: 'state'}]] | |
166 }); | |
167 assertEquals(null, getField('city')); | |
168 | |
169 AutofillEditAddressOverlay.loadAddressComponents({ | |
170 languageCode: 'en', | |
171 components: [[{field: 'city'}]] | |
172 }); | |
173 assertEquals('New York', getField('city').value); | |
174 }); | |
OLD | NEW |