mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
242 lines
6.7 KiB
HTML
242 lines
6.7 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=758258
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for nsIPrincipal extendedOrigin, appStatus and appId</title>
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=758258">Mozilla Bug 758258</a>
|
|
<p id="display"></p>
|
|
<div id="content">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 758258 **/
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
/*
|
|
* gData is an array of objects. Each object represents a test case.
|
|
* - app: gives the app manifest URL, will set mozapp to it on the iframe;
|
|
* - origin: gives the origin of the iframe. This is the URL thas is going to
|
|
* to be passed as iframe.src but also the expected principal's
|
|
* origin.
|
|
* - isapp: tells if the iframe is really a mozapp. If the manifest url isn't
|
|
* valid, the iframe will not be considered as a mozapp.
|
|
* - browser: say if the iframe should be a mozbrowser. This is implicit when
|
|
* app is set.
|
|
* - test: an array of tests to run for this test case:
|
|
* - eo-unique: the extendedOrigin of the prinicpal must be unique in the
|
|
* current list.
|
|
* - eo-as-last: the extendedOrigin of the principal must be the same as the
|
|
* last added to the list.
|
|
*/
|
|
var gData = [
|
|
{
|
|
app: "http://example.org/manifest.webapp",
|
|
src: "http://example.org/",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "https://example.com/manifest.webapp",
|
|
src: "https://example.com/",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://test1.example.org/manifest.webapp",
|
|
src: "http://test1.example.org/",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://test1.example.org:8000/manifest.webapp",
|
|
src: "http://test1.example.org:8000/",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://sub1.test1.example.org/manifest.webapp",
|
|
src: "http://sub1.test1.example.org/",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
// WebApps implementation doesn't allow apps with the same origin. Sad...
|
|
// {
|
|
// app: "http://example.org/foo/manifest.webapp",
|
|
// src: "http://example.org/",
|
|
// isapp: true,
|
|
// test: [ "eo-unique" ],
|
|
// },
|
|
// {
|
|
// app: "http://example.org/bar/manifest.webapp",
|
|
// src: "http://example.org/",
|
|
// isapp: true,
|
|
// test: [ "eo-unique" ],
|
|
// },
|
|
{
|
|
src: "http://example.org/",
|
|
isapp: false,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
browser: true,
|
|
src: "http://example.org/",
|
|
isapp: false,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://example.org/wedonthaveanyappinthatdirectory/manifest.webapp",
|
|
src: "http://example.org/",
|
|
isapp: false,
|
|
// TODO: this is a browser because we need apps to be browser and it's not
|
|
// an app because the manifest is invalid. Ideally, it should not be a
|
|
// browser.
|
|
browser: true,
|
|
test: [ "eo-as-last" ],
|
|
},
|
|
/*
|
|
// {
|
|
// app: "http://example.org/manifest.webapp",
|
|
// src: "data:text/html,foobar",
|
|
// test: [ "todo-src" ],
|
|
// },
|
|
// {
|
|
// app: "http://example.org/manifest.webapp",
|
|
// src: "data:text/html,foobar2",
|
|
// test: [ "todo-src" ],
|
|
// },
|
|
*/
|
|
{
|
|
src: "file:///",
|
|
isapp: false,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
src: "file:///tmp",
|
|
isapp: false,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://example.org/manifest.webapp",
|
|
src: "file:///",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
{
|
|
app: "http://example.org/manifest.webapp",
|
|
src: "file:///tmp",
|
|
isapp: true,
|
|
test: [ "eo-unique" ],
|
|
},
|
|
];
|
|
|
|
// The list of all data ids generated by this test.
|
|
var eoList = [];
|
|
|
|
var content = document.getElementById('content');
|
|
var checkedCount = 0;
|
|
var checksTodo = gData.length;
|
|
|
|
function checkPrincipalForIFrame(aFrame, data) {
|
|
var principal = aFrame.contentDocument.nodePrincipal;
|
|
|
|
if (!data.test) {
|
|
data.test = [];
|
|
}
|
|
|
|
// Temporarily disable that check.
|
|
// is(principal.URI.spec, data.src,
|
|
// 'the correct URL should have been loaded');
|
|
|
|
if (data.isapp) {
|
|
is(principal.appStatus, Ci.nsIPrincipal.APP_STATUS_INSTALLED,
|
|
'this should be an installed app');
|
|
isnot(principal.appId, Ci.nsIScriptSecurityManager.NO_APP_ID,
|
|
"installed app should have a valid appId");
|
|
isnot(principal.appId, Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID,
|
|
"installed app should have a valid appId");
|
|
} else {
|
|
is(principal.appStatus, Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED,
|
|
'this should not be an installed app');
|
|
is(principal.appId, Ci.nsIScriptSecurityManager.NO_APP_ID,
|
|
"principals from non-installed app should have NO_APP_ID");
|
|
}
|
|
|
|
if (!data.isapp && !data.browser) {
|
|
is(principal.extendedOrigin, principal.origin,
|
|
'extendedOrigin should return the origin for non-app and non-browsers principals');
|
|
} else {
|
|
isnot(principal.extendedOrigin, principal.origin,
|
|
'extendedOrigin should not return the origin for apps or mozbrowsers');
|
|
}
|
|
|
|
if (data.test.indexOf("eo-unique") != -1) {
|
|
is(eoList.indexOf(principal.extendedOrigin), -1,
|
|
"extendedOrigin should be unique");
|
|
}
|
|
if (data.test.indexOf("eo-as-last") != -1) {
|
|
is(principal.extendedOrigin, eoList[eoList.length-1],
|
|
"extendedOrigin should be the same as the last inserted one");
|
|
}
|
|
|
|
eoList.push(principal.extendedOrigin);
|
|
|
|
checkedCount++;
|
|
if (checkedCount == checksTodo) {
|
|
SimpleTest.finish();
|
|
}
|
|
}
|
|
|
|
is('appStatus' in document.nodePrincipal, true,
|
|
'appStatus should be present in nsIPrincipal');
|
|
is('extendedOrigin' in document.nodePrincipal, true,
|
|
'extendedOrigin should be present in nsIPrincipal');
|
|
is('appId' in document.nodePrincipal, true,
|
|
'appId should be present in nsIPrincipal');
|
|
|
|
SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true]]}, function() {
|
|
|
|
// For some unknown reasons, this test this to always timeout on Windows.
|
|
if (navigator.platform.indexOf("Win") != -1) {
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
|
|
gData.forEach(function(data) {
|
|
var iframe = document.createElement('iframe');
|
|
iframe.checkPrincipal = function() {
|
|
checkPrincipalForIFrame(this, data);
|
|
};
|
|
|
|
if (data.app) {
|
|
iframe.setAttribute('mozapp', data.app);
|
|
iframe.setAttribute('mozbrowser', '');
|
|
} else if (data.browser) {
|
|
iframe.setAttribute('mozbrowser', '');
|
|
}
|
|
|
|
iframe.src = data.src;
|
|
|
|
iframe.addEventListener('load', iframe.checkPrincipal.bind(iframe));
|
|
|
|
content.appendChild(iframe);
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|