| 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/strings/utf_string_conversions.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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/search/instant_service.h" | 12 #include "chrome/browser/search/instant_service.h" |
| 13 #include "chrome/browser/search/instant_service_factory.h" | 13 #include "chrome/browser/search/instant_service_factory.h" |
| 14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/search_engines/search_terms_data.h" | 15 #include "chrome/browser/search_engines/search_terms_data.h" |
| 16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 46 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 47 void InstantUnitTestBase::SetUpWithoutQueryExtraction() { | 47 void InstantUnitTestBase::SetUpWithoutQueryExtraction() { |
| 48 SetUpHelper(); | 48 SetUpHelper(); |
| 49 } | 49 } |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 void InstantUnitTestBase::SetUserSelectedDefaultSearchProvider( | 52 void InstantUnitTestBase::SetUserSelectedDefaultSearchProvider( |
| 53 const std::string& base_url) { | 53 const std::string& base_url) { |
| 54 TemplateURLData data; | 54 TemplateURLData data; |
| 55 data.SetKeyword(base::UTF8ToUTF16(base_url)); |
| 55 data.SetURL(base_url + "url?bar={searchTerms}"); | 56 data.SetURL(base_url + "url?bar={searchTerms}"); |
| 56 data.instant_url = base_url + | 57 data.instant_url = base_url + |
| 57 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}" | 58 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}" |
| 58 "foo=foo#foo=foo&strk"; | 59 "foo=foo#foo=foo&strk"; |
| 59 data.new_tab_url = base_url + "newtab"; | 60 data.new_tab_url = base_url + "newtab"; |
| 60 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); | 61 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); |
| 61 data.search_terms_replacement_key = "strk"; | 62 data.search_terms_replacement_key = "strk"; |
| 62 | 63 |
| 63 TemplateURL* template_url = new TemplateURL(profile(), data); | 64 TemplateURL* template_url = new TemplateURL(profile(), data); |
| 64 // Takes ownership of |template_url|. | 65 // Takes ownership of |template_url|. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 81 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 81 content::Source<Profile>(profile()->GetOriginalProfile()), | 82 content::Source<Profile>(profile()->GetOriginalProfile()), |
| 82 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); | 83 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 bool InstantUnitTestBase::IsInstantServiceObserver( | 86 bool InstantUnitTestBase::IsInstantServiceObserver( |
| 86 InstantServiceObserver* observer) { | 87 InstantServiceObserver* observer) { |
| 87 return instant_service_->observers_.HasObserver(observer); | 88 return instant_service_->observers_.HasObserver(observer); |
| 88 } | 89 } |
| 89 | 90 |
| 91 TestingProfile* InstantUnitTestBase::CreateProfile() { |
| 92 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); |
| 93 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 94 profile, &TemplateURLServiceFactory::BuildInstanceFor); |
| 95 return profile; |
| 96 } |
| 97 |
| 90 void InstantUnitTestBase::SetUpHelper() { | 98 void InstantUnitTestBase::SetUpHelper() { |
| 91 BrowserWithTestWindowTest::SetUp(); | 99 BrowserWithTestWindowTest::SetUp(); |
| 92 | 100 |
| 93 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 94 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | |
| 95 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); | 101 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); |
| 96 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); | 102 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); |
| 97 | 103 |
| 98 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); | 104 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); |
| 99 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); | 105 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); |
| 100 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL, | 106 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL, |
| 101 new base::StringValue("https://www.google.com/")); | 107 new base::StringValue("https://www.google.com/")); |
| 102 SetUserSelectedDefaultSearchProvider("{google:baseURL}"); | 108 SetUserSelectedDefaultSearchProvider("{google:baseURL}"); |
| 103 instant_service_ = InstantServiceFactory::GetForProfile(profile()); | 109 instant_service_ = InstantServiceFactory::GetForProfile(profile()); |
| 104 } | 110 } |
| OLD | NEW |