Bug 1190586 - UITour should expose if default browser can be set w/o UI on Win8+. r=dolske

This commit is contained in:
Jared Wein 2015-08-19 16:02:54 -04:00
Родитель 960774d138
Коммит a5322fb222
2 изменённых файлов: 50 добавлений и 1 удалений

Просмотреть файл

@ -8,6 +8,7 @@ this.EXPORTED_SYMBOLS = ["UITour", "UITourMetricsProvider"];
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Promise.jsm");
@ -1805,6 +1806,27 @@ this.UITour = {
} }
} catch (e) {} } catch (e) {}
appinfo["defaultBrowser"] = isDefaultBrowser; appinfo["defaultBrowser"] = isDefaultBrowser;
let canSetDefaultBrowserInBackground = true;
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
let prefBranch =
Services.prefs.getBranch("browser.shell.associationHash");
let prefChildren = prefBranch.getChildList("");
canSetDefaultBrowserInBackground = prefChildren.length > 0;
} else if (AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) {
canSetDefaultBrowserInBackground = false;
} else if (AppConstants.platform == "linux") {
// The ShellService may not exist on some versions of Linux.
try {
let shell = aWindow.getShellService();
} catch (e) {
canSetDefaultBrowserInBackground = null;
}
}
appinfo["canSetDefaultBrowserInBackground"] =
canSetDefaultBrowserInBackground;
this.sendPageCallback(aMessageManager, aCallbackID, appinfo); this.sendPageCallback(aMessageManager, aCallbackID, appinfo);
break; break;
case "availableTargets": case "availableTargets":

Просмотреть файл

@ -61,7 +61,34 @@ let tests = [
.getService(Components.interfaces.nsIShellService); .getService(Components.interfaces.nsIShellService);
let isDefault = shell.isDefaultBrowser(false); let isDefault = shell.isDefaultBrowser(false);
gContentAPI.getConfiguration("appinfo", (data) => { gContentAPI.getConfiguration("appinfo", (data) => {
is(data.value, data.defaultBrowser, "gContentAPI result should match shellService.isDefaultBrowser"); is(isDefault, data.defaultBrowser, "gContentAPI result should match shellService.isDefaultBrowser");
done();
});
}),
taskify(function* test_setInBackgroundWhenPrefExists(done) {
Services.prefs.setCharPref("browser.shell.associationHash.http", "ABCDEFG");
gContentAPI.getConfiguration("appinfo", (data) => {
let canSetInBackground = true;
is(canSetInBackground, data.canSetDefaultBrowserInBackground,
"canSetDefaultBrowserInBackground should be true when a hash is present");
Services.prefs.clearUserPref("browser.shell.associationHash.http");
done();
});
}),
taskify(function* test_setInBackgroundWhenPrefDoesntExist(done) {
/* The association hashes are only supported on Windows. */
Cu.import("resource://gre/modules/AppConstants.jsm");
if (AppConstants.platform != "win") {
info("Skipping test_setInBackgroundWhenPrefDoesntExist on non-Windows platform");
return;
}
gContentAPI.getConfiguration("appinfo", (data) => {
let canSetInBackground = false;
is(canSetInBackground, data.canSetDefaultBrowserInBackground,
"canSetDefaultBrowserInBackground should be false when no hashes are present");
done(); done();
}); });
}) })