mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 993326 - Use SpecialPowers.autoConfirmAppInstall to confirm app installation and stop using the browser.mozApps.installer.dry_run pref. r=fabrice
This commit is contained in:
parent
1bd0344246
commit
aa366669d4
@ -48,24 +48,6 @@ var permManager = Cc["@mozilla.org/permissionmanager;1"]
|
||||
var appsService = Cc['@mozilla.org/AppsService;1']
|
||||
.getService(Ci.nsIAppsService);
|
||||
|
||||
/**
|
||||
* This function will make sure that the next applications we try to install
|
||||
* will be installed. That means it will behave like if the user allowed the app
|
||||
* to be installed in the door hanger.
|
||||
*/
|
||||
function confirmNextInstall() {
|
||||
var panel = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler.ownerDocument.defaultView
|
||||
.PopupNotifications.panel
|
||||
|
||||
panel.addEventListener("popupshown", function() {
|
||||
panel.removeEventListener("popupshown", arguments.callee, false);
|
||||
this.childNodes[0].button.doCommand();
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the |storage| that has been given with "foo" => "bar".
|
||||
* Checks that the storage wasn't initialized and checks that the initialization
|
||||
@ -83,25 +65,15 @@ permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
permManager.addFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
var previousPrefs = {
|
||||
mozBrowserFramesEnabled: null,
|
||||
installerDryRun: null,
|
||||
};
|
||||
SimpleTest.registerCleanupFunction(() => {
|
||||
gWitnessStorage.localStorage.clear();
|
||||
gWitnessStorage.sessionStorage.clear();
|
||||
|
||||
// Save the prefs we want to change (so we can re-set them later) and set them
|
||||
// to the needed value.
|
||||
try {
|
||||
previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
|
||||
} catch(e)
|
||||
{
|
||||
}
|
||||
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
|
||||
|
||||
try {
|
||||
previousPrefs.installerDryRun = SpecialPowers.getBoolPref('browser.mozApps.installer.dry_run');
|
||||
} catch(e) {
|
||||
}
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', true);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
});
|
||||
|
||||
// URL of the manifest of the app we want to install.
|
||||
const gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
||||
@ -116,7 +88,7 @@ var gAppStorage = {};
|
||||
// Storage for a mozbrowser inside the app.
|
||||
var gBrowserStorage = {};
|
||||
|
||||
addLoadEvent(function() {
|
||||
function runTest() {
|
||||
/*
|
||||
* We are setuping the witness storage (non-app) and will install the
|
||||
* application.
|
||||
@ -124,8 +96,6 @@ addLoadEvent(function() {
|
||||
* for the load event. to be fired.
|
||||
*/
|
||||
|
||||
confirmNextInstall();
|
||||
|
||||
gWitnessStorage.localStorage = window.frames[0].localStorage;
|
||||
gWitnessStorage.sessionStorage = window.frames[0].sessionStorage;
|
||||
|
||||
@ -145,7 +115,7 @@ addLoadEvent(function() {
|
||||
|
||||
document.body.appendChild(frame);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function appFrameLoadEvent() {
|
||||
/*
|
||||
@ -202,7 +172,7 @@ function browserLoadEvent() {
|
||||
is(gWitnessStorage.localStorage.getItem("foo"), "bar", "data are still there");
|
||||
is(gWitnessStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
|
||||
|
||||
finish();
|
||||
SimpleTest.finish();
|
||||
|
||||
return;
|
||||
};
|
||||
@ -211,24 +181,11 @@ function browserLoadEvent() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when the test will be done. It is going to clear
|
||||
* all storage data, permissions, etc.
|
||||
*/
|
||||
function finish() {
|
||||
gWitnessStorage.localStorage.clear();
|
||||
gWitnessStorage.sessionStorage.clear();
|
||||
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', previousPrefs.installerDryRun);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addLoadEvent(() =>
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.mozBrowserFramesEnabled', true]]}, () =>
|
||||
SpecialPowers.autoConfirmAppInstall(runTest)
|
||||
)
|
||||
);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
@ -49,27 +49,6 @@ var permManager = Cc["@mozilla.org/permissionmanager;1"]
|
||||
var appsService = Cc['@mozilla.org/AppsService;1']
|
||||
.getService(Ci.nsIAppsService);
|
||||
|
||||
var Webapps = {};
|
||||
Cu.import("resource://gre/modules/Webapps.jsm", Webapps);
|
||||
|
||||
/**
|
||||
* This function will make sure that the next applications we try to install
|
||||
* will be installed. That means it will behave like if the user allowed the app
|
||||
* to be installed in the door hanger.
|
||||
*/
|
||||
function confirmNextInstall() {
|
||||
var panel = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler.ownerDocument.defaultView
|
||||
.PopupNotifications.panel
|
||||
|
||||
panel.addEventListener("popupshown", function() {
|
||||
panel.removeEventListener("popupshown", arguments.callee, false);
|
||||
this.childNodes[0].button.doCommand();
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the |storage| that has been given with "foo" => "bar".
|
||||
* Checks that the storage wasn't initialized and checks that the initialization
|
||||
@ -87,29 +66,18 @@ permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
permManager.addFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
var previousPrefs = {
|
||||
mozBrowserFramesEnabled: null,
|
||||
installerDryRun: null,
|
||||
};
|
||||
SimpleTest.registerCleanupFunction(() => {
|
||||
gWitnessStorage.localStorage.clear();
|
||||
gWitnessStorage.sessionStorage.clear();
|
||||
|
||||
// Save the prefs we want to change (so we can re-set them later) and set them
|
||||
// to the needed value.
|
||||
try {
|
||||
previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
|
||||
} catch(e)
|
||||
{
|
||||
}
|
||||
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
|
||||
|
||||
try {
|
||||
previousPrefs.installerDryRun = SpecialPowers.getBoolPref('browser.mozApps.installer.dry_run');
|
||||
} catch(e) {
|
||||
}
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', true);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
});
|
||||
|
||||
// We want to simulate that all apps are launchable, for testing purpose.
|
||||
var gPreviousLaunchableValue = Webapps.DOMApplicationRegistry.allAppsLaunchable;
|
||||
Webapps.DOMApplicationRegistry.allAppsLaunchable = true;
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
|
||||
// URL of the manifest of the app we want to install.
|
||||
const gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
||||
@ -124,7 +92,7 @@ var gAppStorage = {};
|
||||
// Storage for a mozbrowser inside the app.
|
||||
var gBrowserStorage = {};
|
||||
|
||||
addLoadEvent(function() {
|
||||
function runTest() {
|
||||
/*
|
||||
* We are setuping the witness storage (non-app) and will install the
|
||||
* application.
|
||||
@ -132,8 +100,6 @@ addLoadEvent(function() {
|
||||
* for the load event. to be fired.
|
||||
*/
|
||||
|
||||
confirmNextInstall();
|
||||
|
||||
gWitnessStorage.localStorage = window.frames[0].localStorage;
|
||||
gWitnessStorage.sessionStorage = window.frames[0].sessionStorage;
|
||||
|
||||
@ -153,7 +119,7 @@ addLoadEvent(function() {
|
||||
|
||||
document.body.appendChild(frame);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function appFrameLoadEvent() {
|
||||
/*
|
||||
@ -219,35 +185,20 @@ function checks() {
|
||||
is(gWitnessStorage.localStorage.getItem("foo"), "bar", "data are still there");
|
||||
is(gWitnessStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
|
||||
|
||||
Webapps.DOMApplicationRegistry.allAppsLaunchable = gPreviousLaunchableValue;
|
||||
|
||||
// Now we uninstall the app and make sure everything is clean.
|
||||
navigator.mozApps.mgmt.uninstall(app).onsuccess = function() {
|
||||
finish();
|
||||
SimpleTest.finish();
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when the test will be done. It is going to clear
|
||||
* all storage data, permissions, etc.
|
||||
*/
|
||||
function finish() {
|
||||
gWitnessStorage.localStorage.clear();
|
||||
gWitnessStorage.sessionStorage.clear();
|
||||
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', previousPrefs.installerDryRun);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addLoadEvent(() =>
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.mozBrowserFramesEnabled', true]]}, () =>
|
||||
SpecialPowers.autoConfirmAppInstall(runTest)
|
||||
)
|
||||
);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
@ -50,35 +50,6 @@ var cookies = [
|
||||
];
|
||||
var counter = 0;
|
||||
|
||||
function confirmNextInstall() {
|
||||
var panel = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler.ownerDocument.defaultView
|
||||
.PopupNotifications.panel
|
||||
|
||||
panel.addEventListener("popupshown", function() {
|
||||
panel.removeEventListener("popupshown", arguments.callee, false);
|
||||
this.childNodes[0].button.doCommand();
|
||||
}, false);
|
||||
}
|
||||
|
||||
// If aAppId = -1, returns permissions count, regardless of app.
|
||||
function getPermissionCountForApp(aAppId) {
|
||||
var nbPermissions = 0;
|
||||
var enumerator = permManager.enumerator;
|
||||
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
|
||||
if (permission.appId == aAppId || aAppId == -1) {
|
||||
nbPermissions++;
|
||||
}
|
||||
}
|
||||
|
||||
return nbPermissions;
|
||||
}
|
||||
|
||||
function getCookiesCountForApp(aAppId) {
|
||||
var nbCookies = 0;
|
||||
var enumerator = cookieMng.getCookiesForApp(aAppId, false);
|
||||
@ -145,29 +116,20 @@ function setNextCookie(request, data, context) {
|
||||
}
|
||||
}
|
||||
|
||||
var previousDryRunValue = null;
|
||||
try {
|
||||
previousDryRunValue = SpecialPowers.getBoolPref('browser.mozApps.installer.dry_run');
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', true);
|
||||
|
||||
var previousCookiePrefValue = SpecialPowers.getIntPref('network.cookie.cookieBehavior');
|
||||
|
||||
SpecialPowers.setIntPref('network.cookie.cookieBehavior', 0);
|
||||
|
||||
permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
var gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
||||
SimpleTest.registerCleanupFunction(() =>
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION)
|
||||
);
|
||||
|
||||
confirmNextInstall();
|
||||
var gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
||||
|
||||
var gTestAppId = 0;
|
||||
var gCurrentCookiesCount = 0;
|
||||
|
||||
navigator.mozApps.install(gManifestURL, null).onsuccess = function() {
|
||||
function onInstall() {
|
||||
gTestAppId = appsService.getAppLocalIdByManifestURL(gManifestURL);
|
||||
|
||||
cookies[0].loadContext = new LoadContextCallback(gTestAppId, false, false, 1);
|
||||
@ -180,7 +142,7 @@ navigator.mozApps.install(gManifestURL, null).onsuccess = function() {
|
||||
httpserver.start(4444);
|
||||
|
||||
setCookie();
|
||||
};
|
||||
}
|
||||
|
||||
function checkCookie() {
|
||||
var appCookiesCount = getCookiesCountForApp(gTestAppId);
|
||||
@ -199,22 +161,20 @@ function checkCookie() {
|
||||
is(getCookiesCount(), gCurrentCookiesCount,
|
||||
"Number of cookies should not have changed");
|
||||
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', previousDryRunValue);
|
||||
SpecialPowers.setIntPref('network.cookie.cookieBehavior', previousCookiePrefValue);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
httpserver.stop(function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
return;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SpecialPowers.pushPrefEnv({set: [['network.cookie.cookieBehavior', 0]]}, () =>
|
||||
SpecialPowers.autoConfirmAppInstall(() =>
|
||||
navigator.mozApps.install(gManifestURL, null).onsuccess = onInstall
|
||||
)
|
||||
);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
@ -34,19 +34,6 @@ var secMan = Cc['@mozilla.org/scriptsecuritymanager;1']
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
function confirmNextInstall() {
|
||||
var panel = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler.ownerDocument.defaultView
|
||||
.PopupNotifications.panel
|
||||
|
||||
panel.addEventListener("popupshown", function() {
|
||||
panel.removeEventListener("popupshown", arguments.callee, false);
|
||||
this.childNodes[0].button.doCommand();
|
||||
}, false);
|
||||
}
|
||||
|
||||
// If aAppId = -1, returns permissions count, regardless of app.
|
||||
function getPermissionCountForApp(aAppId) {
|
||||
var nbPermissions = 0;
|
||||
@ -63,21 +50,17 @@ function getPermissionCountForApp(aAppId) {
|
||||
return nbPermissions;
|
||||
}
|
||||
|
||||
var previousDryRunValue = null;
|
||||
try {
|
||||
previousDryRunValue = SpecialPowers.getBoolPref('browser.mozApps.installer.dry_run');
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', true);
|
||||
permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
SimpleTest.registerCleanupFunction(() =>
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION)
|
||||
);
|
||||
|
||||
var gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
||||
|
||||
confirmNextInstall();
|
||||
|
||||
navigator.mozApps.install(gManifestURL, null).onsuccess = function() {
|
||||
function onInstall() {
|
||||
var testAppId = appsService.getAppLocalIdByManifestURL(gManifestURL);
|
||||
|
||||
is(getPermissionCountForApp(testAppId), 0, "App should have no permission");
|
||||
@ -112,16 +95,16 @@ navigator.mozApps.install(gManifestURL, null).onsuccess = function() {
|
||||
is(getPermissionCountForApp(-1), currentPermissionCount,
|
||||
"Number of permissions should not have changed");
|
||||
|
||||
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', previousDryRunValue);
|
||||
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
SpecialPowers.autoConfirmAppInstall(() =>
|
||||
navigator.mozApps.install(gManifestURL, null).onsuccess = onInstall
|
||||
);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
Loading…
Reference in New Issue
Block a user