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

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: Applied scr's review suggestions. 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
22 /**
23 * Test fixture for asynchronous tests.
24 * @extends {CertificateViewerUITest}
25 */
26 function CertificateViewerUITestAsync() {};
27
28 CertificateViewerUITestAsync.prototype = {
29 __proto__: CertificateViewerUITest.prototype,
30
31 /** @inheritDoc */
32 isAsync: true,
33 };
34
35 // Include the bulk of c++ code.
36 GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"');
37 GEN('');
38
39 // Constructors and destructors must be provided in .cc to prevent clang errors.
40 GEN('CertificateViewerUITest::CertificateViewerUITest() {}');
41 GEN('CertificateViewerUITest::~CertificateViewerUITest() {}');
42
43 /**
44 * Tests that the dialog opened to the correct URL.
45 */
46 TEST_F('CertificateViewerUITest', 'testDialogURL', function() {
47 assertEquals(chrome.expectedUrl, window.location.href);
48 });
49
50 /**
51 * Tests for the correct common name in the test certificate.
52 */
53 TEST_F('CertificateViewerUITest', 'testCN', function() {
54 assertEquals('www.google.com', $('issued-cn').textContent);
55 });
56
57 /**
58 * Test the details pane of the certificate viewer. This verifies that a
59 * certificate in the chain can be selected to view the fields. And that fields
60 * can be selected to view their values.
61 */
62 TEST_F('CertificateViewerUITestAsync', 'testDetails', function() {
63 var certHierarchy = $('hierarchy');
64 var certFields = $('cert-fields');
65 var certFieldVal = $('cert-field-value');
66
67 // TODO(scr): Fix TEST_F to call testDone when assertions fail in async mode.
68 this.continueTest(WhenTestDone.DEFAULT, function() {
69 // There must be at least one certificate in the hierarchy.
70 assertLT(0, certHierarchy.childNodes.length);
71 // No certificate fields should be currently loaded.
72 assertEquals(0, certFields.childNodes.length);
73
74 // Select the first certificate on the chain and ensure the details show up.
75 // Override the receive certificate function to catch when fields are
76 // loaded.
77 var getCertificateFields = cert_viewer.getCertificateFields;
78 cert_viewer.getCertificateFields = this.continueTest(WhenTestDone.ALWAYS,
79 function(certFieldDetails) {
80 getCertificateFields(certFieldDetails);
81 cert_viewer.getCertificateFields = getCertificateFields;
82 assertLT(0, certFields.childNodes.length);
83
84 // Test that a field can be selected to see the details for that field.
85 var item = getElementWithValue(certFields);
86 assertNotEquals(null, item);
87 certFields.selectedItem = item;
88 assertEquals(item.detail.payload.val, certFieldVal.textContent);
89
90 // Test that selecting an item without a value empties the field.
91 certFields.selectedItem = certFields.childNodes[0];
92 assertEquals('', certFieldVal.textContent);
93 });
94 certHierarchy.selectedItem = certHierarchy.childNodes[0];
95 })();
96 });
97
98 ////////////////////////////////////////////////////////////////////////////////
99 // Support functions
100
101 /**
102 * Find the first tree item (in the certificate fields tree) with a value.
103 * @param {!Element} tree Certificate fields subtree to search.
104 * @return {?Element} The first found element with a value, null if not found.
105 */
106 function getElementWithValue(tree) {
107 for (var i = 0; i < tree.childNodes.length; i++) {
108 var element = tree.childNodes[i];
109 if (element.detail && element.detail.payload && element.detail.payload.val)
110 return element;
111 if (element = getElementWithValue(element))
112 return element;
113 }
114 return null;
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698