Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2728)

Unified Diff: chrome/test/data/webui/settings/languages_page_tests.js

Issue 2867213002: Fix CrSettingsLanguagesPageTest dialog flake (Closed)
Patch Set: parens Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/settings/languages_page_tests.js
diff --git a/chrome/test/data/webui/settings/languages_page_tests.js b/chrome/test/data/webui/settings/languages_page_tests.js
index 8bccfad534280762cb873ba0299faaa60d106d9c..5779f861ded7d23de51d0340d5639440e31ecef0 100644
--- a/chrome/test/data/webui/settings/languages_page_tests.js
+++ b/chrome/test/data/webui/settings/languages_page_tests.js
@@ -77,6 +77,25 @@ cr.define('languages_page_tests', function() {
var dialogItems;
var cancelButton;
var actionButton;
+ var dialogClosedResolver;
+ var dialogClosedObserver;
+
+ // Resolves the PromiseResolver if the mutation includes removal of the
+ // settings-add-languages-dialog.
+ // TODO(michaelpg): Extract into a common method similar to
+ // test_util.whenAttributeIs for use elsewhere.
+ var onMutation = function(mutations, observer) {
+ if (mutations.some(function(mutation) {
+ return mutation.type == 'childList' &&
+ Array.from(mutation.removedNodes).includes(dialog);
+ })) {
+ // Sanity check: the dialog should no longer be in the DOM.
+ assertEquals(null, languagesPage.$$('settings-add-languages-dialog'));
+ observer.disconnect();
+ assertTrue(!!dialogClosedResolver);
+ dialogClosedResolver.resolve();
+ }
+ };
setup(function(done) {
var addLanguagesButton =
@@ -89,6 +108,12 @@ cr.define('languages_page_tests', function() {
dialog = languagesPage.$$('settings-add-languages-dialog');
assertTrue(!!dialog);
+ // Observe the removal of the dialog via MutationObserver since the
+ // HTMLDialogElement 'close' event fires at an unpredictable time.
+ dialogClosedResolver = new PromiseResolver();
+ dialogClosedObserver = new MutationObserver(onMutation);
+ dialogClosedObserver.observe(languagesPage.root, {childList: true});
+
actionButton = assert(dialog.$$('.action-button'));
cancelButton = assert(dialog.$$('.cancel-button'));
@@ -107,30 +132,29 @@ cr.define('languages_page_tests', function() {
});
});
- // After every test, check that the dialog is removed from the DOM.
teardown(function() {
- Polymer.dom.flush();
- assertEquals(null, languagesPage.$$('settings-add-languages-dialog'));
+ dialogClosedObserver.disconnect();
});
test('cancel', function() {
// Canceling the dialog should close and remove it.
MockInteractions.tap(cancelButton);
+
+ return dialogClosedResolver.promise;
});
- test('add languages and cancel', function(done) {
+ test('add languages and cancel', function() {
// Check some languages.
MockInteractions.tap(dialogItems[1]); // en-CA.
MockInteractions.tap(dialogItems[2]); // tk.
// Canceling the dialog should close and remove it without enabling
- // the checked languages. A small timeout lets us check this.
+ // the checked languages.
MockInteractions.tap(cancelButton);
- setTimeout(function() {
+ return dialogClosedResolver.promise.then(function() {
assertEquals(initialLanguages,
languageHelper.getPref(languagesPref).value);
- done();
- }, 100);
+ });
});
test('add languages and confirm', function() {
@@ -157,6 +181,8 @@ cr.define('languages_page_tests', function() {
assertEquals(
initialLanguages + ',en,tk',
languageHelper.getPref(languagesPref).value);
+
+ return dialogClosedResolver.promise;
});
});
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698