Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/search/instant_unittest_base.h" | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/google/google_url_tracker.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/search_terms_data.h" | |
| 16 #include "chrome/browser/search_engines/template_url.h" | |
| 17 #include "chrome/browser/search_engines/template_url_service.h" | |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 21 #include "chrome/test/base/testing_pref_service_syncable.h" | |
| 22 #include "chrome/test/base/ui_test_utils.h" | |
| 23 #include "content/public/browser/notification_details.h" | |
| 24 #include "content/public/browser/notification_service.h" | |
| 25 #include "content/public/browser/notification_source.h" | |
| 26 | |
| 27 void InstantUnitTestBase::SetUp() { | |
| 28 chrome::EnableInstantExtendedAPIForTesting(); | |
| 29 BrowserWithTestWindowTest::SetUp(); | |
| 30 | |
| 31 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 32 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | |
| 33 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); | |
| 34 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); | |
| 35 | |
| 36 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); | |
| 37 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); | |
| 38 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL, | |
| 39 new base::StringValue("https://www.google.com/")); | |
| 40 SetSearchProvider("{google:baseURL}"); | |
| 41 instant_service_ = InstantServiceFactory::GetForProfile(profile()); | |
| 42 } | |
| 43 | |
| 44 void InstantUnitTestBase::TearDown() { | |
| 45 UIThreadSearchTermsData::SetGoogleBaseURL(""); | |
| 46 BrowserWithTestWindowTest::TearDown(); | |
| 47 } | |
| 48 | |
| 49 void InstantUnitTestBase::SetSearchProvider(const std::string& base_url) { | |
| 50 TemplateURLData data; | |
| 51 data.SetURL(base_url + "url?bar={searchTerms}"); | |
| 52 data.instant_url = base_url + "instant?" | |
| 53 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; | |
| 54 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}"); | |
| 55 data.search_terms_replacement_key = "strk"; | |
| 56 | |
| 57 TemplateURL* template_url = new TemplateURL(profile(), data); | |
| 58 // Takes ownership of |template_url|. | |
| 59 template_url_service_->Add(template_url); | |
| 60 template_url_service_->SetDefaultSearchProvider(template_url); | |
| 61 } | |
| 62 | |
| 63 void InstantUnitTestBase::NotifyGoogleBaseURLUpdate( | |
| 64 const std::string& new_google_base_url) { | |
| 65 // GoogleURLTracker is not initialized is not created in tests. | |
|
Jered
2013/08/16 00:13:23
omit either "is not initialized" or "is not creat
Anuj
2013/08/22 00:40:45
Done.
| |
| 66 // (See GoogleURLTrackerFactory::ServiceIsNULLWhileTesting()) | |
| 67 // For determining google:baseURL for NTP, the following is used: | |
| 68 // UIThreadSearchTermsData::GoogleBaseURLValue() | |
| 69 // For simulating test behavior, this is overridden below. | |
| 70 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url); | |
| 71 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"), | |
| 72 GURL(new_google_base_url)); | |
| 73 content::NotificationService::current()->Notify( | |
| 74 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | |
| 75 content::Source<Profile>(profile()->GetOriginalProfile()), | |
| 76 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); | |
| 77 } | |
| OLD | NEW |