gecko/dom/tests/mochitest/webapps/file_bug_779982.js
Patrick Wang 2cfef0b277 Bug 777384 - Test case r=jlebar
--HG--
extra : rebase_source : 777580f0a22bfb3d9d447097b0f4a379f2b7416b
2012-09-27 01:47:57 +08:00

128 lines
3.5 KiB
JavaScript

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);
}
SimpleTest.waitForExplicitFinish();
makeAllAppsLaunchable();
var fileTestOnCurrentOrigin = 'http://example.org/tests/dom/tests/mochitest/webapps/file_bug_779982.html';
var previousPrefs = {
mozBrowserFramesEnabled: undefined,
oop_by_default: undefined,
};
try {
previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
} catch(e)
{
}
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
SpecialPowers.addPermission("browser", true, window.document);
SpecialPowers.addPermission("embed-apps", true, window.document);
var gData = [
// APP 1
{
app: 'http://example.org/manifest.webapp',
action: 'getSelf',
isnull: false,
src: fileTestOnCurrentOrigin,
message: 'getSelf() for app should return something'
},
{
app: 'http://example.org/manifest.webapp',
action: 'checkInstalled',
isnull: false,
src: fileTestOnCurrentOrigin,
message: 'checkInstalled() for app should return true'
},
{
app: 'http://example.org/manifest.webapp',
action: 'checkInstalledWrong',
isnull: true,
src: fileTestOnCurrentOrigin,
message: 'checkInstalled() for browser should return true'
},
// Browser
{
browser: true,
action: 'getSelf',
isnull: true,
src: fileTestOnCurrentOrigin,
message: 'getSelf() for browser should return null'
},
{
browser: true,
action: 'checkInstalled',
isnull: false,
src: fileTestOnCurrentOrigin,
message: 'checkInstalled() for browser should return true'
},
{
browser: true,
action: 'checkInstalledWrong',
isnull: true,
src: fileTestOnCurrentOrigin,
message: 'checkInstalled() for browser should return true'
},
];
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', data.message);
i++;
if (i >= gData.length) {
if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
}
SpecialPowers.removePermission("browser", window.document);
SpecialPowers.removePermission("embed-apps", window.document);
SimpleTest.finish();
} else {
gTestRunner.next();
}
});
}
iframe.src = data.src + '?' + data.action + '&' + data.isnull;
document.getElementById('content').appendChild(iframe);
yield;
}
}
var gTestRunner = runTest();
gTestRunner.next();