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

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

Issue 13905008: Merge local_omnibox_popup into local_ntp. Render the Google logo and fakebox if Google is the sear… (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Respond to Samarth's comments. Created 7 years, 8 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
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/search/search.h" 8 #include "chrome/browser/search/search.h"
9 #include "chrome/browser/search_engines/template_url_service.h" 9 #include "chrome/browser/search_engines/template_url_service.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h" 10 #include "chrome/browser/search_engines/template_url_service_factory.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 data.instant_url = "http://foo.com/instant?" 194 data.instant_url = "http://foo.com/instant?"
195 "{google:omniboxStartMarginParameter}foo=foo#foo=foo"; 195 "{google:omniboxStartMarginParameter}foo=foo#foo=foo";
196 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); 196 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
197 data.search_terms_replacement_key = "strk"; 197 data.search_terms_replacement_key = "strk";
198 198
199 TemplateURL* template_url = new TemplateURL(profile(), data); 199 TemplateURL* template_url = new TemplateURL(profile(), data);
200 // Takes ownership of |template_url|. 200 // Takes ownership of |template_url|.
201 template_url_service->Add(template_url); 201 template_url_service->Add(template_url);
202 template_url_service->SetDefaultSearchProvider(template_url); 202 template_url_service->SetDefaultSearchProvider(template_url);
203 } 203 }
204
205 void SetGoogleAsSearchProvider() {
206 TemplateURLService* template_url_service =
207 TemplateURLServiceFactory::GetForProfile(profile());
208 TemplateURLData data;
209 data.SetURL("http://www.google.com/");
210 data.instant_url = "http://www.google.com/";
211 TemplateURL* template_url = new TemplateURL(profile(), data);
212 // Takes ownership of |template_url|.
213 template_url_service->Add(template_url);
214 template_url_service->SetDefaultSearchProvider(template_url);
215 }
204 }; 216 };
205 217
206 struct SearchTestCase { 218 struct SearchTestCase {
207 const char* url; 219 const char* url;
208 bool expected_result; 220 bool expected_result;
209 const char* comment; 221 const char* comment;
210 }; 222 };
211 223
212 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) { 224 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) {
213 const SearchTestCase kTestCases[] = { 225 const SearchTestCase kTestCases[] = {
(...skipping 22 matching lines...) Expand all
236 EXPECT_EQ(test.expected_result, 248 EXPECT_EQ(test.expected_result,
237 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) 249 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
238 << test.url << " " << test.comment; 250 << test.url << " " << test.comment;
239 } 251 }
240 } 252 }
241 253
242 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { 254 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
243 EnableInstantExtendedAPIForTesting(); 255 EnableInstantExtendedAPIForTesting();
244 256
245 const SearchTestCase kTestCases[] = { 257 const SearchTestCase kTestCases[] = {
246 {chrome::kChromeSearchLocalOmniboxPopupURL, true, ""},
247 {chrome::kChromeSearchLocalNtpUrl, true, ""}, 258 {chrome::kChromeSearchLocalNtpUrl, true, ""},
259 {chrome::kChromeSearchLocalGoogleNtpUrl, true, ""},
248 {"https://foo.com/instant?strk", true, ""}, 260 {"https://foo.com/instant?strk", true, ""},
249 {"https://foo.com/instant#strk", true, ""}, 261 {"https://foo.com/instant#strk", true, ""},
250 {"https://foo.com/instant?strk=0", true, ""}, 262 {"https://foo.com/instant?strk=0", true, ""},
251 {"https://foo.com/url?strk", true, ""}, 263 {"https://foo.com/url?strk", true, ""},
252 {"https://foo.com/alt?strk", true, ""}, 264 {"https://foo.com/alt?strk", true, ""},
253 {"http://foo.com/instant", false, "Non-HTTPS"}, 265 {"http://foo.com/instant", false, "Non-HTTPS"},
254 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, 266 {"http://foo.com/instant?strk", false, "Non-HTTPS"},
255 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, 267 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
256 {"https://foo.com/instant", false, "No search terms replacement"}, 268 {"https://foo.com/instant", false, "No search terms replacement"},
257 {"https://foo.com/?strk", false, "Non-exact path"}, 269 {"https://foo.com/?strk", false, "Non-exact path"},
(...skipping 12 matching lines...) Expand all
270 TemplateURLServiceFactory::GetForProfile(profile())-> 282 TemplateURLServiceFactory::GetForProfile(profile())->
271 GetDefaultSearchProvider(); 283 GetDefaultSearchProvider();
272 EXPECT_EQ( 284 EXPECT_EQ(
273 GURL("https://foo.com/dev?bar=bar#bar=bar"), 285 GURL("https://foo.com/dev?bar=bar#bar=bar"),
274 CoerceCommandLineURLToTemplateURL( 286 CoerceCommandLineURLToTemplateURL(
275 GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), 287 GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"),
276 template_url->instant_url_ref(), kDisableStartMargin)); 288 template_url->instant_url_ref(), kDisableStartMargin));
277 } 289 }
278 290
279 const SearchTestCase kInstantNTPTestCases[] = { 291 const SearchTestCase kInstantNTPTestCases[] = {
280 {"https://foo.com/instant?strk", true, "Valid Instant URL"}, 292 {"https://foo.com/instant?strk", true, "Valid Instant URL"},
281 {"https://foo.com/instant#strk", true, "Valid Instant URL"}, 293 {"https://foo.com/instant#strk", true, "Valid Instant URL"},
282 {"https://foo.com/url?strk", true, "Valid search URL"}, 294 {"https://foo.com/url?strk", true, "Valid search URL"},
283 {"https://foo.com/url#strk", true, "Valid search URL"}, 295 {"https://foo.com/url#strk", true, "Valid search URL"},
284 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, 296 {"https://foo.com/alt?strk", true, "Valid alternative URL"},
285 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, 297 {"https://foo.com/alt#strk", true, "Valid alternative URL"},
286 {"https://foo.com/url?strk&bar=", true, "No query terms"}, 298 {"https://foo.com/url?strk&bar=", true, "No query terms"},
287 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, 299 {"https://foo.com/url?strk&q=abc", true, "No query terms key"},
288 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, 300 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"},
289 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, 301 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"},
290 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, 302 {"http://foo.com/instant?strk=1", false, "Insecure URL"},
291 {"https://foo.com/instant", false, "No search terms replacement"}, 303 {"https://foo.com/instant", false, "No search term replacement"},
292 {"chrome://blank/", false, "Chrome scheme"}, 304 {"chrome://blank/", false, "Chrome scheme"},
293 {"chrome-search//foo", false, "Chrome-search scheme"}, 305 {"chrome-search//foo", false, "Chrome-search scheme"},
294 {chrome::kChromeSearchLocalOmniboxPopupURL, false, "Local omnibox popup"}, 306 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
295 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, 307 {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"},
296 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, 308 {"https://bar.com/instant?strk=1", false, "Random non-search page"},
297 }; 309 };
298 310
299 TEST_F(SearchTest, InstantNTPExtendedEnabled) { 311 TEST_F(SearchTest, InstantNTPExtendedEnabled) {
300 EnableInstantExtendedAPIForTesting(); 312 EnableInstantExtendedAPIForTesting();
301 AddTab(browser(), GURL("chrome://blank")); 313 AddTab(browser(), GURL("chrome://blank"));
302 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 314 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
303 const SearchTestCase& test = kInstantNTPTestCases[i]; 315 const SearchTestCase& test = kInstantNTPTestCases[i];
304 NavigateAndCommitActiveTab(GURL(test.url)); 316 NavigateAndCommitActiveTab(GURL(test.url));
317
318 if (test.url == chrome::kChromeSearchLocalGoogleNtpUrl)
319 SetGoogleAsSearchProvider();
320
305 const content::WebContents* contents = 321 const content::WebContents* contents =
306 browser()->tab_strip_model()->GetWebContentsAt(0); 322 browser()->tab_strip_model()->GetWebContentsAt(0);
307 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) 323 EXPECT_EQ(test.expected_result, IsInstantNTP(contents))
308 << test.url << " " << test.comment; 324 << test.url << " " << test.comment;
309 } 325 }
310 } 326 }
311 327
312 TEST_F(SearchTest, InstantNTPExtendedDisabled) { 328 TEST_F(SearchTest, InstantNTPExtendedDisabled) {
313 AddTab(browser(), GURL("chrome://blank")); 329 AddTab(browser(), GURL("chrome://blank"));
314 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 330 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
315 const SearchTestCase& test = kInstantNTPTestCases[i]; 331 const SearchTestCase& test = kInstantNTPTestCases[i];
316 NavigateAndCommitActiveTab(GURL(test.url)); 332 NavigateAndCommitActiveTab(GURL(test.url));
317 const content::WebContents* contents = 333 const content::WebContents* contents =
318 browser()->tab_strip_model()->GetWebContentsAt(0); 334 browser()->tab_strip_model()->GetWebContentsAt(0);
319 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment; 335 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment;
320 } 336 }
321 } 337 }
322 338
323 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { 339 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
324 EnableInstantExtendedAPIForTesting(); 340 EnableInstantExtendedAPIForTesting();
325 AddTab(browser(), GURL("chrome://blank")); 341 AddTab(browser(), GURL("chrome://blank"));
326 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 342 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
327 const SearchTestCase& test = kInstantNTPTestCases[i]; 343 const SearchTestCase& test = kInstantNTPTestCases[i];
328 NavigateAndCommitActiveTab(GURL(test.url)); 344 NavigateAndCommitActiveTab(GURL(test.url));
345 if (test.url == chrome::kChromeSearchLocalGoogleNtpUrl)
346 SetGoogleAsSearchProvider();
347
329 content::WebContents* contents = 348 content::WebContents* contents =
330 browser()->tab_strip_model()->GetWebContentsAt(0); 349 browser()->tab_strip_model()->GetWebContentsAt(0);
331 content::NavigationController& controller = contents->GetController(); 350 content::NavigationController& controller = contents->GetController();
332 controller.SetTransientEntry( 351 controller.SetTransientEntry(
333 controller.CreateNavigationEntry(GURL("chrome://blank"), 352 controller.CreateNavigationEntry(GURL("chrome://blank"),
334 content::Referrer(), 353 content::Referrer(),
335 content::PAGE_TRANSITION_LINK, 354 content::PAGE_TRANSITION_LINK,
336 false, 355 false,
337 std::string(), 356 std::string(),
338 contents->GetBrowserContext())); 357 contents->GetBrowserContext()));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 TemplateURL* template_url = new TemplateURL(profile(), data); 517 TemplateURL* template_url = new TemplateURL(profile(), data);
499 // Takes ownership of |template_url|. 518 // Takes ownership of |template_url|.
500 template_url_service->Add(template_url); 519 template_url_service->Add(template_url);
501 template_url_service->SetDefaultSearchProvider(template_url); 520 template_url_service->SetDefaultSearchProvider(template_url);
502 } 521 }
503 522
504 EXPECT_FALSE(DefaultSearchProviderSupportsInstant(profile())); 523 EXPECT_FALSE(DefaultSearchProviderSupportsInstant(profile()));
505 } 524 }
506 525
507 } // namespace chrome 526 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698