Add very simple loading test for non-SFI NaCl.
[chromium-blink-merge.git] / chrome / test / data / webui / certificate_viewer_dialog_test.js
bloba83c325cf08e1e9ddffc615c9bf67859c2868dfa
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.
5 /**
6 * Test fixture for generated tests.
7 * @extends {testing.Test}
8 */
9 function CertificateViewerUITest() {}
11 CertificateViewerUITest.prototype = {
12 __proto__: testing.Test.prototype,
14 /**
15 * Define the C++ fixture class and include it.
16 * @type {?string}
17 * @override
19 typedefCppFixture: 'CertificateViewerUITest',
21 /**
22 * Show the certificate viewer dialog.
24 testGenPreamble: function() {
25 GEN('ShowCertificateViewer();');
30 /**
31 * Test fixture for asynchronous tests.
32 * @extends {CertificateViewerUITest}
34 function CertificateViewerUITestAsync() {}
36 CertificateViewerUITestAsync.prototype = {
37 __proto__: CertificateViewerUITest.prototype,
39 /** @inheritDoc */
40 isAsync: true,
43 // Include the bulk of c++ code.
44 // Certificate viewer UI tests are disabled on platforms with native certificate
45 // viewers.
46 GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"');
47 GEN('');
49 // Constructors and destructors must be provided in .cc to prevent clang errors.
50 GEN('CertificateViewerUITest::CertificateViewerUITest() {}');
51 GEN('CertificateViewerUITest::~CertificateViewerUITest() {}');
53 /**
54 * Tests that the dialog opened to the correct URL.
56 TEST_F('CertificateViewerUITest', 'testDialogURL', function() {
57 assertEquals(chrome.getVariableValue('expectedUrl'), window.location.href);
58 });
60 /**
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);
65 });
67 /**
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
85 // loaded.
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 ////////////////////////////////////////////////////////////////////////////////
107 // Support functions
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)
118 return element;
119 if (element = getElementWithValue(element))
120 return element;
122 return null;