tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_search_notification.js (1578B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const { SearchTestUtils } = ChromeUtils.importESModule(
      5  "resource://testing-common/SearchTestUtils.sys.mjs"
      6 );
      7 
      8 SearchTestUtils.init(this);
      9 
     10 add_task(async function () {
     11  // Our search would be handled by the urlbar normally and not by the docshell,
     12  // thus we must force going through dns first, so that the urlbar thinks
     13  // the value may be a url, and asks the docshell to visit it.
     14  // On NS_ERROR_UNKNOWN_HOST the docshell will fix it up.
     15  await SpecialPowers.pushPrefEnv({
     16    set: [["browser.fixup.dns_first_for_single_words", true]],
     17  });
     18  const kSearchEngineID = "test_urifixup_search_engine";
     19  await SearchTestUtils.installSearchExtension(
     20    {
     21      name: kSearchEngineID,
     22      search_url: "http://localhost/",
     23      search_url_get_params: "search={searchTerms}",
     24    },
     25    { setAsDefault: true }
     26  );
     27 
     28  let selectedName = (await Services.search.getDefault()).name;
     29  Assert.equal(
     30    selectedName,
     31    kSearchEngineID,
     32    "Check fake search engine is selected"
     33  );
     34 
     35  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     36  gBrowser.selectedTab = tab;
     37 
     38  gURLBar.value = "firefox";
     39  gURLBar.handleCommand();
     40 
     41  let [subject, data] = await TestUtils.topicObserved("keyword-search");
     42 
     43  let engine = subject.QueryInterface(Ci.nsISupportsString).data;
     44 
     45  Assert.equal(engine, kSearchEngineID, "Should be the search engine id");
     46  Assert.equal(data, "firefox", "Notification data is search term.");
     47 
     48  gBrowser.removeTab(tab);
     49 });