OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 | |
Dan Beam
2016/09/15 18:17:08
nit: remove extra \n
dpapad
2016/09/15 18:52:12
Done.
| |
6 cr.define('test_util', function() { | |
7 /** | |
8 * Observes an HTML attribute and fires a promise when it changes. | |
9 * @param {!HTMLElement} target | |
10 * @param {string} attributeName | |
11 * @return {!Promise} | |
12 */ | |
13 function whenAttributeChanges(target, attributeName) { | |
Dan Beam
2016/09/15 18:17:08
whenAttributeIs(target, attributeName, attributeVa
dpapad
2016/09/15 18:52:12
Done.
| |
14 return new Promise(function(resolve, reject) { | |
15 var observer = new MutationObserver(function(mutations) { | |
16 assertEquals(1, mutations.length); | |
17 assertEquals('attributes', mutations[0].type); | |
18 assertEquals(attributeName, mutations[0].attributeName); | |
19 observer.disconnect(); | |
20 resolve(); | |
21 }); | |
22 observer.observe( | |
23 target, {attributes: true, childList: false, characterData: false}); | |
24 }); | |
25 } | |
26 | |
27 /** | |
28 * Converts an event occurrence to a promise. | |
29 * @param {string} eventType | |
30 * @param {!HTMLElement} target | |
31 * @return {!Promise} A promise firing once the event occurs. | |
32 */ | |
33 function eventToPromise(eventType, target) { | |
34 return new Promise(function(resolve, reject) { | |
35 target.addEventListener(eventType, resolve); | |
36 }); | |
37 } | |
38 | |
39 return { | |
40 eventToPromise: eventToPromise, | |
41 whenAttributeChanges: whenAttributeChanges, | |
42 }; | |
43 }); | |
OLD | NEW |