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();');
29 * Tests that the dialog opened to the correct URL.
31 testDialogUrl: function() {
32 assertEquals(chrome.getVariableValue('expectedUrl'), window.location.href);
36 * Tests for the correct common name in the test certificate.
39 assertEquals('www.google.com', $('issued-cn').textContent);
42 testDetails: function() {
43 var certHierarchy = $('hierarchy');
44 var certFields = $('cert-fields');
45 var certFieldVal = $('cert-field-value');
47 // Select the second tab, causing its data to be loaded if needed.
48 $('tabbox').selectedIndex = 1;
50 // There must be at least one certificate in the hierarchy.
51 assertLT(0, certHierarchy.childNodes.length);
53 // Select the first certificate on the chain and ensure the details show up.
54 // Override the receive certificate function to catch when fields are
56 var getCertificateFields = cert_viewer.getCertificateFields;
57 cert_viewer.getCertificateFields = this.continueTest(WhenTestDone.ALWAYS,
58 function(certFieldDetails) {
59 getCertificateFields(certFieldDetails);
60 cert_viewer.getCertificateFields = getCertificateFields;
61 assertLT(0, certFields.childNodes.length);
63 // Test that a field can be selected to see the details for that field.
64 var item = getElementWithValue(certFields);
65 assertNotEquals(null, item);
66 certFields.selectedItem = item;
67 assertEquals(item.detail.payload.val, certFieldVal.textContent);
69 // Test that selecting an item without a value empties the field.
70 certFields.selectedItem = certFields.childNodes[0];
71 assertEquals('', certFieldVal.textContent);
73 certHierarchy.selectedItem = certHierarchy.childNodes[0];
78 * Test fixture for ChromeOS modal dialog version of certificate viewer.
79 * @extends {CertificateViewerUITest}
81 function CertificateViewerModalUITest() {}
83 CertificateViewerModalUITest.prototype = {
84 __proto__: CertificateViewerUITest.prototype,
87 * Show the certificate viewer dialog.
89 testGenPreamble: function() {
90 GEN('#if defined(OS_CHROMEOS)');
91 GEN('ShowModalCertificateViewer();');
97 * Test fixture for asynchronous tests.
98 * @extends {CertificateViewerUITest}
100 function CertificateViewerUITestAsync() {}
102 CertificateViewerUITestAsync.prototype = {
103 __proto__: CertificateViewerUITest.prototype,
111 * Test fixture for ChromeOS modal dialog version for asynchronous tests.
112 * @extends {CertificateViewerUITest}
114 function CertificateViewerModalUITestAsync() {}
116 CertificateViewerModalUITestAsync.prototype = {
117 __proto__: CertificateViewerModalUITest.prototype,
123 // Include the bulk of c++ code.
124 // Certificate viewer UI tests are disabled on platforms with native certificate
126 GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"');
129 // Constructors and destructors must be provided in .cc to prevent clang errors.
130 GEN('CertificateViewerUITest::CertificateViewerUITest() {}');
131 GEN('CertificateViewerUITest::~CertificateViewerUITest() {}');
134 * Tests that the dialog opened to the correct URL.
136 TEST_F('CertificateViewerUITest', 'testDialogURL', function() {
137 this.testDialogUrl();
141 * Tests for the correct common name in the test certificate.
143 TEST_F('CertificateViewerUITest', 'testCN', function() {
148 * Test the details pane of the certificate viewer. This verifies that a
149 * certificate in the chain can be selected to view the fields. And that fields
150 * can be selected to view their values.
152 TEST_F('CertificateViewerUITestAsync', 'testDetails', function() {
156 // Same tests as above but running within modal (instead of constrained) dialog
157 // version of certificate viewer UI.
158 GEN('#if defined(OS_CHROMEOS)');
160 TEST_F('CertificateViewerModalUITest', 'testDialogURL', function() {
161 this.testDialogUrl();
164 TEST_F('CertificateViewerModalUITest', 'testCN', function() {
168 TEST_F('CertificateViewerModalUITestAsync', 'testDetails', function() {
174 ////////////////////////////////////////////////////////////////////////////////
178 * Find the first tree item (in the certificate fields tree) with a value.
179 * @param {!Element} tree Certificate fields subtree to search.
180 * @return {?Element} The first found element with a value, null if not found.
182 function getElementWithValue(tree) {
183 for (var i = 0; i < tree.childNodes.length; i++) {
184 var element = tree.childNodes[i];
185 if (element.detail && element.detail.payload && element.detail.payload.val)
187 if (element = getElementWithValue(element))