Commit d823f90b authored by kgr@chromium.org's avatar kgr@chromium.org

Fix for broken CertificateViewerUITest.testDetails.

BUG=127732
TEST=browser_tests --gtest_filter="CertificateViewerUITest*.*"


Review URL: https://chromiumcodereview.appspot.com/10382145

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137984 0039d316-1c4b-4281-b951-d872f2087c98
parent f98f509f
...@@ -17,17 +17,31 @@ cr.define('cert_viewer', function() { ...@@ -17,17 +17,31 @@ cr.define('cert_viewer', function() {
var args = JSON.parse(chrome.dialogArguments); var args = JSON.parse(chrome.dialogArguments);
getCertificateInfo(args); getCertificateInfo(args);
/**
* Initialize the second tab's contents.
* This is a 'oneShot' function, meaning it will only be invoked once,
* no matter how many times it is called. This is done for unit-testing
* purposes in case a test needs to initialize the tab before the timer
* fires.
*/
var initializeDetailTab = oneShot(function() {
initializeTree($('hierarchy'), showCertificateFields);
initializeTree($('cert-fields'), showCertificateFieldValue);
createCertificateHierarchy(args.hierarchy);
});
// The second tab's contents aren't visible on startup, so we can // The second tab's contents aren't visible on startup, so we can
// shorten startup by not populating those controls until after we // shorten startup by not populating those controls until after we
// have had a chance to draw the visible controls the first time. // have had a chance to draw the visible controls the first time.
// The value of 200ms is quick enough that the user couldn't open the // The value of 200ms is quick enough that the user couldn't open the
// tab in that time but long enough to allow the first tab to draw on // tab in that time but long enough to allow the first tab to draw on
// even the slowest machine. // even the slowest machine.
setTimeout(function() { setTimeout(initializeDetailTab, 200);
initializeTree($('hierarchy'), showCertificateFields);
initializeTree($('cert-fields'), showCertificateFieldValue); $('tabbox').addEventListener('selectedChange', function f(e) {
createCertificateHierarchy(args.hierarchy); $('tabbox').removeEventListener('selectedChange', f);
}, 200); initializeDetailTab();
});
stripGtkAccessorKeys(); stripGtkAccessorKeys();
...@@ -40,6 +54,18 @@ cr.define('cert_viewer', function() { ...@@ -40,6 +54,18 @@ cr.define('cert_viewer', function() {
}); });
} }
/**
* Decorate a function so that it can only be invoked once.
*/
function oneShot(fn) {
var fired = false;
return function() {
if (fired) return;
fn();
fired = true;
};
}
/** /**
* Initialize a cr.ui.Tree object from a given element using the specified * Initialize a cr.ui.Tree object from a given element using the specified
* change handler. * change handler.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Test fixture for generated tests. * Test fixture for generated tests.
* @extends {testing.Test} * @extends {testing.Test}
*/ */
function CertificateViewerUITest() {}; function CertificateViewerUITest() {}
CertificateViewerUITest.prototype = { CertificateViewerUITest.prototype = {
__proto__: testing.Test.prototype, __proto__: testing.Test.prototype,
...@@ -31,7 +31,7 @@ CertificateViewerUITest.prototype = { ...@@ -31,7 +31,7 @@ CertificateViewerUITest.prototype = {
* Test fixture for asynchronous tests. * Test fixture for asynchronous tests.
* @extends {CertificateViewerUITest} * @extends {CertificateViewerUITest}
*/ */
function CertificateViewerUITestAsync() {}; function CertificateViewerUITestAsync() {}
CertificateViewerUITestAsync.prototype = { CertificateViewerUITestAsync.prototype = {
__proto__: CertificateViewerUITest.prototype, __proto__: CertificateViewerUITest.prototype,
...@@ -44,7 +44,7 @@ CertificateViewerUITestAsync.prototype = { ...@@ -44,7 +44,7 @@ CertificateViewerUITestAsync.prototype = {
// Certificate viewer UI tests are disabled on platforms with native certificate // Certificate viewer UI tests are disabled on platforms with native certificate
// viewers. // viewers.
GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"'); GEN('#include "chrome/test/data/webui/certificate_viewer_ui_test-inl.h"');
GEN('') GEN('');
// Constructors and destructors must be provided in .cc to prevent clang errors. // Constructors and destructors must be provided in .cc to prevent clang errors.
GEN('CertificateViewerUITest::CertificateViewerUITest() {}'); GEN('CertificateViewerUITest::CertificateViewerUITest() {}');
...@@ -68,9 +68,8 @@ TEST_F('CertificateViewerUITest', 'testCN', function() { ...@@ -68,9 +68,8 @@ TEST_F('CertificateViewerUITest', 'testCN', function() {
* Test the details pane of the certificate viewer. This verifies that a * 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 * certificate in the chain can be selected to view the fields. And that fields
* can be selected to view their values. * can be selected to view their values.
* TODO(flackr,kgr): Re-enable this (http://crbug.com/127732).
*/ */
TEST_F('CertificateViewerUITestAsync', 'DISABLED_testDetails', function() { TEST_F('CertificateViewerUITestAsync', 'testDetails', function() {
var certHierarchy = $('hierarchy'); var certHierarchy = $('hierarchy');
var certFields = $('cert-fields'); var certFields = $('cert-fields');
var certFieldVal = $('cert-field-value'); var certFieldVal = $('cert-field-value');
...@@ -78,9 +77,13 @@ TEST_F('CertificateViewerUITestAsync', 'DISABLED_testDetails', function() { ...@@ -78,9 +77,13 @@ TEST_F('CertificateViewerUITestAsync', 'DISABLED_testDetails', function() {
// There must be at least one certificate in the hierarchy. // There must be at least one certificate in the hierarchy.
assertLT(0, certHierarchy.childNodes.length); assertLT(0, certHierarchy.childNodes.length);
// Select the second tab, causing its data to be loaded if needed.
$('tabbox').selectedIndex = 1;
// Select the first certificate on the chain and ensure the details show up. // Select the first certificate on the chain and ensure the details show up.
// Override the receive certificate function to catch when fields are // Override the receive certificate function to catch when fields are
// loaded. // loaded.
certHierarchy.selectedItem = null;
var getCertificateFields = cert_viewer.getCertificateFields; var getCertificateFields = cert_viewer.getCertificateFields;
cert_viewer.getCertificateFields = this.continueTest(WhenTestDone.ALWAYS, cert_viewer.getCertificateFields = this.continueTest(WhenTestDone.ALWAYS,
function(certFieldDetails) { function(certFieldDetails) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment