| 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 (function() { | |
| 8 var thisFile = 'lib/mocha-htmltest.js'; | |
| 9 var base = ''; | |
| 10 | |
| 11 mocha.htmlbase = function(htmlbase) { | |
| 12 base = htmlbase; | |
| 13 }; | |
| 14 | |
| 15 (function() { | |
| 16 var s$ = document.querySelectorAll('script[src]'); | |
| 17 Array.prototype.forEach.call(s$, function(s) { | |
| 18 var src = s.getAttribute('src'); | |
| 19 var re = new RegExp(thisFile + '[^\\\\]*'); | |
| 20 var match = src.match(re); | |
| 21 if (match) { | |
| 22 base = src.slice(0, -match[0].length); | |
| 23 } | |
| 24 }); | |
| 25 })(); | |
| 26 | |
| 27 var next, iframe; | |
| 28 | |
| 29 var listener = function(event) { | |
| 30 if (event.data === 'ok') { | |
| 31 next(); | |
| 32 } else if (event.data && event.data.error) { | |
| 33 // errors cannot be cloned via postMessage according to spec, so we re-err
orify them | |
| 34 throw new Error(event.data.error); | |
| 35 } | |
| 36 }; | |
| 37 | |
| 38 function htmlSetup() { | |
| 39 window.addEventListener("message", listener); | |
| 40 iframe = document.createElement('iframe'); | |
| 41 iframe.style.cssText = 'position: absolute; left: -9000em; width:768px; heig
ht: 1024px'; | |
| 42 document.body.appendChild(iframe); | |
| 43 } | |
| 44 | |
| 45 function htmlTeardown() { | |
| 46 window.removeEventListener('message', listener); | |
| 47 document.body.removeChild(iframe); | |
| 48 } | |
| 49 | |
| 50 function htmlTest(src) { | |
| 51 test(src, function(done) { | |
| 52 next = done; | |
| 53 var url = base + src; | |
| 54 var delimiter = url.indexOf('?') < 0 ? '?' : '&'; | |
| 55 var docSearch = location.search.slice(1); | |
| 56 iframe.src = url + delimiter + Math.random() + '&' + docSearch; | |
| 57 }); | |
| 58 }; | |
| 59 | |
| 60 function htmlSuite(inName, inFn) { | |
| 61 suite(inName, function() { | |
| 62 setup(htmlSetup); | |
| 63 teardown(htmlTeardown); | |
| 64 inFn(); | |
| 65 }); | |
| 66 }; | |
| 67 | |
| 68 window.htmlTest = htmlTest; | |
| 69 window.htmlSuite = htmlSuite; | |
| 70 })(); | |
| OLD | NEW |