Issue #2653 - Part 2: Update tests

This commit is contained in:
Moonchild
2024-11-17 21:37:56 +01:00
committed by roytam1
parent 7b6e3a2d4a
commit 0e6fa95840
13 changed files with 2 additions and 531 deletions
-1
View File
@@ -4,7 +4,6 @@ support-files =
file_disableScript.html
!/js/xpconnect/tests/mochitest/file_empty.html
[test_app_principal_equality.html]
[test_bug246699.html]
[test_bug292789.html]
[test_bug423375.html]
@@ -1,88 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=777467
-->
<head>
<meta charset="utf-8">
<title>Test app principal's equality</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=777467">Mozilla Bug 777467</a>
<p id="display"></p>
<script>
/** Test for app principal's equality **/
SimpleTest.waitForExplicitFinish();
var permissions = new Promise(resolve => {
SpecialPowers.pushPermissions(
[{ type: "browser", allow: true, context: document },
{ type: "embed-apps", allow: true, context: document }],
resolve);
});
permissions.then(() => {
$('content').innerHTML =
'<iframe src="error404"></iframe>\n' +
'<iframe mozbrowser src="error404"></iframe>\n' +
'<iframe mozapp="http://example.org/manifest.webapp" mozbrowser src="error404"></iframe>';
var iframes = document.getElementsByTagName("iframe");
var promises = []
for (var i = 0; i < promises.length; ++i) {
promises.push(new Promise(resolve => {
iframes[i].addEventListener("load", resolve);
}));
}
return Promise.all(promises);
});
var prefs = new Promise(resolve => {
SpecialPowers.pushPrefEnv(
{ set: [[ "dom.mozBrowserFramesEnabled", true ],
[ "dom.ipc.browser_frames.oop_by_default", false ]] },
resolve);
});
</script>
<div id="content" style="display: none;">
</div>
<pre id="test">
<script type="application/javascript">
function canAccessDocument(win) {
var result = true;
try {
win.document;
} catch(e) {
result = false;
}
return result;
}
var loaded = new Promise(resolve => addLoadEvent(resolve));
Promise.all([ permissions, prefs, loaded ]).then(runTest);
function runTest() {
// Test the witness frame (we can access same-origin frame).
is(canAccessDocument(frames[0]), true,
"should be able to access the first frame");
// Test different app/browserElement frames.
for (var i=1; i<frames.length; ++i) {
is(canAccessDocument(frames[i]), false,
"should not be able to access the other frames");
}
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>
@@ -8,27 +8,6 @@
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
// We'll need to get the appId from the current document,
// it's either SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID when
// we are not running inside an app (e.g. Firefox Desktop),
// or the appId of Mochitest app when we are running inside that app
// (e.g. Emulator).
var currentAppId = SpecialPowers.wrap(document).nodePrincipal.appId;
var inApp =
currentAppId !== SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID;
// We will also need the manifest URL and set it on iframes.
var currentAppManifestURL;
if (inApp) {
let appsService = SpecialPowers.Cc["@mozilla.org/AppsService;1"]
.getService(SpecialPowers.Ci.nsIAppsService);
currentAppManifestURL = appsService.getManifestURLByLocalId(currentAppId);
};
info('appId=' + currentAppId);
info('manifestURL=' + currentAppManifestURL);
function setup() {
let appInfo = SpecialPowers.Cc['@mozilla.org/xre/app-info;1']
.getService(SpecialPowers.Ci.nsIXULAppInfo);
@@ -73,9 +52,6 @@ function createFrames() {
for (let i = 0; i < 2; i++) {
let frame = gInputMethodFrames[i] = document.createElement('iframe');
frame.setAttribute('mozbrowser', 'true');
if (currentAppManifestURL) {
frame.setAttribute('mozapp', currentAppManifestURL);
}
frame.addEventListener('mozbrowserloadend', countLoadend);
frame.src = 'file_empty.html#' + i;
document.body.appendChild(frame);
@@ -88,20 +64,10 @@ function setPermissions() {
allow: true,
context: {
url: SimpleTest.getTestFileURL('/file_empty.html'),
originAttributes: {
appId: currentAppId,
inIsolatedMozBrowser: true
}
originAttributes: {}
}
}];
if (inApp) {
// The current document would also need to be given access for IPC to
// recognize our permission (why)?
permissions.push({
type: 'input', allow: true, context: document });
}
SpecialPowers.pushPermissions(permissions,
SimpleTest.waitForFocus.bind(SimpleTest, startTest));
}
@@ -20,7 +20,6 @@
// set 'remote' to true here will make the the iframe remote in _inproc_
// test and in-process in _oop_ test.
iframe.setAttribute('remote', 'true');
iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
iframe.addEventListener('mozbrowserloadend', function(e) {
ok("mute" in iframe, "iframe.mute exists");
@@ -1,88 +0,0 @@
<!DOCTYPE html>
<html>
<body>
foobar!
</body>
<script>
var data = [
{ id: "0", name: "foo" },
];
var action = window.location.search.substring(1);
var finished = false;
var created = false; // We use that for 'read-no' action.
function finish(value) {
value ? alert('success') : alert('failure');
finished = true;
}
var request = window.indexedDB.open('AppIsolationTest');
request.onupgradeneeded = function(event) {
if (finished) {
finish(false);
return;
}
switch (action) {
case 'read-no':
created = true;
break;
case 'read-yes':
finish(false);
break;
case 'write':
created = true;
var db = event.target.result;
var objectStore = db.createObjectStore("test", { keyPath: "id" });
for (var i in data) {
objectStore.add(data[i]);
}
break;
}
}
request.onsuccess = function(event) {
if (finished) {
finish(false);
return;
}
var db = event.target.result;
// Think about close the db!
switch (action) {
case 'read-no':
db.close();
if (created) { // That means we have created it.
indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
finish(true);
};
} else {
finish(false);
}
break;
case 'read-yes':
db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
var name = event.target.result.name;
db.close();
indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
finish(name == 'foo');
};
};
break;
case 'write':
db.close();
// Success only if the db was actually created.
finish(created);
break;
}
};
</script>
</html>
-161
View File
@@ -1,161 +0,0 @@
SimpleTest.waitForExplicitFinish();
var fileTestOnCurrentOrigin = (location.protocol + '//' + location.host + location.pathname)
.replace('test_', 'file_')
.replace('_inproc', '').replace('_oop', '');
var previousPrefs = {
mozBrowserFramesEnabled: undefined,
oop_by_default: undefined,
};
try {
previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
} catch(e)
{
}
try {
previousPrefs.oop_by_default = SpecialPowers.getBoolPref('dom.ipc.browser_frames.oop_by_default');
} catch(e) {
}
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", location.pathname.indexOf('_inproc') == -1);
SpecialPowers.addPermission("browser", true, window.document);
var gData = [
// APP 1
{
app: 'http://example.org/manifest.webapp',
action: 'read-no',
src: fileTestOnCurrentOrigin,
},
{
app: 'http://example.org/manifest.webapp',
action: 'write',
src: fileTestOnCurrentOrigin,
},
{
app: 'http://example.org/manifest.webapp',
action: 'read-yes',
src: fileTestOnCurrentOrigin,
},
// APP 2
{
app: 'https://example.com/manifest.webapp',
action: 'read-no',
src: fileTestOnCurrentOrigin,
},
{
app: 'https://example.com/manifest.webapp',
action: 'write',
src: fileTestOnCurrentOrigin,
},
{
app: 'https://example.com/manifest.webapp',
action: 'read-yes',
src: fileTestOnCurrentOrigin,
},
// Browser
{
browser: true,
action: 'read-no',
src: fileTestOnCurrentOrigin,
},
{
browser: true,
action: 'write',
src: fileTestOnCurrentOrigin,
},
{
browser: true,
action: 'read-yes',
src: fileTestOnCurrentOrigin,
},
];
function runTest() {
for (var i in gData) {
var iframe = document.createElement('iframe');
var data = gData[i];
if (data.app) {
iframe.setAttribute('mozbrowser', '');
iframe.setAttribute('mozapp', data.app);
} else if (data.browser) {
iframe.setAttribute('mozbrowser', '');
}
if (data.app || data.browser) {
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
is(e.detail.message, 'success', 'test number ' + i);
// document.getElementById('content').removeChild(iframe);
i++;
if (i >= gData.length) {
if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
}
if (previousPrefs.oop_by_default !== undefined) {
SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", previousPrefs.oop_by_default);
}
SpecialPowers.removePermission("browser", window.document);
indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
SimpleTest.finish();
};
} else {
gTestRunner.next();
}
});
}
iframe.src = data.src + '?' + data.action;
document.getElementById('content').appendChild(iframe);
yield undefined;
}
}
var gTestRunner = runTest();
function startTest() {
var request = window.indexedDB.open('AppIsolationTest');
var created = false;
request.onupgradeneeded = function(event) {
created = true;
var db = event.target.result;
var data = [
{ id: "0", name: "foo" },
];
var objectStore = db.createObjectStore("test", { keyPath: "id" });
for (var i in data) {
objectStore.add(data[i]);
}
}
request.onsuccess = function(event) {
var db = event.target.result;
is(created, true, "we should have created the db");
db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
is(event.target.result.name, 'foo', 'data have been written');
db.close();
gTestRunner.next();
};
}
}
// TODO: remove unsetting network.disable.ipc.security as part of bug 820712
SpecialPowers.pushPrefEnv({
"set": [
["network.disable.ipc.security", true],
]
}, startTest);
-8
View File
@@ -11,8 +11,6 @@ support-files =
event_propagation_iframe.html
exceptions_in_events_iframe.html
file.js
file_app_isolation.html
file_app_isolation.js
helpers.js
leaving_page_iframe.html
service_worker.js
@@ -125,12 +123,6 @@ support-files =
[test_add_put.html]
[test_add_twice_failure.html]
[test_advance.html]
[test_app_isolation_inproc.html]
# The app isolation tests are only supposed to run in the main process.
skip-if = e10s
[test_app_isolation_oop.html]
# The app isolation tests are only supposed to run in the main process.
skip-if = e10s
[test_autoIncrement.html]
[test_autoIncrement_indexes.html]
[test_bfcache.html]
@@ -1,21 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=756645
-->
<head>
<title>Test for IndexedDB app isolation (unique process)</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=756645">Mozilla Bug 756645</a>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript;version=1.7" src="file_app_isolation.js">
</script>
</pre>
</body>
</html>
@@ -1,21 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=756645
-->
<head>
<title>Test for IndexedDB app isolation (unique process)</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=756645">Mozilla Bug 756645</a>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript;version=1.7" src="file_app_isolation.js">
</script>
</pre>
</body>
</html>
-61
View File
@@ -1,61 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=815105
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 815105 </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=815105">Mozilla Bug 815105 </a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript;version=1.8" src="file_framework.js"></script>
<script type="application/javascript;version=1.8">
/*
* embed-apps allows us to create app iframes,
* creator must also have the browser permission
*/
function verifier(success, failure) {
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', '');
iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
iframe.src = "http://example.org/";
iframe.addEventListener('load', function() {
var appStatus = SpecialPowers.wrap(iframe)
.contentDocument.nodePrincipal.appStatus;
if (appStatus != SpecialPowers.Ci
.nsIPrincipal.APP_STATUS_NOT_INSTALLED) {
success("Got mozapp");
} else {
failure("Didn't get mozapp") ;
}
});
document.getElementById('content').appendChild(iframe);
}
var gData = [
{
perm: ["embed-apps", "browser"],
/*
* Android doesn't have working apps
* Mobile is for B2G which has a weird testing setup
* the app iframe gets embed in the test-container iframe
* which returns APP_STATUS_NOT_INSTALLED
*/
skip: ["Android", "Mobile"],
settings: [["dom.mozBrowserFramesEnabled", true]],
verifier: verifier.toSource(),
}
]
</script>
</pre>
</body>
</html>
+1 -2
View File
@@ -1,4 +1,4 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- /
/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -291,7 +291,6 @@ this.OnRefTestLoad = function OnRefTestLoad(win)
if (gBrowserIsIframe) {
gBrowser = gContainingWindow.document.createElementNS(XHTML_NS, "iframe");
gBrowser.setAttribute("mozbrowser", "");
gBrowser.setAttribute("mozapp", prefs.getCharPref("b2g.system_manifest_url"));
} else {
gBrowser = gContainingWindow.document.createElementNS(XUL_NS, "xul:browser");
}
@@ -1,43 +0,0 @@
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function is_app_offline(appId) {
let ioservice = Cc['@mozilla.org/network/io-service;1'].
getService(Ci.nsIIOService);
return ioservice.isAppOffline(appId);
}
var events_observed_no = 0;
// Holds the last observed app-offline event
var info = null;
function observer(aSubject, aTopic, aData) {
events_observed_no++;
info = aSubject.QueryInterface(Ci.nsIAppOfflineInfo);
dump("ChildObserver - subject: {" + aSubject.appId + ", " + aSubject.mode + "} ");
}
// Add observer for the app-offline notification
function run_test() {
Services.obs.addObserver(observer, "network:app-offline-status-changed", false);
}
// Chech that the app has the proper offline status
function check_status(appId, status)
{
do_check_eq(is_app_offline(appId), status == Ci.nsIAppOfflineInfo.OFFLINE);
}
// Check that the app has the proper offline status
// and that the correct notification has been received
function check_notification_and_status(appId, status) {
do_check_eq(info.appId, appId);
do_check_eq(info.mode, status);
do_check_eq(is_app_offline(appId), status == Ci.nsIAppOfflineInfo.OFFLINE);
}
// Remove the observer from the child process
function finished() {
Services.obs.removeObserver(observer, "network:app-offline-status-changed");
do_check_eq(events_observed_no, 2);
}
-1
View File
@@ -24,7 +24,6 @@
"desktop-notification":{},
"idle":{},
"network-events":{},
"embed-apps":{},
"audio-channel-content":{},
"audio-channel-alarm":{},
"before-after-keyboard-event":{}