Chromium Code Reviews| Index: chrome/test/data/webui/certificate_viewer_dialog_test.js |
| diff --git a/chrome/test/data/webui/certificate_viewer_dialog_test.js b/chrome/test/data/webui/certificate_viewer_dialog_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae5b5fe9d12813772c5fe89a1a87e30bcdb8ecce |
| --- /dev/null |
| +++ b/chrome/test/data/webui/certificate_viewer_dialog_test.js |
| @@ -0,0 +1,120 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * Test fixture for generated tests. |
| + * @extends {testing.Test} |
| + */ |
| +function CertificateViewerUITest() {}; |
| + |
| +CertificateViewerUITest.prototype = { |
| + __proto__: testing.Test.prototype, |
| + |
| + /** |
| + * Define the C++ fixture class and include it. |
| + * @type {?string} |
| + * @override |
| + */ |
| + typedefCppFixture: 'CertificateViewerUITest', |
| + |
| + /** @inheritDoc */ |
| + isAsync: true, |
| +}; |
| + |
| +// Include the bulk of c++ code. |
| +GEN('#include "chrome/browser/ui/webui/certificate_viewer_ui_browsertest.cc"'); |
|
Sheridan Rawlins
2011/09/15 19:11:41
if this is included, please make it certificate_vi
flackr
2011/09/15 21:02:36
Done.
|
| +GEN(''); |
| + |
| +/** |
| + * Tests that the dialog opened to the correct URL. |
| + */ |
| +TEST_F('CertificateViewerUITest', 'testDialogURL', |
| + function() { |
| + runAssertions('testDialogURL', function() { |
|
Sheridan Rawlins
2011/09/15 19:11:41
I'm sorry, but why do you feel you need this? TES
flackr
2011/09/15 21:02:36
Done.
|
| + assertEquals(chrome.expectedUrl, window.location.href); |
| + testDone(); |
| + }); |
| +}); |
| + |
| +/** |
| + * Tests for the correct common name in the test certificate. |
| + */ |
| +TEST_F('CertificateViewerUITest', 'testCN', |
| + function() { |
| + runAssertions('testCN', function() { |
|
Sheridan Rawlins
2011/09/15 19:11:41
ditch runAssertions.
flackr
2011/09/15 21:02:36
Done.
|
| + assertEquals('www.google.com', $('issued-cn').textContent); |
| + testDone(); |
| + }); |
| +}); |
| + |
| +/** |
| + * Test the details pane of the certificate viewer. This verifies that a |
| + * certificate in the chain can be selected to view the fields. And that fields |
| + * can be selected to view their values. |
| + */ |
| +TEST_F('CertificateViewerUITest', 'testDetails', |
| + function() { |
| + var certHierarchy = $('hierarchy'); |
| + var certFields = $('cert-fields'); |
| + var certFieldVal = $('cert-field-value'); |
| + |
| + // There must be at least one certificate in the hierarchy. |
| + assertLT(0, certHierarchy.childNodes.length); |
| + // No certificate fields should be currently loaded. |
| + assertEquals(0, certFields.childNodes.length); |
| + |
| + // Select the first certificate on the chain and ensure the details show up. |
| + // Override the receive certificate function to catch when fields are loaded. |
| + var getCertificateFields = cert_viewer.getCertificateFields; |
| + cert_viewer.getCertificateFields = function(certFieldDetails) { |
|
Sheridan Rawlins
2011/09/15 19:11:41
You can use this.continueTest to wrap and ditch ru
flackr
2011/09/15 21:02:36
Done.
|
| + getCertificateFields(certFieldDetails); |
| + cert_viewer.getCertificateFields = getCertificateFields; |
| + runAssertions('testDetails', function() { |
| + assertLT(0, certFields.childNodes.length); |
| + |
| + // Test that a field can be selected to see the details for that field. |
| + var item = getElementWithValue(certFields); |
| + assertNotEquals(null, item); |
| + certFields.selectedItem = item; |
| + assertEquals(item.detail.payload.val, certFieldVal.textContent); |
| + |
| + // Test that selecting an item without a value empties the field. |
| + certFields.selectedItem = certFields.childNodes[0]; |
| + assertEquals('', certFieldVal.textContent); |
| + |
| + testDone(); |
| + }); |
| + } |
| + certHierarchy.selectedItem = certHierarchy.childNodes[0]; |
| +}); |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Support functions |
| + |
| +/** |
| + * Run a block of code failing the asynchronous test on any failed assertions. |
| + * @param {string} testName The name of the test being run (for error messages). |
| + * @param {function()} f A function to run which may throw an exception. |
| + */ |
| +function runAssertions(testName, f) { |
|
Sheridan Rawlins
2011/09/15 19:11:41
Why is this needed? Please remove this function.
flackr
2011/09/15 21:02:36
Done.
|
| + var result = runTestFunction(testName, f, []); |
| + if (!result[0]) |
| + testDone(); |
| +} |
| + |
| +/** |
| + * Find the first tree item (in the certificate fields tree) with a value. |
| + * @param {!Element} tree Certificate fields subtree to search. |
| + * @return {Element} The first found element with a value, or null if not found. |
|
Sheridan Rawlins
2011/09/15 19:11:41
{?Element}
flackr
2011/09/15 21:02:36
Done.
|
| + */ |
| +function getElementWithValue(tree) { |
| + for (var i = 0; i < tree.childNodes.length; i++) { |
| + var element = tree.childNodes[i]; |
| + if (element.detail && element.detail.payload && element.detail.payload.val) |
| + return element; |
| + if (element = getElementWithValue(element)) |
| + return element; |
| + } |
| + return null; |
| +} |