| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 The Polymer Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style | |
| 4 * license that can be found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 // if standalone | |
| 8 if (window.top === window) { | |
| 9 // if standalone | |
| 10 var failed = false; | |
| 11 window.done = function() { | |
| 12 window.onerror = null; | |
| 13 if (!failed) { | |
| 14 var d = document.createElement('pre'); | |
| 15 d.style.cssText = 'padding: 6px; background-color: lightgreen; position: a
bsolute; bottom:0; right:10px;'; | |
| 16 d.textContent = 'Passed'; | |
| 17 document.body.appendChild(d); | |
| 18 } | |
| 19 }; | |
| 20 window.onerror = function(x) { | |
| 21 failed = true; | |
| 22 var d = document.createElement('pre'); | |
| 23 d.style.cssText = 'padding: 6px; background-color: #FFE0E0; position: absolu
te; bottom:0; right:10px;'; | |
| 24 d.textContent = 'FAILED: ' + x; | |
| 25 document.body.appendChild(d); | |
| 26 }; | |
| 27 } else | |
| 28 // if part of a test suite | |
| 29 { | |
| 30 window.done = function() { | |
| 31 window.onerror = null; | |
| 32 parent.postMessage('ok', '*'); | |
| 33 }; | |
| 34 | |
| 35 window.onerror = function(x) { | |
| 36 parent.postMessage({error: x}, '*'); | |
| 37 }; | |
| 38 } | |
| 39 | |
| 40 window.asyncSeries = function(series, callback, forwardExceptions) { | |
| 41 series = series.slice(); | |
| 42 var next = function(err) { | |
| 43 if (err) { | |
| 44 if (callback) { | |
| 45 callback(err); | |
| 46 } | |
| 47 } else { | |
| 48 var f = series.shift(); | |
| 49 if (f) { | |
| 50 if (!forwardExceptions) { | |
| 51 f(next); | |
| 52 } else { | |
| 53 try { | |
| 54 f(next); | |
| 55 } catch(e) { | |
| 56 if (callback) { | |
| 57 callback(e); | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 } else { | |
| 62 if (callback) { | |
| 63 callback(); | |
| 64 } | |
| 65 } | |
| 66 } | |
| 67 }; | |
| 68 next(); | |
| 69 }; | |
| 70 | |
| 71 window.waitFor = function(fn, next, intervalOrMutationEl, timeout, timeoutTime)
{ | |
| 72 timeoutTime = timeoutTime || Date.now() + (timeout || 1000); | |
| 73 intervalOrMutationEl = intervalOrMutationEl || 32; | |
| 74 try { | |
| 75 fn(); | |
| 76 } catch (e) { | |
| 77 if (Date.now() > timeoutTime) { | |
| 78 throw e; | |
| 79 } else { | |
| 80 if (isNaN(intervalOrMutationEl)) { | |
| 81 intervalOrMutationEl.onMutation(intervalOrMutationEl, function() { | |
| 82 waitFor(fn, next, intervalOrMutationEl, timeout, timeoutTime); | |
| 83 }); | |
| 84 } else { | |
| 85 setTimeout(function() { | |
| 86 waitFor(fn, next, intervalOrMutationEl, timeout, timeoutTime); | |
| 87 }, intervalOrMutationEl); | |
| 88 } | |
| 89 return; | |
| 90 } | |
| 91 } | |
| 92 next(); | |
| 93 }; | |
| OLD | NEW |