gecko-dev/dom/base/test/test_messagemanager_assertpermission.html
Yoshi Huang 176a15f268 Bug 1196665 - Add originAttributes into SpecialPowers. r=bholley
From 7bb0fbba24f4f65d3fa83efe223b1431cd71fdb6 Mon Sep 17 00:00:00 2001
---
 dom/apps/tests/test_third_party_homescreen.html    |   8 +-
 .../test/test_messagemanager_assertpermission.html |   4 +-
 dom/base/test/test_messagemanager_targetchain.html |  16 +--
 ...rowserElement_AllowEmbedAppsInNestedOOIframe.js |  11 +-
 .../mochitest/browserElement_CopyPaste.js          |   9 +-
 .../browserElement_DisallowEmbedAppsInOOP.js       |   9 +-
 .../mochitest/browserElement_Proxy.js              |  10 +-
 .../browserElement_SetInputMethodActive.js         |   3 +-
 .../mochitest/browserElement_SetVisibleFrames.js   |  17 ++--
 .../mochitest/browserElement_SetVisibleFrames2.js  |  16 +--
 .../priority/test_ExpectingSystemMessage2.html     |  16 +--
 .../mochitest/priority/test_NestedFrames.html      |  16 +--
 dom/cache/test/mochitest/driver.js                 |  11 +-
 .../test/mochitest/test_cache_orphaned_body.html   |  33 +-----
 .../test/mochitest/test_cache_orphaned_cache.html  |  33 +-----
 dom/cache/test/mochitest/test_cache_restart.html   |  11 +-
 dom/cache/test/mochitest/test_cache_shrink.html    |  33 +-----
 dom/indexedDB/test/file.js                         |  12 +--
 dom/indexedDB/test/helpers.js                      |   9 +-
 dom/indexedDB/test/webapp_clearBrowserData.js      |   6 +-
 dom/inputmethod/mochitest/test_bug1043828.html     |   5 +-
 dom/inputmethod/mochitest/test_bug944397.html      |   5 +-
 .../mochitest/test_focus_blur_manage_events.html   |   5 +-
 .../mochitest/test_input_registry_events.html      |   5 +-
 .../mochitest/test_simple_manage_events.html       |   5 +-
 .../tests/test_permission_for_nested_oop_app.html  |   3 +-
 .../tests/test_permission_for_two_oop_apps.html    |   3 +-
 dom/ipc/tests/test_permission_helper.js            |  21 ++--
 .../test_permission_when_oop_app_crashes.html      |   3 +-
 dom/tv/test/mochitest/head.js                      |   5 +-
 .../test_SpecialPowersPushAppPermissions.html      |  14 ++-
 .../tests/Harness_sanity/test_bug816847.html       |   6 +-
 .../components/SpecialPowersObserver.js            |   4 +-
 .../content/SpecialPowersObserverAPI.js            |  24 +----
 testing/specialpowers/content/specialpowersAPI.js  | 111 ++++++++-------------
 35 files changed, 173 insertions(+), 329 deletions(-)
2015-10-07 14:35:43 +08:00

