Commit 19ec19e9 authored by Romain Courteaud's avatar Romain Courteaud

Iframe gadget: launch the timeout only after the iframe load.

This should improve renderJS usage on slow network.
parent 74505395
......@@ -794,6 +794,17 @@
gadget_instance = new RenderJSIframeGadget();
setAqParent(gadget_instance, parent_gadget);
iframe = document.createElement("iframe");
iframe.addEventListener('error', function (error) {
iframe_loading_deferred.reject(error);
});
iframe.addEventListener('load', function () {
return RSVP.timeout(5000)
.fail(function () {
iframe_loading_deferred.reject(
new Error('Timeout while loading: ' + url)
);
});
});
// gadget_instance.element.setAttribute("seamless", "seamless");
iframe.setAttribute("src", url);
gadget_instance.__path = url;
......@@ -857,18 +868,7 @@
trans.delayReturn(true);
});
return RSVP.any([
iframe_loading_deferred.promise,
// Timeout to prevent non renderJS embeddable gadget
// XXX Maybe using iframe.onload/onerror would be safer?
new RSVP.Queue()
.push(function () {
return RSVP.timeout(5000);
})
.push(undefined, function () {
throw new Error('Timeout while loading: ' + url);
})
]);
return iframe_loading_deferred.promise;
}
/////////////////////////////////////////////////////////////////
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Embedded page for renderJS test</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../node_modules/rsvp/dist/rsvp-2.0.4.js" type="text/javascript"></script>
<script src="../dist/renderjs-latest.js" type="text/javascript"></script>
<script src="./embedded_404.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Embedded page for renderJS test</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
</body>
</html>
......@@ -5038,6 +5038,102 @@
});
});
test('checking wrong HTML iframe gadget', function () {
// Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(),
url = "./embedded_empty.html";
stop();
gadget.declareGadget(url, {
sandbox: 'iframe',
element: document.getElementById('qunit-fixture')
})
.then(function (new_gadget) {
ok(false);
})
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "Timeout while loading: ./embedded_empty.html");
})
.always(function () {
start();
});
});
test('checking 404 html iframe gadget', function () {
// Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(),
url = "./embedded_404.html";
stop();
gadget.declareGadget(url, {
sandbox: 'iframe',
element: document.getElementById('qunit-fixture')
})
.then(function (new_gadget) {
ok(false);
})
.fail(function (error) {
ok(error instanceof Error);
equal(
error.message,
"Timeout while loading: ./embedded_404.html"
);
})
.always(function () {
start();
});
});
/*
test('checking 404 js iframe gadget', function () {
// Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(),
url = "./embedded_404_js.html";
gadget.__sub_gadget_dict = {};
stop();
gadget.declareGadget(url, {
sandbox: 'iframe',
element: document.getElementById('qunit-fixture')
})
.then(function (new_gadget) {
ok(false);
})
.fail(function (error) {
deepEqual(error, {});
})
.always(function () {
start();
});
});
*/
test('checking non renderjs iframe gadget', function () {
// Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(),
url = "./embedded_non_renderjs.html";
stop();
gadget.declareGadget(url, {
sandbox: 'iframe',
element: document.getElementById('qunit-fixture')
})
.then(function (new_gadget) {
ok(false);
})
.fail(function (error) {
ok(error instanceof Error);
equal(
error.message,
"Timeout while loading: ./embedded_non_renderjs.html"
);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// RenderJSGadget.declareGadget (dataurl)
/////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment