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