Bug 777384 - Test case r=jlebar

--HG--
extra : rebase_source : 777580f0a22bfb3d9d447097b0f4a379f2b7416b
This commit is contained in:
Patrick Wang 2012-09-27 01:47:57 +08:00
parent 71f4b773d3
commit d4e9c05829
12 changed files with 117 additions and 6 deletions

View File

@ -364,6 +364,7 @@ function checkIFrame(aFrame, data) {
checkedCount++;
if (checkedCount == checksTodo) {
SpecialPowers.removePermission("browser", "http://example.org");
SpecialPowers.removePermission("embed-apps", "http://example.org");
SimpleTest.finish();
} else {
gTestRunner.next();
@ -389,6 +390,7 @@ function runTest() {
};
iframe.addChild = function() {
SpecialPowers.addPermission("browser", true, iframe.contentDocument);
SpecialPowers.addPermission("embed-apps", true, iframe.contentDocument);
var childFrame = document.createElement('iframe');

View File

@ -111,6 +111,7 @@ function setUp() {
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", true);
SpecialPowers.addPermission("browser", true, window.document);
SpecialPowers.addPermission("embed-apps", true, window.document);
runNextTest();
}

View File

@ -32,6 +32,7 @@ function setUp() {
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", true);
SpecialPowers.addPermission("browser", true, window.document);
SpecialPowers.addPermission("embed-apps", true, window.document);
let appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
SpecialPowers.addPermission("foobar", true, { url: APP_URL,

View File

@ -133,6 +133,9 @@ MOCHITEST_FILES = \
test_browserElement_inproc_RemoveBrowserElement.html \
browserElement_DOMRequestError.js \
test_browserElement_inproc_DOMRequestError.html \
file_browserElement_AppFramePermission.html \
browserElement_AppFramePermission.js \
test_browserElement_inproc_AppFramePermission.html \
$(NULL)
# Disabled due to https://bugzilla.mozilla.org/show_bug.cgi?id=774100
@ -193,6 +196,7 @@ MOCHITEST_FILES += \
test_browserElement_oop_Auth.html \
test_browserElement_oop_RemoveBrowserElement.html \
test_browserElement_oop_DOMRequestError.html \
test_browserElement_oop_AppFramePermission.html \
$(NULL)
endif #}
endif #}

View File

@ -0,0 +1,52 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 777384 - Test mozapp permission.
"use strict";
SimpleTest.waitForExplicitFinish();
function makeAllAppsLaunchable() {
var Webapps = {};
SpecialPowers.wrap(Components).utils.import("resource://gre/modules/Webapps.jsm", Webapps);
var appRegistry = SpecialPowers.wrap(Webapps.DOMApplicationRegistry);
var originalValue = appRegistry.allAppsLaunchable;
appRegistry.allAppsLaunchable = true;
// Clean up after ourselves once tests are done so the test page is unloaded.
window.addEventListener("unload", function restoreAllAppsLaunchable(event) {
if (event.target == window.document) {
window.removeEventListener("unload", restoreAllAppsLaunchable, false);
appRegistry.allAppsLaunchable = originalValue;
}
}, false);
}
makeAllAppsLaunchable();
function testAppElement(expectAnApp, callback) {
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
is(e.detail.message == 'app', expectAnApp, e.detail.message);
SimpleTest.executeSoon(callback);
});
document.body.appendChild(iframe);
iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AppFramePermission.html';
}
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
SpecialPowers.addPermission("embed-apps", true, document);
testAppElement(true, function() {
SpecialPowers.removePermission("embed-apps", document);
testAppElement(false, function() {
SimpleTest.finish();
});
});
}
runTest();

View File

@ -9,6 +9,8 @@ SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
// Permission to embed an app.
SpecialPowers.addPermission("embed-apps", true, document);
var iframe1 = document.createElement('iframe');
iframe1.mozbrowser = true;
@ -29,6 +31,7 @@ function runTest() {
iframe2.addEventListener('mozbrowseropenwindow', function(e) {
ok(true, "Got second mozbrowseropenwindow event.");
SpecialPowers.removePermission("embed-apps", document);
SimpleTest.finish();
});

View File

@ -0,0 +1,17 @@
<html>
<head>
<script type="text/javascript">
addEventListener('load', function(e) {
navigator.mozApps.getSelf().onsuccess = function onGetSelf() {
if (this.result) {
alert('app');
} else {
alert('notapp');
}
};
});
</script>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 777384</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_AppFramePermission.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 777384</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_AppFramePermission.js">
</script>
</body>
</html>

View File

@ -25,6 +25,7 @@ try {
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
SpecialPowers.addPermission("browser", true, window.document);
SpecialPowers.addPermission("embed-apps", true, window.document);
var gData = [
// APP 1
@ -107,6 +108,7 @@ function runTest()
localStorage.clear();
SpecialPowers.removePermission("browser", window.document);
SpecialPowers.removePermission("embed-apps", window.document);
if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);

View File

@ -34,6 +34,7 @@ try {
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
SpecialPowers.addPermission("browser", true, window.document);
SpecialPowers.addPermission("embed-apps", true, window.document);
var gData = [
// APP 1
@ -105,6 +106,7 @@ function runTest() {
}
SpecialPowers.removePermission("browser", window.document);
SpecialPowers.removePermission("embed-apps", window.document);
SimpleTest.finish();
} else {

View File

@ -127,6 +127,7 @@
"docshell/test/test_bug637644.html": "",
"docshell/test/test_bug668513.html": "RANDOM",
"dom/browser-element/mochitest/test_browserElement_oop_SecurityChange.html": "TIMED_OUT, bug 766586",
"dom/browser-element/mochitest/test_browserElement_inproc_AppFramePermission.html": "",
"dom/browser-element/mochitest/test_browserElement_inproc_AppWindowNamespace.html": "TIMED_OUT, bug 783509",
"dom/browser-element/mochitest/test_browserElement_inproc_SecurityChange.html": "TIMED_OUT, bug 766586",
"dom/devicestorage": "bug 781789 & bug 782275",