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. |
(...skipping 16 matching lines...) Expand all Loading... |
27 /** @override */ | 27 /** @override */ |
28 browsePreload: | 28 browsePreload: |
29 'chrome://md-settings/passwords_and_forms_page/passwords_section.html', | 29 'chrome://md-settings/passwords_and_forms_page/passwords_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 PolymerTest.clearBody(); | |
38 | |
39 // Test is run on an individual element that won't have a page language. | 37 // Test is run on an individual element that won't have a page language. |
40 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 38 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
41 }, | 39 }, |
42 | 40 |
| 41 }; |
| 42 |
| 43 /** This test will validate that the section is loaded with data. */ |
| 44 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { |
43 /** | 45 /** |
44 * Helper method that validates a that elements in the password list match | 46 * Helper method that validates a that elements in the password list match |
45 * the expected data. | 47 * the expected data. |
46 * @param {!Element} listElement The iron-list element that will be checked. | 48 * @param {!Element} listElement The iron-list element that will be checked. |
47 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList The | 49 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList The |
48 * expected data. | 50 * expected data. |
49 * @private | 51 * @private |
50 */ | 52 */ |
51 validatePasswordList: function(listElement, passwordList) { | 53 function validatePasswordList(listElement, passwordList) { |
52 assertEquals(passwordList.length, listElement.items.length); | 54 assertEquals(passwordList.length, listElement.items.length); |
53 if (passwordList.length > 0) { | 55 if (passwordList.length > 0) { |
54 // The first child is a template, skip and get the real 'first child'. | 56 // The first child is a template, skip and get the real 'first child'. |
55 var node = Polymer.dom(listElement).children[1]; | 57 var node = Polymer.dom(listElement).children[1]; |
56 assert(node); | 58 assert(node); |
57 var passwordInfo = passwordList[0]; | 59 var passwordInfo = passwordList[0]; |
58 assertEquals(passwordInfo.loginPair.originUrl, | 60 assertEquals(passwordInfo.loginPair.originUrl, |
59 node.querySelector('#originUrl').textContent.trim()); | 61 node.querySelector('#originUrl').textContent.trim()); |
60 assertEquals(passwordInfo.linkUrl, | 62 assertEquals(passwordInfo.linkUrl, |
61 node.querySelector('#originUrl').href); | 63 node.querySelector('#originUrl').href); |
62 assertEquals(passwordInfo.loginPair.username, | 64 assertEquals(passwordInfo.loginPair.username, |
63 node.querySelector('#username').textContent); | 65 node.querySelector('#username').textContent); |
64 assertEquals(passwordInfo.numCharactersInPassword, | 66 assertEquals(passwordInfo.numCharactersInPassword, |
65 node.querySelector('#password').value.length); | 67 node.querySelector('#password').value.length); |
66 } | 68 } |
67 }, | 69 } |
68 | 70 |
69 /** | 71 /** |
70 * Helper method that validates a that elements in the exception list match | 72 * Helper method that validates a that elements in the exception list match |
71 * the expected data. | 73 * the expected data. |
72 * @param {!Array<!Element>} nodes The nodes that will be checked. | 74 * @param {!Array<!Element>} nodes The nodes that will be checked. |
73 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList The | 75 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList The |
74 * expected data. | 76 * expected data. |
75 * @private | 77 * @private |
76 */ | 78 */ |
77 validateExceptionList_: function(nodes, exceptionList) { | 79 function validateExceptionList(nodes, exceptionList) { |
78 assertEquals(exceptionList.length, nodes.length); | 80 assertEquals(exceptionList.length, nodes.length); |
79 for (var index = 0; index < exceptionList.length; ++index) { | 81 for (var index = 0; index < exceptionList.length; ++index) { |
80 var node = nodes[index]; | 82 var node = nodes[index]; |
81 var exception = exceptionList[index]; | 83 var exception = exceptionList[index]; |
82 assertEquals(exception.exceptionUrl, | 84 assertEquals(exception.exceptionUrl, |
83 node.querySelector('#exception').textContent); | 85 node.querySelector('#exception').textContent); |
84 assertEquals(exception.linkUrl, | 86 assertEquals(exception.linkUrl, |
85 node.querySelector('#exception').href); | 87 node.querySelector('#exception').href); |
86 } | 88 } |
87 }, | 89 } |
88 | 90 |
89 /** | 91 /** |
90 * Returns all children of an element that has children added by a dom-repeat. | 92 * Returns all children of an element that has children added by a dom-repeat. |
91 * @param {!Element} element | 93 * @param {!Element} element |
92 * @return {!Array<!Element>} | 94 * @return {!Array<!Element>} |
93 * @private | 95 * @private |
94 */ | 96 */ |
95 getDomRepeatChildren_: function(element) { | 97 function getDomRepeatChildren(element) { |
96 var nodes = element.querySelectorAll('.list-item:not([id])'); | 98 var nodes = element.querySelectorAll('.list-item:not([id])'); |
97 return nodes; | 99 return nodes; |
98 }, | 100 } |
| 101 |
| 102 /** |
| 103 * Allow the iron-list to be sized properly. |
| 104 * @param {!Object} passwordsSection |
| 105 * @private |
| 106 */ |
| 107 function flushPasswordSection(passwordsSection) { |
| 108 passwordsSection.$.passwordList.notifyResize(); |
| 109 Polymer.dom.flush(); |
| 110 } |
99 | 111 |
100 /** | 112 /** |
101 * Helper method used to create a password section for the given lists. | 113 * Helper method used to create a password section for the given lists. |
| 114 * @param {!PasswordManager} passwordManager |
102 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 115 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
103 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | 116 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList |
104 * @return {!Object} | 117 * @return {!Object} |
105 * @private | 118 * @private |
106 */ | 119 */ |
107 createPasswordsSection_: function(passwordList, exceptionList) { | 120 function createPasswordsSection(passwordManager, passwordList, |
| 121 exceptionList) { |
| 122 // Override the PasswordManager data for testing. |
| 123 passwordManager.data.passwords = passwordList; |
| 124 passwordManager.data.exceptions = exceptionList; |
| 125 |
108 // Create a passwords-section to use for testing. | 126 // Create a passwords-section to use for testing. |
109 var passwordsSection = document.createElement('passwords-section'); | 127 var passwordsSection = document.createElement('passwords-section'); |
110 passwordsSection.savedPasswords = passwordList; | |
111 passwordsSection.passwordExceptions = exceptionList; | |
112 document.body.appendChild(passwordsSection); | 128 document.body.appendChild(passwordsSection); |
113 this.flushPasswordSection_(passwordsSection); | 129 flushPasswordSection(passwordsSection); |
114 return passwordsSection; | 130 return passwordsSection; |
115 }, | 131 } |
116 | 132 |
117 /** | 133 /** |
118 * Helper method used to create a password editing dialog. | 134 * Helper method used to create a password editing dialog. |
119 * @param {!chrome.passwordsPrivate.PasswordUiEntry} passwordItem | 135 * @param {!chrome.passwordsPrivate.PasswordUiEntry} passwordItem |
120 * @return {!Object} | 136 * @return {!Object} |
121 * @private | 137 * @private |
122 */ | 138 */ |
123 createPasswordDialog_: function(passwordItem) { | 139 function createPasswordDialog(passwordItem) { |
124 var passwordDialog = document.createElement('password-edit-dialog'); | 140 var passwordDialog = document.createElement('password-edit-dialog'); |
125 passwordDialog.item = passwordItem; | 141 passwordDialog.item = passwordItem; |
126 document.body.appendChild(passwordDialog); | 142 document.body.appendChild(passwordDialog); |
127 Polymer.dom.flush(); | 143 Polymer.dom.flush(); |
128 return passwordDialog; | 144 return passwordDialog; |
129 }, | 145 } |
130 | 146 |
131 /** | 147 /** |
132 * Helper method used to test for a url in a list of passwords. | 148 * Helper method used to test for a url in a list of passwords. |
133 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 149 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
134 * @param {string} url The URL that is being searched for. | 150 * @param {string} url The URL that is being searched for. |
135 */ | 151 */ |
136 listContainsUrl(passwordList, url) { | 152 function listContainsUrl(passwordList, url) { |
137 for (var i = 0; i < passwordList.length; ++i) { | 153 for (var i = 0; i < passwordList.length; ++i) { |
138 if (passwordList[i].loginPair.originUrl == url) | 154 if (passwordList[i].loginPair.originUrl == url) |
139 return true; | 155 return true; |
140 } | 156 } |
141 return false; | 157 return false; |
142 }, | 158 } |
143 | 159 |
144 /** | 160 /** |
145 * Helper method used to test for a url in a list of passwords. | 161 * Helper method used to test for a url in a list of passwords. |
146 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | 162 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList |
147 * @param {string} url The URL that is being searched for. | 163 * @param {string} url The URL that is being searched for. |
148 */ | 164 */ |
149 exceptionsListContainsUrl(exceptionList, url) { | 165 function exceptionsListContainsUrl(exceptionList, url) { |
150 for (var i = 0; i < exceptionList.length; ++i) { | 166 for (var i = 0; i < exceptionList.length; ++i) { |
151 if (exceptionList[i].exceptionUrl == url) | 167 if (exceptionList[i].exceptionUrl == url) |
152 return true; | 168 return true; |
153 } | 169 } |
154 return false; | 170 return false; |
155 }, | 171 } |
156 | |
157 /** | |
158 * Allow the iron-list to be sized properly. | |
159 * @param {!Object} passwordsSection | |
160 * @private | |
161 */ | |
162 flushPasswordSection_: function(passwordsSection) { | |
163 passwordsSection.$.passwordList.notifyResize(); | |
164 Polymer.dom.flush(); | |
165 }, | |
166 }; | |
167 | |
168 /** This test will validate that the section is loaded with data. */ | |
169 TEST_F('SettingsPasswordSectionBrowserTest', 'uiTests', function() { | |
170 var self = this; | |
171 | 172 |
172 suite('PasswordsSection', function() { | 173 suite('PasswordsSection', function() { |
| 174 /** @type {TestPasswordManager} */ |
| 175 var passwordManager = null; |
| 176 |
| 177 setup(function() { |
| 178 PolymerTest.clearBody(); |
| 179 // Override the PasswordManagerImpl for testing. |
| 180 passwordManager = new TestPasswordManager(); |
| 181 PasswordManagerImpl.instance_ = passwordManager; |
| 182 }); |
| 183 |
173 test('verifyNoSavedPasswords', function() { | 184 test('verifyNoSavedPasswords', function() { |
174 var passwordsSection = self.createPasswordsSection_([], []); | 185 var passwordsSection = createPasswordsSection(passwordManager, [], []); |
175 | 186 |
176 self.validatePasswordList(passwordsSection.$.passwordList, []); | 187 validatePasswordList(passwordsSection.$.passwordList, []); |
177 | 188 |
178 assertFalse(passwordsSection.$.noPasswordsLabel.hidden); | 189 assertFalse(passwordsSection.$.noPasswordsLabel.hidden); |
179 assertTrue(passwordsSection.$.savedPasswordsHeading.hidden); | 190 assertTrue(passwordsSection.$.savedPasswordsHeading.hidden); |
180 }); | 191 }); |
181 | 192 |
182 test('verifySavedPasswordLength', function() { | 193 test('verifySavedPasswordLength', function() { |
183 var passwordList = [ | 194 var passwordList = [ |
184 FakeDataMaker.passwordEntry('site1.com', 'luigi', 1), | 195 FakeDataMaker.passwordEntry('site1.com', 'luigi', 1), |
185 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), | 196 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), |
186 FakeDataMaker.passwordEntry('site2.com', 'mario', 70), | 197 FakeDataMaker.passwordEntry('site2.com', 'mario', 70), |
187 FakeDataMaker.passwordEntry('site1.com', 'peach', 11), | 198 FakeDataMaker.passwordEntry('site1.com', 'peach', 11), |
188 FakeDataMaker.passwordEntry('google.com', 'mario', 7), | 199 FakeDataMaker.passwordEntry('google.com', 'mario', 7), |
189 FakeDataMaker.passwordEntry('site2.com', 'luigi', 8), | 200 FakeDataMaker.passwordEntry('site2.com', 'luigi', 8), |
190 ]; | 201 ]; |
191 | 202 |
192 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 203 var passwordsSection = createPasswordsSection( |
| 204 passwordManager, passwordList, []); |
193 | 205 |
194 // Assert that the data is passed into the iron list. If this fails, | 206 // Assert that the data is passed into the iron list. If this fails, |
195 // then other expectations will also fail. | 207 // then other expectations will also fail. |
196 assertEquals(passwordList, passwordsSection.$.passwordList.items); | 208 assertEquals(passwordList, passwordsSection.$.passwordList.items); |
197 | 209 |
198 self.validatePasswordList(passwordsSection.$.passwordList, passwordList); | 210 validatePasswordList(passwordsSection.$.passwordList, passwordList); |
199 | 211 |
200 assertTrue(passwordsSection.$.noPasswordsLabel.hidden); | 212 assertTrue(passwordsSection.$.noPasswordsLabel.hidden); |
201 assertFalse(passwordsSection.$.savedPasswordsHeading.hidden); | 213 assertFalse(passwordsSection.$.savedPasswordsHeading.hidden); |
202 }); | 214 }); |
203 | 215 |
204 // Test verifies that removing a password will update the elements. | 216 // Test verifies that removing a password will update the elements. |
205 test('verifyPasswordListRemove', function() { | 217 test('verifyPasswordListRemove', function() { |
206 var passwordList = [ | 218 var passwordList = [ |
207 FakeDataMaker.passwordEntry('anotherwebsite.com', 'luigi', 1), | 219 FakeDataMaker.passwordEntry('anotherwebsite.com', 'luigi', 1), |
208 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), | 220 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), |
209 FakeDataMaker.passwordEntry('website.com', 'mario', 70) | 221 FakeDataMaker.passwordEntry('website.com', 'mario', 70) |
210 ]; | 222 ]; |
211 | 223 |
212 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 224 var passwordsSection = createPasswordsSection( |
| 225 passwordManager, passwordList, []); |
213 | 226 |
214 self.validatePasswordList(passwordsSection.$.passwordList, passwordList); | 227 validatePasswordList(passwordsSection.$.passwordList, passwordList); |
215 // Simulate 'longwebsite.com' being removed from the list. | 228 // Simulate 'longwebsite.com' being removed from the list. |
216 passwordsSection.splice('savedPasswords', 1, 1); | 229 passwordsSection.splice('savedPasswords', 1, 1); |
217 self.flushPasswordSection_(passwordsSection); | 230 flushPasswordSection(passwordsSection); |
218 | 231 |
219 assertFalse(self.listContainsUrl(passwordsSection.savedPasswords, | 232 assertFalse(listContainsUrl(passwordsSection.savedPasswords, |
220 'longwebsite.com')); | 233 'longwebsite.com')); |
221 assertFalse(self.listContainsUrl(passwordList, 'longwebsite.com')); | 234 assertFalse(listContainsUrl(passwordList, 'longwebsite.com')); |
222 | 235 |
223 self.validatePasswordList(passwordsSection.$.passwordList, passwordList); | 236 validatePasswordList(passwordsSection.$.passwordList, passwordList); |
224 }); | 237 }); |
225 | 238 |
226 // Test verifies that pressing the 'remove' button will trigger a remove | 239 // Test verifies that pressing the 'remove' button will trigger a remove |
227 // event. Does not actually remove any passwords. | 240 // event. Does not actually remove any passwords. |
228 test('verifyPasswordItemRemoveButton', function(done) { | 241 test('verifyPasswordItemRemoveButton', function(done) { |
229 var passwordList = [ | 242 var passwordList = [ |
230 FakeDataMaker.passwordEntry('one', 'six', 5), | 243 FakeDataMaker.passwordEntry('one', 'six', 5), |
231 FakeDataMaker.passwordEntry('two', 'five', 3), | 244 FakeDataMaker.passwordEntry('two', 'five', 3), |
232 FakeDataMaker.passwordEntry('three', 'four', 1), | 245 FakeDataMaker.passwordEntry('three', 'four', 1), |
233 FakeDataMaker.passwordEntry('four', 'three', 2), | 246 FakeDataMaker.passwordEntry('four', 'three', 2), |
234 FakeDataMaker.passwordEntry('five', 'two', 4), | 247 FakeDataMaker.passwordEntry('five', 'two', 4), |
235 FakeDataMaker.passwordEntry('six', 'one', 6), | 248 FakeDataMaker.passwordEntry('six', 'one', 6), |
236 ]; | 249 ]; |
237 | 250 |
238 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 251 var passwordsSection = createPasswordsSection( |
| 252 passwordManager, passwordList, []); |
239 | 253 |
240 // The first child is a template, skip and get the real 'first child'. | 254 // The first child is a template, skip and get the real 'first child'. |
241 var firstNode = Polymer.dom(passwordsSection.$.passwordList).children[1]; | 255 var firstNode = Polymer.dom(passwordsSection.$.passwordList).children[1]; |
242 assert(firstNode); | 256 assert(firstNode); |
243 var firstPassword = passwordList[0]; | 257 var firstPassword = passwordList[0]; |
244 | 258 |
245 // Listen for the remove event. If this event isn't received, the test | 259 passwordManager.onRemoveSavedPassword = function(detail) { |
246 // will time out and fail. | |
247 passwordsSection.addEventListener('remove-saved-password', | |
248 function(event) { | |
249 // Verify that the event matches the expected value. | 260 // Verify that the event matches the expected value. |
250 assertEquals(firstPassword.loginPair.originUrl, | 261 assertEquals(firstPassword.loginPair.originUrl, detail.originUrl); |
251 event.detail.originUrl); | 262 assertEquals(firstPassword.loginPair.username, detail.username); |
252 assertEquals(firstPassword.loginPair.username, | 263 |
253 event.detail.username); | 264 // Clean up after self. |
| 265 passwordManager.onRemoveSavedPassword = null; |
| 266 |
254 done(); | 267 done(); |
255 }); | 268 }; |
256 | 269 |
257 // Click the remove button on the first password. | 270 // Click the remove button on the first password. |
258 MockInteractions.tap(firstNode.querySelector('#passwordMenu')); | 271 MockInteractions.tap(firstNode.querySelector('#passwordMenu')); |
259 MockInteractions.tap(passwordsSection.$.menuRemovePassword); | 272 MockInteractions.tap(passwordsSection.$.menuRemovePassword); |
260 }); | 273 }); |
261 | 274 |
262 test('verifyFilterPasswords', function() { | 275 test('verifyFilterPasswords', function() { |
263 var passwordList = [ | 276 var passwordList = [ |
264 FakeDataMaker.passwordEntry('one.com', 'show', 5), | 277 FakeDataMaker.passwordEntry('one.com', 'show', 5), |
265 FakeDataMaker.passwordEntry('two.com', 'shower', 3), | 278 FakeDataMaker.passwordEntry('two.com', 'shower', 3), |
266 FakeDataMaker.passwordEntry('three.com/show', 'four', 1), | 279 FakeDataMaker.passwordEntry('three.com/show', 'four', 1), |
267 FakeDataMaker.passwordEntry('four.com', 'three', 2), | 280 FakeDataMaker.passwordEntry('four.com', 'three', 2), |
268 FakeDataMaker.passwordEntry('five.com', 'two', 4), | 281 FakeDataMaker.passwordEntry('five.com', 'two', 4), |
269 FakeDataMaker.passwordEntry('six-show.com', 'one', 6), | 282 FakeDataMaker.passwordEntry('six-show.com', 'one', 6), |
270 ]; | 283 ]; |
271 | 284 |
272 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 285 var passwordsSection = createPasswordsSection( |
| 286 passwordManager, passwordList, []); |
273 passwordsSection.filter = 'show'; | 287 passwordsSection.filter = 'show'; |
274 Polymer.dom.flush(); | 288 Polymer.dom.flush(); |
275 | 289 |
276 var expectedList = [ | 290 var expectedList = [ |
277 FakeDataMaker.passwordEntry('one.com', 'show', 5), | 291 FakeDataMaker.passwordEntry('one.com', 'show', 5), |
278 FakeDataMaker.passwordEntry('two.com', 'shower', 3), | 292 FakeDataMaker.passwordEntry('two.com', 'shower', 3), |
279 FakeDataMaker.passwordEntry('three.com/show', 'four', 1), | 293 FakeDataMaker.passwordEntry('three.com/show', 'four', 1), |
280 FakeDataMaker.passwordEntry('six-show.com', 'one', 6), | 294 FakeDataMaker.passwordEntry('six-show.com', 'one', 6), |
281 ]; | 295 ]; |
282 | 296 |
283 self.validatePasswordList(passwordsSection.$.passwordList, expectedList); | 297 validatePasswordList(passwordsSection.$.passwordList, expectedList); |
284 }); | 298 }); |
285 | 299 |
286 test('verifyFilterPasswordExceptions', function() { | 300 test('verifyFilterPasswordExceptions', function() { |
287 var exceptionList = [ | 301 var exceptionList = [ |
288 FakeDataMaker.exceptionEntry('docsshow.google.com'), | 302 FakeDataMaker.exceptionEntry('docsshow.google.com'), |
289 FakeDataMaker.exceptionEntry('showmail.com'), | 303 FakeDataMaker.exceptionEntry('showmail.com'), |
290 FakeDataMaker.exceptionEntry('google.com'), | 304 FakeDataMaker.exceptionEntry('google.com'), |
291 FakeDataMaker.exceptionEntry('inbox.google.com'), | 305 FakeDataMaker.exceptionEntry('inbox.google.com'), |
292 FakeDataMaker.exceptionEntry('mapsshow.google.com'), | 306 FakeDataMaker.exceptionEntry('mapsshow.google.com'), |
293 FakeDataMaker.exceptionEntry('plus.google.comshow'), | 307 FakeDataMaker.exceptionEntry('plus.google.comshow'), |
294 ]; | 308 ]; |
295 | 309 |
296 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 310 var passwordsSection = createPasswordsSection( |
| 311 passwordManager, [], exceptionList); |
297 passwordsSection.filter = 'show'; | 312 passwordsSection.filter = 'show'; |
298 Polymer.dom.flush(); | 313 Polymer.dom.flush(); |
299 | 314 |
300 var expectedExceptionList = [ | 315 var expectedExceptionList = [ |
301 FakeDataMaker.exceptionEntry('docsshow.google.com'), | 316 FakeDataMaker.exceptionEntry('docsshow.google.com'), |
302 FakeDataMaker.exceptionEntry('showmail.com'), | 317 FakeDataMaker.exceptionEntry('showmail.com'), |
303 FakeDataMaker.exceptionEntry('mapsshow.google.com'), | 318 FakeDataMaker.exceptionEntry('mapsshow.google.com'), |
304 FakeDataMaker.exceptionEntry('plus.google.comshow'), | 319 FakeDataMaker.exceptionEntry('plus.google.comshow'), |
305 ]; | 320 ]; |
306 | 321 |
307 self.validateExceptionList_( | 322 validateExceptionList( |
308 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList), | 323 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), |
309 expectedExceptionList); | 324 expectedExceptionList); |
310 }); | 325 }); |
311 | 326 |
312 test('verifyNoPasswordExceptions', function() { | 327 test('verifyNoPasswordExceptions', function() { |
313 var passwordsSection = self.createPasswordsSection_([], []); | 328 var passwordsSection = createPasswordsSection(passwordManager, [], []); |
314 | 329 |
315 self.validateExceptionList_( | 330 validateExceptionList( |
316 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList), | 331 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), |
317 []); | 332 []); |
318 | 333 |
319 assertFalse(passwordsSection.$.noExceptionsLabel.hidden); | 334 assertFalse(passwordsSection.$.noExceptionsLabel.hidden); |
320 }); | 335 }); |
321 | 336 |
322 test('verifyPasswordExceptions', function() { | 337 test('verifyPasswordExceptions', function() { |
323 var exceptionList = [ | 338 var exceptionList = [ |
324 FakeDataMaker.exceptionEntry('docs.google.com'), | 339 FakeDataMaker.exceptionEntry('docs.google.com'), |
325 FakeDataMaker.exceptionEntry('mail.com'), | 340 FakeDataMaker.exceptionEntry('mail.com'), |
326 FakeDataMaker.exceptionEntry('google.com'), | 341 FakeDataMaker.exceptionEntry('google.com'), |
327 FakeDataMaker.exceptionEntry('inbox.google.com'), | 342 FakeDataMaker.exceptionEntry('inbox.google.com'), |
328 FakeDataMaker.exceptionEntry('maps.google.com'), | 343 FakeDataMaker.exceptionEntry('maps.google.com'), |
329 FakeDataMaker.exceptionEntry('plus.google.com'), | 344 FakeDataMaker.exceptionEntry('plus.google.com'), |
330 ]; | 345 ]; |
331 | 346 |
332 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 347 var passwordsSection = createPasswordsSection( |
| 348 passwordManager, [], exceptionList); |
333 | 349 |
334 self.validateExceptionList_( | 350 validateExceptionList( |
335 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList), | 351 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), |
336 exceptionList); | 352 exceptionList); |
337 | 353 |
338 assertTrue(passwordsSection.$.noExceptionsLabel.hidden); | 354 assertTrue(passwordsSection.$.noExceptionsLabel.hidden); |
339 }); | 355 }); |
340 | 356 |
341 // Test verifies that removing an exception will update the elements. | 357 // Test verifies that removing an exception will update the elements. |
342 test('verifyPasswordExceptionRemove', function() { | 358 test('verifyPasswordExceptionRemove', function() { |
343 var exceptionList = [ | 359 var exceptionList = [ |
344 FakeDataMaker.exceptionEntry('docs.google.com'), | 360 FakeDataMaker.exceptionEntry('docs.google.com'), |
345 FakeDataMaker.exceptionEntry('mail.com'), | 361 FakeDataMaker.exceptionEntry('mail.com'), |
346 FakeDataMaker.exceptionEntry('google.com'), | 362 FakeDataMaker.exceptionEntry('google.com'), |
347 FakeDataMaker.exceptionEntry('inbox.google.com'), | 363 FakeDataMaker.exceptionEntry('inbox.google.com'), |
348 FakeDataMaker.exceptionEntry('maps.google.com'), | 364 FakeDataMaker.exceptionEntry('maps.google.com'), |
349 FakeDataMaker.exceptionEntry('plus.google.com'), | 365 FakeDataMaker.exceptionEntry('plus.google.com'), |
350 ]; | 366 ]; |
351 | 367 |
352 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 368 var passwordsSection = createPasswordsSection( |
| 369 passwordManager, [], exceptionList); |
353 | 370 |
354 self.validateExceptionList_( | 371 validateExceptionList( |
355 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList), | 372 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), |
356 exceptionList); | 373 exceptionList); |
357 | 374 |
358 // Simulate 'mail.com' being removed from the list. | 375 // Simulate 'mail.com' being removed from the list. |
359 passwordsSection.splice('passwordExceptions', 1, 1); | 376 passwordsSection.splice('passwordExceptions', 1, 1); |
360 assertFalse(self.exceptionsListContainsUrl( | 377 assertFalse(exceptionsListContainsUrl( |
361 passwordsSection.passwordExceptions, 'mail.com')); | 378 passwordsSection.passwordExceptions, 'mail.com')); |
362 assertFalse(self.exceptionsListContainsUrl(exceptionList, 'mail.com')); | 379 assertFalse(exceptionsListContainsUrl(exceptionList, 'mail.com')); |
363 self.flushPasswordSection_(passwordsSection); | 380 flushPasswordSection(passwordsSection); |
364 | 381 |
365 self.validateExceptionList_( | 382 validateExceptionList( |
366 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList), | 383 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList), |
367 exceptionList); | 384 exceptionList); |
368 }); | 385 }); |
369 | 386 |
370 // Test verifies that pressing the 'remove' button will trigger a remove | 387 // Test verifies that pressing the 'remove' button will trigger a remove |
371 // event. Does not actually remove any exceptions. | 388 // event. Does not actually remove any exceptions. |
372 test('verifyPasswordExceptionRemoveButton', function(done) { | 389 test('verifyPasswordExceptionRemoveButton', function(done) { |
373 var exceptionList = [ | 390 var exceptionList = [ |
374 FakeDataMaker.exceptionEntry('docs.google.com'), | 391 FakeDataMaker.exceptionEntry('docs.google.com'), |
375 FakeDataMaker.exceptionEntry('mail.com'), | 392 FakeDataMaker.exceptionEntry('mail.com'), |
376 FakeDataMaker.exceptionEntry('google.com'), | 393 FakeDataMaker.exceptionEntry('google.com'), |
377 FakeDataMaker.exceptionEntry('inbox.google.com'), | 394 FakeDataMaker.exceptionEntry('inbox.google.com'), |
378 FakeDataMaker.exceptionEntry('maps.google.com'), | 395 FakeDataMaker.exceptionEntry('maps.google.com'), |
379 FakeDataMaker.exceptionEntry('plus.google.com'), | 396 FakeDataMaker.exceptionEntry('plus.google.com'), |
380 ]; | 397 ]; |
381 | 398 |
382 var passwordsSection = self.createPasswordsSection_([], exceptionList); | 399 var passwordsSection = createPasswordsSection( |
| 400 passwordManager, [], exceptionList); |
383 | 401 |
384 var exceptions = | 402 var exceptions = |
385 self.getDomRepeatChildren_(passwordsSection.$.passwordExceptionsList); | 403 getDomRepeatChildren(passwordsSection.$.passwordExceptionsList); |
386 | 404 |
387 // The index of the button currently being checked. | 405 // The index of the button currently being checked. |
388 var index = 0; | 406 var index = 0; |
389 | 407 |
390 var clickRemoveButton = function() { | 408 var clickRemoveButton = function() { |
391 MockInteractions.tap( | 409 MockInteractions.tap( |
392 exceptions[index].querySelector('#removeExceptionButton')); | 410 exceptions[index].querySelector('#removeExceptionButton')); |
393 }; | 411 }; |
394 | 412 |
395 // Listen for the remove event. If this event isn't received, the test | 413 passwordManager.onRemoveException = function(detail) { |
396 // will time out and fail. | |
397 passwordsSection.addEventListener('remove-password-exception', | |
398 function(event) { | |
399 // Verify that the event matches the expected value. | 414 // Verify that the event matches the expected value. |
400 assertTrue(index < exceptionList.length); | 415 assertTrue(index < exceptionList.length); |
401 assertEquals(exceptionList[index].exceptionUrl, event.detail); | 416 assertEquals(exceptionList[index].exceptionUrl, detail); |
402 | 417 |
403 if (++index < exceptionList.length) | 418 if (++index < exceptionList.length) { |
404 clickRemoveButton(); // Click 'remove' on all passwords, one by one. | 419 clickRemoveButton(); // Click 'remove' on all passwords, one by one. |
405 else | 420 } else { |
| 421 // Clean up after self. |
| 422 passwordManager.onRemoveException = null; |
| 423 |
406 done(); | 424 done(); |
407 }); | 425 } |
| 426 }; |
408 | 427 |
409 // Start removing. | 428 // Start removing. |
410 clickRemoveButton(); | 429 clickRemoveButton(); |
411 }); | 430 }); |
412 | 431 |
413 test('showSavedPassword', function() { | 432 test('showSavedPassword', function() { |
414 var PASSWORD = 'bAn@n@5'; | 433 var PASSWORD = 'bAn@n@5'; |
415 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', PASSWORD.length); | 434 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', PASSWORD.length); |
416 var passwordDialog = self.createPasswordDialog_(item); | 435 var passwordDialog = createPasswordDialog(item); |
417 | 436 |
418 passwordDialog.password = PASSWORD; | 437 passwordDialog.password = PASSWORD; |
419 passwordDialog.showPassword = true; | 438 passwordDialog.showPassword = true; |
420 | 439 |
421 Polymer.dom.flush(); | 440 Polymer.dom.flush(); |
422 | 441 |
423 assertEquals(PASSWORD, | 442 assertEquals(PASSWORD, |
424 passwordDialog.$.passwordInput.value); | 443 passwordDialog.$.passwordInput.value); |
425 // Password should be visible. | 444 // Password should be visible. |
426 assertEquals('text', | 445 assertEquals('text', |
427 passwordDialog.$.passwordInput.type); | 446 passwordDialog.$.passwordInput.type); |
428 }); | 447 }); |
429 | 448 |
430 // Test will timeout if event is not received. | 449 // Test will timeout if event is not received. |
431 test('onShowSavedPassword', function(done) { | 450 test('onShowSavedPassword', function(done) { |
432 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', 1); | 451 var item = FakeDataMaker.passwordEntry('goo.gl', 'bart', 1); |
433 var passwordDialog = self.createPasswordDialog_(item); | 452 var passwordDialog = createPasswordDialog(item); |
434 | 453 |
435 passwordDialog.addEventListener('show-password', function(event) { | 454 passwordDialog.addEventListener('show-password', function(event) { |
436 assertEquals(item.loginPair.originUrl, event.detail.originUrl); | 455 assertEquals(item.loginPair.originUrl, event.detail.originUrl); |
437 assertEquals(item.loginPair.username, event.detail.username); | 456 assertEquals(item.loginPair.username, event.detail.username); |
438 done(); | 457 done(); |
439 }); | 458 }); |
440 | 459 |
441 MockInteractions.tap(passwordDialog.$.showPasswordButton); | 460 MockInteractions.tap(passwordDialog.$.showPasswordButton); |
442 }); | 461 }); |
443 }); | 462 }); |
444 | 463 |
445 mocha.run(); | 464 mocha.run(); |
446 }); | 465 }); |
OLD | NEW |