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

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

Issue 2341493003: MD Settings: Deflake attempt for CrSettingsPrivacyPageTest.PrivacyPage. (Closed)
Patch Set: Check for specific value. 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..ea50c397dd552c3c9dd866be3b3db3d89b985477
--- /dev/null
+++ b/chrome/test/data/webui/settings/test_util.js
@@ -0,0 +1,48 @@
+// 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.
+
+cr.define('test_util', function() {
+ /**
+ * Observes an HTML attribute and fires a promise when it matches a given
+ * value.
+ * @param {!HTMLElement} target
+ * @param {string} attributeName
+ * @param {*} attributeValue
+ * @return {!Promise}
+ */
+ function whenAttributeIs(target, attributeName, attributeValue) {
+ function isDone() { return target[attributeName] === attributeValue; }
+
+ return isDone() ? Promise.resolve() : new Promise(function(resolve) {
+ new MutationObserver(function(mutations, observer) {
+ for (var mutation of mutations) {
+ assertEquals('attributes', mutation.type);
+ if (mutation.attributeName == attributeName && isDone()) {
+ observer.disconnect();
+ resolve();
+ return;
+ }
+ }
+ }).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,
+ whenAttributeIs: whenAttributeIs,
+ };
+});
« 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