[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / search / instant_unittest_base.cc
blob4e8002a4548a1f71730a5c19e51ac6957579f4a5
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/search/instant_unittest_base.h"
7 #include <string>
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/instant_service.h"
13 #include "chrome/browser/search/instant_service_factory.h"
14 #include "chrome/browser/search/search.h"
15 #include "chrome/browser/search_engines/template_url_service_factory.h"
16 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
17 #include "chrome/test/base/browser_with_test_window_test.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/google/core/browser/google_pref_names.h"
20 #include "components/google/core/browser/google_url_tracker.h"
21 #include "components/search_engines/template_url.h"
22 #include "components/search_engines/template_url_service.h"
23 #include "components/variations/entropy_provider.h"
25 InstantUnitTestBase::InstantUnitTestBase() {
26 field_trial_list_.reset(new base::FieldTrialList(
27 new metrics::SHA1EntropyProvider("42")));
30 InstantUnitTestBase::~InstantUnitTestBase() {
33 void InstantUnitTestBase::SetUp() {
34 chrome::EnableQueryExtractionForTesting();
35 SetUpHelper();
38 void InstantUnitTestBase::TearDown() {
39 UIThreadSearchTermsData::SetGoogleBaseURL("");
40 BrowserWithTestWindowTest::TearDown();
43 #if !defined(OS_IOS) && !defined(OS_ANDROID)
44 void InstantUnitTestBase::SetUpWithoutQueryExtraction() {
45 SetUpHelper();
47 #endif
49 void InstantUnitTestBase::SetUserSelectedDefaultSearchProvider(
50 const std::string& base_url) {
51 TemplateURLData data;
52 data.SetShortName(base::UTF8ToUTF16(base_url));
53 data.SetKeyword(base::UTF8ToUTF16(base_url));
54 data.SetURL(base_url + "url?bar={searchTerms}");
55 data.instant_url = base_url +
56 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}"
57 "foo=foo#foo=foo&strk";
58 data.new_tab_url = base_url + "newtab";
59 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}");
60 data.search_terms_replacement_key = "strk";
62 TemplateURL* template_url = new TemplateURL(data);
63 // Takes ownership of |template_url|.
64 template_url_service_->Add(template_url);
65 template_url_service_->SetUserSelectedDefaultSearchProvider(template_url);
68 void InstantUnitTestBase::NotifyGoogleBaseURLUpdate(
69 const std::string& new_google_base_url) {
70 // GoogleURLTracker is not created in tests.
71 // (See GoogleURLTrackerFactory::ServiceIsNULLWhileTesting())
72 // For determining google:baseURL for NTP, the following is used:
73 // UIThreadSearchTermsData::GoogleBaseURLValue()
74 // For simulating test behavior, this is overridden below.
75 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url);
76 TemplateURLServiceFactory::GetForProfile(profile())->GoogleBaseURLChanged();
79 bool InstantUnitTestBase::IsInstantServiceObserver(
80 const InstantServiceObserver* observer) const {
81 return instant_service_->observers_.HasObserver(observer);
84 TestingProfile* InstantUnitTestBase::CreateProfile() {
85 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
86 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
87 profile, &TemplateURLServiceFactory::BuildInstanceFor);
88 return profile;
91 void InstantUnitTestBase::SetUpHelper() {
92 BrowserWithTestWindowTest::SetUp();
94 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile());
95 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_);
97 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/");
98 SetUserSelectedDefaultSearchProvider("{google:baseURL}");
99 instant_service_ = InstantServiceFactory::GetForProfile(profile());