Fix firefox iframe timing issue, fixes #25

This commit is contained in:
Ryan Seddon
2015-02-05 17:23:56 +11:00
committed by Ryan Seddon
parent e52c67b902
commit 1ad94fa4e1

View File

@@ -44,17 +44,23 @@ var layoutTestUtils = (function() {
}; };
} }
function renderIframe() {
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
return iframe;
}
var cachedIframe; var cachedIframe;
function getIframe() { function getIframe() {
if (cachedIframe) { if (cachedIframe) {
return cachedIframe; return cachedIframe;
} }
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var doc = iframe.contentDocument; var doc = iframe.contentDocument;
if(doc.readyState === 'complete') {
var style = document.createElement('style'); var style = document.createElement('style');
style.innerText = (function() {/* style.textContent = (function() {/*
body, div { body, div {
box-sizing: border-box; box-sizing: border-box;
border: 0 solid black; border: 0 solid black;
@@ -83,8 +89,15 @@ var layoutTestUtils = (function() {
doc.head.appendChild(style); doc.head.appendChild(style);
cachedIframe = iframe; cachedIframe = iframe;
return iframe; return iframe;
} else {
setTimeout(getIframe, 0);
}
} }
if (typeof window !== 'undefined') {
var iframe = renderIframe();
getIframe();
}
if (typeof computeLayout === 'function') { if (typeof computeLayout === 'function') {
var realComputeLayout = computeLayout; var realComputeLayout = computeLayout;