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

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

Issue 1815733004: MD Settings: Certificate manager, hooking up all dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@certificates_basic_ui
Patch Set: Adding more tests. Created 4 years, 9 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 cr.define('certificate_manager_page', function() { 5 cr.define('certificate_manager_page', function() {
6 /** 6 /**
7 * A test version of CertificatesBrowserProxy. Provides helper methods 7 * A test version of CertificatesBrowserProxy. Provides helper methods
8 * for allowing tests to know when a method was called, as well as 8 * for allowing tests to know when a method was called, as well as
9 * specifying mock responses. 9 * specifying mock responses.
10 * 10 *
11 * @constructor 11 * @constructor
12 * @implements {settings.CertificatesBrowserProxy} 12 * @implements {settings.CertificatesBrowserProxy}
13 * @extends {settings.TestBrowserProxy} 13 * @extends {settings.TestBrowserProxy}
14 */ 14 */
15 var TestCertificatesBrowserProxy = function() { 15 var TestCertificatesBrowserProxy = function() {
16 settings.TestBrowserProxy.call(this, [ 16 settings.TestBrowserProxy.call(this, [
17 'deleteCertificate', 17 'deleteCertificate',
18 'editCaCertificateTrust', 18 'editCaCertificateTrust',
19 'exportCertificate',
20 'exportPersonalCertificate',
19 'exportPersonalCertificatePasswordSelected', 21 'exportPersonalCertificatePasswordSelected',
20 'getCaCertificateTrust', 22 'getCaCertificateTrust',
21 'importPersonalCertificatePasswordSelected', 23 'importPersonalCertificatePasswordSelected',
22 'refreshCertificates', 24 'refreshCertificates',
25 'viewCertificate',
23 ]); 26 ]);
24 27
25 /** @private {!CaTrustInfo} */ 28 /** @private {!CaTrustInfo} */
26 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; 29 this.caTrustInfo_ = {ssl: true, email: true, objSign: true};
30
31 /** @private {?CertificatesError} */
32 this.certificatesError_ = null;
27 }; 33 };
28 34
29 TestCertificatesBrowserProxy.prototype = { 35 TestCertificatesBrowserProxy.prototype = {
30 __proto__: settings.TestBrowserProxy.prototype, 36 __proto__: settings.TestBrowserProxy.prototype,
31 37
32 /** 38 /**
33 * @param {!CaTrustInfo} caTrustInfo 39 * @param {!CaTrustInfo} caTrustInfo
34 */ 40 */
35 setCaCertificateTrust: function(caTrustInfo) { 41 setCaCertificateTrust: function(caTrustInfo) {
36 this.caTrustInfo_ = caTrustInfo; 42 this.caTrustInfo_ = caTrustInfo;
37 }, 43 },
38 44
39 /** @override */ 45 /** @override */
40 getCaCertificateTrust: function(id) { 46 getCaCertificateTrust: function(id) {
41 this.methodCalled('getCaCertificateTrust', id); 47 this.methodCalled('getCaCertificateTrust', id);
42 return Promise.resolve(this.caTrustInfo_); 48 return Promise.resolve(this.caTrustInfo_);
43 }, 49 },
44 50
45 /** @override */ 51 /** @override */
46 editCaCertificateTrust: function(id, ssl, email, objSign) { 52 editCaCertificateTrust: function(id, ssl, email, objSign) {
47 this.methodCalled('editCaCertificateTrust', { 53 this.methodCalled('editCaCertificateTrust', {
48 id: id, ssl: ssl, email: email, objSign: objSign, 54 id: id, ssl: ssl, email: email, objSign: objSign,
49 }); 55 });
50 return Promise.resolve(); 56 return this.fulfillRequest_();
57 },
58
59 /**
60 * Forces some of the browser proxy methods to start returning errors.
61 */
62 forceCertificatesError: function() {
63 this.certificatesError_ = /** @type {!CertificatesError} */ ({
64 title: 'DummyError', description: 'DummyDescription'
65 });
66 },
67
68 /**
69 * @return {!Promise} A promise that is resolved or rejected based on the
70 * value of |certificatesError_|.
71 * @private
72 */
73 fulfillRequest_: function() {
74 return this.certificatesError_ === null ?
75 Promise.resolve() : Promise.reject(this.certificatesError_);
51 }, 76 },
52 77
53 /** @override */ 78 /** @override */
54 deleteCertificate: function(id) { 79 deleteCertificate: function(id) {
55 this.methodCalled('deleteCertificate', id); 80 this.methodCalled('deleteCertificate', id);
56 return Promise.resolve(); 81 return this.fulfillRequest_();
57 }, 82 },
58 83
59 /** @override */ 84 /** @override */
60 exportPersonalCertificatePasswordSelected: function(password) { 85 exportPersonalCertificatePasswordSelected: function(password) {
61 this.resolverMap_.get( 86 this.resolverMap_.get(
62 'exportPersonalCertificatePasswordSelected').resolve(password); 87 'exportPersonalCertificatePasswordSelected').resolve(password);
63 return Promise.resolve(); 88 return this.fulfillRequest_();
64 }, 89 },
65 90
66 /** @override */ 91 /** @override */
67 importPersonalCertificatePasswordSelected: function(password) { 92 importPersonalCertificatePasswordSelected: function(password) {
68 this.resolverMap_.get( 93 this.resolverMap_.get(
69 'importPersonalCertificatePasswordSelected').resolve(password); 94 'importPersonalCertificatePasswordSelected').resolve(password);
70 return Promise.resolve(); 95 return this.fulfillRequest_();
71 }, 96 },
72 97
73 /** @override */ 98 /** @override */
74 refreshCertificates: function() { 99 refreshCertificates: function() {
75 this.methodCalled('refreshCertificates'); 100 this.methodCalled('refreshCertificates');
76 }, 101 },
102
103 /** @override */
104 viewCertificate: function(id) {
105 this.methodCalled('viewCertificate', id);
106 },
107
108 /** @override */
109 exportCertificate: function(id) {
110 this.methodCalled('exportCertificate', id);
111 },
112
113 /** @override */
114 exportPersonalCertificate: function(id) {
115 this.methodCalled('exportPersonalCertificate', id);
116 return Promise.resolve();
117 },
77 }; 118 };
78 119
79 /** @return {!Certificate} */ 120 /** @return {!Certificate} */
80 function createSampleCertificate() { 121 function createSampleCertificate() {
81 return { 122 return {
82 id: 'dummyCertificateId', 123 id: 'dummyCertificateId',
83 name: 'dummyCertificateName', 124 name: 'dummyCertificateName',
84 subnodes: [ 125 subnodes: [
85 createSampleCertificateSubnode() 126 createSampleCertificateSubnode()
86 ], 127 ],
(...skipping 17 matching lines...) Expand all
104 * Triggers an 'input' event on the given text input field (which triggers 145 * Triggers an 'input' event on the given text input field (which triggers
105 * validation to occur for password fields being tested in this file). 146 * validation to occur for password fields being tested in this file).
106 * @param {!PaperInputElement} element 147 * @param {!PaperInputElement} element
107 */ 148 */
108 function triggerInputEvent(element) { 149 function triggerInputEvent(element) {
109 // The actual key code is irrelevant for tests. 150 // The actual key code is irrelevant for tests.
110 var kSpaceBar = 32; 151 var kSpaceBar = 32;
111 MockInteractions.keyEventOn(element, 'input', kSpaceBar); 152 MockInteractions.keyEventOn(element, 'input', kSpaceBar);
112 } 153 }
113 154
155 /**
156 * Converts an event occurrence to a promise.
157 * @param {string} eventType
158 * @param {!HTMLElement} target
159 * @return {!Promise} A promise firing once the event occurs.
160 */
161 function waitForEvent(eventType, target) {
162 return new Promise(function(resolve, reject) {
163 target.addEventListener(eventType, resolve);
tommycli 2016/03/23 19:28:05 Is it a problem that we never remove the event lis
dpapad 2016/03/24 22:06:11 It is not a problem, for two reasons. 1) "target"
164 });
165 }
166
tommycli 2016/03/23 19:28:05 nit: extra newline
dpapad 2016/03/24 22:06:11 Removed.
167
114 function registerCaTrustEditDialogTests() { 168 function registerCaTrustEditDialogTests() {
115 /** @type {?SettingsCaTrustEditDialogElement} */ 169 /** @type {?SettingsCaTrustEditDialogElement} */
116 var dialog = null; 170 var dialog = null;
117 171
118 /** @type {?TestCertificatesBrowserProxy} */ 172 /** @type {?TestCertificatesBrowserProxy} */
119 var browserProxy = null; 173 var browserProxy = null;
120 174
121 /** @type {!CertificateSubnode} */ 175 /** @type {!CertificateSubnode} */
122 var model = createSampleCertificateSubnode(); 176 var model = createSampleCertificateSubnode();
123 177
124 /** @type {!CaTrustInfo} */ 178 /** @type {!CaTrustInfo} */
125 var caTrustInfo = { ssl: true, email: false, objSign: false }; 179 var caTrustInfo = { ssl: true, email: false, objSign: false };
126 180
127 suite('CaTrustEditDialogTests', function() { 181 suite('CaTrustEditDialogTests', function() {
128 setup(function() { 182 setup(function() {
129 browserProxy = new TestCertificatesBrowserProxy(); 183 browserProxy = new TestCertificatesBrowserProxy();
130 browserProxy.setCaCertificateTrust(caTrustInfo); 184 browserProxy.setCaCertificateTrust(caTrustInfo);
131 185
132 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 186 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
133 PolymerTest.clearBody(); 187 PolymerTest.clearBody();
134 dialog = document.createElement('settings-ca-trust-edit-dialog'); 188 dialog = document.createElement('settings-ca-trust-edit-dialog');
135 dialog.model = model; 189 dialog.model = model;
136 document.body.appendChild(dialog); 190 document.body.appendChild(dialog);
137 }); 191 });
138 192
139 teardown(function() { dialog.remove(); }); 193 teardown(function() { dialog.remove(); });
140 194
141 test('Dialog', function() { 195 test('EditSuccess', function() {
142 return browserProxy.whenCalled('getCaCertificateTrust').then( 196 return browserProxy.whenCalled('getCaCertificateTrust').then(
143 function(id) { 197 function(id) {
144 assertEquals(model.id, id); 198 assertEquals(model.id, id);
145 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); 199 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked);
146 assertEquals(caTrustInfo.email, dialog.$.email.checked); 200 assertEquals(caTrustInfo.email, dialog.$.email.checked);
147 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); 201 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked);
148 202
149 // Simulate toggling all checkboxes. 203 // Simulate toggling all checkboxes.
150 MockInteractions.tap(dialog.$.ssl); 204 MockInteractions.tap(dialog.$.ssl);
151 MockInteractions.tap(dialog.$.email); 205 MockInteractions.tap(dialog.$.email);
152 MockInteractions.tap(dialog.$.objSign); 206 MockInteractions.tap(dialog.$.objSign);
153 207
154 // Simulate clicking 'OK'. 208 // Simulate clicking 'OK'.
155 MockInteractions.tap(dialog.$.ok); 209 MockInteractions.tap(dialog.$.ok);
156 210
157 return browserProxy.whenCalled('editCaCertificateTrust').then( 211 return browserProxy.whenCalled('editCaCertificateTrust');
tommycli 2016/03/23 19:28:05 Interesting. I assume you are just linearizing the
dpapad 2016/03/24 22:06:11 Yes, this is a typical case of chaining promises o
158 function(args) { 212 }).then(
159 assertEquals(model.id, args.id); 213 function(args) {
160 // Checking that the values sent to C++ are reflecting the 214 assertEquals(model.id, args.id);
161 // changes made by the user (toggling all checkboxes). 215 // Checking that the values sent to C++ are reflecting the
162 assertEquals(caTrustInfo.ssl, !args.ssl); 216 // changes made by the user (toggling all checkboxes).
163 assertEquals(caTrustInfo.email, !args.email); 217 assertEquals(caTrustInfo.ssl, !args.ssl);
164 assertEquals(caTrustInfo.objSign, !args.objSign); 218 assertEquals(caTrustInfo.email, !args.email);
165 // Check that the dialog is closed. 219 assertEquals(caTrustInfo.objSign, !args.objSign);
166 assertFalse(dialog.$.dialog.opened); 220 // Check that the dialog is closed.
167 }); 221 assertFalse(dialog.$.dialog.opened);
222 });
223 });
224
225 test('EditError', function() {
226 browserProxy.forceCertificatesError();
227 var whenErrorEventFired = waitForEvent('certificates-error', dialog);
228
229 return browserProxy.whenCalled('getCaCertificateTrust').then(
230 function() {
231 MockInteractions.tap(dialog.$.ok);
232 return browserProxy.whenCalled('editCaCertificateTrust');
233 }).then(
234 function() {
235 return whenErrorEventFired;
168 }); 236 });
169 }); 237 });
170 }); 238 });
171 } 239 }
172 240
173 function registerDeleteDialogTests() { 241 function registerDeleteDialogTests() {
174 /** @type {?SettingsCertificateDeleteConfirmationDialogElement} */ 242 /** @type {?SettingsCertificateDeleteConfirmationDialogElement} */
175 var dialog = null; 243 var dialog = null;
176 244
177 /** @type {?TestCertificatesBrowserProxy} */ 245 /** @type {?TestCertificatesBrowserProxy} */
(...skipping 25 matching lines...) Expand all
203 // Simulate clicking 'OK'. 271 // Simulate clicking 'OK'.
204 MockInteractions.tap(dialog.$.ok); 272 MockInteractions.tap(dialog.$.ok);
205 273
206 return browserProxy.whenCalled('deleteCertificate').then( 274 return browserProxy.whenCalled('deleteCertificate').then(
207 function(id) { 275 function(id) {
208 assertEquals(model.id, id); 276 assertEquals(model.id, id);
209 // Check that the dialog is closed. 277 // Check that the dialog is closed.
210 assertFalse(dialog.$.dialog.opened); 278 assertFalse(dialog.$.dialog.opened);
211 }); 279 });
212 }); 280 });
281
282 test('DeleteError', function() {
283 browserProxy.forceCertificatesError();
284 var whenErrorEventFired = waitForEvent('certificates-error', dialog);
285
286 // Simulate clicking 'OK'.
287 MockInteractions.tap(dialog.$.ok);
288 return browserProxy.whenCalled('deleteCertificate').then(
289 function(id) {
290 assertEquals(model.id, id);
291 // Ensure that the 'error' event was fired.
292 return whenErrorEventFired;
293 });
294 });
213 }); 295 });
214 } 296 }
215 297
216 function registerPasswordEncryptDialogTests() { 298 function registerPasswordEncryptDialogTests() {
217 /** @type {?SettingsCertificatePasswordEncryptionDialogElement} */ 299 /** @type {?SettingsCertificatePasswordEncryptionDialogElement} */
218 var dialog = null; 300 var dialog = null;
219 301
220 /** @type {?TestCertificatesBrowserProxy} */ 302 /** @type {?TestCertificatesBrowserProxy} */
221 var browserProxy = null; 303 var browserProxy = null;
222 304
223 /** @type {!CertificateSubnode} */ 305 /** @type {!CertificateSubnode} */
224 var model = createSampleCertificateSubnode(); 306 var model = createSampleCertificateSubnode();
225 307
308 var methodName = 'exportPersonalCertificatePasswordSelected';
309
226 suite('CertificatePasswordEncryptionDialogTests', function() { 310 suite('CertificatePasswordEncryptionDialogTests', function() {
227 setup(function() { 311 setup(function() {
228 browserProxy = new TestCertificatesBrowserProxy(); 312 browserProxy = new TestCertificatesBrowserProxy();
229 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 313 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
230 PolymerTest.clearBody(); 314 PolymerTest.clearBody();
231 dialog = document.createElement( 315 dialog = document.createElement(
232 'settings-certificate-password-encryption-dialog'); 316 'settings-certificate-password-encryption-dialog');
233 dialog.model = model; 317 dialog.model = model;
234 document.body.appendChild(dialog); 318 document.body.appendChild(dialog);
235 }); 319 });
(...skipping 19 matching lines...) Expand all
255 passwordInputElement.value = 'foopassword'; 339 passwordInputElement.value = 'foopassword';
256 triggerInputEvent(passwordInputElement); 340 triggerInputEvent(passwordInputElement);
257 assertTrue(dialog.$.ok.disabled); 341 assertTrue(dialog.$.ok.disabled);
258 confirmPasswordInputElement.value = passwordInputElement.value; 342 confirmPasswordInputElement.value = passwordInputElement.value;
259 triggerInputEvent(confirmPasswordInputElement); 343 triggerInputEvent(confirmPasswordInputElement);
260 assertFalse(dialog.$.ok.disabled); 344 assertFalse(dialog.$.ok.disabled);
261 345
262 // Simulate clicking 'OK'. 346 // Simulate clicking 'OK'.
263 MockInteractions.tap(dialog.$.ok); 347 MockInteractions.tap(dialog.$.ok);
264 348
265 var methodName = 'exportPersonalCertificatePasswordSelected';
266 return browserProxy.whenCalled(methodName).then(function(password) { 349 return browserProxy.whenCalled(methodName).then(function(password) {
267 assertEquals(passwordInputElement.value, password); 350 assertEquals(passwordInputElement.value, password);
268 // Check that the dialog is closed. 351 // Check that the dialog is closed.
269 assertFalse(dialog.$.dialog.opened); 352 assertFalse(dialog.$.dialog.opened);
270 }); 353 });
271 }); 354 });
355
356 test('EncryptError', function() {
357 browserProxy.forceCertificatesError();
358
359 var passwordInputElements =
360 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input');
361 var passwordInputElement = passwordInputElements[0];
362 passwordInputElement.value = 'foopassword';
363 var confirmPasswordInputElement = passwordInputElements[1];
364 confirmPasswordInputElement.value = passwordInputElement.value;
365 triggerInputEvent(passwordInputElement);
366
367 var whenErrorEventFired = waitForEvent('certificates-error', dialog);
tommycli 2016/03/23 19:28:05 It is a bit unfortunate that we have to attach thi
dpapad 2016/03/24 22:06:11 Done. I moved it to the setup() per your 1st sugge
tommycli 2016/03/24 22:34:14 Ah given your point about the scope maybe the orig
368 MockInteractions.tap(dialog.$.ok);
369
370 return browserProxy.whenCalled(methodName).then(function() {
371 return whenErrorEventFired;
372 });
373 });
272 }); 374 });
273 } 375 }
274 376
275 function registerPasswordDecryptDialogTests() { 377 function registerPasswordDecryptDialogTests() {
276 /** @type {?SettingsCertificatePasswordDecryptionDialogElement} */ 378 /** @type {?SettingsCertificatePasswordDecryptionDialogElement} */
277 var dialog = null; 379 var dialog = null;
278 380
279 /** @type {?TestCertificatesBrowserProxy} */ 381 /** @type {?TestCertificatesBrowserProxy} */
280 var browserProxy = null; 382 var browserProxy = null;
281 383
384 var methodName = 'importPersonalCertificatePasswordSelected';
385
282 suite('CertificatePasswordDecryptionDialogTests', function() { 386 suite('CertificatePasswordDecryptionDialogTests', function() {
283 setup(function() { 387 setup(function() {
284 browserProxy = new TestCertificatesBrowserProxy(); 388 browserProxy = new TestCertificatesBrowserProxy();
285 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 389 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
286 PolymerTest.clearBody(); 390 PolymerTest.clearBody();
287 dialog = document.createElement( 391 dialog = document.createElement(
288 'settings-certificate-password-decryption-dialog'); 392 'settings-certificate-password-decryption-dialog');
289 document.body.appendChild(dialog); 393 document.body.appendChild(dialog);
290 }); 394 });
291 395
292 teardown(function() { dialog.remove(); }); 396 teardown(function() { dialog.remove(); });
293 397
294 test('DecryptSuccess', function() { 398 test('DecryptSuccess', function() {
295 var passwordInputElement = 399 var passwordInputElement =
296 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); 400 Polymer.dom(dialog.$.dialog).querySelector('paper-input');
297 assertTrue(dialog.$.dialog.opened); 401 assertTrue(dialog.$.dialog.opened);
298 assertTrue(dialog.$.ok.disabled); 402 assertTrue(dialog.$.ok.disabled);
299 403
300 // Test that the 'OK' button is disabled when the password field is 404 // Test that the 'OK' button is disabled when the password field is
301 // empty. 405 // empty.
302 triggerInputEvent(passwordInputElement); 406 triggerInputEvent(passwordInputElement);
303 assertTrue(dialog.$.ok.disabled); 407 assertTrue(dialog.$.ok.disabled);
304 passwordInputElement.value = 'foopassword'; 408 passwordInputElement.value = 'foopassword';
305 triggerInputEvent(passwordInputElement); 409 triggerInputEvent(passwordInputElement);
306 assertFalse(dialog.$.ok.disabled); 410 assertFalse(dialog.$.ok.disabled);
307 411
308 // Simulate clicking 'OK'. 412 // Simulate clicking 'OK'.
309 MockInteractions.tap(dialog.$.ok); 413 MockInteractions.tap(dialog.$.ok);
310 414
311 var methodName = 'importPersonalCertificatePasswordSelected';
312 return browserProxy.whenCalled(methodName).then(function(password) { 415 return browserProxy.whenCalled(methodName).then(function(password) {
313 assertEquals(passwordInputElement.value, password); 416 assertEquals(passwordInputElement.value, password);
314 // Check that the dialog is closed. 417 // Check that the dialog is closed.
315 assertFalse(dialog.$.dialog.opened); 418 assertFalse(dialog.$.dialog.opened);
316 }); 419 });
317 }); 420 });
421
422 test('DecryptError', function() {
423 browserProxy.forceCertificatesError();
424 // Simulate entering some password.
425 var passwordInputElement =
426 Polymer.dom(dialog.$.dialog).querySelector('paper-input');
427 passwordInputElement.value = 'foopassword';
428 triggerInputEvent(passwordInputElement);
429
430 var whenErrorEventFired = waitForEvent('certificates-error', dialog);
431 MockInteractions.tap(dialog.$.ok);
432 return browserProxy.whenCalled(methodName).then(function() {
433 return whenErrorEventFired;
434 });
435 });
318 }); 436 });
319 } 437 }
320 438
439 function registerCertificateSubentryTests() {
440 var subentry = null;
441
442 /** @type {?TestCertificatesBrowserProxy} */
443 var browserProxy = null;
444
445 var waitForActionEvent = function() {
tommycli 2016/03/23 19:28:04 Same comment as above, it would be easier for me t
dpapad 2016/03/24 22:06:11 Added JSDoc for the local function which I think m
446 return waitForEvent(settings.CertificateActionEvent, subentry);
447 };
448
449 suite('CertificateManagerPageTests', function() {
450 setup(function() {
451 browserProxy = new TestCertificatesBrowserProxy();
452 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
453 PolymerTest.clearBody();
454 subentry = document.createElement('settings-certificate-subentry');
455 subentry.model = createSampleCertificateSubnode();
456 subentry.certificateType = settings.CertificateType.PERSONAL;
457 document.body.appendChild(subentry);
458
459 // Bring up the popup menu for the following tests to use.
460 MockInteractions.tap(subentry.$.dots);
461 Polymer.dom.flush();
462 });
463
464 teardown(function() { subentry.remove(); });
465
466 // Test case where 'View' option is tapped.
467 test('MenuOptions_View', function() {
468 var viewButton = subentry.shadowRoot.querySelector('#view');
469 MockInteractions.tap(viewButton);
470 return browserProxy.whenCalled('viewCertificate').then(function(id) {
471 assertEquals(subentry.model.id, id);
472 });
473 });
474
475 // Test that the 'Edit' option is only shown when appropriate and that
476 // once tapped the correct event is fired.
477 test('MenuOptions_Edit', function() {
478 var editButton = subentry.shadowRoot.querySelector('#edit');
479 // Should be disabled for any certificate type other than
480 // CertificateType.CA
481 assertTrue(editButton.hidden);
482 subentry.certificateType = settings.CertificateType.CA;
483 assertFalse(editButton.hidden);
484
485 var whenActionEventFired = waitForActionEvent();
tommycli 2016/03/23 19:28:04 Same comment as above, I just found this required
dpapad 2016/03/24 22:06:11 I am sensing that you are not very fond/comfortabl
dpapad 2016/03/24 22:11:17 To be more precise I forgot some stuff in my snipp
tommycli 2016/03/24 22:34:14 Hi Demetrios, Although the above would be easy to
dpapad 2016/03/25 17:36:03 Thanks for explaining the points of confusion Tomm
486 MockInteractions.tap(editButton);
487 return whenActionEventFired.then(function(event) {
488 var detail = /** @type {!CertificateActionEventDetail} */ (
489 event.detail);
490 assertEquals(settings.CertificateAction.EDIT, detail.action);
491 assertEquals(subentry.model.id, detail.subnode.id);
492 assertEquals(subentry.certificateType, detail.certificateType);
493 });
494 });
495
496 // Test that the 'Delete' option is only shown when appropriate and that
497 // once tapped the correct event is fired.
498 test('MenuOptions_Delete', function() {
499 subentry.set('model.readonly', true);
500
501 var deleteButton = subentry.shadowRoot.querySelector('#delete');
502 // Should be disabled when 'model.readonly' is true.
503 assertTrue(deleteButton.hidden);
504 subentry.set('model.readonly', false);
505 assertFalse(deleteButton.hidden);
506
507 var whenActionEventFired = waitForActionEvent();
508 MockInteractions.tap(deleteButton);
509 return whenActionEventFired.then(function(event) {
510 var detail = /** @type {!CertificateActionEventDetail} */ (
511 event.detail);
512 assertEquals(settings.CertificateAction.DELETE, detail.action);
513 assertEquals(subentry.model.id, detail.subnode.id);
514 });
515 });
516
517 // Test case of exporting a certificate that is not PERSONAL.
518 test('MenuOptions_Export', function() {
519 subentry.certificateType = settings.CertificateType.SERVER;
520 var exportButton = subentry.shadowRoot.querySelector('#export');
521 MockInteractions.tap(exportButton);
522 return browserProxy.whenCalled('exportCertificate').then(function(id) {
523 assertEquals(subentry.model.id, id);
524 });
525 });
526
527 // Test case of exporting a PERSONAL certificate.
528 test('MenuOptions_ExportPersonal', function() {
529 var whenActionEventFired = waitForActionEvent();
530
531 var exportButton = subentry.shadowRoot.querySelector('#export');
532 MockInteractions.tap(exportButton);
533 return browserProxy.whenCalled('exportPersonalCertificate').then(
534 function(id) {
535 assertEquals(subentry.model.id, id);
536 return whenActionEventFired;
537 }).then(
538 function(event) {
539 var detail = /** @type {!CertificateActionEventDetail} */ (
540 event.detail);
541 assertEquals(
542 settings.CertificateAction.EXPORT_PERSONAL,
543 detail.action);
544 assertEquals(subentry.model.id, detail.subnode.id);
545 });
546 });
547 });
548 }
549
321 function registerPageTests() { 550 function registerPageTests() {
322 /** @type {?SettingsCertificateManagerPage} */ 551 /** @type {?SettingsCertificateManagerPage} */
323 var page = null; 552 var page = null;
324 553
325 /** @type {?TestCertificatesBrowserProxy} */ 554 /** @type {?TestCertificatesBrowserProxy} */
326 var browserProxy = null; 555 var browserProxy = null;
327 556
328 /** @enum {number} */ 557 /** @enum {number} */
329 var CertificateCategoryIndex = { 558 var CertificateCategoryIndex = {
330 PERSONAL: 0, 559 PERSONAL: 0,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 'certificates-changed', 'caCerts', 615 'certificates-changed', 'caCerts',
387 [createSampleCertificate(), createSampleCertificate()]); 616 [createSampleCertificate(), createSampleCertificate()]);
388 Polymer.dom.flush(); 617 Polymer.dom.flush();
389 618
390 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1); 619 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1);
391 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); 620 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0);
392 assertCertificateListLength(CertificateCategoryIndex.CA, 2); 621 assertCertificateListLength(CertificateCategoryIndex.CA, 2);
393 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); 622 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0);
394 }); 623 });
395 }); 624 });
625
626 /**
627 * Dispatches a settings.CertificateActionEvent.
628 * @param {!settings.CertificateAction} action The type of action to
629 * simulate.
630 */
631 function dispatchCertificateActionEvent(action) {
632 var eventDetail = /** @type {!CertificateActionEventDetail} */ ({
633 action: action,
634 subnode: createSampleCertificateSubnode(),
635 certificateType: settings.CertificateType.PERSONAL
636 });
637 page.dispatchEvent(new CustomEvent(
638 settings.CertificateActionEvent, {detail: eventDetail}));
639 }
640
641 /**
642 * Tests that a dialog opens as a response to a
643 * settings.CertificateActionEvent.
644 * @param {string} dialogTagName The type of dialog to test.
645 * @param {!settings.CertificateAction} action The action that is supposed
646 * to trigger the dialog.
647 */
648 function testDialogOpensOnAction(dialogTagName, action) {
649 assertFalse(!!page.shadowRoot.querySelector(dialogTagName));
650 dispatchCertificateActionEvent(action);
651 Polymer.dom.flush();
652 assertTrue(!!page.shadowRoot.querySelector(dialogTagName));
653 }
654
655 test('OpensDialog_DeleteConfirmation', function() {
656 testDialogOpensOnAction(
657 'settings-certificate-delete-confirmation-dialog',
658 settings.CertificateAction.DELETE);
659 });
660
661 test('OpensDialog_PasswordEncryption', function() {
662 testDialogOpensOnAction(
663 'settings-certificate-password-encryption-dialog',
664 settings.CertificateAction.EXPORT_PERSONAL);
665 });
666
667 test('OpensDialog_PasswordDecryption', function() {
668 testDialogOpensOnAction(
669 'settings-certificate-password-decryption-dialog',
670 settings.CertificateAction.IMPORT_PERSONAL);
671 });
672
673 test('OpensDialog_CaTrustEdit', function() {
674 testDialogOpensOnAction(
675 'settings-ca-trust-edit-dialog', settings.CertificateAction.EDIT);
676 });
396 }); 677 });
397 } 678 }
398 679
399 return { 680 return {
400 registerTests: function() { 681 registerTests: function() {
401 registerCaTrustEditDialogTests(); 682 registerCaTrustEditDialogTests();
402 registerDeleteDialogTests(); 683 registerDeleteDialogTests();
403 registerPasswordEncryptDialogTests(); 684 registerPasswordEncryptDialogTests();
404 registerPasswordDecryptDialogTests(); 685 registerPasswordDecryptDialogTests();
405 registerPageTests(); 686 registerPageTests();
687 registerCertificateSubentryTests();
406 }, 688 },
407 }; 689 };
408 }); 690 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698