| 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 /* | 13 |
| 14 /** |
| 14 * Forces distribution of light children, and lifecycle callbacks on the | 15 * Forces distribution of light children, and lifecycle callbacks on the |
| 15 * Custom Elements polyfill. Used when testing elements that rely on their | 16 * Custom Elements polyfill. Used when testing elements that rely on their |
| 16 * distributed children. | 17 * distributed children. |
| 17 */ | 18 */ |
| 18 global.flushAsynchronousOperations = function() { | 19 global.flushAsynchronousOperations = function() { |
| 19 // force distribution | 20 // force distribution |
| 20 Polymer.dom.flush(); | 21 Polymer.dom.flush(); |
| 21 // force lifecycle callback to fire on polyfill | 22 // force lifecycle callback to fire on polyfill |
| 22 window.CustomElements && window.CustomElements.takeRecords(); | 23 window.CustomElements && window.CustomElements.takeRecords(); |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 /* | 26 /** |
| 26 * Stamps and renders a `dom-if` template. | 27 * Stamps and renders a `dom-if` template. |
| 27 * | 28 * |
| 28 * @param {HTMLElement} node The node containing the template, | 29 * @param {HTMLElement} node The node containing the template, |
| 29 */ | 30 */ |
| 30 global.forceXIfStamp = function(node) { | 31 global.forceXIfStamp = function(node) { |
| 31 var templates = Polymer.dom(node.root).querySelectorAll('template[is=dom-if]
'); | 32 var templates = Polymer.dom(node.root).querySelectorAll('template[is=dom-if]
'); |
| 32 for (var tmpl, i = 0; tmpl = templates[i]; i++) { | 33 for (var tmpl, i = 0; tmpl = templates[i]; i++) { |
| 33 tmpl.render(); | 34 tmpl.render(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 global.flushAsynchronousOperations(); | 37 global.flushAsynchronousOperations(); |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 /* | 40 /** |
| 40 * Fires a custom event on a specific node. This event bubbles and is cancella
ble. | 41 * Fires a custom event on a specific node. This event bubbles and is cancella
ble. |
| 41 * | 42 * |
| 42 * @param {String} type The type of event. | 43 * @param {string} type The type of event. |
| 43 * @param {Object} props Any custom properties the event contains. | 44 * @param {Object} props Any custom properties the event contains. |
| 44 * @param {HTMLElement} node The node to fire the event on. | 45 * @param {HTMLElement} node The node to fire the event on. |
| 45 */ | 46 */ |
| 46 global.fireEvent = function(type, props, node) { | 47 global.fireEvent = function(type, props, node) { |
| 47 var event = new CustomEvent(type, { | 48 var event = new CustomEvent(type, { |
| 48 bubbles: true, | 49 bubbles: true, |
| 49 cancelable: true | 50 cancelable: true |
| 50 }); | 51 }); |
| 51 for (var p in props) { | 52 for (var p in props) { |
| 52 event[p] = props[p]; | 53 event[p] = props[p]; |
| 53 } | 54 } |
| 54 node.dispatchEvent(event); | 55 node.dispatchEvent(event); |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 /* | 58 /** |
| 58 * Skips a test unless a condition is met. Sample use: | 59 * Skips a test unless a condition is met. Sample use: |
| 59 * function isNotIE() { | 60 * function isNotIE() { |
| 60 * return !navigator.userAgent.match(/MSIE/i); | 61 * return !navigator.userAgent.match(/MSIE/i); |
| 61 * } | 62 * } |
| 62 * test('runs on non IE browsers', skipUnless(isNotIE, function() { | 63 * test('runs on non IE browsers', skipUnless(isNotIE, function() { |
| 63 * ... | 64 * ... |
| 64 * }); | 65 * }); |
| 65 * | 66 * |
| 66 * @param {String} condition The name of a Boolean function determining if the
test should be run. | 67 * @param {Function} condition The name of a Boolean function determining if t
he test should be run. |
| 67 * @param {Function} test The test to be run. | 68 * @param {Function} test The test to be run. |
| 68 */ | 69 */ |
| 69 | 70 |
| 70 global.skipUnless = function(condition, test) { | 71 global.skipUnless = function(condition, test) { |
| 71 var isAsyncTest = !!test.length; | 72 var isAsyncTest = !!test.length; |
| 72 | 73 |
| 73 return function(done) { | 74 return function(done) { |
| 74 var testCalledDone = false; | 75 var testCalledDone = false; |
| 75 | 76 |
| 76 if (!condition()) { | 77 if (!condition()) { |
| 77 return done(); | 78 return done(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 var result = test.call(this, done); | 81 var result = test.call(this, done); |
| 81 | 82 |
| 82 if (!isAsyncTest) { | 83 if (!isAsyncTest) { |
| 83 done(); | 84 done(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 return result; | 87 return result; |
| 87 }; | 88 }; |
| 88 }; | 89 }; |
| 90 |
| 91 global.TestHelpers = { |
| 92 flushAsynchronousOperations: global.flushAsynchronousOperations, |
| 93 forceXIfStamp: global.forceXIfStamp, |
| 94 fireEvent: global.fireEvent, |
| 95 skipUnless: global.skipUnless |
| 96 }; |
| 89 })(this); | 97 })(this); |
| OLD | NEW |