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