Commit dcd325ee authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1500379 - Split homepage test into two tests. r=mconley

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

--HG--
extra : moz-landing-system : lando
parent 0633976e
...@@ -47,5 +47,6 @@ skip-if = (verify && debug && (os == 'mac')) ...@@ -47,5 +47,6 @@ skip-if = (verify && debug && (os == 'mac'))
[browser_policy_search_engine.js] [browser_policy_search_engine.js]
[browser_policy_searchbar.js] [browser_policy_searchbar.js]
[browser_policy_set_homepage.js] [browser_policy_set_homepage.js]
[browser_policy_set_startpage.js]
[browser_policy_support_menu.js] [browser_policy_support_menu.js]
[browser_policy_websitefilter.js] [browser_policy_websitefilter.js]
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */ * http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict"; "use strict";
ChromeUtils.defineModuleGetter(
this,
"HomePage",
"resource:///modules/HomePage.jsm"
);
registerCleanupFunction(function restore_pref_values() { registerCleanupFunction(function restore_pref_values() {
// These two prefs are set as user prefs in case the "Locked" // These two prefs are set as user prefs in case the "Locked"
// option from this policy was not used. In this case, it won't // option from this policy was not used. In this case, it won't
...@@ -15,109 +9,6 @@ registerCleanupFunction(function restore_pref_values() { ...@@ -15,109 +9,6 @@ registerCleanupFunction(function restore_pref_values() {
Services.prefs.clearUserPref("browser.startup.homepage"); Services.prefs.clearUserPref("browser.startup.homepage");
}); });
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 }) {
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;
}
await content.gotoPref("paneHome");
let homepageTextbox = content.document.getElementById("homePageUrl");
// Unfortunately this test does not work because the new UI does not fill
// default values into the URL box at the moment.
// is(homepageTextbox.value, expectedURL,
// "Homepage URL should match expected");
// Wait for rendering to be finished
await ContentTaskUtils.waitForCondition(
() =>
content.document.getElementById("useCurrentBtn").disabled === locked
);
is(
homepageTextbox.disabled,
locked,
"Homepage URL text box disabled status should match expected"
);
is(
content.document.getElementById("homeMode").disabled,
locked,
"Home mode drop down disabled status should match expected"
);
is(
content.document.getElementById("useCurrentBtn").disabled,
locked,
'"Use current page" button disabled status should match expected'
);
is(
content.document.getElementById("useBookmarkBtn").disabled,
locked,
'"Use bookmark" button disabled status should match expected'
);
is(
content.document.getElementById("restoreDefaultHomePageBtn").disabled,
locked,
'"Restore defaults" button disabled status should match expected'
);
}
);
await BrowserTestUtils.removeTab(tab);
}
add_task(async function homepage_test_simple() { add_task(async function homepage_test_simple() {
await setupPolicyEngineWithJson({ await setupPolicyEngineWithJson({
policies: { policies: {
...@@ -222,81 +113,3 @@ add_task(async function homepage_test_anchor_link() { ...@@ -222,81 +113,3 @@ add_task(async function homepage_test_anchor_link() {
}); });
await check_homepage({ expectedURL: "http://example1.com/#test" }); 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 });
});
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function setup() {
// browser.startup.page is set by unittest-required/user.js,
// but we need the default value
await SpecialPowers.pushPrefEnv({
clear: [["browser.startup.page"]],
});
});
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 });
});
...@@ -13,6 +13,12 @@ const { TestUtils } = ChromeUtils.import( ...@@ -13,6 +13,12 @@ const { TestUtils } = ChromeUtils.import(
null null
); );
ChromeUtils.defineModuleGetter(
this,
"HomePage",
"resource:///modules/HomePage.jsm"
);
PoliciesPrefTracker.start(); PoliciesPrefTracker.start();
async function setupPolicyEngineWithJson(json, customSchema) { async function setupPolicyEngineWithJson(json, customSchema) {
...@@ -59,6 +65,109 @@ async function checkBlockedPage(url, expectedBlocked) { ...@@ -59,6 +65,109 @@ async function checkBlockedPage(url, expectedBlocked) {
); );
} }
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 }) {
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;
}
await content.gotoPref("paneHome");
let homepageTextbox = content.document.getElementById("homePageUrl");
// Unfortunately this test does not work because the new UI does not fill
// default values into the URL box at the moment.
// is(homepageTextbox.value, expectedURL,
// "Homepage URL should match expected");
// Wait for rendering to be finished
await ContentTaskUtils.waitForCondition(
() =>
content.document.getElementById("useCurrentBtn").disabled === locked
);
is(
homepageTextbox.disabled,
locked,
"Homepage URL text box disabled status should match expected"
);
is(
content.document.getElementById("homeMode").disabled,
locked,
"Home mode drop down disabled status should match expected"
);
is(
content.document.getElementById("useCurrentBtn").disabled,
locked,
'"Use current page" button disabled status should match expected'
);
is(
content.document.getElementById("useBookmarkBtn").disabled,
locked,
'"Use bookmark" button disabled status should match expected'
);
is(
content.document.getElementById("restoreDefaultHomePageBtn").disabled,
locked,
'"Restore defaults" button disabled status should match expected'
);
}
);
await BrowserTestUtils.removeTab(tab);
}
add_task(async function policies_headjs_startWithCleanSlate() { add_task(async function policies_headjs_startWithCleanSlate() {
if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) { if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) {
await setupPolicyEngineWithJson(""); await setupPolicyEngineWithJson("");
......
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