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, |
+ }; |
+}); |