Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: chrome/test/data/webui/certificate_viewer_dialog_test.js

Issue 7861024: Adds testing infrastructure to web_ui_browsertest to support testing HtmlDialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Run testDetails asserts in function that catches assertion failures as well. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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"');
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() {
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() {
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 runAssertions('testDetails', function() {
63 // There must be at least one certificate in the hierarchy.
64 assertLT(0, certHierarchy.childNodes.length);
65 // No certificate fields should be currently loaded.
66 assertEquals(0, certFields.childNodes.length);
67
68 // Select the first certificate on the chain and ensure the details show up.
69 // Override the receive certificate function to catch when fields are
70 // loaded.
71 var getCertificateFields = cert_viewer.getCertificateFields;
72 cert_viewer.getCertificateFields = function(certFieldDetails) {
73 getCertificateFields(certFieldDetails);
74 cert_viewer.getCertificateFields = getCertificateFields;
75 runAssertions('testDetails', function() {
76 assertLT(0, certFields.childNodes.length);
77
78 // Test that a field can be selected to see the details for that field.
79 var item = getElementWithValue(certFields);
80 assertNotEquals(null, item);
81 certFields.selectedItem = item;
82 assertEquals(item.detail.payload.val, certFieldVal.textContent);
83
84 // Test that selecting an item without a value empties the field.
85 certFields.selectedItem = certFields.childNodes[0];
86 assertEquals('', certFieldVal.textContent);
87
88 testDone();
89 });
90 }
91 certHierarchy.selectedItem = certHierarchy.childNodes[0];
92 });
93 });
94
95 ////////////////////////////////////////////////////////////////////////////////
96 // Support functions
97
98 /**
99 * Run a block of code failing the asynchronous test on any failed assertions.
100 * @param {string} testName The name of the test being run (for error messages).
101 * @param {function()} f A function to run which may throw an exception.
102 */
103 function runAssertions(testName, f) {
104 var result = runTestFunction(testName, f, []);
105 if (!result[0])
106 testDone();
107 }
108
109 /**
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, or null if not found.
113 */
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;
121 }
122 return null;
123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698