Commit 46284798 authored by Romain Courteaud's avatar Romain Courteaud

Test: allow dataurl sandbox test to run on any URL

parent 8781c770
......@@ -89,7 +89,9 @@ module.exports = function (grunt) {
'URI',
'URL',
'__RenderJSIframeGadget',
'__RenderJSEmbeddedGadget'
'__RenderJSEmbeddedGadget',
'FileReader',
'Blob'
]
}
}
......
......@@ -34,6 +34,19 @@
);
}
function readBlobAsDataURL(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject) {
fr.addEventListener("load", function (evt) {
resolve(evt.target.result);
});
fr.addEventListener("error", reject);
fr.readAsDataURL(blob);
}, function () {
fr.abort();
});
}
/////////////////////////////////////////////////////////////////
// parseGadgetHTMLDocument
/////////////////////////////////////////////////////////////////
......@@ -3407,34 +3420,37 @@
test('dataurl provide an iframed gadget as callback parameter', function () {
// Check that declare gadget returns the gadget
var parent_gadget = new RenderJSGadget(),
topURL = "http://example.org/topGadget",
topURL = "https://example.org/topGadget",
parsed = URI.parse(window.location.href),
parent_path = URI.build({protocol: parsed.protocol,
hostname: parsed.hostname,
port: parsed.port,
path: parsed.path}).toString(),
absolute_path = parent_path + "mixed_embedded.html",
data_url = "data:text/html;charset=utf-8;base64,PGh0bWw+PGhlYWQ+PGJhc2" +
"UgaHJlZj0iaHR0cDovLzEyNy4wLjAuMTo5MDAwL3Rlc3QvbWl4ZWRfZW1iZWRkZWQua" +
"HRtbCI+PGJhc2UgaHJlZj0iaHR0cDovLzEyNy4wLjAuMTo5MDAwIj48c2NyaXB0IHNy" +
"Yz0iLi4vbm9kZV9tb2R1bGVzL3JzdnAvZGlzdC9yc3ZwLTIuMC40LmpzIiB0eXBlPSJ" +
"0ZXh0L2phdmFzY3JpcHQiPjwvc2NyaXB0PjxzY3JpcHQgc3JjPSIuLi9kaXN0L3Jlbm" +
"RlcmpzLWxhdGVzdC5qcyIgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij48L3NjcmlwdD48L" +
"2hlYWQ+PGJvZHk+PHA+bXkgbWl4ZWQgZm9vPC9wPjwvYm9keT48L2h0bWw+";
// data:text/html;charset=utf-8;base64,
// PGh0bWw+PGJvZHk+PHA+Zm9vPC9wPjwvYm9keT48L2h0bWw+"
this.server.respondWith("GET", "/test/mixed_embedded.html", [200, {
"Content-Type": "text/html"
}, '<html><head>' +
'<base href="http://127.0.0.1:9000"></base>' +
'<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>' +
'</head><body><p>my mixed foo</p></body></html>']);
// absolute_path = parent_path + "mixed_embedded.html",
absolute_path = "https://example.org/mixed_embedded.html",
iframe_html_prefix = '<html><head>',
iframe_html_suffix = '<script src="' +
new URL('../node_modules/rsvp/dist/rsvp-2.0.4.js',
window.location).href +
'" ' +
'type="text/javascript"></script>' +
'<script src="' + new URL('../dist/renderjs-latest.js',
window.location).href + '" ' +
'type="text/javascript"></script>' +
'</head><body><p>my mixed foo</p></body></html>',
iframe_html = iframe_html_prefix + iframe_html_suffix,
data_url_html = iframe_html_prefix +
'<base href="' + absolute_path + '">' +
iframe_html_suffix,
data_url;
this.server.respondWith(
"GET",
absolute_path,
[200, {
"Content-Type": "text/html"
}, iframe_html]
);
document.getElementById("qunit-fixture").textContent = "";
parent_gadget.__path = parent_path;
......@@ -3444,10 +3460,18 @@
};
stop();
parent_gadget.declareGadget(absolute_path, {
sandbox: 'dataurl',
element: document.getElementById('qunit-fixture')
})
return new RSVP.Queue()
.then(function () {
return readBlobAsDataURL(new Blob([data_url_html],
{type: "text/html;charset=UTF-8"}));
})
.then(function (result) {
data_url = result;
return parent_gadget.declareGadget(absolute_path, {
sandbox: 'dataurl',
element: document.getElementById('qunit-fixture')
});
})
.then(function (new_gadget) {
equal(new_gadget.__path, data_url);
ok(new_gadget instanceof RenderJSIframeGadget);
......
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