gecko/testing/mochitest/tests/Harness_sanity/test_bug816847.html
Joel Maher a46890e4bd Bug 971025 - move testing/mochitest/test/test_* to testing/mochitest/test/Harness_sanity. r=ted
--HG--
rename : testing/mochitest/tests/SpecialPowersLoadChromeScript.js => testing/mochitest/tests/Harness_sanity/SpecialPowersLoadChromeScript.js
rename : testing/mochitest/tests/file_SpecialPowersFrame1.html => testing/mochitest/tests/Harness_sanity/file_SpecialPowersFrame1.html
rename : testing/mochitest/tests/test_SimpleTestGetTestFileURL.html => testing/mochitest/tests/Harness_sanity/test_SimpleTestGetTestFileURL.html
rename : testing/mochitest/tests/test_SpecialPowersExtension.html => testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html
rename : testing/mochitest/tests/test_SpecialPowersExtension2.html => testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension2.html
rename : testing/mochitest/tests/test_SpecialPowersLoadChromeScript.html => testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html
rename : testing/mochitest/tests/test_SpecialPowersPushPermissions.html => testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html
rename : testing/mochitest/tests/test_SpecialPowersPushPrefEnv.html => testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
rename : testing/mochitest/tests/test_bug362788.xhtml => testing/mochitest/tests/Harness_sanity/test_bug362788.xhtml
rename : testing/mochitest/tests/test_bug816847.html => testing/mochitest/tests/Harness_sanity/test_bug816847.html
rename : testing/mochitest/tests/test_sanity.html => testing/mochitest/tests/Harness_sanity/test_sanity.html
rename : testing/mochitest/tests/test_sanityEventUtils.html => testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
rename : testing/mochitest/tests/test_sanityException.html => testing/mochitest/tests/Harness_sanity/test_sanityException.html
rename : testing/mochitest/tests/test_sanityException2.html => testing/mochitest/tests/Harness_sanity/test_sanityException2.html
rename : testing/mochitest/tests/test_sanitySimpletest.html => testing/mochitest/tests/Harness_sanity/test_sanitySimpletest.html
rename : testing/mochitest/tests/test_sanityWindowSnapshot.html => testing/mochitest/tests/Harness_sanity/test_sanityWindowSnapshot.html
rename : testing/mochitest/tests/test_sanity_cleanup.html => testing/mochitest/tests/Harness_sanity/test_sanity_cleanup.html
rename : testing/mochitest/tests/test_sanity_cleanup2.html => testing/mochitest/tests/Harness_sanity/test_sanity_cleanup2.html
2014-03-05 10:32:02 -05:00

102 lines
3.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=816847
-->
<head>
<title>Test for Bug 816847</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="starttest();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=816847">Mozilla Bug 816847</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 816847 **/
SimpleTest.waitForExplicitFinish();
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Cu = SpecialPowers.Cu;
const Services = Cu.import("resource://gre/modules/Services.jsm").Services;
const appsSvc = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService)
const manifest = "https://example.com/manifest.webapp";
const allow = Ci.nsIPermissionManager.ALLOW_ACTION;
const unknown = Ci.nsIPermissionManager.UNKNOWN_ACTION;
const perms = ['network-events', 'geolocation', 'camera', 'alarms']
function createPrincipal(aURI, aIsApp, aIsInBrowserElement) {
if(aIsApp) {
var app = appsSvc.getAppByManifestURL(aURI);
var localId = appsSvc.getAppLocalIdByManifestURL(aURI);
var uri = Services.io.newURI(app.origin, null, null);
return Services.scriptSecurityManager
.getAppCodebasePrincipal(uri,
localId,
aIsInBrowserElement);
}
var uri = Services.io.newURI(aURI, null, null);
return Services.scriptSecurityManager
.getNoAppCodebasePrincipal(uri);
}
// test addPermission and removePermission
function starttest(){
var app = appsSvc.getAppByManifestURL(manifest);
ok(app != null, "Got an app ");
var origin = app.origin
var nodePrincipal = SpecialPowers.wrap(document).nodePrincipal;
var appPrincipal = createPrincipal(manifest, true);
var noappPrincipal = createPrincipal(origin, false);
SpecialPowers.addPermission(perms[0], true, origin);
SpecialPowers.addPermission(perms[1], true, {manifestURL: manifest});
SpecialPowers.addPermission(perms[2], true, document);
SpecialPowers.addPermission(perms[3], true, {url: origin,
appId: Ci.nsIScriptSecurityManager.NO_APP_ID});
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]),
allow, "Set permission by string");
is(Services.perms.testPermissionFromPrincipal(appPrincipal, perms[1]),
allow, "Set permission by manifestURL");
is(Services.perms.testPermissionFromPrincipal(nodePrincipal, perms[2]),
allow, "Set permission by principal");
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[3]),
allow, "Set permission by other");
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[1]),
unknown, "Check that app permission doesn't leak to normal page");
SpecialPowers.removePermission(perms[0], origin);
SpecialPowers.removePermission(perms[1], {manifestURL: manifest});
SpecialPowers.removePermission(perms[2], document);
SpecialPowers.removePermission(perms[3], {url: origin,
appId: Ci.nsIScriptSecurityManager.NO_APP_ID});
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]),
unknown, "Removed permission by string");
is(Services.perms.testPermissionFromPrincipal(appPrincipal, perms[1]),
unknown, "Removed permission by manifestURL");
is(Services.perms.testPermissionFromPrincipal(nodePrincipal, perms[2]),
unknown, "Removed permission by principal");
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[3]),
unknown, "Removed permission by other");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>