From c1a3be3fdc3b609cb9df8ebee5731b34b8214210 Mon Sep 17 00:00:00 2001 From: Ed Lee Date: Thu, 8 Jun 2017 16:44:38 -0700 Subject: [PATCH] Bug 1371479 - Update search behavior about:newtab tests to work with activity-stream.enabled true and false. r=ursula Update tests to select the search input for either about:newtab with a querySelector instead of specific id. Also removes gSearch checks that are always false anyway with the move to e10s contentSearch. MozReview-Commit-ID: 8knCvfzA6yk --HG-- extra : rebase_source : 484dd855dd96e587dbc1a61bf53fdad3759a7caf --- .../search/test/browser_amazon_behavior.js | 29 +++++++++---------- .../search/test/browser_bing_behavior.js | 29 +++++++++---------- .../search/test/browser_ddg_behavior.js | 29 +++++++++---------- .../search/test/browser_google_behavior.js | 29 +++++++++---------- .../search/test/browser_yahoo_behavior.js | 29 +++++++++---------- 5 files changed, 65 insertions(+), 80 deletions(-) diff --git a/browser/components/search/test/browser_amazon_behavior.js b/browser/components/search/test/browser_amazon_behavior.js index 1ced3a515b71..e39b5461481b 100644 --- a/browser/components/search/test/browser_amazon_behavior.js +++ b/browser/components/search/test/browser_amazon_behavior.js @@ -76,8 +76,10 @@ function test() { function doSearch(doc) { // Re-add the listener, and perform a search gBrowser.addProgressListener(listener); - doc.getElementById("newtab-search-text").value = "foo"; - doc.getElementById("newtab-search-submit").click(); + let input = doc.querySelector("input[id*=search-]"); + input.focus(); + input.value = "foo"; + EventUtils.synthesizeKey("VK_RETURN", {}); } // load about:newtab, but remove the listener first so it doesn't @@ -95,20 +97,15 @@ function test() { // Observe page setup let win = gBrowser.contentWindowAsCPOW; - if (win.gSearch.currentEngineName == - Services.search.currentEngine.name) { - doSearch(win.document); - } else { - info("Waiting for newtab search init"); - win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { - info("Got newtab search event " + contentSearchServiceEvent.detail.type); - if (contentSearchServiceEvent.detail.type == "State") { - win.removeEventListener("ContentSearchService", done); - // Let gSearch respond to the event before continuing. - executeSoon(() => doSearch(win.document)); - } - }); - } + info("Waiting for newtab search init"); + win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { + info("Got newtab search event " + contentSearchServiceEvent.detail.type); + if (contentSearchServiceEvent.detail.type == "State") { + win.removeEventListener("ContentSearchService", done); + // Let gSearch respond to the event before continuing. + executeSoon(() => doSearch(win.document)); + } + }); }, true); } } diff --git a/browser/components/search/test/browser_bing_behavior.js b/browser/components/search/test/browser_bing_behavior.js index 03e9dc5bcd17..bbde6ec7c979 100644 --- a/browser/components/search/test/browser_bing_behavior.js +++ b/browser/components/search/test/browser_bing_behavior.js @@ -76,8 +76,10 @@ function test() { function doSearch(doc) { // Re-add the listener, and perform a search gBrowser.addProgressListener(listener); - doc.getElementById("newtab-search-text").value = "foo"; - doc.getElementById("newtab-search-submit").click(); + let input = doc.querySelector("input[id*=search-]"); + input.focus(); + input.value = "foo"; + EventUtils.synthesizeKey("VK_RETURN", {}); } // load about:newtab, but remove the listener first so it doesn't @@ -95,20 +97,15 @@ function test() { // Observe page setup let win = gBrowser.contentWindowAsCPOW; - if (win.gSearch.currentEngineName == - Services.search.currentEngine.name) { - doSearch(win.document); - } else { - info("Waiting for newtab search init"); - win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { - info("Got newtab search event " + contentSearchServiceEvent.detail.type); - if (contentSearchServiceEvent.detail.type == "State") { - win.removeEventListener("ContentSearchService", done); - // Let gSearch respond to the event before continuing. - executeSoon(() => doSearch(win.document)); - } - }); - } + info("Waiting for newtab search init"); + win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { + info("Got newtab search event " + contentSearchServiceEvent.detail.type); + if (contentSearchServiceEvent.detail.type == "State") { + win.removeEventListener("ContentSearchService", done); + // Let gSearch respond to the event before continuing. + executeSoon(() => doSearch(win.document)); + } + }); }, true); } } diff --git a/browser/components/search/test/browser_ddg_behavior.js b/browser/components/search/test/browser_ddg_behavior.js index a85f9fa3b390..939ad0d4b580 100644 --- a/browser/components/search/test/browser_ddg_behavior.js +++ b/browser/components/search/test/browser_ddg_behavior.js @@ -76,8 +76,10 @@ function test() { function doSearch(doc) { // Re-add the listener, and perform a search gBrowser.addProgressListener(listener); - doc.getElementById("newtab-search-text").value = "foo"; - doc.getElementById("newtab-search-submit").click(); + let input = doc.querySelector("input[id*=search-]"); + input.focus(); + input.value = "foo"; + EventUtils.synthesizeKey("VK_RETURN", {}); } // load about:newtab, but remove the listener first so it doesn't @@ -95,20 +97,15 @@ function test() { // Observe page setup let win = gBrowser.contentWindowAsCPOW; - if (win.gSearch.currentEngineName == - Services.search.currentEngine.name) { - doSearch(win.document); - } else { - info("Waiting for newtab search init"); - win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { - info("Got newtab search event " + contentSearchServiceEvent.detail.type); - if (contentSearchServiceEvent.detail.type == "State") { - win.removeEventListener("ContentSearchService", done); - // Let gSearch respond to the event before continuing. - executeSoon(() => doSearch(win.document)); - } - }); - } + info("Waiting for newtab search init"); + win.addEventListener("ContentSearchService", function done(contentSearchServiceEvent) { + info("Got newtab search event " + contentSearchServiceEvent.detail.type); + if (contentSearchServiceEvent.detail.type == "State") { + win.removeEventListener("ContentSearchService", done); + // Let gSearch respond to the event before continuing. + executeSoon(() => doSearch(win.document)); + } + }); }, true); } } diff --git a/browser/components/search/test/browser_google_behavior.js b/browser/components/search/test/browser_google_behavior.js index 3d25fee71c3c..53349bd53817 100644 --- a/browser/components/search/test/browser_google_behavior.js +++ b/browser/components/search/test/browser_google_behavior.js @@ -74,8 +74,10 @@ function test() { function doSearch(doc) { // Re-add the listener, and perform a search gBrowser.addProgressListener(listener); - doc.getElementById("newtab-search-text").value = "foo"; - doc.getElementById("newtab-search-submit").click(); + let input = doc.querySelector("input[id*=search-]"); + input.focus(); + input.value = "foo"; + EventUtils.synthesizeKey("VK_RETURN", {}); } // load about:newtab, but remove the listener first so it doesn't @@ -93,20 +95,15 @@ function test() { // Observe page setup let win = gBrowser.contentWindowAsCPOW; - if (win.gSearch.currentEngineName == - Services.search.currentEngine.name) { - doSearch(win.document); - } else { - info("Waiting for newtab search init"); - win.addEventListener("ContentSearchService", function done(searchServiceEvent) { - info("Got newtab search event " + searchServiceEvent.detail.type); - if (searchServiceEvent.detail.type == "State") { - win.removeEventListener("ContentSearchService", done); - // Let gSearch respond to the event before continuing. - executeSoon(() => doSearch(win.document)); - } - }); - } + info("Waiting for newtab search init"); + win.addEventListener("ContentSearchService", function done(searchServiceEvent) { + info("Got newtab search event " + searchServiceEvent.detail.type); + if (searchServiceEvent.detail.type == "State") { + win.removeEventListener("ContentSearchService", done); + // Let gSearch respond to the event before continuing. + executeSoon(() => doSearch(win.document)); + } + }); }, true); } } diff --git a/browser/components/search/test/browser_yahoo_behavior.js b/browser/components/search/test/browser_yahoo_behavior.js index 7b51c0af2f5a..17d7e25806cf 100644 --- a/browser/components/search/test/browser_yahoo_behavior.js +++ b/browser/components/search/test/browser_yahoo_behavior.js @@ -76,8 +76,10 @@ function test() { function doSearch(doc) { // Re-add the listener, and perform a search gBrowser.addProgressListener(listener); - doc.getElementById("newtab-search-text").value = "foo"; - doc.getElementById("newtab-search-submit").click(); + let input = doc.querySelector("input[id*=search-]"); + input.focus(); + input.value = "foo"; + EventUtils.synthesizeKey("VK_RETURN", {}); } // load about:newtab, but remove the listener first so it doesn't @@ -95,20 +97,15 @@ function test() { // Observe page setup let win = gBrowser.contentWindowAsCPOW; - if (win.gSearch.currentEngineName == - Services.search.currentEngine.name) { - doSearch(win.document); - } else { - info("Waiting for newtab search init"); - win.addEventListener("ContentSearchService", function done(searchServiceEvent) { - info("Got newtab search event " + searchServiceEvent.detail.type); - if (searchServiceEvent.detail.type == "State") { - win.removeEventListener("ContentSearchService", done); - // Let gSearch respond to the event before continuing. - executeSoon(() => doSearch(win.document)); - } - }); - } + info("Waiting for newtab search init"); + win.addEventListener("ContentSearchService", function done(searchServiceEvent) { + info("Got newtab search event " + searchServiceEvent.detail.type); + if (searchServiceEvent.detail.type == "State") { + win.removeEventListener("ContentSearchService", done); + // Let gSearch respond to the event before continuing. + executeSoon(() => doSearch(win.document)); + } + }); }, true); } }