193 lines
6.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test for the nsIProcessChecker part of Message Managers</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="runTests();">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.8">
const APP_URL = "http://example.org";
const APP_MANIFEST = "http://example.org/manifest.webapp";
const CHILD_PROCESS_SHUTDOWN_MESSAGE = "child-process-shutdown";
let ppmm = SpecialPowers.Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(SpecialPowers.Ci.nsIMessageBroadcaster);
let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
.getService(SpecialPowers.Ci.nsISyncMessageSender);
let gAppsService = SpecialPowers.Cc["@mozilla.org/AppsService;1"]
.getService(SpecialPowers.Ci.nsIAppsService);
function setUp() {
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,
originAttributes: { appId: appId }
});
SpecialPowers.pushPrefEnv({"set":[['dom.mozBrowserFramesEnabled', true],
['dom.ipc.browser_frames.oop_by_default', true]]}, runNextTest);
}
/**
* Load the example.org app in an <iframe mozbrowser mozapp>
*/
function loadApp(callback) {
let iframe = document.createElement("iframe");
iframe.setAttribute("mozapp", APP_MANIFEST);
SpecialPowers.wrap(iframe).mozbrowser = true;
iframe.src = APP_URL;
document.getElementById("content").appendChild(iframe);
iframe.addEventListener("mozbrowserloadend", function onloadend() {
iframe.removeEventListener("mozbrowserloadend", onloadend);
callback(iframe);
});
}
/**
* Prepare the child process for an intentional crash. This is to keep
* the leak automation tools happy.
*
* This also allows us to acquire the process message manaager that
* corresponds to the process by sending a message to a frame script
* in the content process and having it reply to us via the child
* process message manager.
*/
function prepareProcess(frameMM, callback) {
let frameScript = 'data:,\
privateNoteIntentionalCrash();\
var cpmm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]\
.getService(Components.interfaces.nsISyncMessageSender);\
addMessageListener("TestChild:Ohai", function receiveMessage(msg) {\
cpmm.sendAsyncMessage("TestChild:Ohai");\
});';
frameMM.loadFrameScript(frameScript, false);
frameMM.sendAsyncMessage("TestChild:Ohai");
ppmm.addMessageListener("TestChild:Ohai", function receiveMessage(msg) {
ppmm.removeMessageListener("TestChild:Ohai", receiveMessage);
msg = SpecialPowers.wrap(msg);
callback(msg.target);
});
}
/**
* Expects an OOP frame's process to shut down and report three
* events/messages: an error event on the browser element, and a
* 'child-process-shutdown' message on both the frame and process
* message managers.
*/
function expectFrameProcessShutdown(iframe, frameMM, processMM, callback) {
let msgCount = 0;
function countMessage() {
msgCount += 1;
if (msgCount == 3) {
ok(true, "Observed all three expected events.");
callback();
}
};
iframe.addEventListener("mozbrowsererror", function onerror(event) {
iframe.removeEventListener("mozbrowsererror", onerror);
is(event.detail.type, "fatal", "Observed expected event.");
countMessage();
});
processMM.addMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, function receiveMessage() {
processMM.removeMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, receiveMessage);
ok(true, "Received 'child-process-shutdown' message from process message manager.");
countMessage();
});
frameMM.addMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, function receiveMessage() {
frameMM.removeMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, receiveMessage);
ok(true, "Received 'child-process-shutdown' message from frame message manager.");
countMessage();
});
}
function testSameProcess() {
// Assert permissions on the in-process child process message manager.
// It always has all permissions, including ones that were never
// assigned to anybody.
cpmm.sendAsyncMessage("TestPermission:InProcess");
ppmm.addMessageListener("TestPermission:InProcess", function receiveMessage(msg) {
ppmm.removeMessageListener("TestPermission:InProcess", receiveMessage);
msg = SpecialPowers.wrap(msg);
ok(msg.target.assertPermission("frobnaz"), "in-process cpmm always has all capabilities");
runNextTest();
});
}
function testFrameMessageManager() {
// Assert permissions on the frame message manager.
loadApp(function (iframe) {
let frameMM = SpecialPowers.getBrowserFrameMessageManager(iframe);
prepareProcess(frameMM, function (processMM) {
ok(frameMM.assertPermission("foobar"),
"Frame mm has assigned permission.");
ok(!frameMM.assertPermission("frobnaz"),
"Frame mm doesn't have non-existing permission.");
expectFrameProcessShutdown(iframe, frameMM, processMM, function () {
iframe.parentNode.removeChild(iframe);
runNextTest();
});
});
});
}
function testChildProcessMessageManager() {
// Assert permissions on the child process message manager.
loadApp(function (iframe) {
let frameMM = SpecialPowers.getBrowserFrameMessageManager(iframe);
prepareProcess(frameMM, function (processMM) {
ok(processMM.assertPermission("foobar"),
"Process mm has assigned permission.");
ok(!processMM.assertPermission("frobnaz"),
"Process mm doesn't have non-existing permission.");
expectFrameProcessShutdown(iframe, frameMM, processMM, function () {
iframe.parentNode.removeChild(iframe);
runNextTest();
});
});
});
}
function tearDown() {
SimpleTest.finish();
}
let _tests = [
setUp,
testSameProcess,
testFrameMessageManager,
testChildProcessMessageManager,
tearDown
]
function runNextTest() {
SimpleTest.executeSoon(_tests.shift());
}
function runTests() {
SimpleTest.waitForExplicitFinish();
runNextTest();
}
</script>
</pre>
</body>
</html>