tenfourfox/dom/activities/tests/mochi/test_dev_mode_activity.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

272 lines
7.7 KiB
HTML

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id={1123846}
-->
<head>
<title>Test for Bug {1123846}</title>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript"
src="http://test/chrome/dom/activities/tests/mochi/common.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1123846}">Mozilla Bug {1123846}</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
/**
* Tests the developer mode activities that can only be provided by the
* system app.
*
* We test the following:
* 1) No dev mode, no system app installed (failure).
* 2) No dev mode, system app installed (failure).
* 3) No dev mode, system app and other app installed (failure).
* 4) Dev mode, system app and other app installed (success, only system app returned).
*/
var gGenerator = runTest();
function go() {
SpecialPowers.pushPermissions(
[{ "type": "webapps-manage", "allow": 1, "context": document },
{ "type": "browser", "allow": 1, "context": document },
{ "type": "embed-apps", "allow": 1, "context": document }],
function() {
SpecialPowers.pushPrefEnv(
{'set': [["dom.mozBrowserFramesEnabled", true],
["dom.sysmsg.enabled", true],
["dom.apps.developer_mode", false],
["dom.activities.developer_mode_only", "import-app"]]},
continueTest) });
}
SimpleTest.waitForExplicitFinish();
var systemAppUrl = gRootUrl + "system.webapp";
var otherAppUrl = gRootUrl + "manifest.webapp";
function installApp(aUrl) {
var request = navigator.mozApps.install(aUrl, { });
request.onerror = cbError;
request.onsuccess = continueTest;
return request;
}
function installSystemApp() {
return installApp(systemAppUrl);
}
function installOtherApp() {
return installApp(otherAppUrl);
}
function uninstall(aApp) {
info("Uninstalling " + (aApp ? aApp.manifestURL : "NO APP!!"));
var request = navigator.mozApps.mgmt.uninstall(aApp);
request.onerror = cbError;
request.onsuccess = continueTest;
}
var ActivityGlue = {
// nsISupports implementation.
QueryInterface: function(iid) {
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsIActivityUIGlue)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation.
createInstance: function(outer, iid) {
return this.QueryInterface(iid);
},
// nsIActivityUIGlue implementation.
chooseActivity: function(aOptions, aActivities, aCallback) {
aCallback.handleEvent(Ci.nsIActivityUIGlueCallback.WEBAPPS_ACTIVITY,
aActivities.length == 1 ? 0 : -1);
}
};
var SystemMessageGlue = {
// nsISupports implementation.
QueryInterface: function(iid) {
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsISystemMessageGlue)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation.
createInstance: function(outer, iid) {
return this.QueryInterface(iid);
},
// nsISystemMessageGlue implementation.
openApp(pageURL, manifestURL, type, target, showApp, onlyShowApp, extra) {
// We should only try to open a page in the system app.
is(manifestURL, systemAppUrl, "Opening a page in the system app.");
}
};
registerComponent(ActivityGlue,
"Activity Glue",
"@mozilla.org/dom/activities/ui-glue;1",
ACTIVITY_GLUE_CID);
registerComponent(SystemMessageGlue,
"System Message Glue",
"@mozilla.org/dom/messages/system-message-glue;1",
SYS_MSG_GLUE_CID);
function finish() {
unregisterComponent(ActivityGlue);
unregisterComponent(SystemMessageGlue);
obsService.removeObserver(continueTest, "new-activity-registered-success");
obsService.removeObserver(continueTest, "new-activity-registered-failure");
SimpleTest.finish();
}
function continueTest() {
try {
gGenerator.next();
} catch (e if e instanceof StopIteration) {
finish();
}
}
var obsService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
obsService.addObserver(continueTest, "new-activity-registered-success", false);
obsService.addObserver(continueTest, "new-activity-registered-failure", false);
/**
* Test dev mode activity.
*/
function runTest() {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
// Check how many apps we are starting with.
var request = navigator.mozApps.mgmt.getAll();
request.onerror = cbError;
request.onsuccess = continueTest;
yield undefined;
var initialAppsCount = request.result.length;
info("Starting with " + initialAppsCount + " apps installed.");
// 1) No dev mode, no system app installed (failure).
var activity = new MozActivity({ name: "import-app" });
activity.onerror = function() {
ok(true, "1) No dev mode, no system app installed");
continueTest();
}
activity.onsuccess = unexpectedSuccess("1) No dev mode, no system app installed");
yield undefined;
// 2) No dev mode, system app installed (failure).
// Configure the system app manifest url.
SpecialPowers.pushPrefEnv(
{'set': [["b2g.system_manifest_url", systemAppUrl]]},
continueTest);
yield undefined;
// Install the system app.
request = installSystemApp();
yield undefined;
var systemApp = request.result;
ok(systemApp, "systemApp is non-null");
// yielding for the activity install observer.
yield undefined;
activity = new MozActivity({ name: "import-app" });
activity.onerror = function() {
ok(true, "2) No dev mode, system app installed");
continueTest();
}
activity.onsuccess = unexpectedSuccess("2) No dev mode, system app installed");
yield undefined;
// 3) No dev mode, system app and other app installed (failure).
request = installOtherApp();
yield undefined;
var otherApp = request.result;
ok(otherApp, "otherApp is non-null");
// yielding for the activity install observer.
yield undefined;
activity = new MozActivity({ name: "import-app" });
activity.onerror = function() {
ok(true, "3) No dev mode, system app and other app installed");
continueTest();
}
activity.onsuccess = unexpectedSuccess("3) No dev mode, system app and other app installed");
yield undefined;
// 4) Dev mode, system app and other app installed.
SpecialPowers.pushPrefEnv(
{'set': [["dom.apps.developer_mode", true]]},
continueTest);
yield undefined;
activity = new MozActivity({ name: "import-app" });
activity.onsuccess = function() {
ok(true, "4) Dev mode, system app and other app installed");
continueTest();
}
activity.onerror = function(aEvent) {
ok(false, "4) Got error: " + aEvent.error.name);
finish();
}
yield undefined;
// Cleanup
uninstall(systemApp);
yield undefined;
uninstall(otherApp);
yield undefined;
// Check that we restored the app registry.
request = navigator.mozApps.mgmt.getAll();
request.onerror = cbError;
request.onsuccess = continueTest;
yield undefined;
is(request.result.length, initialAppsCount, "All apps are uninstalled.");
}
addLoadEvent(go);
</script>
</pre>
</body>
</html>