| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('test_util', function() { | 5 cr.define('test_util', function() { |
| 6 /** | 6 /** |
| 7 * Observes an HTML attribute and fires a promise when it matches a given | 7 * Observes an HTML attribute and fires a promise when it matches a given |
| 8 * value. | 8 * value. |
| 9 * @param {!HTMLElement} target | 9 * @param {!HTMLElement} target |
| 10 * @param {string} attributeName | 10 * @param {string} attributeName |
| 11 * @param {*} attributeValue | 11 * @param {*} attributeValue |
| 12 * @return {!Promise} | 12 * @return {!Promise} |
| 13 */ | 13 */ |
| 14 function whenAttributeIs(target, attributeName, attributeValue) { | 14 function whenAttributeIs(target, attributeName, attributeValue) { |
| 15 function isDone() { return target[attributeName] === attributeValue; } | 15 function isDone() { |
| 16 // TODO(dpapad): Following line should check for an attribute, not a |
| 17 // property, meaning target.getAttribute(attributeName). Fix this and |
| 18 // update callers to pass an attribute value instead. |
| 19 return target[attributeName] === attributeValue; |
| 20 } |
| 16 | 21 |
| 17 return isDone() ? Promise.resolve() : new Promise(function(resolve) { | 22 return isDone() ? Promise.resolve() : new Promise(function(resolve) { |
| 18 new MutationObserver(function(mutations, observer) { | 23 new MutationObserver(function(mutations, observer) { |
| 19 for (var mutation of mutations) { | 24 for (var mutation of mutations) { |
| 20 assertEquals('attributes', mutation.type); | 25 assertEquals('attributes', mutation.type); |
| 21 if (mutation.attributeName == attributeName && isDone()) { | 26 if (mutation.attributeName == attributeName && isDone()) { |
| 22 observer.disconnect(); | 27 observer.disconnect(); |
| 23 resolve(); | 28 resolve(); |
| 24 return; | 29 return; |
| 25 } | 30 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 el1.addEventListener(property + '-changed', forwardChange.bind(null, el2)); | 65 el1.addEventListener(property + '-changed', forwardChange.bind(null, el2)); |
| 61 el2.addEventListener(property + '-changed', forwardChange.bind(null, el1)); | 66 el2.addEventListener(property + '-changed', forwardChange.bind(null, el1)); |
| 62 } | 67 } |
| 63 | 68 |
| 64 return { | 69 return { |
| 65 eventToPromise: eventToPromise, | 70 eventToPromise: eventToPromise, |
| 66 fakeDataBind: fakeDataBind, | 71 fakeDataBind: fakeDataBind, |
| 67 whenAttributeIs: whenAttributeIs, | 72 whenAttributeIs: whenAttributeIs, |
| 68 }; | 73 }; |
| 69 }); | 74 }); |
| OLD | NEW |