From 5e171cbf09b5dbc9058dbbd6d2edffb1071d8c09 Mon Sep 17 00:00:00 2001 From: Andrei Oprea Date: Mon, 4 Feb 2019 16:38:45 +0100 Subject: [PATCH] Bug 1524593 - (Follow-up) Test fixes nsISearchService changes --- test/unit/lib/SnippetsFeed.test.js | 9 +++++++++ test/unit/lib/TopSitesFeed.test.js | 4 ++-- test/unit/unit-entry.js | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/unit/lib/SnippetsFeed.test.js b/test/unit/lib/SnippetsFeed.test.js index 1568dbfa3..d3d0a370f 100644 --- a/test/unit/lib/SnippetsFeed.test.js +++ b/test/unit/lib/SnippetsFeed.test.js @@ -167,6 +167,15 @@ describe("SnippetsFeed", () => { assert.equal(action.type, at.SNIPPETS_DATA); assert.deepEqual(action.data, {selectedSearchEngine: searchData}); }); + it("should catch errors when calling getVisibleEngines", async () => { + const feed = new SnippetsFeed(); + sandbox.stub(global.Services.search, "getVisibleEngines").rejects(); + + const result = await feed.getSelectedSearchEngine(); + + assert.lengthOf(result.engines, 0); + assert.equal(result.searchEngineIdentifier, ""); + }); it("should call showFirefoxAccounts", () => { const feed = new SnippetsFeed(); const browser = {}; diff --git a/test/unit/lib/TopSitesFeed.test.js b/test/unit/lib/TopSitesFeed.test.js index 14b6fa606..3a402196b 100644 --- a/test/unit/lib/TopSitesFeed.test.js +++ b/test/unit/lib/TopSitesFeed.test.js @@ -1124,7 +1124,7 @@ describe("Top Sites Feed", () => { describe("improvesearch.noDefaultSearchTile experiment", () => { const NO_DEFAULT_SEARCH_TILE_PREF = "improvesearch.noDefaultSearchTile"; beforeEach(() => { - global.Services.search.getDefault = async () => {identifier: "google", searchForm: "google.com"}; + global.Services.search.getDefault = async () => ({identifier: "google", searchForm: "google.com"}); feed.store.state.Prefs.values[NO_DEFAULT_SEARCH_TILE_PREF] = true; }); it("should filter out alexa top 5 search from the default sites", async () => { @@ -1162,7 +1162,7 @@ describe("Top Sites Feed", () => { }); it("should call refresh and set ._currentSearchHostname to the new engine hostname when the the default search engine has been set", () => { sinon.stub(feed, "refresh"); - global.Services.search.getDefault = async () => {identifier: "ddg", searchForm: "duckduckgo.com"}; + sandbox.stub(global.Services.search, "defaultEngine").value({identifier: "ddg", searchForm: "duckduckgo.com"}); feed.observe(null, "browser-search-engine-modified", "engine-current"); assert.equal(feed._currentSearchHostname, "duckduckgo"); assert.calledOnce(feed.refresh); diff --git a/test/unit/unit-entry.js b/test/unit/unit-entry.js index 5acc92faa..0efb2b617 100644 --- a/test/unit/unit-entry.js +++ b/test/unit/unit-entry.js @@ -218,8 +218,8 @@ const TEST_GLOBAL = { }), }, search: { - init(cb) { cb(); }, - getVisibleEngines: () => [{identifier: "google"}, {identifier: "bing"}], + init() { return Promise.resolve(); }, + getVisibleEngines: () => Promise.resolve([{identifier: "google"}, {identifier: "bing"}]), defaultEngine: { identifier: "google", searchForm: "https://www.google.com/search?q=&ie=utf-8&oe=utf-8&client=firefox-b",