Commit 55ff0214 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[ntp] Simplify InstantTestBase

This CL:

* Merges InstantTestBase::Init into InstantTestBase::SetupInstant.
  Both functions were required to be called successively for instant
  setup to take effect. Merging the functions makes this more explicit.

* Removes option to initialize a suggestion URL since that functionality
  was never used.

* Removes some getters and fields, which are no longer needed.

Change-Id: Ia0c9f7f601f71b5fe41c74e067a0aa1f6aaa543d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515222Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824039}
parent 6910d174
...@@ -139,9 +139,7 @@ IN_PROC_BROWSER_TEST_F(IsolatedOriginNTPBrowserTest, ...@@ -139,9 +139,7 @@ IN_PROC_BROWSER_TEST_F(IsolatedOriginNTPBrowserTest,
https_test_server().GetURL("ntp.com", "/instant_extended.html"); https_test_server().GetURL("ntp.com", "/instant_extended.html");
GURL ntp_url = GURL ntp_url =
https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html"); https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html");
InstantTestBase::Init(base_url, ntp_url, false); SetupInstant(browser()->profile(), base_url, ntp_url);
SetupInstant(browser());
// Sanity check that a SiteInstance for a generic ntp.com URL requires a // Sanity check that a SiteInstance for a generic ntp.com URL requires a
// dedicated process. // dedicated process.
...@@ -203,9 +201,7 @@ IN_PROC_BROWSER_TEST_F(OpenWindowFromNTPBrowserTest, ...@@ -203,9 +201,7 @@ IN_PROC_BROWSER_TEST_F(OpenWindowFromNTPBrowserTest,
https_test_server().GetURL("ntp.com", "/instant_extended.html"); https_test_server().GetURL("ntp.com", "/instant_extended.html");
GURL ntp_url = GURL ntp_url =
https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html"); https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html");
InstantTestBase::Init(search_url, ntp_url, false); SetupInstant(browser()->profile(), search_url, ntp_url);
SetupInstant(browser());
// Navigate to the NTP URL and verify that the resulting process is marked as // Navigate to the NTP URL and verify that the resulting process is marked as
// an Instant process. // an Instant process.
......
...@@ -41,11 +41,12 @@ class InstantExtendedTest : public InProcessBrowserTest, ...@@ -41,11 +41,12 @@ class InstantExtendedTest : public InProcessBrowserTest,
is_focused_(false) {} is_focused_(false) {}
protected: protected:
void SetUpInProcessBrowserTestFixture() override { void SetUpOnMainThread() override {
ASSERT_TRUE(https_test_server().Start()); ASSERT_TRUE(https_test_server().Start());
GURL base_url = https_test_server().GetURL("/instant_extended.html?"); GURL base_url = https_test_server().GetURL("/instant_extended.html?");
GURL ntp_url = https_test_server().GetURL("/instant_extended_ntp.html?"); GURL ntp_url = https_test_server().GetURL("/instant_extended_ntp.html?");
InstantTestBase::Init(base_url, ntp_url, false); ASSERT_NO_FATAL_FAILURE(
SetupInstant(browser()->profile(), base_url, ntp_url));
} }
bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
...@@ -63,19 +64,19 @@ class InstantExtendedTest : public InProcessBrowserTest, ...@@ -63,19 +64,19 @@ class InstantExtendedTest : public InProcessBrowserTest,
} }
OmniboxView* omnibox() { OmniboxView* omnibox() {
return instant_browser()->window()->GetLocationBar()->GetOmniboxView(); return browser()->window()->GetLocationBar()->GetOmniboxView();
} }
void FocusOmnibox() { void FocusOmnibox() {
// If the omnibox already has focus, just notify OmniboxTabHelper. // If the omnibox already has focus, just notify OmniboxTabHelper.
if (omnibox()->model()->has_focus()) { if (omnibox()->model()->has_focus()) {
content::WebContents* active_tab = content::WebContents* active_tab =
instant_browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
OmniboxTabHelper::FromWebContents(active_tab) OmniboxTabHelper::FromWebContents(active_tab)
->OnFocusChanged(OMNIBOX_FOCUS_VISIBLE, ->OnFocusChanged(OMNIBOX_FOCUS_VISIBLE,
OMNIBOX_FOCUS_CHANGE_EXPLICIT); OMNIBOX_FOCUS_CHANGE_EXPLICIT);
} else { } else {
instant_browser()->window()->GetLocationBar()->FocusLocation(false); browser()->window()->GetLocationBar()->FocusLocation(false);
} }
} }
...@@ -88,7 +89,7 @@ class InstantExtendedTest : public InProcessBrowserTest, ...@@ -88,7 +89,7 @@ class InstantExtendedTest : public InProcessBrowserTest,
content::WindowedNotificationObserver nav_observer( content::WindowedNotificationObserver nav_observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
instant_browser()->window()->GetLocationBar()->AcceptInput(); browser()->window()->GetLocationBar()->AcceptInput();
nav_observer.Wait(); nav_observer.Wait();
} }
...@@ -96,7 +97,7 @@ class InstantExtendedTest : public InProcessBrowserTest, ...@@ -96,7 +97,7 @@ class InstantExtendedTest : public InProcessBrowserTest,
content::WindowedNotificationObserver nav_observer( content::WindowedNotificationObserver nav_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
instant_browser()->window()->GetLocationBar()->AcceptInput(); browser()->window()->GetLocationBar()->AcceptInput();
nav_observer.Wait(); nav_observer.Wait();
} }
...@@ -114,9 +115,6 @@ class InstantExtendedTest : public InProcessBrowserTest, ...@@ -114,9 +115,6 @@ class InstantExtendedTest : public InProcessBrowserTest,
// Test to verify that switching tabs should not dispatch onmostvisitedchanged // Test to verify that switching tabs should not dispatch onmostvisitedchanged
// events. // events.
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) {
// Initialize Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
// Open new tab. // Open new tab.
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(chrome::kChromeUINewTabURL), browser(), GURL(chrome::kChromeUINewTabURL),
...@@ -144,7 +142,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { ...@@ -144,7 +142,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) {
} }
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateBackToNTP) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateBackToNTP) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
FocusOmnibox(); FocusOmnibox();
// Open a new tab page. // Open a new tab page.
...@@ -175,8 +172,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateBackToNTP) { ...@@ -175,8 +172,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateBackToNTP) {
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
DispatchMVChangeEventWhileNavigatingBackToNTP) { DispatchMVChangeEventWhileNavigatingBackToNTP) {
// Setup Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
FocusOmnibox(); FocusOmnibox();
// Open new tab. // Open new tab.
...@@ -220,7 +215,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { ...@@ -220,7 +215,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL result_url = embedded_test_server()->GetURL( GURL result_url = embedded_test_server()->GetURL(
"/referrer_policy/referrer-policy-log.html"); "/referrer_policy/referrer-policy-log.html");
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
FocusOmnibox(); FocusOmnibox();
// Type a query and press enter to get results. // Type a query and press enter to get results.
...@@ -239,6 +233,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { ...@@ -239,6 +233,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) {
EXPECT_TRUE(content::WaitForLoadStop(contents)); EXPECT_TRUE(content::WaitForLoadStop(contents));
std::string expected_title = std::string expected_title =
"Referrer is " + base_url().GetWithEmptyPath().spec(); "Referrer is " + https_test_server().base_url().spec();
EXPECT_EQ(base::ASCIIToUTF16(expected_title), contents->GetTitle()); EXPECT_EQ(base::ASCIIToUTF16(expected_title), contents->GetTitle());
} }
...@@ -9,43 +9,30 @@ ...@@ -9,43 +9,30 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/search_test_utils.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "content/public/browser/web_contents.h" #include "url/gurl.h"
InstantTestBase::InstantTestBase() InstantTestBase::InstantTestBase()
: browser_(nullptr), : https_test_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
https_test_server_(net::EmbeddedTestServer::TYPE_HTTPS),
init_suggestions_url_(false) {
https_test_server_.ServeFilesFromSourceDirectory("chrome/test/data"); https_test_server_.ServeFilesFromSourceDirectory("chrome/test/data");
} }
InstantTestBase::~InstantTestBase() {} InstantTestBase::~InstantTestBase() = default;
void InstantTestBase::SetupInstant(Browser* browser) {
browser_ = browser;
void InstantTestBase::SetupInstant(Profile* profile,
const GURL& base_url,
const GURL& ntp_url) {
TemplateURLService* service = TemplateURLService* service =
TemplateURLServiceFactory::GetForProfile(browser_->profile()); TemplateURLServiceFactory::GetForProfile(profile);
search_test_utils::WaitForTemplateURLServiceToLoad(service); search_test_utils::WaitForTemplateURLServiceToLoad(service);
TemplateURLData data; TemplateURLData data;
data.SetShortName(base::ASCIIToUTF16("name")); data.SetShortName(base::ASCIIToUTF16("name"));
data.SetURL(base_url_.spec() + "q={searchTerms}&is_search"); data.SetURL(base_url.spec() + "q={searchTerms}&is_search");
data.new_tab_url = ntp_url_.spec(); data.new_tab_url = ntp_url.spec();
if (init_suggestions_url_) data.alternate_urls.push_back(base_url.spec() + "#q={searchTerms}");
data.suggestions_url = base_url_.spec() + "#q={searchTerms}";
data.alternate_urls.push_back(base_url_.spec() + "#q={searchTerms}");
TemplateURL* template_url = service->Add(std::make_unique<TemplateURL>(data)); TemplateURL* template_url = service->Add(std::make_unique<TemplateURL>(data));
service->SetUserSelectedDefaultSearchProvider(template_url); service->SetUserSelectedDefaultSearchProvider(template_url);
} }
void InstantTestBase::Init(const GURL& base_url,
const GURL& ntp_url,
bool init_suggestions_url) {
base_url_ = base_url;
ntp_url_ = ntp_url;
init_suggestions_url_ = init_suggestions_url;
}
...@@ -5,48 +5,31 @@ ...@@ -5,48 +5,31 @@
#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_ #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_
#define CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_ #define CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_
#include <string>
#include "base/macros.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
class Browser; class GURL;
class Profile;
// This utility class is meant to be used in a "mix-in" fashion, giving the // This utility class is meant to be used in a "mix-in" fashion, giving the
// derived test class additional Instant-related functionality. // derived test class additional Instant-related functionality.
class InstantTestBase { class InstantTestBase {
public:
InstantTestBase(const InstantTestBase&) = delete;
InstantTestBase& operator=(const InstantTestBase&) = delete;
protected: protected:
InstantTestBase(); InstantTestBase();
virtual ~InstantTestBase(); virtual ~InstantTestBase();
protected: void SetupInstant(Profile* profile,
Browser* instant_browser() { return browser_; } const GURL& base_url,
const GURL& ntp_url);
void SetupInstant(Browser* browser);
void Init(const GURL& base_url,
const GURL& ntp_url,
bool init_suggestions_url);
const GURL& base_url() const { return base_url_; }
const GURL& ntp_url() const { return ntp_url_; }
net::EmbeddedTestServer& https_test_server() { return https_test_server_; } net::EmbeddedTestServer& https_test_server() { return https_test_server_; }
private: private:
GURL base_url_;
GURL ntp_url_;
Browser* browser_;
// HTTPS Testing server, started on demand. // HTTPS Testing server, started on demand.
net::EmbeddedTestServer https_test_server_; net::EmbeddedTestServer https_test_server_;
// Set to true to initialize suggestions URL in default search provider.
bool init_suggestions_url_;
DISALLOW_COPY_AND_ASSIGN(InstantTestBase);
}; };
#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_ #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_BASE_H_
...@@ -82,14 +82,13 @@ class InstantThemeTest : public extensions::ExtensionBrowserTest, ...@@ -82,14 +82,13 @@ class InstantThemeTest : public extensions::ExtensionBrowserTest,
InstantThemeTest() {} InstantThemeTest() {}
protected: protected:
void SetUpInProcessBrowserTestFixture() override { void SetUpOnMainThread() override {
ASSERT_TRUE(https_test_server().Start()); ASSERT_TRUE(https_test_server().Start());
GURL base_url = https_test_server().GetURL("/instant_extended.html"); GURL base_url = https_test_server().GetURL("/instant_extended.html");
GURL ntp_url = https_test_server().GetURL("/instant_extended_ntp.html"); GURL ntp_url = https_test_server().GetURL("/instant_extended_ntp.html");
InstantTestBase::Init(base_url, ntp_url, false); ASSERT_NO_FATAL_FAILURE(
} SetupInstant(browser()->profile(), base_url, ntp_url));
void SetUpOnMainThread() override {
extensions::ExtensionBrowserTest::SetUpOnMainThread(); extensions::ExtensionBrowserTest::SetUpOnMainThread();
content::URLDataSource::Add(profile(), content::URLDataSource::Add(profile(),
...@@ -149,7 +148,6 @@ class InstantThemeTest : public extensions::ExtensionBrowserTest, ...@@ -149,7 +148,6 @@ class InstantThemeTest : public extensions::ExtensionBrowserTest,
IN_PROC_BROWSER_TEST_F(InstantThemeTest, ThemeBackgroundAccess) { IN_PROC_BROWSER_TEST_F(InstantThemeTest, ThemeBackgroundAccess) {
ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(chrome::kChromeSearchLocalNtpUrl), browser(), GURL(chrome::kChromeSearchLocalNtpUrl),
......
...@@ -49,8 +49,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPBrowserTest, EmbeddedMostVisitedIframe) { ...@@ -49,8 +49,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPBrowserTest, EmbeddedMostVisitedIframe) {
https_test_server().GetURL("ntp.com", "/instant_extended.html"); https_test_server().GetURL("ntp.com", "/instant_extended.html");
GURL ntp_url = GURL ntp_url =
https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html"); https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html");
InstantTestBase::Init(base_url, ntp_url, false); SetupInstant(browser()->profile(), base_url, ntp_url);
SetupInstant(browser());
// Navigate to the NTP URL and verify that the resulting process is marked as // Navigate to the NTP URL and verify that the resulting process is marked as
// an Instant process. // an Instant process.
...@@ -95,8 +94,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPBrowserTest, ProcessPerSite) { ...@@ -95,8 +94,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPBrowserTest, ProcessPerSite) {
https_test_server().GetURL("ntp.com", "/instant_extended.html"); https_test_server().GetURL("ntp.com", "/instant_extended.html");
GURL ntp_url = GURL ntp_url =
https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html"); https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html");
InstantTestBase::Init(base_url, ntp_url, false); SetupInstant(browser()->profile(), base_url, ntp_url);
SetupInstant(browser());
// Open NTP in |tab1|. // Open NTP in |tab1|.
content::WebContents* tab1; content::WebContents* tab1;
......
...@@ -51,8 +51,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPUiTest, Reloads) { ...@@ -51,8 +51,7 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyNTPUiTest, Reloads) {
https_test_server().GetURL("ntp.com", "/instant_extended.html"); https_test_server().GetURL("ntp.com", "/instant_extended.html");
GURL ntp_url = GURL ntp_url =
https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html"); https_test_server().GetURL("ntp.com", "/instant_extended_ntp.html");
InstantTestBase::Init(base_url, ntp_url, false); SetupInstant(browser()->profile(), base_url, ntp_url);
SetupInstant(browser());
// Verify that at the start of the test the tab contents has focus. // Verify that at the start of the test the tab contents has focus.
browser()->tab_strip_model()->GetActiveWebContents()->Focus(); browser()->tab_strip_model()->GetActiveWebContents()->Focus();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment