/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ // Tests that the newtab and the handoff search bar take turns // registering as New Tab's search component, depending on the urlbar's newtab // feature gate. "use strict"; const { AboutNewTabComponentRegistry } = ChromeUtils.importESModule( "moz-src:///browser/components/newtab/AboutNewTabComponents.sys.mjs" ); function searchComponentOf(registry) { return registry.values.find( config => config.type == AboutNewTabComponentRegistry.TYPES.SEARCH ); } async function setFeatureGate(registry, enabled) { let updated = registry.once(AboutNewTabComponentRegistry.UPDATED_EVENT); UrlbarPrefs.set("newtab.featureGate", enabled); await updated; } add_task(async function test_featureGate() { UrlbarPrefs.set("newtab.featureGate", false); let registry = new AboutNewTabComponentRegistry(); registerCleanupFunction(() => { registry.destroy(); Services.prefs.clearUserPref("browser.urlbar.newtab.featureGate"); }); Assert.equal( searchComponentOf(registry).tagName, "content-search-handoff-ui", "The handoff search bar is registered while the feature gate is disabled" ); await setFeatureGate(registry, true); let component = searchComponentOf(registry); Assert.equal( component.tagName, "moz-urlbar", " supersedes the handoff search bar once the gate is enabled" ); Assert.equal( component.componentURL, "chrome://browser/content/urlbar/UrlbarInput.mjs", " is delivered from the module that defines it" ); Assert.equal( component.attributes["sap-name"], "newtab_searchbar", " reports the newtab search access point" ); await setFeatureGate(registry, false); Assert.equal( searchComponentOf(registry).tagName, "content-search-handoff-ui", "The handoff search bar comes back once the gate is disabled again" ); }); add_task(async function test_nimbusRollout() { UrlbarPrefs.set("newtab.featureGate", false); let registry = new AboutNewTabComponentRegistry(); registerCleanupFunction(() => { registry.destroy(); Services.prefs.clearUserPref("browser.urlbar.newtab.featureGate"); }); Assert.equal( searchComponentOf(registry).tagName, "content-search-handoff-ui", "The handoff search bar is registered while the gate is disabled" ); let updated = registry.once(AboutNewTabComponentRegistry.UPDATED_EVENT); let unenroll = await UrlbarTestUtils.initNimbusFeature({ newtabFeatureGate: true, }); await updated; Assert.equal( searchComponentOf(registry).tagName, "moz-urlbar", "A Nimbus rollout enables over the disabled pref" ); updated = registry.once(AboutNewTabComponentRegistry.UPDATED_EVENT); await unenroll(); await updated; Assert.equal( searchComponentOf(registry).tagName, "content-search-handoff-ui", "The handoff search bar comes back once the rollout ends" ); });