OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 /** | |
6 * Test fixture for generated tests. | |
7 * @extends {testing.Test} | |
8 */ | |
9 function CertificateViewerUITest() {}; | |
10 | |
11 CertificateViewerUITest.prototype = { | |
12 __proto__: testing.Test.prototype, | |
13 | |
14 /** | |
15 * Define the C++ fixture class and include it. | |
16 * @type {?string} | |
17 * @override | |
18 */ | |
19 typedefCppFixture: 'CertificateViewerUITest', | |
20 | |
21 /** @inheritDoc */ | |
22 isAsync: true, | |
23 }; | |
24 | |
25 // Include the bulk of c++ code. | |
26 GEN('#include "chrome/browser/ui/webui/certificate_viewer_ui_browsertest.cc"'); | |
Sheridan Rawlins
2011/09/15 19:11:41
if this is included, please make it certificate_vi
flackr
2011/09/15 21:02:36
Done.
| |
27 GEN(''); | |
28 | |
29 /** | |
30 * Tests that the dialog opened to the correct URL. | |
31 */ | |
32 TEST_F('CertificateViewerUITest', 'testDialogURL', | |
33 function() { | |
34 runAssertions('testDialogURL', function() { | |
Sheridan Rawlins
2011/09/15 19:11:41
I'm sorry, but why do you feel you need this? TES
flackr
2011/09/15 21:02:36
Done.
| |
35 assertEquals(chrome.expectedUrl, window.location.href); | |
36 testDone(); | |
37 }); | |
38 }); | |
39 | |
40 /** | |
41 * Tests for the correct common name in the test certificate. | |
42 */ | |
43 TEST_F('CertificateViewerUITest', 'testCN', | |
44 function() { | |
45 runAssertions('testCN', function() { | |
Sheridan Rawlins
2011/09/15 19:11:41
ditch runAssertions.
flackr
2011/09/15 21:02:36
Done.
| |
46 assertEquals('www.google.com', $('issued-cn').textContent); | |
47 testDone(); | |
48 }); | |
49 }); | |
50 | |
51 /** | |
52 * Test the details pane of the certificate viewer. This verifies that a | |
53 * certificate in the chain can be selected to view the fields. And that fields | |
54 * can be selected to view their values. | |
55 */ | |
56 TEST_F('CertificateViewerUITest', 'testDetails', | |
57 function() { | |
58 var certHierarchy = $('hierarchy'); | |
59 var certFields = $('cert-fields'); | |
60 var certFieldVal = $('cert-field-value'); | |
61 | |
62 // There must be at least one certificate in the hierarchy. | |
63 assertLT(0, certHierarchy.childNodes.length); | |
64 // No certificate fields should be currently loaded. | |
65 assertEquals(0, certFields.childNodes.length); | |
66 | |
67 // Select the first certificate on the chain and ensure the details show up. | |
68 // Override the receive certificate function to catch when fields are loaded. | |
69 var getCertificateFields = cert_viewer.getCertificateFields; | |
70 cert_viewer.getCertificateFields = function(certFieldDetails) { | |
Sheridan Rawlins
2011/09/15 19:11:41
You can use this.continueTest to wrap and ditch ru
flackr
2011/09/15 21:02:36
Done.
| |
71 getCertificateFields(certFieldDetails); | |
72 cert_viewer.getCertificateFields = getCertificateFields; | |
73 runAssertions('testDetails', function() { | |
74 assertLT(0, certFields.childNodes.length); | |
75 | |
76 // Test that a field can be selected to see the details for that field. | |
77 var item = getElementWithValue(certFields); | |
78 assertNotEquals(null, item); | |
79 certFields.selectedItem = item; | |
80 assertEquals(item.detail.payload.val, certFieldVal.textContent); | |
81 | |
82 // Test that selecting an item without a value empties the field. | |
83 certFields.selectedItem = certFields.childNodes[0]; | |
84 assertEquals('', certFieldVal.textContent); | |
85 | |
86 testDone(); | |
87 }); | |
88 } | |
89 certHierarchy.selectedItem = certHierarchy.childNodes[0]; | |
90 }); | |
91 | |
92 //////////////////////////////////////////////////////////////////////////////// | |
93 // Support functions | |
94 | |
95 /** | |
96 * Run a block of code failing the asynchronous test on any failed assertions. | |
97 * @param {string} testName The name of the test being run (for error messages). | |
98 * @param {function()} f A function to run which may throw an exception. | |
99 */ | |
100 function runAssertions(testName, f) { | |
Sheridan Rawlins
2011/09/15 19:11:41
Why is this needed? Please remove this function.
flackr
2011/09/15 21:02:36
Done.
| |
101 var result = runTestFunction(testName, f, []); | |
102 if (!result[0]) | |
103 testDone(); | |
104 } | |
105 | |
106 /** | |
107 * Find the first tree item (in the certificate fields tree) with a value. | |
108 * @param {!Element} tree Certificate fields subtree to search. | |
109 * @return {Element} The first found element with a value, or null if not found. | |
Sheridan Rawlins
2011/09/15 19:11:41
{?Element}
flackr
2011/09/15 21:02:36
Done.
| |
110 */ | |
111 function getElementWithValue(tree) { | |
112 for (var i = 0; i < tree.childNodes.length; i++) { | |
113 var element = tree.childNodes[i]; | |
114 if (element.detail && element.detail.payload && element.detail.payload.val) | |
115 return element; | |
116 if (element = getElementWithValue(element)) | |
117 return element; | |
118 } | |
119 return null; | |
120 } | |
OLD | NEW |