diff options
Diffstat (limited to 'browser/components/urlbar/tests/browser-tips/suppress-tips')
5 files changed, 159 insertions, 0 deletions
diff --git a/browser/components/urlbar/tests/browser-tips/suppress-tips/active-update.xml b/browser/components/urlbar/tests/browser-tips/suppress-tips/active-update.xml new file mode 100644 index 0000000000..6e32eb1be2 --- /dev/null +++ b/browser/components/urlbar/tests/browser-tips/suppress-tips/active-update.xml @@ -0,0 +1 @@ +<?xml version="1.0"?><updates xmlns="http://www.mozilla.org/2005/app-update"><update xmlns="http://www.mozilla.org/2005/app-update" appVersion="99999999.0" buildID="20990101111111" channel="test" detailsURL="https://127.0.0.1/" displayVersion="1.0" installDate="1555716429454" isCompleteUpdate="true" name="What's New Page Test" previousAppVersion="60.0" serviceURL="https://127.0.0.1/update.xml" type="minor" platformVersion="99999999.0" actions="showURL" openURL="https://example.com/|https://example.com/"><patch size="1" type="complete" URL="https://127.0.0.1/complete.mar" selected="true" state="pending"/></update></updates> diff --git a/browser/components/urlbar/tests/browser-tips/suppress-tips/browser.toml b/browser/components/urlbar/tests/browser-tips/suppress-tips/browser.toml new file mode 100644 index 0000000000..24c805b2fe --- /dev/null +++ b/browser/components/urlbar/tests/browser-tips/suppress-tips/browser.toml @@ -0,0 +1,24 @@ +# This test environment is copied from "browser/components/tests/browser/whats_new_page/". + +[DEFAULT] +skip-if = [ + "verify", + "os == 'win' && msix", # Updater is disabled in MSIX builds; what's new pages therefore have no meaning. +] +reason = "This is a startup test. Verify runs tests multiple times after startup." +support-files = [ + "../head.js", + "active-update.xml", + "updates/0/update.status", + "config_localhost_update_url.json", +] +prefs = [ + "app.update.altUpdateDirPath='<test-root>/browser/components/urlbar/tests/browser-tips/suppress-tips'", + "app.update.disabledForTesting=false", + "browser.aboutwelcome.enabled=false", + "browser.startup.homepage_override.mstone='60.0'", + "browser.startup.upgradeDialog.enabled=false", + "browser.policies.alternatePath='<test-root>/browser/components/urlbar/tests/browser-tips/suppress-tips/config_localhost_update_url.json'", +] + +["browser_suppressTips.js"] diff --git a/browser/components/urlbar/tests/browser-tips/suppress-tips/browser_suppressTips.js b/browser/components/urlbar/tests/browser-tips/suppress-tips/browser_suppressTips.js new file mode 100644 index 0000000000..44fa912356 --- /dev/null +++ b/browser/components/urlbar/tests/browser-tips/suppress-tips/browser_suppressTips.js @@ -0,0 +1,128 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that the browser tips are suppressed correctly. + +"use strict"; + +/* import-globals-from ../head.js */ + +ChromeUtils.defineESModuleGetters(this, { + LaterRun: "resource:///modules/LaterRun.sys.mjs", + UrlbarProviderSearchTips: + "resource:///modules/UrlbarProviderSearchTips.sys.mjs", +}); + +const LAST_UPDATE_THRESHOLD_HOURS = 24; + +add_setup(async function () { + await PlacesUtils.history.clear(); + + await SpecialPowers.pushPrefEnv({ + set: [ + [ + `browser.urlbar.tipShownCount.${UrlbarProviderSearchTips.TIP_TYPE.ONBOARD}`, + 0, + ], + ], + }); + + registerCleanupFunction(() => { + resetSearchTipsProvider(); + Services.prefs.clearUserPref( + "browser.laterrun.bookkeeping.profileCreationTime" + ); + Services.prefs.clearUserPref( + "browser.laterrun.bookkeeping.updateAppliedTime" + ); + }); +}); + +add_task(async function updateApplied() { + // Check the update time. + Assert.notEqual( + Services.prefs.getIntPref( + "browser.laterrun.bookkeeping.updateAppliedTime", + 0 + ), + 0, + "updateAppliedTime pref should be updated when booting this test" + ); + Assert.equal( + LaterRun.hoursSinceUpdate, + 0, + "LaterRun.hoursSinceUpdate is 0 since one hour should not have passed from starting this test" + ); + + // To not suppress the tip by profile creation. + Services.prefs.setIntPref( + "browser.laterrun.bookkeeping.profileCreationTime", + secondsBasedOnNow(LAST_UPDATE_THRESHOLD_HOURS + 0.5) + ); + + // The test harness will use the current tab and remove the tab's history. + // Since the page that is tested is opened prior to the test harness taking + // over the current tab the active-update.xml specifies two pages to open by + // having 'https://example.com/|https://example.com/' for the value of openURL + // and then uses the first tab for the test. + gBrowser.selectedTab = gBrowser.tabs[0]; + // The test harness also changes the page to about:blank so go back to the + // page that was originally opened. + gBrowser.goBack(); + // Wait for the page to go back to the original page. + await TestUtils.waitForCondition( + () => gBrowser.selectedBrowser?.currentURI?.spec == "https://example.com/", + "Waiting for the expected page to reopen" + ); + gBrowser.removeTab(gBrowser.selectedTab); + + // Check whether the tip is suppressed by update. + await checkTab(window, "about:newtab"); + + // Clean up. + const alternatePath = Services.prefs.getCharPref( + "app.update.altUpdateDirPath" + ); + const testRoot = Services.prefs.getCharPref("mochitest.testRoot"); + let relativePath = alternatePath.substring("<test-root>".length); + if (AppConstants.platform == "win") { + relativePath = relativePath.replace(/\//g, "\\"); + } + const updateDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); + updateDir.initWithPath(testRoot + relativePath); + const updatesFile = updateDir.clone(); + updatesFile.append("updates.xml"); + await TestUtils.waitForCondition( + () => updatesFile.exists(), + "Waiting until the updates.xml file exists" + ); + updatesFile.remove(false); +}); + +add_task(async function profileAge() { + // To not suppress the tip by profile creation and update. + Services.prefs.setIntPref( + "browser.laterrun.bookkeeping.profileCreationTime", + secondsBasedOnNow(LAST_UPDATE_THRESHOLD_HOURS + 0.5) + ); + Services.prefs.setIntPref( + "browser.laterrun.bookkeeping.updateAppliedTime", + secondsBasedOnNow(LAST_UPDATE_THRESHOLD_HOURS + 0.5) + ); + await checkTab( + window, + "about:newtab", + UrlbarProviderSearchTips.TIP_TYPE.ONBOARD + ); + + // To suppress the tip by profile creation. + Services.prefs.setIntPref( + "browser.laterrun.bookkeeping.profileCreationTime", + secondsBasedOnNow() + ); + await checkTab(window, "about:newtab"); +}); + +function secondsBasedOnNow(howManyHoursAgo = 0) { + return Math.floor(Date.now() / 1000 - howManyHoursAgo * 60 * 60); +} diff --git a/browser/components/urlbar/tests/browser-tips/suppress-tips/config_localhost_update_url.json b/browser/components/urlbar/tests/browser-tips/suppress-tips/config_localhost_update_url.json new file mode 100644 index 0000000000..4766b6a3fd --- /dev/null +++ b/browser/components/urlbar/tests/browser-tips/suppress-tips/config_localhost_update_url.json @@ -0,0 +1,5 @@ +{ + "policies": { + "AppUpdateURL": "http://127.0.0.1:8888/update.xml" + } +} diff --git a/browser/components/urlbar/tests/browser-tips/suppress-tips/updates/0/update.status b/browser/components/urlbar/tests/browser-tips/suppress-tips/updates/0/update.status new file mode 100644 index 0000000000..774a5c0df4 --- /dev/null +++ b/browser/components/urlbar/tests/browser-tips/suppress-tips/updates/0/update.status @@ -0,0 +1 @@ +succeeded |