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 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', |
| 47 function() { |
| 48 assertEquals(chrome.expectedUrl, window.location.href); |
| 49 }); |
| 50 |
| 51 /** |
| 52 * Tests for the correct common name in the test certificate. |
| 53 */ |
| 54 TEST_F('CertificateViewerUITest', 'testCN', |
| 55 function() { |
| 56 assertEquals('www.google.com', $('issued-cn').textContent); |
| 57 }); |
| 58 |
| 59 /** |
| 60 * Test the details pane of the certificate viewer. This verifies that a |
| 61 * certificate in the chain can be selected to view the fields. And that fields |
| 62 * can be selected to view their values. |
| 63 */ |
| 64 TEST_F('CertificateViewerUITestAsync', 'testDetails', |
| 65 function() { |
| 66 var certHierarchy = $('hierarchy'); |
| 67 var certFields = $('cert-fields'); |
| 68 var certFieldVal = $('cert-field-value'); |
| 69 |
| 70 this.continueTest(WhenTestDone.DEFAULT, function() { |
| 71 // There must be at least one certificate in the hierarchy. |
| 72 assertLT(0, certHierarchy.childNodes.length); |
| 73 // No certificate fields should be currently loaded. |
| 74 assertEquals(0, certFields.childNodes.length); |
| 75 |
| 76 // Select the first certificate on the chain and ensure the details show up. |
| 77 // Override the receive certificate function to catch when fields are |
| 78 // loaded. |
| 79 var getCertificateFields = cert_viewer.getCertificateFields; |
| 80 cert_viewer.getCertificateFields = this.continueTest(WhenTestDone.ALWAYS, |
| 81 function(certFieldDetails) { |
| 82 getCertificateFields(certFieldDetails); |
| 83 cert_viewer.getCertificateFields = getCertificateFields; |
| 84 assertLT(0, certFields.childNodes.length); |
| 85 |
| 86 // Test that a field can be selected to see the details for that field. |
| 87 var item = getElementWithValue(certFields); |
| 88 assertNotEquals(null, item); |
| 89 certFields.selectedItem = item; |
| 90 assertEquals(item.detail.payload.val, certFieldVal.textContent); |
| 91 |
| 92 // Test that selecting an item without a value empties the field. |
| 93 certFields.selectedItem = certFields.childNodes[0]; |
| 94 assertEquals('', certFieldVal.textContent); |
| 95 }); |
| 96 certHierarchy.selectedItem = certHierarchy.childNodes[0]; |
| 97 })(); |
| 98 }); |
| 99 |
| 100 //////////////////////////////////////////////////////////////////////////////// |
| 101 // Support functions |
| 102 |
| 103 /** |
| 104 * Find the first tree item (in the certificate fields tree) with a value. |
| 105 * @param {!Element} tree Certificate fields subtree to search. |
| 106 * @return {?Element} The first found element with a value, null if not found. |
| 107 */ |
| 108 function getElementWithValue(tree) { |
| 109 for (var i = 0; i < tree.childNodes.length; i++) { |
| 110 var element = tree.childNodes[i]; |
| 111 if (element.detail && element.detail.payload && element.detail.payload.val) |
| 112 return element; |
| 113 if (element = getElementWithValue(element)) |
| 114 return element; |
| 115 } |
| 116 return null; |
| 117 } |
OLD | NEW |