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

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

Issue 2341493003: MD Settings: Deflake attempt for CrSettingsPrivacyPageTest.PrivacyPage. (Closed)
Patch Set: Use MutationObserver, refactor. Created 4 years, 3 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/privacy_page_test.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/test_util.js
diff --git a/chrome/test/data/webui/settings/test_util.js b/chrome/test/data/webui/settings/test_util.js
new file mode 100644
index 0000000000000000000000000000000000000000..72a1cced91f1837b4dce72b4bf43ce6930155e20
--- /dev/null
+++ b/chrome/test/data/webui/settings/test_util.js
@@ -0,0 +1,43 @@
+// Copyright 2016 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.
+
+
Dan Beam 2016/09/15 18:17:08 nit: remove extra \n
dpapad 2016/09/15 18:52:12 Done.
+cr.define('test_util', function() {
+ /**
+ * Observes an HTML attribute and fires a promise when it changes.
+ * @param {!HTMLElement} target
+ * @param {string} attributeName
+ * @return {!Promise}
+ */
+ function whenAttributeChanges(target, attributeName) {
Dan Beam 2016/09/15 18:17:08 whenAttributeIs(target, attributeName, attributeVa
dpapad 2016/09/15 18:52:12 Done.
+ return new Promise(function(resolve, reject) {
+ var observer = new MutationObserver(function(mutations) {
+ assertEquals(1, mutations.length);
+ assertEquals('attributes', mutations[0].type);
+ assertEquals(attributeName, mutations[0].attributeName);
+ observer.disconnect();
+ resolve();
+ });
+ observer.observe(
+ target, {attributes: true, childList: false, characterData: false});
+ });
+ }
+
+ /**
+ * Converts an event occurrence to a promise.
+ * @param {string} eventType
+ * @param {!HTMLElement} target
+ * @return {!Promise} A promise firing once the event occurs.
+ */
+ function eventToPromise(eventType, target) {
+ return new Promise(function(resolve, reject) {
+ target.addEventListener(eventType, resolve);
+ });
+ }
+
+ return {
+ eventToPromise: eventToPromise,
+ whenAttributeChanges: whenAttributeChanges,
+ };
+});
« no previous file with comments | « chrome/test/data/webui/settings/privacy_page_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698