| OLD | NEW |
| 1 /** | 1 /** |
| 2 * @license | 2 * @license |
| 3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt | 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
| 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt | 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
| 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt | 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
| 7 * Code distributed by Google as part of the polymer project is also | 7 * Code distributed by Google as part of the polymer project is also |
| 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt | 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
| 9 */ | 9 */ |
| 10 (function(global) { | 10 (function(global) { |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /* |
| 14 * Forces distribution of light children, and lifecycle callbacks on the |
| 15 * Custom Elements polyfill. Used when testing elements that rely on their |
| 16 * distributed children. |
| 17 */ |
| 13 global.flushAsynchronousOperations = function() { | 18 global.flushAsynchronousOperations = function() { |
| 14 // force distribution | 19 // force distribution |
| 15 Polymer.dom.flush(); | 20 Polymer.dom.flush(); |
| 16 // force lifecycle callback to fire on polyfill | 21 // force lifecycle callback to fire on polyfill |
| 17 window.CustomElements && window.CustomElements.takeRecords(); | 22 window.CustomElements && window.CustomElements.takeRecords(); |
| 18 }; | 23 }; |
| 19 | 24 |
| 25 /* |
| 26 * Stamps and renders a `dom-if` template. |
| 27 * |
| 28 * @param {HTMLElement} node The node containing the template, |
| 29 */ |
| 20 global.forceXIfStamp = function(node) { | 30 global.forceXIfStamp = function(node) { |
| 21 var templates = Polymer.dom(node.root).querySelectorAll('template[is=dom-if]
'); | 31 var templates = Polymer.dom(node.root).querySelectorAll('template[is=dom-if]
'); |
| 22 for (var tmpl, i = 0; tmpl = templates[i]; i++) { | 32 for (var tmpl, i = 0; tmpl = templates[i]; i++) { |
| 23 tmpl.render(); | 33 tmpl.render(); |
| 24 } | 34 } |
| 25 | 35 |
| 26 global.flushAsynchronousOperations(); | 36 global.flushAsynchronousOperations(); |
| 27 }; | 37 }; |
| 28 | 38 |
| 39 /* |
| 40 * Fires a custom event on a specific node. This event bubbles and is cancella
ble. |
| 41 * |
| 42 * @param {String} type The type of event. |
| 43 * @param {Object} props Any custom properties the event contains. |
| 44 * @param {HTMLElement} node The node to fire the event on. |
| 45 */ |
| 29 global.fireEvent = function(type, props, node) { | 46 global.fireEvent = function(type, props, node) { |
| 30 var event = new CustomEvent(type, { | 47 var event = new CustomEvent(type, { |
| 31 bubbles: true, | 48 bubbles: true, |
| 32 cancelable: true | 49 cancelable: true |
| 33 }); | 50 }); |
| 34 for (var p in props) { | 51 for (var p in props) { |
| 35 event[p] = props[p]; | 52 event[p] = props[p]; |
| 36 } | 53 } |
| 37 node.dispatchEvent(event); | 54 node.dispatchEvent(event); |
| 38 }; | 55 }; |
| 39 | 56 |
| 57 /* |
| 58 * Skips a test unless a condition is met. Sample use: |
| 59 * function isNotIE() { |
| 60 * return !navigator.userAgent.match(/MSIE/i); |
| 61 * } |
| 62 * test('runs on non IE browsers', skipUnless(isNotIE, function() { |
| 63 * ... |
| 64 * }); |
| 65 * |
| 66 * @param {String} condition The name of a Boolean function determining if the
test should be run. |
| 67 * @param {Function} test The test to be run. |
| 68 */ |
| 69 |
| 40 global.skipUnless = function(condition, test) { | 70 global.skipUnless = function(condition, test) { |
| 41 var isAsyncTest = !!test.length; | 71 var isAsyncTest = !!test.length; |
| 42 | 72 |
| 43 return function(done) { | 73 return function(done) { |
| 44 var testCalledDone = false; | 74 var testCalledDone = false; |
| 45 | 75 |
| 46 if (!condition()) { | 76 if (!condition()) { |
| 47 return done(); | 77 return done(); |
| 48 } | 78 } |
| 49 | 79 |
| 50 var result = test.call(this, done); | 80 var result = test.call(this, done); |
| 51 | 81 |
| 52 if (!isAsyncTest) { | 82 if (!isAsyncTest) { |
| 53 done(); | 83 done(); |
| 54 } | 84 } |
| 55 | 85 |
| 56 return result; | 86 return result; |
| 57 }; | 87 }; |
| 58 }; | 88 }; |
| 59 })(this); | 89 })(this); |
| OLD | NEW |