Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: chrome/browser/search/instant_unittest_base.cc

Issue 141893009: Create a new helper function to extract search terms from the URL irrespective of the availablility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
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"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/browser_with_test_window_test.h" 20 #include "chrome/test/base/browser_with_test_window_test.h"
21 #include "chrome/test/base/testing_pref_service_syncable.h" 21 #include "chrome/test/base/testing_pref_service_syncable.h"
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/variations/entropy_provider.h" 23 #include "components/variations/entropy_provider.h"
24 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
27 27
28 InstantUnitTestBase::InstantUnitTestBase() { 28 InstantUnitTestBase::InstantUnitTestBase()
29 : enable_query_extraction_(true) {
29 field_trial_list_.reset(new base::FieldTrialList( 30 field_trial_list_.reset(new base::FieldTrialList(
30 new metrics::SHA1EntropyProvider("42"))); 31 new metrics::SHA1EntropyProvider("42")));
31 } 32 }
32 33
33 InstantUnitTestBase::~InstantUnitTestBase() { 34 InstantUnitTestBase::~InstantUnitTestBase() {
34 } 35 }
35 36
36 void InstantUnitTestBase::SetUp() { 37 void InstantUnitTestBase::SetUp() {
37 SetUpHelper(); 38 SetUpHelper();
38 } 39 }
39 40
41 void InstantUnitTestBase::TearDown() {
42 UIThreadSearchTermsData::SetGoogleBaseURL("");
43 BrowserWithTestWindowTest::TearDown();
44 }
45
40 void InstantUnitTestBase::SetUpWithoutCacheableNTP() { 46 void InstantUnitTestBase::SetUpWithoutCacheableNTP() {
41 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 47 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
42 "InstantExtended", "Group1 use_cacheable_ntp:0")); 48 "InstantExtended", "Group1 use_cacheable_ntp:0"));
43 SetUpHelper(); 49 SetUpHelper();
44 } 50 }
45 51
46 void InstantUnitTestBase::SetUpHelper() { 52 void InstantUnitTestBase::SetUpWithoutQueryExtraction() {
47 chrome::EnableQueryExtractionForTesting(); 53 enable_query_extraction_ = false;
Jered 2014/02/07 03:02:26 Note that query extraction is enabled unconditiona
kmadhusu 2014/02/11 01:40:02 Ack.
48 BrowserWithTestWindowTest::SetUp(); 54 SetUpHelper();
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() {
64 UIThreadSearchTermsData::SetGoogleBaseURL("");
65 BrowserWithTestWindowTest::TearDown();
66 } 55 }
67 56
68 void InstantUnitTestBase::SetDefaultSearchProvider( 57 void InstantUnitTestBase::SetDefaultSearchProvider(
69 const std::string& base_url) { 58 const std::string& base_url) {
70 TemplateURLData data; 59 TemplateURLData data;
71 data.SetURL(base_url + "url?bar={searchTerms}"); 60 data.SetURL(base_url + "url?bar={searchTerms}");
72 data.instant_url = base_url + 61 data.instant_url = base_url +
73 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}" 62 "instant?{google:omniboxStartMarginParameter}{google:forceInstantResults}"
74 "foo=foo#foo=foo&strk"; 63 "foo=foo#foo=foo&strk";
75 data.new_tab_url = base_url + "newtab"; 64 data.new_tab_url = base_url + "newtab";
(...skipping 15 matching lines...) Expand all
91 // For simulating test behavior, this is overridden below. 80 // For simulating test behavior, this is overridden below.
92 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url); 81 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url);
93 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"), 82 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"),
94 GURL(new_google_base_url)); 83 GURL(new_google_base_url));
95 content::NotificationService::current()->Notify( 84 content::NotificationService::current()->Notify(
96 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 85 chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
97 content::Source<Profile>(profile()->GetOriginalProfile()), 86 content::Source<Profile>(profile()->GetOriginalProfile()),
98 content::Details<GoogleURLTracker::UpdatedDetails>(&details)); 87 content::Details<GoogleURLTracker::UpdatedDetails>(&details));
99 } 88 }
100 89
101
102 bool InstantUnitTestBase::IsInstantServiceObserver( 90 bool InstantUnitTestBase::IsInstantServiceObserver(
103 InstantServiceObserver* observer) { 91 InstantServiceObserver* observer) {
104 return instant_service_->observers_.HasObserver(observer); 92 return instant_service_->observers_.HasObserver(observer);
105 } 93 }
106 94
95 void InstantUnitTestBase::SetUpHelper() {
96 if (enable_query_extraction_)
Jered 2014/02/07 03:02:26 What disables query extraction if this is false? A
kmadhusu 2014/02/11 01:40:02 I agree that it is kind of tricky with a boolean m
97 chrome::EnableQueryExtractionForTesting();
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698