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 * Tests that the dialog opened to the correct URL. | |
7 * @param {string} url The URL to verify against, passed in from C++ to use the | |
8 * value in url_constants.cc. | |
9 */ | |
10 function testDialogURL(url) { | |
11 assertEquals(url, window.location.href); | |
12 } | |
13 | |
14 /** | |
15 * Tests for the correct common name in the test certificate. | |
16 */ | |
17 function testCN() { | |
18 assertEquals('www.google.com', $('issued-cn').textContent); | |
19 } | |
20 | |
21 /** | |
22 * Test the details pane of the certificate viewer. This verifies that a | |
23 * certificate in the chain can be selected to view the fields. And that fields | |
24 * can be selected to view their values. | |
25 */ | |
26 function testDetails() { | |
27 var certHierarchy = $('hierarchy'); | |
28 var certFields = $('cert-fields'); | |
29 var certFieldVal = $('cert-field-value'); | |
30 | |
31 // There must be at least one certificate in the hierarchy. | |
32 assertLT(0, certHierarchy.childNodes.length); | |
33 // No certificate fields should be currently loaded. | |
34 assertEquals(0, certFields.childNodes.length); | |
35 | |
36 // Select the first certificate on the chain and ensure the details show up. | |
37 // Override the receive certificate function to catch when fields are loaded. | |
38 var getCertificateFields = cert_viewer.getCertificateFields; | |
39 cert_viewer.getCertificateFields = function(certFieldDetails) { | |
40 getCertificateFields(certFieldDetails); | |
41 cert_viewer.getCertificateFields = getCertificateFields; | |
42 runAssertions('testDetails', function() { | |
43 assertLT(0, certFields.childNodes.length); | |
44 | |
45 // Test that a field can be selected to see the details for that field. | |
46 var item = getElementWithValue(certFields); | |
47 assertNotEquals(null, item); | |
48 certFields.selectedItem = item; | |
49 assertEquals(item.detail.payload.val, certFieldVal.textContent); | |
50 | |
51 // Test that selecting an item without a value empties the field. | |
52 certFields.selectedItem = certFields.childNodes[0]; | |
53 assertEquals('', certFieldVal.textContent); | |
54 | |
55 testDone(); | |
56 }); | |
57 } | |
58 certHierarchy.selectedItem = certHierarchy.childNodes[0]; | |
59 } | |
60 | |
61 //////////////////////////////////////////////////////////////////////////////// | |
62 // Support functions | |
Sheridan Rawlins
2011/09/09 15:47:50
I don't think you should need these - I would hope
flackr
2011/09/15 18:41:52
The issue I'm having is that the callback function
| |
63 | |
64 /** | |
65 * Run a block of code failing the asynchronous test on any failed assertions. | |
66 * @param {string} testName The name of the test being run (for error messages). | |
67 * @param {function()} f A function to run which may throw an exception. | |
68 */ | |
69 function runAssertions(testName, f) { | |
70 var result = runTestFunction(testName, f, []); | |
71 if (!result[0]) | |
72 testDone(); | |
73 } | |
74 | |
75 /** | |
76 * Find the first tree item (in the certificate fields tree) with a value. | |
77 * @param {!Element} tree Certificate fields subtree to search. | |
78 * @return {Element} The first found element with a value, or null if not found. | |
79 */ | |
80 function getElementWithValue(tree) { | |
81 for (var i = 0; i < tree.childNodes.length; i++) { | |
82 var element = tree.childNodes[i]; | |
83 if (element.detail && element.detail.payload && element.detail.payload.val) | |
84 return element; | |
85 if (element = getElementWithValue(element)) | |
86 return element; | |
87 } | |
88 return null; | |
89 } | |
OLD | NEW |