mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 05:35:31 +00:00
169 lines
5.4 KiB
HTML
169 lines
5.4 KiB
HTML
<html>
|
|
<head>
|
|
<script type="text/javascript" src="manifest.js"></script>
|
|
</head>
|
|
<body onload="setTimeout(load, 0);" onunload="done()">
|
|
<script>
|
|
|
|
// Page URL: http://example.org/tests/content/media/test/file_access_controls.html
|
|
|
|
var gResource = getPlayableVideo(gSmallTests).name;
|
|
|
|
var gTests = [
|
|
{
|
|
// Test 0
|
|
url: "redirect.sjs?domain=example.com&file="+ gResource,
|
|
result: "error",
|
|
description: "Won't load when redirected to different domain",
|
|
},{
|
|
// Test 1
|
|
url: "redirect.sjs?domain=example.com&allowed&file=" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load when redirected to different domain with allow-origin",
|
|
},{
|
|
// Test 2
|
|
url: "redirect.sjs?domain=test1.example.org&file=" + gResource,
|
|
result: "error",
|
|
description: "Won't load when redirected to subdomain",
|
|
},{
|
|
// Test 3
|
|
url: "redirect.sjs?domain=test1.example.org&allowed&file=" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load when redirected to subdomain with allow-origin",
|
|
},{
|
|
// Test 4
|
|
url: "redirect.sjs?domain=example.org&file=" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load when redirected to same domain",
|
|
},{
|
|
// Test 5
|
|
url: "http://example.org/tests/content/media/test/" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load from same domain"
|
|
},{
|
|
// Test 6
|
|
url: "http://example.org:8000/tests/content/media/test/" + gResource,
|
|
result: "error",
|
|
description: "Won't load from different port on same domain"
|
|
},{
|
|
// Test 7
|
|
url: "http://example.org:8000/tests/content/media/test/allowed.sjs?" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load from different port on same domain with allow-origin",
|
|
},{
|
|
// Test 8
|
|
url: "http://example.com/tests/content/media/test/" + gResource,
|
|
result: "error",
|
|
description: "Won't load cross domain",
|
|
},{
|
|
// Test 9
|
|
url: "http://example.com/tests/content/media/test/allowed.sjs?" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load cross domain with allow-origin",
|
|
},{
|
|
// Test 10
|
|
url: "http://test1.example.org/tests/content/media/test/allowed.sjs?" + gResource,
|
|
result: "loadeddata",
|
|
description: "Can load from subdomain with allow-origin",
|
|
},{
|
|
// Test 11
|
|
url: "http://test1.example.org/tests/content/media/test/" + gResource,
|
|
result: "error",
|
|
description: "Won't load from subdomain",
|
|
}
|
|
];
|
|
|
|
var gTestNum = 0;
|
|
var gVideo = null;
|
|
var gTestedRemoved = false;
|
|
var gOldPref;
|
|
|
|
function eventHandler(event) {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
//dump((gTestNum - 1) + ": " + event.type + "\n");
|
|
var video = event.target;
|
|
opener.is(event.type, video.expectedResult, video.testDescription +
|
|
(gTestedRemoved ? " (element not in document)" : " (element in document)"));
|
|
// Make sure any extra events cause an error
|
|
video.expectedResult = "<none>";
|
|
nextTest();
|
|
}
|
|
|
|
function createVideo() {
|
|
var v = document.createElement('video');
|
|
v.addEventListener('loadeddata', eventHandler, false);
|
|
v.addEventListener('error', eventHandler, false);
|
|
return v;
|
|
}
|
|
|
|
function load() {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
opener.is(window.location.href,
|
|
"http://example.org/tests/content/media/test/file_access_controls.html",
|
|
"We must be on a example.org:80");
|
|
|
|
// Ensure access control check pref is on.
|
|
// media.enforce_same_site_origin
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
opener.ok(prefService!=null, "Get pref service");
|
|
var branch = prefService.getBranch("media.");
|
|
opener.ok(branch!=null, "Get media pref branch");
|
|
gOldPref = branch.getBoolPref("enforce_same_site_origin");
|
|
branch.setBoolPref("enforce_same_site_origin", true);
|
|
nextTest();
|
|
}
|
|
|
|
function nextTest() {
|
|
//dump("nextTest() called, gTestNum="+gTestNum+" gTestedRemoved="+gTestedRemoved+"\n");
|
|
if (gTestNum == gTests.length) {
|
|
//dump("gTestNum == gTests.length\n");
|
|
if (!gTestedRemoved) {
|
|
// Repeat all tests with element removed from doc, should get same result.
|
|
gTestedRemoved = true;
|
|
gTestNum = 0;
|
|
} else {
|
|
//dump("Exiting...\n");
|
|
// We're done, exit the test.
|
|
window.close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (gVideo && gVideo.parentNode)
|
|
gVideo.parentNode.removeChild(gVideo);
|
|
|
|
gVideo = null;
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
Components.utils.forceGC();
|
|
|
|
gVideo = createVideo();
|
|
gVideo.expectedResult = gTests[gTestNum].result;
|
|
gVideo.testDescription = gTests[gTestNum].description;
|
|
gVideo.src = gTests[gTestNum].url;
|
|
//dump("Starting test " + gTestNum + " at " + gVideo.src + " expecting:" + gVideo.expectedResult + "\n");
|
|
if (!gTestedRemoved) {
|
|
document.body.appendChild(gVideo);
|
|
// Will cause load() to be invoked.
|
|
} else {
|
|
gVideo.load();
|
|
}
|
|
gTestNum++;
|
|
}
|
|
|
|
function done() {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
// Undo change to access control check pref.
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
var branch = prefService.getBranch("media.");
|
|
branch.setBoolPref("enforce_same_site_origin", gOldPref);
|
|
mediaTestCleanup();
|
|
opener.done();
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|