Bug 774585 - Tests. r=sicking

This commit is contained in:
Mounir Lamouri 2012-07-20 00:26:05 -07:00
parent c3bf967163
commit a511b952f1

View File

@ -24,45 +24,86 @@ 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:443/manifest.webapp",
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" ],
// },
{
app: "http://example.org/foo/manifest.webapp",
src: "http://example.org/",
},
{
app: "http://example.org/bar/manifest.webapp",
src: "http://example.org/",
isapp: false,
test: [ "eo-unique" ],
},
{
browser: true,
src: "http://example.org/",
},
{
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" ],
},
/*
{
@ -78,20 +119,31 @@ var gData = [
*/
{
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;
@ -99,7 +151,6 @@ var checksTodo = gData.length;
function checkPrincipalForIFrame(aFrame, data) {
var principal = aFrame.contentDocument.nodePrincipal;
// TODO: TEMP.
if (!data.test) {
data.test = [];
}
@ -107,12 +158,38 @@ function checkPrincipalForIFrame(aFrame, data) {
is(principal.URI.spec, data.src,
'the correct URL should have been loaded');
is(principal.appStatus, Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED,
'principal is not part of an installed app');
is(principal.extendedOrigin, principal.origin,
"extendedOrigin returns the origin for the moment");
is(principal.appId, Ci.nsIScriptSecurityManager.NO_APP_ID,
"appId is always NO_APP_ID for the moment");
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) {
@ -127,6 +204,14 @@ is('extendedOrigin' in document.nodePrincipal, true,
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() {
@ -147,6 +232,8 @@ gData.forEach(function(data) {
content.appendChild(iframe);
});
});
</script>
</pre>
</body>