Commit 75e29f77 authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Fix flaky printmanagement browser test

- The original cause of the flaky is because the page element was not
  ready by the time we try to query for elements within it.
- The fix is to attach a promise to the instatiation of the page and
  to only continue with the test once the promise is resolved. This
  ensures that each step of the test is handled synchronously.

Bug: 1068860
Test: browser_tests
Change-Id: I0a30e2971107b44354603adbb0396ddfea3c218d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142951Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757687}
parent 5aab96b0
...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; ...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://print-management/print_management.js'; import 'chrome://print-management/print_management.js';
import {setMetadataProviderForTesting} from 'chrome://print-management/mojo_interface_provider.js'; import {setMetadataProviderForTesting} from 'chrome://print-management/mojo_interface_provider.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flushTasks} from 'chrome://test/test_util.m.js';
const CompletionStatus = { const CompletionStatus = {
FAILED: 0, FAILED: 0,
...@@ -84,7 +84,6 @@ function verifyPrintJobs(expected, actual) { ...@@ -84,7 +84,6 @@ function verifyPrintJobs(expected, actual) {
* @return {!Array<!HTMLElement>} * @return {!Array<!HTMLElement>}
*/ */
function getPrintJobEntries(page) { function getPrintJobEntries(page) {
flush();
const entryList = page.$$('#entryList'); const entryList = page.$$('#entryList');
return Array.from( return Array.from(
entryList.querySelectorAll('print-job-entry:not([hidden])')); entryList.querySelectorAll('print-job-entry:not([hidden])'));
...@@ -198,7 +197,7 @@ suite('PrintManagementTest', () => { ...@@ -198,7 +197,7 @@ suite('PrintManagementTest', () => {
mojoApi_.setPrintJobs(printJobs); mojoApi_.setPrintJobs(printJobs);
page = document.createElement('print-management'); page = document.createElement('print-management');
document.body.appendChild(page); document.body.appendChild(page);
flush(); return flushTasks();
} }
test('PrintHistoryListIsSortedReverseChronologically', () => { test('PrintHistoryListIsSortedReverseChronologically', () => {
...@@ -217,11 +216,13 @@ suite('PrintManagementTest', () => { ...@@ -217,11 +216,13 @@ suite('PrintManagementTest', () => {
// Initialize with a reversed array of |expectedArr|, since we expect the // Initialize with a reversed array of |expectedArr|, since we expect the
// app to sort the list when it first loads. Since reverse() mutates the // app to sort the list when it first loads. Since reverse() mutates the
// original array, use a copy array to prevent mutating |expectedArr|. // original array, use a copy array to prevent mutating |expectedArr|.
initializePrintManagementApp(expectedArr.slice().reverse()); initializePrintManagementApp(expectedArr.slice().reverse())
.then(() => {
mojoApi_.whenCalled('getPrintJobs').then(() => { return mojoApi_.whenCalled('getPrintJobs');
verifyPrintJobs(expectedArr, getPrintJobEntries(page)); })
}); .then(() => {
verifyPrintJobs(expectedArr, getPrintJobEntries(page));
});
}); });
}); });
......
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