OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/search/instant_unittest_base.h" | 5 #include "chrome/browser/search/instant_unittest_base.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 InstantUnitTestBase::InstantUnitTestBase() { | 27 InstantUnitTestBase::InstantUnitTestBase() { |
28 field_trial_list_.reset(new base::FieldTrialList( | 28 field_trial_list_.reset(new base::FieldTrialList( |
29 new metrics::SHA1EntropyProvider("42"))); | 29 new metrics::SHA1EntropyProvider("42"))); |
30 } | 30 } |
31 | 31 |
32 InstantUnitTestBase::~InstantUnitTestBase() { | 32 InstantUnitTestBase::~InstantUnitTestBase() { |
33 } | 33 } |
34 | 34 |
35 void InstantUnitTestBase::SetUp() { | 35 void InstantUnitTestBase::SetUp() { |
36 search::EnableQueryExtractionForTesting(); | 36 BrowserWithTestWindowTest::SetUp(); |
37 SetUpHelper(); | 37 |
| 38 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); |
| 39 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); |
| 40 |
| 41 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); |
| 42 SetUserSelectedDefaultSearchProvider("{google:baseURL}"); |
| 43 instant_service_ = InstantServiceFactory::GetForProfile(profile()); |
38 } | 44 } |
39 | 45 |
40 void InstantUnitTestBase::TearDown() { | 46 void InstantUnitTestBase::TearDown() { |
41 UIThreadSearchTermsData::SetGoogleBaseURL(""); | 47 UIThreadSearchTermsData::SetGoogleBaseURL(""); |
42 BrowserWithTestWindowTest::TearDown(); | 48 BrowserWithTestWindowTest::TearDown(); |
43 } | 49 } |
44 | 50 |
45 #if !defined(OS_ANDROID) | |
46 void InstantUnitTestBase::SetUpWithoutQueryExtraction() { | |
47 SetUpHelper(); | |
48 } | |
49 #endif | |
50 | |
51 void InstantUnitTestBase::SetUserSelectedDefaultSearchProvider( | 51 void InstantUnitTestBase::SetUserSelectedDefaultSearchProvider( |
52 const std::string& base_url) { | 52 const std::string& base_url) { |
53 TemplateURLData data; | 53 TemplateURLData data; |
54 data.SetShortName(base::UTF8ToUTF16(base_url)); | 54 data.SetShortName(base::UTF8ToUTF16(base_url)); |
55 data.SetKeyword(base::UTF8ToUTF16(base_url)); | 55 data.SetKeyword(base::UTF8ToUTF16(base_url)); |
56 data.SetURL(base_url + "url?bar={searchTerms}"); | 56 data.SetURL(base_url + "url?bar={searchTerms}"); |
57 data.instant_url = | 57 data.instant_url = |
58 base_url + "instant?{google:forceInstantResults}foo=foo#foo=foo&strk"; | 58 base_url + "instant?{google:forceInstantResults}foo=foo#foo=foo&strk"; |
59 data.new_tab_url = base_url + "newtab"; | 59 data.new_tab_url = base_url + "newtab"; |
60 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); | 60 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); |
(...skipping 20 matching lines...) Expand all Loading... |
81 const InstantServiceObserver* observer) const { | 81 const InstantServiceObserver* observer) const { |
82 return instant_service_->observers_.HasObserver(observer); | 82 return instant_service_->observers_.HasObserver(observer); |
83 } | 83 } |
84 | 84 |
85 TestingProfile* InstantUnitTestBase::CreateProfile() { | 85 TestingProfile* InstantUnitTestBase::CreateProfile() { |
86 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); | 86 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); |
87 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 87 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
88 profile, &TemplateURLServiceFactory::BuildInstanceFor); | 88 profile, &TemplateURLServiceFactory::BuildInstanceFor); |
89 return profile; | 89 return profile; |
90 } | 90 } |
91 | |
92 void InstantUnitTestBase::SetUpHelper() { | |
93 BrowserWithTestWindowTest::SetUp(); | |
94 | |
95 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); | |
96 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); | |
97 | |
98 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); | |
99 SetUserSelectedDefaultSearchProvider("{google:baseURL}"); | |
100 instant_service_ = InstantServiceFactory::GetForProfile(profile()); | |
101 } | |
OLD | NEW |