зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1114507 - Part 4: Test cases. r=kanru
This commit is contained in:
Родитель
3ccf001aaa
Коммит
6efd887296
|
@ -0,0 +1,55 @@
|
|||
var gBasePath = "tests/dom/ipc/tests/";
|
||||
|
||||
function handleRequest(request, response) {
|
||||
var query = getQuery(request);
|
||||
|
||||
var testToken = '';
|
||||
if ('testToken' in query) {
|
||||
testToken = query.testToken;
|
||||
}
|
||||
|
||||
var template = '';
|
||||
if ('template' in query) {
|
||||
template = query.template;
|
||||
}
|
||||
var template = gBasePath + template;
|
||||
response.setHeader("Content-Type", "application/x-web-app-manifest+json", false);
|
||||
response.write(readTemplate(template).replace(/TESTTOKEN/g, testToken));
|
||||
}
|
||||
|
||||
// Copy-pasted incantations. There ought to be a better way to synchronously read
|
||||
// a file into a string, but I guess we're trying to discourage that.
|
||||
function readTemplate(path) {
|
||||
var file = Components.classes["@mozilla.org/file/directory_service;1"].
|
||||
getService(Components.interfaces.nsIProperties).
|
||||
get("CurWorkD", Components.interfaces.nsILocalFile);
|
||||
var fis = Components.classes['@mozilla.org/network/file-input-stream;1'].
|
||||
createInstance(Components.interfaces.nsIFileInputStream);
|
||||
var cis = Components.classes["@mozilla.org/intl/converter-input-stream;1"].
|
||||
createInstance(Components.interfaces.nsIConverterInputStream);
|
||||
var split = path.split("/");
|
||||
for(var i = 0; i < split.length; ++i) {
|
||||
file.append(split[i]);
|
||||
}
|
||||
fis.init(file, -1, -1, false);
|
||||
cis.init(fis, "UTF-8", 0, 0);
|
||||
|
||||
var data = "";
|
||||
let str = {};
|
||||
let read = 0;
|
||||
do {
|
||||
read = cis.readString(0xffffffff, str); // read as much as we can and put it in str.value
|
||||
data += str.value;
|
||||
} while (read != 0);
|
||||
cis.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
function getQuery(request) {
|
||||
var query = {};
|
||||
request.queryString.split('&').forEach(function (val) {
|
||||
var [name, value] = val.split('=');
|
||||
query[name] = unescape(value);
|
||||
});
|
||||
return query;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Nested-OOP",
|
||||
"description": "Nested-OOP test app used for mochitest.",
|
||||
"launch_path": "/tests/dom/ipc/tests/TESTTOKEN",
|
||||
"icons": { "128": "default_icon" }
|
||||
}
|
|
@ -21,3 +21,39 @@ skip-if = true # bug 1166923
|
|||
skip-if = toolkit == 'cocoa' # disabled due to hangs, see changeset 6852e7c47edf
|
||||
[test_CrashService_crash.html]
|
||||
skip-if = !(crashreporter && !e10s && (toolkit == 'gtk2' || toolkit == 'gtk3' || toolkit == 'cocoa' || toolkit == 'windows') && (buildapp != 'b2g' || toolkit == 'gonk') && (buildapp != 'mulet')) # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
|
||||
[test_permission_for_in_process_app.html]
|
||||
skip-if = e10s || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
|
||||
support-files =
|
||||
test_permission_helper.js
|
||||
[test_permission_for_oop_app.html]
|
||||
skip-if = buildapp == 'mulet' || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
|
||||
support-files =
|
||||
file_app.sjs
|
||||
file_app.template.webapp
|
||||
test_permission_helper.js
|
||||
test_permission_embed.html
|
||||
test_permission_framescript.js
|
||||
[test_permission_for_nested_oop_app.html]
|
||||
skip-if = buildapp == 'mulet' || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
|
||||
support-files =
|
||||
file_app.sjs
|
||||
file_app.template.webapp
|
||||
test_permission_helper.js
|
||||
test_permission_embed.html
|
||||
test_permission_framescript.js
|
||||
[test_permission_for_two_oop_apps.html]
|
||||
skip-if = buildapp == 'mulet' || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
|
||||
support-files =
|
||||
file_app.sjs
|
||||
file_app.template.webapp
|
||||
test_permission_helper.js
|
||||
test_permission_embed.html
|
||||
test_permission_framescript.js
|
||||
[test_permission_when_oop_app_crashes.html]
|
||||
skip-if = buildapp == 'mulet' || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
|
||||
support-files =
|
||||
file_app.sjs
|
||||
file_app.template.webapp
|
||||
test_permission_helper.js
|
||||
test_permission_embed.html
|
||||
test_permission_framescript.js
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>oop-test apps</title>
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
|
||||
var queryString = decodeURIComponent(window.location.hash.substring(1));
|
||||
|
||||
// test-target-app
|
||||
var APP_URL = "http://example.org";
|
||||
var APP_MANIFEST = "http://example.org/manifest.webapp";
|
||||
var APP_IFRAME_ID = "test-target";
|
||||
|
||||
function removeAppFrame(){
|
||||
var ifr = document.getElementById(APP_IFRAME_ID);
|
||||
ifr.remove();
|
||||
}
|
||||
|
||||
function allocateAppFrame(source, manifestURL, useRemote) {
|
||||
var ifr = document.createElement('iframe');
|
||||
ifr.setAttribute('id', APP_IFRAME_ID);
|
||||
ifr.setAttribute('remote', useRemote? "true" : "false");
|
||||
ifr.setAttribute('mozbrowser', 'true');
|
||||
ifr.setAttribute('mozapp', manifestURL);
|
||||
ifr.setAttribute('src', source);
|
||||
|
||||
ifr.addEventListener('mozbrowserloadend', function () {
|
||||
if (queryString == "crash") {
|
||||
// Send a crash request to parent-process
|
||||
sendMessgeToParent('crash');
|
||||
} else {
|
||||
removeAppFrame();
|
||||
}
|
||||
});
|
||||
|
||||
document.body.appendChild(ifr);
|
||||
}
|
||||
|
||||
function sendMessgeToParent(msg) {
|
||||
window.alert(msg);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
allocateAppFrame(APP_URL, APP_MANIFEST, true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1114507
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1114507</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114507">Mozilla Bug1114507</a>
|
||||
<p id="display"></p>
|
||||
<div id="container" style="display: none"></div>
|
||||
<script type="text/javascript" src="test_permission_helper.js"></script>
|
||||
<script type="application/javascript">
|
||||
// Put all the tests in order
|
||||
var tests = [
|
||||
// Setup preferences and permissions
|
||||
setupPrefsAndPermissions,
|
||||
|
||||
// +-------------------------------------------+
|
||||
// | Test 1: Open and close a in-process |
|
||||
// | test-target-app in chrome-process |
|
||||
// +-------------------------------------------+
|
||||
//
|
||||
// level
|
||||
// 1 chrome process <-- app is here
|
||||
|
||||
// Add permission to app
|
||||
function () {
|
||||
addPermissionToApp(APP_URL, APP_MANIFEST);
|
||||
},
|
||||
|
||||
test1
|
||||
];
|
||||
|
||||
runTests();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,75 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1114507
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1114507</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114507">Mozilla Bug1114507</a>
|
||||
<p id="display"></p>
|
||||
<div id="container" style="display: none"></div>
|
||||
<script type="text/javascript" src="test_permission_helper.js"></script>
|
||||
<script type="application/javascript">
|
||||
// Put all the tests in order
|
||||
var tests = [
|
||||
// Setup preferences and permissions
|
||||
setupPrefsAndPermissions,
|
||||
|
||||
// ****************************************************
|
||||
// Setup the enviroment for testing nested-oop cases: *
|
||||
// test 3,4,5 *
|
||||
// ****************************************************
|
||||
|
||||
// Install the app
|
||||
installApp,
|
||||
|
||||
// Allow permission for embedApp to open mozbrowser and mozapp
|
||||
function() {
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
|
||||
var context = { url: embedApp.origin,
|
||||
appId: appId,
|
||||
isInBrowserElement: false };
|
||||
setupOpenAppPermission(context, runTests);
|
||||
},
|
||||
|
||||
// +-------------------------------------------+
|
||||
// | Test 3: Open a test-target-app on 3rd |
|
||||
// | level child-process then close it |
|
||||
// +-------------------------------------------+
|
||||
//
|
||||
// level
|
||||
// 1 chrome process
|
||||
// |
|
||||
// 2 child process
|
||||
// |
|
||||
// 3 child process <-- app is here
|
||||
|
||||
// Add permission to app
|
||||
function() {
|
||||
addPermissionToApp(APP_URL, APP_MANIFEST);
|
||||
},
|
||||
|
||||
test3,
|
||||
|
||||
// Remove the child-process on 2nd level
|
||||
function() {
|
||||
var afterShutdown = function() {
|
||||
runTests();
|
||||
};
|
||||
afterContentShutdown(1, afterShutdown);
|
||||
removeAppFrame(APP_IFRAME_ID);
|
||||
},
|
||||
|
||||
uninstallApp
|
||||
];
|
||||
|
||||
runTests();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1114507
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1114507</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114507">Mozilla Bug1114507</a>
|
||||
<p id="display"></p>
|
||||
<div id="container" style="display: none"></div>
|
||||
<script type="text/javascript" src="test_permission_helper.js"></script>
|
||||
<script type="application/javascript">
|
||||
// Put all the tests in order
|
||||
var tests = [
|
||||
// Setup preferences and permissions
|
||||
setupPrefsAndPermissions,
|
||||
|
||||
// +------------------------------------------+
|
||||
// | Test 2: Open and close a test-target-app |
|
||||
// | on 2nd level child-process |
|
||||
// +------------------------------------------+
|
||||
//
|
||||
// level
|
||||
// 1 chrome process
|
||||
// |
|
||||
// 2 child process <-- app is here
|
||||
|
||||
// Add permission to app
|
||||
function() {
|
||||
addPermissionToApp(APP_URL, APP_MANIFEST);
|
||||
},
|
||||
|
||||
test2,
|
||||
];
|
||||
|
||||
runTests();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,88 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1114507
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1114507</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114507">Mozilla Bug1114507</a>
|
||||
<p id="display"></p>
|
||||
<div id="container" style="display: none"></div>
|
||||
<script type="text/javascript" src="test_permission_helper.js"></script>
|
||||
<script type="application/javascript">
|
||||
// Put all the tests in order
|
||||
var tests = [
|
||||
// Setup preferences and permissions
|
||||
setupPrefsAndPermissions,
|
||||
|
||||
// ****************************************************
|
||||
// Setup the enviroment for testing nested-oop cases: *
|
||||
// test 3,4,5 *
|
||||
// ****************************************************
|
||||
|
||||
// Install the app
|
||||
installApp,
|
||||
|
||||
// Allow permission for embedApp to open mozbrowser and mozapp
|
||||
function() {
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
|
||||
var context = { url: embedApp.origin,
|
||||
appId: appId,
|
||||
isInBrowserElement: false };
|
||||
setupOpenAppPermission(context, runTests);
|
||||
},
|
||||
|
||||
// +---------------------------------------------------------+
|
||||
// | Test 4: Open two test-target-app on 2nd and 3rd level |
|
||||
// | child-processes then close the one on 3rd level |
|
||||
// +---------------------------------------------------------+
|
||||
//
|
||||
// level
|
||||
// 1 chrome process
|
||||
// / \
|
||||
// 2 child process child process <-- app is here
|
||||
// /
|
||||
// 3 child process <-- app is here
|
||||
|
||||
// Add permission to app
|
||||
function() {
|
||||
addPermissionToApp(APP_URL, APP_MANIFEST);
|
||||
},
|
||||
|
||||
test4,
|
||||
|
||||
// Remove another test-target-app on 2nd level process
|
||||
function() {
|
||||
var afterShutdown = function() {
|
||||
// We expect there is no permission for the test-target-app now
|
||||
runNextIfAppHasPermission(4, false, APP_URL, APP_MANIFEST);
|
||||
};
|
||||
// Test permission after test-target-app
|
||||
// on 2nd level process is killed
|
||||
afterContentShutdown(1, afterShutdown);
|
||||
|
||||
removeAppFrame(APP_IFRAME_ID2);
|
||||
},
|
||||
|
||||
// Remove the last child-process on 2nd level
|
||||
function() {
|
||||
var afterShutdown = function() {
|
||||
runTests();
|
||||
};
|
||||
afterContentShutdown(1, afterShutdown);
|
||||
removeAppFrame(APP_IFRAME_ID);
|
||||
},
|
||||
|
||||
uninstallApp
|
||||
];
|
||||
|
||||
runTests();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
let cm = Services.crashmanager;
|
||||
var cpIdList = [];
|
||||
|
||||
var shutdownObs = {
|
||||
observe: function(subject, topic, data) {
|
||||
if (topic == 'ipc:content-shutdown') {
|
||||
var index = cpIdList.indexOf(parseInt(data));
|
||||
if (index > -1) {
|
||||
cpIdList.splice(index, 1);
|
||||
sendAsyncMessage('content-shutdown', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var createdObs = {
|
||||
observe: function(subject, topic, data) {
|
||||
if (topic == 'ipc:content-created') {
|
||||
cpIdList.push(parseInt(data));
|
||||
sendAsyncMessage('content-created', '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addMessageListener('crashreporter-status', function(message) {
|
||||
sendAsyncMessage('crashreporter-enable', !!cm);
|
||||
});
|
||||
|
||||
Services.obs.addObserver(shutdownObs, 'ipc:content-shutdown', false);
|
||||
Services.obs.addObserver(createdObs, 'ipc:content-created', false);
|
|
@ -0,0 +1,362 @@
|
|||
"use strict";
|
||||
|
||||
// Used to access the DOM node in this test
|
||||
const DOM_PARENT_ID = "container";
|
||||
const DOM_PARENT = document.getElementById(DOM_PARENT_ID);
|
||||
const APP_IFRAME_ID = "appFrame";
|
||||
const APP_IFRAME_ID2 = "appFrame2";
|
||||
|
||||
// Settings for testing the permission
|
||||
const SESSION_PERSIST_MINUTES = 10;
|
||||
const PERMISSION_TYPE = "geolocation";
|
||||
const permManager = SpecialPowers.Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(SpecialPowers.Ci.nsIPermissionManager);
|
||||
|
||||
// Used to access App's information like appId
|
||||
const gAppsService = SpecialPowers.Cc["@mozilla.org/AppsService;1"]
|
||||
.getService(SpecialPowers.Ci.nsIAppsService);
|
||||
|
||||
// Target-app for this testing
|
||||
const APP_URL = "http://example.org";
|
||||
const APP_MANIFEST = "http://example.org/manifest.webapp";
|
||||
|
||||
// Used to embed a remote app that open the test-target-app above
|
||||
const embedAppHostedManifestURL = window.location.origin +
|
||||
'/tests/dom/ipc/tests/file_app.sjs?testToken=test_permission_embed.html&template=file_app.template.webapp';
|
||||
var embedApp;
|
||||
|
||||
// Used to add listener for ipc:content-shutdown that
|
||||
// will be triggered after ContentParent::DeallocateTabId
|
||||
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('test_permission_framescript.js'));
|
||||
|
||||
// Delay reporting a result until after finish() got called
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
// Allow tests to disable the per platform app validity checks
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
|
||||
// Run tests in order
|
||||
function runTests() {
|
||||
if (!tests.length) {
|
||||
ok(true, "pass all tests!");
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
var test = tests.shift();
|
||||
test();
|
||||
}
|
||||
|
||||
function test1() {
|
||||
allocateAppFrame(APP_IFRAME_ID, DOM_PARENT, APP_URL, APP_MANIFEST);
|
||||
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
|
||||
|
||||
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
|
||||
{ url: APP_URL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false })) {
|
||||
errorHandler('[test 1] App should have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
|
||||
removeAppFrame(APP_IFRAME_ID);
|
||||
|
||||
// We expect there is no permission for the test-target-app
|
||||
// after removing the in-process iframe embedding this app
|
||||
runNextIfAppHasPermission(1, false, APP_URL, APP_MANIFEST);
|
||||
}
|
||||
|
||||
function test2() {
|
||||
var afterShutdown = function () {
|
||||
// We expect there is no permission for the test-target-app
|
||||
// after removing the remote iframe embedding this app
|
||||
runNextIfAppHasPermission(2, false, APP_URL, APP_MANIFEST);
|
||||
};
|
||||
|
||||
// Test permission after the child-process containing
|
||||
// test-target-app is killed
|
||||
afterContentShutdown(1, afterShutdown);
|
||||
|
||||
allocateAppFrame(APP_IFRAME_ID, DOM_PARENT, APP_URL, APP_MANIFEST, true);
|
||||
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
|
||||
|
||||
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
|
||||
{ url: APP_URL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false })) {
|
||||
errorHandler('[test 2] App should have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
|
||||
removeAppFrame(APP_IFRAME_ID);
|
||||
}
|
||||
|
||||
function test3() {
|
||||
var afterGrandchildShutdown = function () {
|
||||
// We expect there is no permission for the test-target-app
|
||||
// after removing the remote iframe embedding this app
|
||||
runNextIfAppHasPermission(3, false, APP_URL, APP_MANIFEST);
|
||||
};
|
||||
|
||||
// Test permission after the grandchild-process
|
||||
// containing test-target-app is killed
|
||||
afterContentShutdown(1, afterGrandchildShutdown);
|
||||
|
||||
allocateAppFrame(APP_IFRAME_ID,
|
||||
DOM_PARENT,
|
||||
embedApp.manifest.launch_path,
|
||||
embedApp.manifestURL,
|
||||
true);
|
||||
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
|
||||
|
||||
if (!SpecialPowers.hasPermission(PERMISSION_TYPE,
|
||||
{ url: APP_URL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false })) {
|
||||
errorHandler('[test 3] App should have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
function test4() {
|
||||
var afterGrandchildShutdown = function () {
|
||||
// We expect there is still a permission for the test-target-app
|
||||
// after killing test-target-app on 3rd-level process
|
||||
runNextIfAppHasPermission(4, true, APP_URL, APP_MANIFEST);
|
||||
};
|
||||
|
||||
// Test permission after the grandchild-process
|
||||
// containing test-target-app is killed
|
||||
afterContentShutdown(1, afterGrandchildShutdown);
|
||||
|
||||
// Open a child process(2nd level) and a grandchild process(3rd level)
|
||||
// that contains a test-target-app
|
||||
allocateAppFrame(APP_IFRAME_ID,
|
||||
DOM_PARENT,
|
||||
embedApp.manifest.launch_path,
|
||||
embedApp.manifestURL,
|
||||
true);
|
||||
|
||||
// Open another child process that contains
|
||||
// another test-target-app(2nd level)
|
||||
allocateAppFrame(APP_IFRAME_ID2,
|
||||
DOM_PARENT,
|
||||
APP_URL,
|
||||
APP_MANIFEST,
|
||||
true);
|
||||
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
|
||||
|
||||
if (!SpecialPowers.hasPermission(PERMISSION_TYPE,
|
||||
{ url: APP_URL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false })) {
|
||||
errorHandler('[test 4] App should have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
function test5() {
|
||||
var afterShutdown = function () {
|
||||
// We expect there is no permission for the test-target-app
|
||||
// after crashing its parent-process
|
||||
runNextIfAppHasPermission(5, false, APP_URL, APP_MANIFEST);
|
||||
};
|
||||
|
||||
// Test permission after the parent-process of test-target-app is crashed.
|
||||
afterContentShutdown(2, afterShutdown);
|
||||
|
||||
allocateAppFrame(APP_IFRAME_ID,
|
||||
DOM_PARENT,
|
||||
embedApp.manifest.launch_path + '#' + encodeURIComponent('crash'),
|
||||
embedApp.manifestURL,
|
||||
true);
|
||||
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
|
||||
|
||||
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
|
||||
{ url: APP_URL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false })) {
|
||||
errorHandler('[test 5] App should have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
|
||||
// Crash the child-process on 2nd level after
|
||||
// the grandchild process on 3rd is allocated
|
||||
var handler = {'crash': function() {
|
||||
gScript.sendAsyncMessage("crashreporter-status", {});
|
||||
|
||||
getCrashReporterStatus(function(enable) {
|
||||
if (enable) {
|
||||
SimpleTest.expectChildProcessCrash();
|
||||
}
|
||||
crashChildProcess(APP_IFRAME_ID);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
receiveMessageFromChildFrame(APP_IFRAME_ID, handler);
|
||||
}
|
||||
|
||||
// Setup the prefrences and permissions.
|
||||
// This function should be called before any tests
|
||||
function setupPrefsAndPermissions() {
|
||||
SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.mozBrowserFramesEnabled", true],
|
||||
["dom.ipc.tabs.nested.enabled", true],
|
||||
["dom.ipc.tabs.disabled", false]]},
|
||||
function() {
|
||||
var autoManageApp = function () {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
// No confirmation needed when an app is installed and uninstalled.
|
||||
SpecialPowers.autoConfirmAppInstall(() => {
|
||||
// This callback should trigger the first test
|
||||
SpecialPowers.autoConfirmAppUninstall(runTests);
|
||||
});
|
||||
};
|
||||
|
||||
setupOpenAppPermission(document, autoManageApp);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function setupOpenAppPermission(ctx, callback) {
|
||||
SpecialPowers.pushPermissions([
|
||||
{ "type": "browser", "allow": true, "context": ctx}, // for mozbrowser
|
||||
{ "type": "embed-apps", "allow": true, "context": ctx }, // for mozapp
|
||||
{ "type": "webapps-manage", "allow": true, "context": ctx }], // for (un)installing apps
|
||||
function checkPermissions() {
|
||||
if (SpecialPowers.hasPermission("browser", ctx) &&
|
||||
SpecialPowers.hasPermission("embed-apps", ctx) &&
|
||||
SpecialPowers.hasPermission("webapps-manage", ctx)) {
|
||||
callback();
|
||||
} else {
|
||||
errorHandler(">> At least one of required permissions to open app is disallowed!\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function installApp() {
|
||||
// Install App from manifest
|
||||
var request = navigator.mozApps.install(embedAppHostedManifestURL);
|
||||
request.onerror = cbError;
|
||||
request.onsuccess = function() {
|
||||
// Get installed app
|
||||
embedApp = request.result; // Assign to global variable
|
||||
runTests();
|
||||
}
|
||||
}
|
||||
|
||||
function uninstallApp() {
|
||||
var request = navigator.mozApps.mgmt.uninstall(embedApp);
|
||||
request.onerror = cbError;
|
||||
request.onsuccess = function() {
|
||||
info("uninstall app susseccfully!");
|
||||
runTests();
|
||||
}
|
||||
}
|
||||
|
||||
function removeAppFrame(id) {
|
||||
var ifr = document.getElementById(id);
|
||||
ifr.remove();
|
||||
}
|
||||
|
||||
function allocateAppFrame(id, parentNode, appSRC, manifestURL, useRemote = false) {
|
||||
var ifr = document.createElement('iframe');
|
||||
ifr.setAttribute('id', id);
|
||||
ifr.setAttribute('remote', useRemote? "true" : "false");
|
||||
ifr.setAttribute('mozbrowser', 'true');
|
||||
ifr.setAttribute('mozapp', manifestURL);
|
||||
ifr.setAttribute('src', appSRC);
|
||||
parentNode.appendChild(ifr);
|
||||
}
|
||||
|
||||
function receiveMessageFromChildFrame(id, handlers) {
|
||||
var ifr = document.getElementById(id);
|
||||
ifr.addEventListener('mozbrowsershowmodalprompt', function (recvMsg) {
|
||||
var msg = recvMsg.detail.message;
|
||||
handlers[msg]();
|
||||
});
|
||||
}
|
||||
|
||||
function addPermissionToApp(appURL, manifestURL) {
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(manifestURL);
|
||||
|
||||
// Get the time now. This is used for permission manager's expire_time
|
||||
var now = Number(Date.now());
|
||||
|
||||
// Add app's permission asynchronously
|
||||
SpecialPowers.pushPermissions([
|
||||
{ "type":PERMISSION_TYPE,
|
||||
"allow": 1,
|
||||
"expireType":permManager.EXPIRE_SESSION,
|
||||
"expireTime":now + SESSION_PERSIST_MINUTES*60*1000,
|
||||
"context": { url: appURL,
|
||||
appId: appId,
|
||||
isInBrowserElement:false }
|
||||
}
|
||||
], function() {
|
||||
runTests();
|
||||
});
|
||||
}
|
||||
|
||||
function runNextIfAppHasPermission(round, expect, appURL, manifestURL) {
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(manifestURL);
|
||||
|
||||
var hasPerm = SpecialPowers.hasPermission(PERMISSION_TYPE,
|
||||
{ url: appURL,
|
||||
appId: appId,
|
||||
isInBrowserElement: false });
|
||||
var result = (expect==hasPerm);
|
||||
if (result) {
|
||||
runTests();
|
||||
} else {
|
||||
errorHandler( '[test ' + round + '] App should ' + ((expect)? '':'NOT ') +
|
||||
'have permission: ' + PERMISSION_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
function afterContentShutdown(times, callback) {
|
||||
// handle the message from test_permission_framescript.js
|
||||
var num = 0;
|
||||
gScript.addMessageListener('content-shutdown', function onShutdown(data) {
|
||||
num += 1;
|
||||
if (num >= times) {
|
||||
gScript.removeMessageListener('content-shutdown', onShutdown);
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCrashReporterStatus(callback) {
|
||||
gScript.addMessageListener('crashreporter-enable', function getStatus(data) {
|
||||
gScript.removeMessageListener('crashreporter-enable', getStatus);
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
|
||||
// Inject a frame script that crashes the content process
|
||||
function crashChildProcess(frameId) {
|
||||
var child = document.getElementById(frameId);
|
||||
var mm = SpecialPowers.getBrowserFrameMessageManager(child);
|
||||
var childFrameScriptStr =
|
||||
'function ContentScriptScope() {' +
|
||||
'var Cu = Components.utils;' +
|
||||
'Cu.import("resource://gre/modules/ctypes.jsm");' +
|
||||
'var crash = function() {' +
|
||||
'var zero = new ctypes.intptr_t(8);' +
|
||||
'var badptr = ctypes.cast(zero, ctypes.PointerType(ctypes.int32_t));' +
|
||||
'badptr.contents;' +
|
||||
'};' +
|
||||
'privateNoteIntentionalCrash();' +
|
||||
'crash();' +
|
||||
'}';
|
||||
mm.loadFrameScript('data:,new ' + childFrameScriptStr, false);
|
||||
}
|
||||
|
||||
function errorHandler(errMsg) {
|
||||
ok(false, errMsg);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function cbError(e) {
|
||||
errorHandler("Error callback invoked: " + this.error.name);
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1114507
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1114507</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114507">Mozilla Bug1114507</a>
|
||||
<p id="display"></p>
|
||||
<div id="container" style="display: none"></div>
|
||||
<script type="text/javascript" src="test_permission_helper.js"></script>
|
||||
<script type="application/javascript">
|
||||
// Put all the tests in order
|
||||
var tests = [
|
||||
// Setup preferences and permissions
|
||||
setupPrefsAndPermissions,
|
||||
|
||||
// ****************************************************
|
||||
// Setup the enviroment for testing nested-oop cases: *
|
||||
// test 3,4,5 *
|
||||
// ****************************************************
|
||||
|
||||
// Install the app
|
||||
installApp,
|
||||
|
||||
// Allow permission for embedApp to open mozbrowser and mozapp
|
||||
function() {
|
||||
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
|
||||
var context = { url: embedApp.origin,
|
||||
appId: appId,
|
||||
isInBrowserElement: false };
|
||||
setupOpenAppPermission(context, runTests);
|
||||
},
|
||||
|
||||
// +-----------------------------------------------+
|
||||
// | Test 5: Open a test-target-app on 3rd level |
|
||||
// | process then crash its parent-process |
|
||||
// +-----------------------------------------------+
|
||||
//
|
||||
// level
|
||||
// 1 chrome process
|
||||
// |
|
||||
// 2 child process <-- crash this process
|
||||
// |
|
||||
// 3 child process <-- app is here
|
||||
|
||||
// Add permission to app
|
||||
function() {
|
||||
addPermissionToApp(APP_URL, APP_MANIFEST);
|
||||
},
|
||||
|
||||
test5,
|
||||
|
||||
uninstallApp
|
||||
|
||||
];
|
||||
|
||||
runTests();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче