gecko/content/media/video/test/file_access_controls.html
Chris Pearce 74bfee1398 b=465458 Media selection algorithm changed in r2403 of HTML5 spec r=doublec sr=roc
--HG--
extra : rebase_source : 09a091ebb5c7a42480a423ac304aacedfa286c4c
2009-02-20 15:49:00 +13:00

161 lines
5.3 KiB
HTML

<html>
<head>
</head>
<body onload="setTimeout(load, 0);" onunload="done()">
<script>
// Page URL: http://example.org/tests/content/media/video/test/file_access_controls.html
var gTests = [
{
// Test 0
url: "redirect.sjs?http://example.com/tests/content/media/video/test/320x240.ogv",
result: "error",
description: "Won't load when redirected to different domain",
},{
// Test 1
url: "redirect.sjs?http://example.com/tests/content/media/video/test/320x240.allow-origin.ogv",
result: "loaded",
description: "Can load when redirected to different domain with allow-origin",
},{
// Test 2
url: "redirect.sjs?http://test1.example.org/tests/content/media/video/test/320x240.ogv",
result: "error",
description: "Won't load when redirected to subdomain",
},{
// Test 3
url: "redirect.sjs?http://test1.example.org/tests/content/media/video/test/320x240.allow-origin.ogv",
result: "loaded",
description: "Can load when redirected to subdomain with allow-origin",
},{
// Test 4
url: "redirect.sjs?http://example.org/tests/content/media/video/test/320x240.ogv",
result: "loaded",
description: "Can load when redirected to same domain",
},{
// Test 5
url: "http://example.org/tests/content/media/video/test/320x240.ogv",
result: "loaded",
description: "Can load from same domain"
},{
// Test 6
url: "http://example.org:8000/tests/content/media/video/test/320x240.ogv",
result: "error",
description: "Won't load from differnet port on same domain"
},{
// Test 7
url: "http://example.org:8000/tests/content/media/video/test/320x240.allow-origin.ogv",
result: "loaded",
description: "Can load from different port on same domain with allow-origin",
},{
// Test 8
url: "http://example.com/tests/content/media/video/test/320x240.ogv",
result: "error",
description: "Won't load cross domain",
},{
// Test 9
url: "http://example.com/tests/content/media/video/test/320x240.allow-origin.ogv",
result: "loaded",
description: "Can load cross domain with allow-origin",
},{
// Test 10
url: "http://test1.example.org/tests/content/media/video/test/320x240.allow-origin.ogv",
result: "loaded",
description: "Can load from subdomain with allow-origin",
},{
// Test 11
url: "http://test1.example.org/tests/content/media/video/test/320x240.ogv",
result: "error",
description: "Won't load from subdomain",
}
];
var gTestNum = 0;
var gExpectedResult = null;
var gTestDescription = null;
var gVideo = null;
var gTestedRemoved = false;
var gOldPref;
function result(code) {
//dump((gTestNum - 1) + ": " + code + "\n");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
opener.is(code, gExpectedResult, gTestDescription);
nextTest();
}
function createVideo() {
var v = document.createElement('video');
v.addEventListener('loadeddata', function(){result('loaded');}, false);
v.addEventListener('error', function(){result('error');}, false);
v.id = 'video';
return v;
}
function load() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
opener.is(window.location.href,
"http://example.org/tests/content/media/video/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");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
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;
}
}
gExpectedResult = gTests[gTestNum].result;
gTestDescription = gTests[gTestNum].description;
//dump("Starting test " + gTestNum + " at " + gTests[gTestNum].url + " expecting:" + gExpectedResult + "\n");
if (gVideo && gVideo.parentNode)
gVideo.parentNode.removeChild(gVideo);
gVideo = createVideo();
gVideo.src = gTests[gTestNum].url;
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);
opener.done();
}
</script>
</body>
</html>