Commit 10727cff authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1469951 - Update homepage policy to include startpage r=Felipe

Differential Revision: https://phabricator.services.mozilla.com/D8562

--HG--
extra : moz-landing-system : lando
parent 02618be0
......@@ -548,23 +548,41 @@ var Policies = {
// |homepages| will be a string containing a pipe-separated ('|') list of
// URLs because that is what the "Home page" section of about:preferences
// (and therefore what the pref |browser.startup.homepage|) accepts.
let homepages = param.URL.href;
if (param.Additional && param.Additional.length > 0) {
homepages += "|" + param.Additional.map(url => url.href).join("|");
if (param.URL) {
let homepages = param.URL.href;
if (param.Additional && param.Additional.length > 0) {
homepages += "|" + param.Additional.map(url => url.href).join("|");
}
if (param.Locked) {
setAndLockPref("browser.startup.homepage", homepages);
setAndLockPref("pref.browser.homepage.disable_button.current_page", true);
setAndLockPref("pref.browser.homepage.disable_button.bookmark_page", true);
setAndLockPref("pref.browser.homepage.disable_button.restore_default", true);
} else {
setDefaultPref("browser.startup.homepage", homepages);
runOncePerModification("setHomepage", homepages, () => {
Services.prefs.clearUserPref("browser.startup.homepage");
});
}
}
if (param.Locked) {
setAndLockPref("browser.startup.homepage", homepages);
setAndLockPref("browser.startup.page", 1);
setAndLockPref("pref.browser.homepage.disable_button.current_page", true);
setAndLockPref("pref.browser.homepage.disable_button.bookmark_page", true);
setAndLockPref("pref.browser.homepage.disable_button.restore_default", true);
} else {
setDefaultPref("browser.startup.homepage", homepages);
setDefaultPref("browser.startup.page", 1);
runOncePerModification("setHomepage", homepages, () => {
Services.prefs.clearUserPref("browser.startup.homepage");
Services.prefs.clearUserPref("browser.startup.page");
});
if (param.StartPage) {
let prefValue;
switch (param.StartPage) {
case "none":
prefValue = 0;
break;
case "homepage":
prefValue = 1;
break;
case "previous-session":
prefValue = 3;
break;
}
if (param.Locked) {
setAndLockPref("browser.startup.page", prefValue);
} else {
setDefaultPref("browser.startup.page", prefValue);
}
}
},
},
......
......@@ -348,9 +348,12 @@
"items": {
"type": "URL"
}
},
"StartPage": {
"type": "string",
"enum": ["none", "homepage", "previous-session"]
}
},
"required": ["URL"]
}
},
"InstallAddonsPermission": {
......
......@@ -10,31 +10,41 @@ registerCleanupFunction(function restore_pref_values() {
// option from this policy was not used. In this case, it won't
// be tracked nor restored by the PoliciesPrefTracker.
Services.prefs.clearUserPref("browser.startup.homepage");
Services.prefs.clearUserPref("browser.startup.page");
});
async function check_homepage({expectedURL, expectedPageVal = 1, locked = false}) {
is(HomePage.get(),
expectedURL, "Homepage URL should match expected");
is(Services.prefs.getIntPref("browser.startup.page", -1), expectedPageVal,
"Pref page value should match expected");
is(Services.prefs.prefIsLocked("browser.startup.homepage"), locked,
"Lock status of browser.startup.homepage should match expected");
is(Services.prefs.prefIsLocked("browser.startup.page"), locked,
"Lock status of browser.startup.page should match expected");
async function check_homepage({expectedURL, expectedPageVal = -1, locked = false}) {
if (expectedURL) {
is(HomePage.get(),
expectedURL, "Homepage URL should match expected");
is(Services.prefs.prefIsLocked("browser.startup.homepage"), locked,
"Lock status of browser.startup.homepage should match expected");
}
if (expectedPageVal != -1) {
is(Services.prefs.getIntPref("browser.startup.page", -1), expectedPageVal,
"Pref page value should match expected");
is(Services.prefs.prefIsLocked("browser.startup.page"), locked,
"Lock status of browser.startup.page should match expected");
}
// Test that UI is disabled when the Locked property is enabled
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
await ContentTask.spawn(tab.linkedBrowser, {expectedURL, expectedPageVal, locked},
// eslint-disable-next-line no-shadow
async function({expectedURL, expectedPageVal, locked}) {
let browserRestoreSessionCheckbox = content.document.getElementById("browserRestoreSession");
is(browserRestoreSessionCheckbox.disabled, locked,
"Disabled status of session restore status should match expected");
let shouldBeChecked = expectedPageVal === 3;
is(browserRestoreSessionCheckbox.checked, shouldBeChecked,
"Session restore status checkbox should be: " + (shouldBeChecked ? "checked" : "unchecked"));
if (expectedPageVal != -1) {
// Only check restore checkbox for StartPage
let browserRestoreSessionCheckbox = content.document.getElementById("browserRestoreSession");
is(browserRestoreSessionCheckbox.disabled, locked,
"Disabled status of session restore status should match expected");
let shouldBeChecked = expectedPageVal === 3;
is(browserRestoreSessionCheckbox.checked, shouldBeChecked,
"Session restore status checkbox should be: " + (shouldBeChecked ? "checked" : "unchecked"));
}
if (!expectedURL) {
// If only StartPage was changed, no need to check these
return;
}
content.document.getElementById("category-home").click();
let homepageTextbox = content.document.getElementById("homePageUrl");
......@@ -88,6 +98,7 @@ add_task(async function homepage_test_repeat_same_policy_value() {
});
await check_homepage({expectedURL: "http://example2.com/",
expectedPageVal: 3});
Services.prefs.clearUserPref("browser.startup.page");
});
add_task(async function homepage_test_different_policy_value() {
......@@ -165,3 +176,74 @@ add_task(async function homepage_test_anchor_link() {
});
await check_homepage({expectedURL: "http://example1.com/#test"});
});
add_task(async function homepage_test_startpage_homepage() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"URL": "http://example1.com/#test",
"StartPage": "homepage",
},
},
});
await check_homepage({expectedURL: "http://example1.com/#test", expectedPageVal: 1});
});
add_task(async function homepage_test_startpage_homepage_locked() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"URL": "http://example1.com/#test",
"StartPage": "homepage",
"Locked": true,
},
},
});
await check_homepage({expectedURL: "http://example1.com/#test", expectedPageVal: 1, locked: true});
});
add_task(async function homepage_test_startpage_none() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"StartPage": "none",
},
},
});
await check_homepage({expectedPageVal: 0});
});
add_task(async function homepage_test_startpage_none_locked() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"StartPage": "none",
"Locked": true,
},
},
});
await check_homepage({expectedPageVal: 0, locked: true});
});
add_task(async function homepage_test_startpage_restore() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"StartPage": "previous-session",
},
},
});
await check_homepage({expectedPageVal: 3});
});
add_task(async function homepage_test_startpage_restore_locked() {
await setupPolicyEngineWithJson({
"policies": {
"Homepage": {
"StartPage": "previous-session",
"Locked": true,
},
},
});
await check_homepage({expectedPageVal: 3, locked: true});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment