2010-03-02 23:51:09 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
2010-09-15 15:52:49 -07:00
|
|
|
<title>Test for File urls</title>
|
2010-03-02 23:51:09 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="gen.next()">
|
|
|
|
<p id="display">
|
|
|
|
<iframe id=inner></iframe>
|
|
|
|
<iframe id=iframe></iframe>
|
|
|
|
<img id=img onload="gen.send(event);">
|
2011-05-07 23:24:09 -07:00
|
|
|
<audio id=audio onloadeddata="gen.send(event);">
|
2010-03-02 23:51:09 -08:00
|
|
|
<input type=file id=fileList>
|
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="application/javascript;version=1.8">
|
|
|
|
|
2010-10-02 01:24:41 -07:00
|
|
|
try {
|
2010-11-23 00:50:55 -08:00
|
|
|
URL.createObjectURL(undefined);
|
2010-10-02 01:24:41 -07:00
|
|
|
} catch(e) { }
|
|
|
|
|
2010-03-02 23:51:09 -08:00
|
|
|
window.addEventListener("message", function(e) {
|
|
|
|
gen.send(JSON.parse(e.data));
|
|
|
|
}, false);
|
|
|
|
|
2010-10-02 00:32:49 -07:00
|
|
|
const innerSameSiteURI = "file_mozfiledataurl_inner.html";
|
|
|
|
const innerCrossSiteURI = "http://example.com/tests/content/base/test/file_mozfiledataurl_inner.html"
|
2010-03-02 23:51:09 -08:00
|
|
|
|
|
|
|
gen = runTest();
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
inner = document.getElementById('inner');
|
|
|
|
img = document.getElementById('img');
|
2010-10-02 00:32:49 -07:00
|
|
|
audio = document.getElementById('audio');
|
2010-03-02 23:51:09 -08:00
|
|
|
iframe = document.getElementById('iframe');
|
|
|
|
inner.onload = function() { gen.send("inner loaded"); };
|
|
|
|
|
|
|
|
// Attempt to load a image in this document
|
2010-10-02 00:32:49 -07:00
|
|
|
var file = getFile("file_mozfiledataurl_img.jpg");
|
2010-11-23 00:50:55 -08:00
|
|
|
var fileurl = URL.createObjectURL(file);
|
2010-09-15 15:52:49 -07:00
|
|
|
img.src = fileurl;
|
2010-03-02 23:51:09 -08:00
|
|
|
var e = (yield);
|
|
|
|
is(e.type, "load", "loaded successfully");
|
|
|
|
is(img.width, 120, "correct width");
|
|
|
|
is(img.height, 90, "correct height");
|
|
|
|
|
2010-09-15 15:52:49 -07:00
|
|
|
// Revoke url and attempt to load a image in this document
|
2010-10-02 00:32:49 -07:00
|
|
|
img.src = "file_mozfiledataurl_img.jpg";
|
2010-09-15 15:52:49 -07:00
|
|
|
is((yield).type, "load", "successfull reset image");
|
2010-11-23 00:50:55 -08:00
|
|
|
URL.revokeObjectURL(fileurl);
|
2010-09-15 15:52:49 -07:00
|
|
|
todo(false, "urls need to act like 404s, not fail to parse");
|
|
|
|
/* img.src = fileurl;
|
|
|
|
var e = (yield);
|
|
|
|
is(e.type, "error", "failed successfully");
|
|
|
|
isnot(img.width, 120, "correct error width");
|
|
|
|
isnot(img.height, 90, "correct error height");
|
|
|
|
*/
|
|
|
|
// Generate new fileurl and make sure it's different from the old
|
|
|
|
var oldFileurl = fileurl;
|
2010-11-23 00:50:55 -08:00
|
|
|
var fileurl = URL.createObjectURL(file);
|
|
|
|
isnot(fileurl, oldFileurl, "URL.createObjectURL generated the same url twice");
|
2010-09-15 15:52:49 -07:00
|
|
|
|
2010-03-02 23:51:09 -08:00
|
|
|
// Attempt to load an image in a different same-origin document
|
|
|
|
inner.src = innerSameSiteURI;
|
|
|
|
yield;
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({img:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "load", "loaded successfully");
|
|
|
|
is(res.width, 120, "correct width");
|
|
|
|
is(res.height, 90, "correct height");
|
|
|
|
|
|
|
|
// Attempt to load an image in a different cross-origin document
|
|
|
|
inner.src = innerCrossSiteURI;
|
|
|
|
yield;
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({img:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "error", "failed successfully");
|
|
|
|
isnot(res.width, 120, "correct error width");
|
|
|
|
isnot(res.height, 90, "correct error height");
|
|
|
|
|
2010-10-02 00:32:49 -07:00
|
|
|
// Attempt to load an audio in this document
|
|
|
|
var file = getFile("file_mozfiledataurl_audio.ogg");
|
2010-11-23 00:50:55 -08:00
|
|
|
var fileurl = URL.createObjectURL(file);
|
2010-10-02 00:32:49 -07:00
|
|
|
audio.src = fileurl;
|
|
|
|
var e = (yield);
|
2011-05-07 23:24:09 -07:00
|
|
|
is(e.type, "loadeddata", "loaded successfully");
|
2010-10-02 00:32:49 -07:00
|
|
|
|
|
|
|
// Revoke url and attempt to load a audio in this document
|
|
|
|
audio.src = "file_mozfiledataurl_audio.ogg";
|
2011-05-07 23:24:09 -07:00
|
|
|
is((yield).type, "loadeddata", "successfully reset audio");
|
2010-11-23 00:50:55 -08:00
|
|
|
URL.revokeObjectURL(fileurl);
|
2010-10-02 00:32:49 -07:00
|
|
|
todo(false, "urls need to act like 404s, not fail to parse");
|
|
|
|
/* img.src = fileurl;
|
|
|
|
var e = (yield);
|
|
|
|
is(e.type, "error", "failed successfully");
|
|
|
|
isnot(img.width, 120, "correct error width");
|
|
|
|
isnot(img.height, 90, "correct error height");
|
|
|
|
*/
|
|
|
|
// Generate new fileurl and make sure it's different from the old
|
|
|
|
var oldFileurl = fileurl;
|
2010-11-23 00:50:55 -08:00
|
|
|
var fileurl = URL.createObjectURL(file);
|
|
|
|
isnot(fileurl, oldFileurl, "URL.createObjectURL generated the same url twice");
|
2010-10-02 00:32:49 -07:00
|
|
|
|
|
|
|
// Attempt to load an audio in a different same-origin document
|
|
|
|
inner.src = innerSameSiteURI;
|
|
|
|
yield;
|
|
|
|
inner.contentWindow.postMessage(JSON.stringify({audio:fileurl}), "*");
|
|
|
|
var res = (yield);
|
2011-05-07 23:24:09 -07:00
|
|
|
is(res.type, "loadeddata", "loaded successfully");
|
2010-10-02 00:32:49 -07:00
|
|
|
|
|
|
|
// Attempt to load an audio in a different cross-origin document
|
|
|
|
inner.src = innerCrossSiteURI;
|
|
|
|
yield;
|
|
|
|
inner.contentWindow.postMessage(JSON.stringify({audio:fileurl}), "*");
|
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "error", "failed successfully");
|
|
|
|
|
2010-03-02 23:51:09 -08:00
|
|
|
// Attempt to load a HTML document in an iframe in this document
|
|
|
|
iframe.onload = function() { gen.next(); };
|
2010-10-02 00:32:49 -07:00
|
|
|
iframe.src = "file_mozfiledataurl_doc.html";
|
2010-03-02 23:51:09 -08:00
|
|
|
yield;
|
|
|
|
is(iframe.contentDocument.getElementsByTagName("p")[0].textContent,
|
|
|
|
"This here is a document!",
|
|
|
|
"iframe loaded successfully");
|
|
|
|
is(iframe.contentDocument.getElementById("img").width, 120,
|
|
|
|
"image in iframe width");
|
|
|
|
is(iframe.contentDocument.getElementById("img").height, 90,
|
|
|
|
"image in iframe height");
|
|
|
|
|
|
|
|
// Attempt to load a HTML document in an iframe in this document, using file url
|
2010-10-02 00:32:49 -07:00
|
|
|
file = getFile("file_mozfiledataurl_doc.html");
|
2010-11-23 00:50:55 -08:00
|
|
|
fileurl = URL.createObjectURL(file);
|
2010-09-15 15:52:49 -07:00
|
|
|
iframe.src = fileurl;
|
2010-03-02 23:51:09 -08:00
|
|
|
yield;
|
|
|
|
is(iframe.contentDocument.getElementsByTagName("p")[0].textContent,
|
|
|
|
"This here is a document!",
|
|
|
|
"iframe loaded successfully");
|
|
|
|
isnot(iframe.contentDocument.getElementById("img").width, 120,
|
|
|
|
"failed image in iframe width");
|
|
|
|
isnot(iframe.contentDocument.getElementById("img").height, 90,
|
|
|
|
"failed image in iframe height");
|
|
|
|
|
|
|
|
// Attempt to load a HTML document in an iframe in inner document
|
|
|
|
inner.src = innerSameSiteURI;
|
|
|
|
is((yield), "inner loaded", "correct gen.next()");
|
2010-10-02 00:32:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({iframe:"file_mozfiledataurl_doc.html"}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "load", "loaded successfully");
|
|
|
|
is(res.text, "This here is a document!", "loaded successfully");
|
|
|
|
is(res.imgWidth, 120, "correct width");
|
|
|
|
|
|
|
|
// Attempt to load a HTML document in an iframe in inner document, using file url
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({iframe:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "load", "loaded successfully");
|
|
|
|
is(res.text, "This here is a document!", "loaded successfully");
|
|
|
|
isnot(res.imgWidth, 120, "correct width");
|
|
|
|
|
|
|
|
// Attempt to load a HTML document in an iframe in inner cross-site document, using file url
|
|
|
|
inner.src = innerCrossSiteURI;
|
|
|
|
is((yield), "inner loaded", "correct gen.next()");
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({iframe:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.type, "error", "load failed successfully");
|
|
|
|
|
|
|
|
// Attempt to load file url using XHR
|
2010-10-02 00:32:49 -07:00
|
|
|
file = getFile("file_mozfiledataurl_text.txt");
|
2010-11-23 00:50:55 -08:00
|
|
|
fileurl = URL.createObjectURL(file);
|
2010-03-02 23:51:09 -08:00
|
|
|
xhr = new XMLHttpRequest;
|
|
|
|
xhr.onload = function() { gen.send("XHR finished"); };
|
2010-09-15 15:52:49 -07:00
|
|
|
xhr.open("GET", fileurl);
|
2010-03-02 23:51:09 -08:00
|
|
|
xhr.send();
|
|
|
|
is((yield), "XHR finished", "correct gen.next()");
|
|
|
|
xhr.responseText == "Yarr, here be plaintext file, ya landlubber\n";
|
|
|
|
|
|
|
|
// Attempt to load file url using XHR in inner document
|
|
|
|
inner.src = innerSameSiteURI;
|
|
|
|
is((yield), "inner loaded", "correct gen.next()");
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({xhr:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.didThrow, undefined, "load successful");
|
|
|
|
is(res.text, "Yarr, here be plaintext file, ya landlubber\n", "load successful");
|
|
|
|
|
|
|
|
// Attempt to load file url using XHR
|
|
|
|
inner.src = innerCrossSiteURI;
|
|
|
|
is((yield), "inner loaded", "correct gen.next()");
|
2010-09-15 15:52:49 -07:00
|
|
|
inner.contentWindow.postMessage(JSON.stringify({xhr:fileurl}), "*");
|
2010-03-02 23:51:09 -08:00
|
|
|
var res = (yield);
|
|
|
|
is(res.didThrow, true, "load failed successfully");
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var basePath = "";
|
|
|
|
function getFile(name) {
|
|
|
|
if (!basePath) {
|
|
|
|
let xhr = new XMLHttpRequest;
|
|
|
|
xhr.open("GET", "/dynamic/getMyDirectory.sjs", false);
|
|
|
|
xhr.send();
|
|
|
|
basePath = xhr.responseText;
|
|
|
|
}
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
|
|
|
var fileList = document.getElementById('fileList');
|
|
|
|
fileList.value = basePath + name;
|
|
|
|
|
|
|
|
return fileList.files[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|