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.
6 * Test fixture for generated tests.
7 * @extends {testing.Test}
9 function CertificateViewerUITest() {}
11 CertificateViewerUITest
.prototype = {
12 __proto__
: testing
.Test
.prototype,
15 * Define the C++ fixture class and include it.
19 typedefCppFixture
: 'CertificateViewerUITest',
22 * Show the certificate viewer dialog.
24 testGenPreamble: function() {
25 GEN('ShowCertificateViewer();');
31 * Test fixture for asynchronous tests.
32 * @extends {CertificateViewerUITest}
34 function CertificateViewerUITestAsync() {}
36 CertificateViewerUITestAsync
.prototype = {
37 __proto__
: CertificateViewerUITest
.prototype,
43 // Include the bulk of c++ code.
44 // Certificate viewer UI tests are disabled on platforms with native certificate
46 GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"');
49 // Constructors and destructors must be provided in .cc to prevent clang errors.
50 GEN('CertificateViewerUITest::CertificateViewerUITest() {}');
51 GEN('CertificateViewerUITest::~CertificateViewerUITest() {}');
54 * Tests that the dialog opened to the correct URL.
56 TEST_F('CertificateViewerUITest', 'testDialogURL', function() {
57 assertEquals(chrome
.getVariableValue('expectedUrl'), window
.location
.href
);
61 * Tests for the correct common name in the test certificate.
63 TEST_F('CertificateViewerUITest', 'testCN', function() {
64 assertEquals('www.google.com', $('issued-cn').textContent
);
68 * Test the details pane of the certificate viewer. This verifies that a
69 * certificate in the chain can be selected to view the fields. And that fields
70 * can be selected to view their values.
72 TEST_F('CertificateViewerUITestAsync', 'testDetails', function() {
73 var certHierarchy
= $('hierarchy');
74 var certFields
= $('cert-fields');
75 var certFieldVal
= $('cert-field-value');
77 // Select the second tab, causing its data to be loaded if needed.
78 $('tabbox').selectedIndex
= 1;
80 // There must be at least one certificate in the hierarchy.
81 assertLT(0, certHierarchy
.childNodes
.length
);
83 // Select the first certificate on the chain and ensure the details show up.
84 // Override the receive certificate function to catch when fields are
86 var getCertificateFields
= cert_viewer
.getCertificateFields
;
87 cert_viewer
.getCertificateFields
= this.continueTest(WhenTestDone
.ALWAYS
,
88 function(certFieldDetails
) {
89 getCertificateFields(certFieldDetails
);
90 cert_viewer
.getCertificateFields
= getCertificateFields
;
91 assertLT(0, certFields
.childNodes
.length
);
93 // Test that a field can be selected to see the details for that field.
94 var item
= getElementWithValue(certFields
);
95 assertNotEquals(null, item
);
96 certFields
.selectedItem
= item
;
97 assertEquals(item
.detail
.payload
.val
, certFieldVal
.textContent
);
99 // Test that selecting an item without a value empties the field.
100 certFields
.selectedItem
= certFields
.childNodes
[0];
101 assertEquals('', certFieldVal
.textContent
);
103 certHierarchy
.selectedItem
= certHierarchy
.childNodes
[0];
106 ////////////////////////////////////////////////////////////////////////////////
110 * Find the first tree item (in the certificate fields tree) with a value.
111 * @param {!Element} tree Certificate fields subtree to search.
112 * @return {?Element} The first found element with a value, null if not found.
114 function getElementWithValue(tree
) {
115 for (var i
= 0; i
< tree
.childNodes
.length
; i
++) {
116 var element
= tree
.childNodes
[i
];
117 if (element
.detail
&& element
.detail
.payload
&& element
.detail
.payload
.val
)
119 if (element
= getElementWithValue(element
))