| 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 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/google/google_url_tracker.h" | 10 #include "chrome/browser/google/google_url_tracker.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 InstantUnitTestBase::InstantUnitTestBase() { | 28 InstantUnitTestBase::InstantUnitTestBase() { |
| 29 field_trial_list_.reset(new base::FieldTrialList( | 29 field_trial_list_.reset(new base::FieldTrialList( |
| 30 new metrics::SHA1EntropyProvider("42"))); | 30 new metrics::SHA1EntropyProvider("42"))); |
| 31 } | 31 } |
| 32 | 32 |
| 33 InstantUnitTestBase::~InstantUnitTestBase() { | 33 InstantUnitTestBase::~InstantUnitTestBase() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void InstantUnitTestBase::SetUp() { | 36 void InstantUnitTestBase::SetUp() { |
| 37 chrome::EnableQueryExtractionForTesting(); |
| 37 SetUpHelper(); | 38 SetUpHelper(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void InstantUnitTestBase::SetUpWithoutCacheableNTP() { | |
| 41 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 42 "InstantExtended", "Group1 use_cacheable_ntp:0")); | |
| 43 SetUpHelper(); | |
| 44 } | |
| 45 | |
| 46 void InstantUnitTestBase::SetUpHelper() { | |
| 47 chrome::EnableQueryExtractionForTesting(); | |
| 48 BrowserWithTestWindowTest::SetUp(); | |
| 49 | |
| 50 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 51 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | |
| 52 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); | |
| 53 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); | |
| 54 | |
| 55 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); | |
| 56 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); | |
| 57 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL, | |
| 58 new base::StringValue("https://www.google.com/")); | |
| 59 SetDefaultSearchProvider("{google:baseURL}"); | |
| 60 instant_service_ = InstantServiceFactory::GetForProfile(profile()); | |
| 61 } | |
| 62 | |
| 63 void InstantUnitTestBase::TearDown() { | 41 void InstantUnitTestBase::TearDown() { |
| 64 UIThreadSearchTermsData::SetGoogleBaseURL(""); | 42 UIThreadSearchTermsData::SetGoogleBaseURL(""); |
| 65 BrowserWithTestWindowTest::TearDown(); | 43 BrowserWithTestWindowTest::TearDown(); |
| 66 } | 44 } |
| 67 | 45 |
| 46 void InstantUnitTestBase::SetUpWithoutCacheableNTP() { |
| 47 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 48 "InstantExtended", "Group1 use_cacheable_ntp:0")); |
| 49 chrome::EnableQueryExtractionForTesting(); |
| 50 SetUpHelper(); |
| 51 } |
| 52 |
| 53 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 54 void InstantUnitTestBase::SetUpWithoutQueryExtraction() { |
| 55 SetUpHelper(); |
| 56 } |
| 57 #endif |
| 58 |
| 68 void InstantUnitTestBase::SetDefaultSearchProvider( | 59 void InstantUnitTestBase::SetDefaultSearchProvider( |
| 69 const std::string& base_url) { | 60 const std::string& base_url) { |
| 70 TemplateURLData data; | 61 TemplateURLData data; |
| 71 data.SetURL(base_url + "url?bar={searchTerms}"); | 62 data.SetURL(base_url + "url?bar={searchTerms}"); |
| 72 data.instant_url = base_url + | 63 data.instant_url = base_url + |
| 73 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}" | 64 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}" |
| 74 "foo=foo#foo=foo&strk"; | 65 "foo=foo#foo=foo&strk"; |
| 75 data.new_tab_url = base_url + "newtab"; | 66 data.new_tab_url = base_url + "newtab"; |
| 76 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); | 67 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); |
| 77 data.search_terms_replacement_key = "strk"; | 68 data.search_terms_replacement_key = "strk"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 91 // For simulating test behavior, this is overridden below. | 82 // For simulating test behavior, this is overridden below. |
| 92 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url); | 83 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url); |
| 93 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"), | 84 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"), |
| 94 GURL(new_google_base_url)); | 85 GURL(new_google_base_url)); |
| 95 content::NotificationService::current()->Notify( | 86 content::NotificationService::current()->Notify( |
| 96 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 87 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 97 content::Source<Profile>(profile()->GetOriginalProfile()), | 88 content::Source<Profile>(profile()->GetOriginalProfile()), |
| 98 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); | 89 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); |
| 99 } | 90 } |
| 100 | 91 |
| 101 | |
| 102 bool InstantUnitTestBase::IsInstantServiceObserver( | 92 bool InstantUnitTestBase::IsInstantServiceObserver( |
| 103 InstantServiceObserver* observer) { | 93 InstantServiceObserver* observer) { |
| 104 return instant_service_->observers_.HasObserver(observer); | 94 return instant_service_->observers_.HasObserver(observer); |
| 105 } | 95 } |
| 106 | 96 |
| 97 void InstantUnitTestBase::SetUpHelper() { |
| 98 BrowserWithTestWindowTest::SetUp(); |
| 99 |
| 100 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 101 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 102 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); |
| 103 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); |
| 104 |
| 105 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); |
| 106 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); |
| 107 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL, |
| 108 new base::StringValue("https://www.google.com/")); |
| 109 SetDefaultSearchProvider("{google:baseURL}"); |
| 110 instant_service_ = InstantServiceFactory::GetForProfile(profile()); |
| 111 } |
| OLD | NEW |