OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 114 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
115 }; | 115 }; |
116 | 116 |
117 struct SearchTestCase { | 117 struct SearchTestCase { |
118 const char* url; | 118 const char* url; |
119 bool expected_result; | 119 bool expected_result; |
120 const char* comment; | 120 const char* comment; |
121 }; | 121 }; |
122 | 122 |
123 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { | 123 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { |
124 EnableQueryExtractionForTesting(); | |
125 | |
126 const SearchTestCase kTestCases[] = { | 124 const SearchTestCase kTestCases[] = { |
127 {chrome::kChromeSearchLocalNtpUrl, true, ""}, | 125 {chrome::kChromeSearchLocalNtpUrl, true, ""}, |
128 {"https://foo.com/instant?strk", true, ""}, | 126 {"https://foo.com/instant?strk", true, ""}, |
129 {"https://foo.com/instant#strk", true, ""}, | 127 {"https://foo.com/instant#strk", true, ""}, |
130 {"https://foo.com/instant?strk=0", true, ""}, | 128 {"https://foo.com/instant?strk=0", true, ""}, |
131 {"https://foo.com/url?strk", true, ""}, | 129 {"https://foo.com/url?strk", false, ""}, |
132 {"https://foo.com/alt?strk", true, ""}, | 130 {"https://foo.com/alt?strk", false, ""}, |
133 {"http://foo.com/instant", false, "Non-HTTPS"}, | 131 {"http://foo.com/instant", false, "Non-HTTPS"}, |
134 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, | 132 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, |
135 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, | 133 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, |
136 {"https://foo.com/instant", false, "No search terms replacement"}, | 134 {"https://foo.com/instant", false, "No search terms replacement"}, |
137 {"https://foo.com/?strk", false, "Non-exact path"}, | 135 {"https://foo.com/?strk", false, "Non-exact path"}, |
138 }; | 136 }; |
139 | 137 |
140 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 138 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
141 const SearchTestCase& test = kTestCases[i]; | 139 const SearchTestCase& test = kTestCases[i]; |
142 EXPECT_EQ(test.expected_result, | 140 EXPECT_EQ(test.expected_result, |
(...skipping 22 matching lines...) Expand all Loading... |
165 | 163 |
166 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 164 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
167 const SearchTestCase& test = kTestCases[i]; | 165 const SearchTestCase& test = kTestCases[i]; |
168 EXPECT_EQ(test.expected_result, | 166 EXPECT_EQ(test.expected_result, |
169 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | 167 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) |
170 << test.url << " " << test.comment; | 168 << test.url << " " << test.comment; |
171 } | 169 } |
172 } | 170 } |
173 | 171 |
174 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { | 172 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { |
175 EnableQueryExtractionForTesting(); | |
176 | |
177 const SearchTestCase kTestCases[] = { | 173 const SearchTestCase kTestCases[] = { |
178 {"chrome-search://local-ntp", true, "Local NTP"}, | 174 {"chrome-search://local-ntp", true, "Local NTP"}, |
179 {"chrome-search://remote-ntp", true, "Remote NTP"}, | 175 {"chrome-search://remote-ntp", true, "Remote NTP"}, |
180 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, | 176 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, |
181 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, | 177 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, |
182 {"chrome-search://foo.com", false, "Search result page"}, | 178 {"chrome-search://foo.com", false, "Search result page"}, |
183 {"https://foo.com/instant?strk", false, ""}, | 179 {"https://foo.com/instant?strk", false, ""}, |
184 {"https://foo.com/instant#strk", false, ""}, | 180 {"https://foo.com/instant#strk", false, ""}, |
185 {"https://foo.com/instant?strk=0", false, ""}, | 181 {"https://foo.com/instant?strk=0", false, ""}, |
186 {"https://foo.com/url?strk", false, ""}, | 182 {"https://foo.com/url?strk", false, ""}, |
(...skipping 22 matching lines...) Expand all Loading... |
209 const struct ProcessIsolationTestCase { | 205 const struct ProcessIsolationTestCase { |
210 const char* description; | 206 const char* description; |
211 const char* start_url; | 207 const char* start_url; |
212 bool start_in_instant_process; | 208 bool start_in_instant_process; |
213 const char* end_url; | 209 const char* end_url; |
214 bool end_in_instant_process; | 210 bool end_in_instant_process; |
215 bool same_site_instance; | 211 bool same_site_instance; |
216 } kProcessIsolationTestCases[] = { | 212 } kProcessIsolationTestCases[] = { |
217 {"Local NTP -> SRP", | 213 {"Local NTP -> SRP", |
218 "chrome-search://local-ntp", true, | 214 "chrome-search://local-ntp", true, |
219 "https://foo.com/url?strk", true, false }, | 215 "https://foo.com/url?strk", false, false }, |
220 {"Local NTP -> Regular", | 216 {"Local NTP -> Regular", |
221 "chrome-search://local-ntp", true, | 217 "chrome-search://local-ntp", true, |
222 "https://foo.com/other", false, false }, | 218 "https://foo.com/other", false, false }, |
223 {"Remote NTP -> SRP", | 219 {"Remote NTP -> SRP", |
224 "https://foo.com/newtab?strk", true, | 220 "https://foo.com/newtab?strk", true, |
225 "https://foo.com/url?strk", true, false }, | 221 "https://foo.com/url?strk", false, false }, |
226 {"Remote NTP -> Regular", | 222 {"Remote NTP -> Regular", |
227 "https://foo.com/newtab?strk", true, | 223 "https://foo.com/newtab?strk", true, |
228 "https://foo.com/other", false, false }, | 224 "https://foo.com/other", false, false }, |
229 {"SRP -> SRP", | 225 {"SRP -> SRP", |
230 "https://foo.com/url?strk", true, | 226 "https://foo.com/url?strk", false, |
231 "https://foo.com/url?strk", true, true }, | 227 "https://foo.com/url?strk", false, true }, |
232 {"SRP -> Regular", | 228 {"SRP -> Regular", |
233 "https://foo.com/url?strk", true, | 229 "https://foo.com/url?strk", false, |
234 "https://foo.com/other", false, false }, | 230 "https://foo.com/other", false, true }, |
235 {"Regular -> SRP", | 231 {"Regular -> SRP", |
236 "https://foo.com/other", false, | 232 "https://foo.com/other", false, |
237 "https://foo.com/url?strk", true, false }, | 233 "https://foo.com/url?strk", false, true }, |
238 }; | 234 }; |
239 | 235 |
240 TEST_F(SearchTest, ProcessIsolation) { | 236 TEST_F(SearchTest, ProcessIsolation) { |
241 EnableQueryExtractionForTesting(); | |
242 | |
243 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 237 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
244 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 238 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
245 AddTab(browser(), GURL("chrome://blank")); | 239 AddTab(browser(), GURL("chrome://blank")); |
246 const content::WebContents* contents = | 240 const content::WebContents* contents = |
247 browser()->tab_strip_model()->GetActiveWebContents(); | 241 browser()->tab_strip_model()->GetActiveWebContents(); |
248 | 242 |
249 // Navigate to start URL. | 243 // Navigate to start URL. |
250 NavigateAndCommitActiveTab(GURL(test.start_url)); | 244 NavigateAndCommitActiveTab(GURL(test.start_url)); |
251 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 245 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
252 << test.description; | 246 << test.description; |
(...skipping 17 matching lines...) Expand all Loading... |
270 EXPECT_EQ(test.same_site_instance, | 264 EXPECT_EQ(test.same_site_instance, |
271 start_rvh == contents->GetRenderViewHost()) | 265 start_rvh == contents->GetRenderViewHost()) |
272 << test.description; | 266 << test.description; |
273 EXPECT_EQ(test.same_site_instance, | 267 EXPECT_EQ(test.same_site_instance, |
274 start_rph == contents->GetRenderProcessHost()) | 268 start_rph == contents->GetRenderProcessHost()) |
275 << test.description; | 269 << test.description; |
276 } | 270 } |
277 } | 271 } |
278 | 272 |
279 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { | 273 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { |
280 EnableQueryExtractionForTesting(); | |
281 | |
282 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 274 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
283 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 275 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
284 AddTab(browser(), GURL("chrome://blank")); | 276 AddTab(browser(), GURL("chrome://blank")); |
285 content::WebContents* contents = | 277 content::WebContents* contents = |
286 browser()->tab_strip_model()->GetActiveWebContents(); | 278 browser()->tab_strip_model()->GetActiveWebContents(); |
287 | 279 |
288 // Navigate to start URL. | 280 // Navigate to start URL. |
289 NavigateAndCommitActiveTab(GURL(test.start_url)); | 281 NavigateAndCommitActiveTab(GURL(test.start_url)); |
290 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 282 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
291 << test.description; | 283 << test.description; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 {"https://foo.com/instant", false, "No search term replacement"}, | 329 {"https://foo.com/instant", false, "No search term replacement"}, |
338 {"chrome://blank/", false, "Chrome scheme"}, | 330 {"chrome://blank/", false, "Chrome scheme"}, |
339 {"chrome-search://foo", false, "Chrome-search scheme"}, | 331 {"chrome-search://foo", false, "Chrome-search scheme"}, |
340 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, | 332 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, |
341 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, | 333 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, |
342 {"https://foo.com/newtab?strk", true, "New tab URL"}, | 334 {"https://foo.com/newtab?strk", true, "New tab URL"}, |
343 {"http://foo.com/newtab?strk", false, "Insecure New tab URL"}, | 335 {"http://foo.com/newtab?strk", false, "Insecure New tab URL"}, |
344 }; | 336 }; |
345 | 337 |
346 TEST_F(SearchTest, InstantNTPExtendedEnabled) { | 338 TEST_F(SearchTest, InstantNTPExtendedEnabled) { |
347 EnableQueryExtractionForTesting(); | |
348 AddTab(browser(), GURL("chrome://blank")); | 339 AddTab(browser(), GURL("chrome://blank")); |
349 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 340 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
350 const SearchTestCase& test = kInstantNTPTestCases[i]; | 341 const SearchTestCase& test = kInstantNTPTestCases[i]; |
351 NavigateAndCommitActiveTab(GURL(test.url)); | 342 NavigateAndCommitActiveTab(GURL(test.url)); |
352 const content::WebContents* contents = | 343 const content::WebContents* contents = |
353 browser()->tab_strip_model()->GetWebContentsAt(0); | 344 browser()->tab_strip_model()->GetWebContentsAt(0); |
354 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) | 345 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) |
355 << test.url << " " << test.comment; | 346 << test.url << " " << test.comment; |
356 } | 347 } |
357 } | 348 } |
358 | 349 |
359 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { | 350 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { |
360 EnableQueryExtractionForTesting(); | |
361 AddTab(browser(), GURL("chrome://blank")); | 351 AddTab(browser(), GURL("chrome://blank")); |
362 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 352 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
363 const SearchTestCase& test = kInstantNTPTestCases[i]; | 353 const SearchTestCase& test = kInstantNTPTestCases[i]; |
364 NavigateAndCommitActiveTab(GURL(test.url)); | 354 NavigateAndCommitActiveTab(GURL(test.url)); |
365 content::WebContents* contents = | 355 content::WebContents* contents = |
366 browser()->tab_strip_model()->GetWebContentsAt(0); | 356 browser()->tab_strip_model()->GetWebContentsAt(0); |
367 content::NavigationController& controller = contents->GetController(); | 357 content::NavigationController& controller = contents->GetController(); |
368 controller.SetTransientEntry( | 358 controller.SetTransientEntry( |
369 controller.CreateNavigationEntry(GURL("chrome://blank"), | 359 controller.CreateNavigationEntry(GURL("chrome://blank"), |
370 content::Referrer(), | 360 content::Referrer(), |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 } | 568 } |
579 | 569 |
580 | 570 |
581 TEST_F(SearchTest, IsNTPURL) { | 571 TEST_F(SearchTest, IsNTPURL) { |
582 GURL invalid_url; | 572 GURL invalid_url; |
583 GURL ntp_url(chrome::kChromeUINewTabURL); | 573 GURL ntp_url(chrome::kChromeUINewTabURL); |
584 GURL local_ntp_url(chrome::kChromeSearchLocalNtpUrl); | 574 GURL local_ntp_url(chrome::kChromeSearchLocalNtpUrl); |
585 | 575 |
586 EXPECT_FALSE(IsNTPURL(invalid_url, profile())); | 576 EXPECT_FALSE(IsNTPURL(invalid_url, profile())); |
587 // No margin. | 577 // No margin. |
588 EnableQueryExtractionForTesting(); | |
589 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 578 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
590 GURL remote_ntp_url(GetInstantURL(profile(), false)); | 579 GURL remote_ntp_url(GetInstantURL(profile(), false)); |
591 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); | 580 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); |
592 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); | 581 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); |
593 | 582 |
594 EXPECT_FALSE(IsNTPURL(ntp_url, profile())); | 583 EXPECT_FALSE(IsNTPURL(ntp_url, profile())); |
595 EXPECT_TRUE(IsNTPURL(local_ntp_url, profile())); | 584 EXPECT_TRUE(IsNTPURL(local_ntp_url, profile())); |
596 EXPECT_TRUE(IsNTPURL(remote_ntp_url, profile())); | 585 EXPECT_TRUE(IsNTPURL(remote_ntp_url, profile())); |
597 EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, profile())); | 586 EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, profile())); |
598 EXPECT_TRUE(IsNTPURL(search_url_without_search_terms, profile())); | 587 EXPECT_FALSE(IsNTPURL(search_url_without_search_terms, profile())); |
599 | 588 |
600 EXPECT_FALSE(IsNTPURL(ntp_url, NULL)); | 589 EXPECT_FALSE(IsNTPURL(ntp_url, NULL)); |
601 EXPECT_FALSE(IsNTPURL(local_ntp_url, NULL)); | 590 EXPECT_FALSE(IsNTPURL(local_ntp_url, NULL)); |
602 EXPECT_FALSE(IsNTPURL(remote_ntp_url, NULL)); | 591 EXPECT_FALSE(IsNTPURL(remote_ntp_url, NULL)); |
603 EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, NULL)); | 592 EXPECT_FALSE(IsNTPURL(search_url_with_search_terms, NULL)); |
604 EXPECT_FALSE(IsNTPURL(search_url_without_search_terms, NULL)); | 593 EXPECT_FALSE(IsNTPURL(search_url_without_search_terms, NULL)); |
605 } | 594 } |
606 | 595 |
607 TEST_F(SearchTest, GetSearchURLs) { | 596 TEST_F(SearchTest, GetSearchURLs) { |
608 std::vector<GURL> search_urls = GetSearchURLs(profile()); | 597 std::vector<GURL> search_urls = GetSearchURLs(profile()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 data.search_terms_replacement_key = "espv"; | 701 data.search_terms_replacement_key = "espv"; |
713 template_url_ = new TemplateURL(data); | 702 template_url_ = new TemplateURL(data); |
714 // |template_url_service| takes ownership of |template_url_|. | 703 // |template_url_service| takes ownership of |template_url_|. |
715 template_url_service->Add(template_url_); | 704 template_url_service->Add(template_url_); |
716 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); | 705 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); |
717 } | 706 } |
718 | 707 |
719 TemplateURL* template_url_; | 708 TemplateURL* template_url_; |
720 }; | 709 }; |
721 | 710 |
722 TEST_F(SearchURLTest, QueryExtractionEnabled) { | 711 TEST_F(SearchURLTest, QueryExtractionDisabled) { |
723 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); | 712 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); |
724 EnableQueryExtractionForTesting(); | |
725 EXPECT_TRUE(IsQueryExtractionEnabled()); | |
726 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); | 713 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
727 GURL result(template_url_->url_ref().ReplaceSearchTerms( | 714 GURL result(template_url_->url_ref().ReplaceSearchTerms( |
728 search_terms_args, UIThreadSearchTermsData(profile()))); | 715 search_terms_args, UIThreadSearchTermsData(profile()))); |
729 ASSERT_TRUE(result.is_valid()); | |
730 // Query extraction is enabled. Make sure | |
731 // {google:instantExtendedEnabledParameter} is set in the search URL. | |
732 EXPECT_EQ("http://www.google.com/search?espv=2&q=foo", result.spec()); | |
733 } | |
734 | |
735 TEST_F(SearchURLTest, QueryExtractionDisabled) { | |
736 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); | |
737 EXPECT_FALSE(IsQueryExtractionEnabled()); | |
738 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); | |
739 GURL result(template_url_->url_ref().ReplaceSearchTerms( | |
740 search_terms_args, UIThreadSearchTermsData(profile()))); | |
741 ASSERT_TRUE(result.is_valid()); | 716 ASSERT_TRUE(result.is_valid()); |
742 // Query extraction is disabled. Make sure | 717 // Query extraction is disabled. Make sure |
743 // {google:instantExtendedEnabledParameter} is not set in the search URL. | 718 // {google:instantExtendedEnabledParameter} is not set in the search URL. |
744 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); | 719 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); |
745 } | 720 } |
746 | 721 |
747 } // namespace search | 722 } // namespace search |
OLD | NEW |