Commit b9f5fe33 authored by dpapad's avatar dpapad Committed by Commit Bot

De-flake CertificateViewerUITest.Details.Test.

The test code was waiting for an event emitted from the prod code,
but in some cases the event had already fired before the test code
had registered the listener, causing the test to hang indefinitely.

Fixed: 1104824
Change-Id: I10597aabc565ecbcef2dcd4e191cc80521f1686e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316129
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791527}
parent 77f73738
......@@ -185,7 +185,7 @@
// Ensure the list is scrolled to the top by selecting the first item.
treeItem.children[0].selected = true;
document.body.dispatchEvent(
new CustomEvent('certificate-fields-updated-for-tesing'));
new CustomEvent('certificate-fields-updated-for-testing'));
}
/**
......
......@@ -34,7 +34,8 @@ suite('CertificateViewer', function() {
assertEquals('www.google.com', $('issued-cn').textContent);
});
test('Details', function() {
test('Details', async function() {
var certHierarchy = $('hierarchy');
var certFields = $('cert-fields');
var certFieldVal = $('cert-field-value');
......@@ -45,24 +46,26 @@ suite('CertificateViewer', function() {
// There must be at least one certificate in the hierarchy.
assertLT(0, certHierarchy.childNodes.length);
// Wait for the '-for-testing' event to fire only if |certFields| is not
// populated yet, otherwise don't wait, the event has already fired.
const whenLoaded = certFields.childNodes.length === 0 ?
test_util.eventToPromise(
'certificate-fields-updated-for-testing', document.body) :
Promise.resolve();
// Select the first certificate on the chain and ensure the details show up.
// Override the receive certificate function to catch when fields are
// loaded.
return test_util
.eventToPromise('certificate-fields-updated-for-tesing', document.body)
.then(() => {
assertLT(0, certFields.childNodes.length);
await whenLoaded;
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 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);
});
// Test that selecting an item without a value empties the field.
certFields.selectedItem = certFields.childNodes[0];
assertEquals('', certFieldVal.textContent);
});
});
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