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

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: Fix suggestion truncation. 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
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/ui/search/instant_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 class SearchTest : public BrowserWithTestWindowTest { 182 class SearchTest : public BrowserWithTestWindowTest {
183 protected: 183 protected:
184 virtual void SetUp() OVERRIDE { 184 virtual void SetUp() OVERRIDE {
185 BrowserWithTestWindowTest::SetUp(); 185 BrowserWithTestWindowTest::SetUp();
186 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 186 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
187 profile(), &TemplateURLServiceFactory::BuildInstanceFor); 187 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
188 TemplateURLService* template_url_service = 188 TemplateURLService* template_url_service =
189 TemplateURLServiceFactory::GetForProfile(profile()); 189 TemplateURLServiceFactory::GetForProfile(profile());
190 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); 190 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
191 SetSearchProvider(false);
192 }
191 193
194 void SetSearchProvider(bool is_google) {
195 TemplateURLService* template_url_service =
196 TemplateURLServiceFactory::GetForProfile(profile());
192 TemplateURLData data; 197 TemplateURLData data;
193 data.SetURL("http://foo.com/url?bar={searchTerms}"); 198 if (is_google) {
194 data.instant_url = "http://foo.com/instant?" 199 data.SetURL("http://www.google.com/");
195 "{google:omniboxStartMarginParameter}foo=foo#foo=foo"; 200 data.instant_url = "http://www.google.com/";
196 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); 201 } else {
197 data.search_terms_replacement_key = "strk"; 202 data.SetURL("http://foo.com/url?bar={searchTerms}");
198 203 data.instant_url = "http://foo.com/instant?"
204 "{google:omniboxStartMarginParameter}foo=foo#foo=foo";
205 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
206 data.search_terms_replacement_key = "strk";
207 }
199 TemplateURL* template_url = new TemplateURL(profile(), data); 208 TemplateURL* template_url = new TemplateURL(profile(), data);
200 // Takes ownership of |template_url|. 209 // Takes ownership of |template_url|.
201 template_url_service->Add(template_url); 210 template_url_service->Add(template_url);
202 template_url_service->SetDefaultSearchProvider(template_url); 211 template_url_service->SetDefaultSearchProvider(template_url);
203 } 212 }
204 }; 213 };
205 214
206 struct SearchTestCase { 215 struct SearchTestCase {
207 const char* url; 216 const char* url;
208 bool expected_result; 217 bool expected_result;
(...skipping 27 matching lines...) Expand all
236 EXPECT_EQ(test.expected_result, 245 EXPECT_EQ(test.expected_result,
237 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) 246 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
238 << test.url << " " << test.comment; 247 << test.url << " " << test.comment;
239 } 248 }
240 } 249 }
241 250
242 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { 251 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
243 EnableInstantExtendedAPIForTesting(); 252 EnableInstantExtendedAPIForTesting();
244 253
245 const SearchTestCase kTestCases[] = { 254 const SearchTestCase kTestCases[] = {
246 {chrome::kChromeSearchLocalOmniboxPopupURL, true, ""},
247 {chrome::kChromeSearchLocalNtpUrl, true, ""}, 255 {chrome::kChromeSearchLocalNtpUrl, true, ""},
256 {chrome::kChromeSearchLocalGoogleNtpUrl, true, ""},
248 {"https://foo.com/instant?strk", true, ""}, 257 {"https://foo.com/instant?strk", true, ""},
249 {"https://foo.com/instant#strk", true, ""}, 258 {"https://foo.com/instant#strk", true, ""},
250 {"https://foo.com/instant?strk=0", true, ""}, 259 {"https://foo.com/instant?strk=0", true, ""},
251 {"https://foo.com/url?strk", true, ""}, 260 {"https://foo.com/url?strk", true, ""},
252 {"https://foo.com/alt?strk", true, ""}, 261 {"https://foo.com/alt?strk", true, ""},
253 {"http://foo.com/instant", false, "Non-HTTPS"}, 262 {"http://foo.com/instant", false, "Non-HTTPS"},
254 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, 263 {"http://foo.com/instant?strk", false, "Non-HTTPS"},
255 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, 264 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
256 {"https://foo.com/instant", false, "No search terms replacement"}, 265 {"https://foo.com/instant", false, "No search terms replacement"},
257 {"https://foo.com/?strk", false, "Non-exact path"}, 266 {"https://foo.com/?strk", false, "Non-exact path"},
(...skipping 12 matching lines...) Expand all
270 TemplateURLServiceFactory::GetForProfile(profile())-> 279 TemplateURLServiceFactory::GetForProfile(profile())->
271 GetDefaultSearchProvider(); 280 GetDefaultSearchProvider();
272 EXPECT_EQ( 281 EXPECT_EQ(
273 GURL("https://foo.com/dev?bar=bar#bar=bar"), 282 GURL("https://foo.com/dev?bar=bar#bar=bar"),
274 CoerceCommandLineURLToTemplateURL( 283 CoerceCommandLineURLToTemplateURL(
275 GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), 284 GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"),
276 template_url->instant_url_ref(), kDisableStartMargin)); 285 template_url->instant_url_ref(), kDisableStartMargin));
277 } 286 }
278 287
279 const SearchTestCase kInstantNTPTestCases[] = { 288 const SearchTestCase kInstantNTPTestCases[] = {
280 {"https://foo.com/instant?strk", true, "Valid Instant URL"}, 289 {"https://foo.com/instant?strk", true, "Valid Instant URL"},
281 {"https://foo.com/instant#strk", true, "Valid Instant URL"}, 290 {"https://foo.com/instant#strk", true, "Valid Instant URL"},
282 {"https://foo.com/url?strk", true, "Valid search URL"}, 291 {"https://foo.com/url?strk", true, "Valid search URL"},
283 {"https://foo.com/url#strk", true, "Valid search URL"}, 292 {"https://foo.com/url#strk", true, "Valid search URL"},
284 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, 293 {"https://foo.com/alt?strk", true, "Valid alternative URL"},
285 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, 294 {"https://foo.com/alt#strk", true, "Valid alternative URL"},
286 {"https://foo.com/url?strk&bar=", true, "No query terms"}, 295 {"https://foo.com/url?strk&bar=", true, "No query terms"},
287 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, 296 {"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"}, 297 {"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"}, 298 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"},
290 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, 299 {"http://foo.com/instant?strk=1", false, "Insecure URL"},
291 {"https://foo.com/instant", false, "No search terms replacement"}, 300 {"https://foo.com/instant", false, "No search term replacement"},
292 {"chrome://blank/", false, "Chrome scheme"}, 301 {"chrome://blank/", false, "Chrome scheme"},
293 {"chrome-search//foo", false, "Chrome-search scheme"}, 302 {"chrome-search://foo", false, "Chrome-search scheme"},
294 {chrome::kChromeSearchLocalOmniboxPopupURL, false, "Local omnibox popup"}, 303 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
295 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, 304 {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"},
296 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, 305 {"https://bar.com/instant?strk=1", false, "Random non-search page"},
297 }; 306 };
298 307
299 TEST_F(SearchTest, InstantNTPExtendedEnabled) { 308 TEST_F(SearchTest, InstantNTPExtendedEnabled) {
300 EnableInstantExtendedAPIForTesting(); 309 EnableInstantExtendedAPIForTesting();
301 AddTab(browser(), GURL("chrome://blank")); 310 AddTab(browser(), GURL("chrome://blank"));
302 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 311 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
303 const SearchTestCase& test = kInstantNTPTestCases[i]; 312 const SearchTestCase& test = kInstantNTPTestCases[i];
304 NavigateAndCommitActiveTab(GURL(test.url)); 313 NavigateAndCommitActiveTab(GURL(test.url));
314 SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl);
305 const content::WebContents* contents = 315 const content::WebContents* contents =
306 browser()->tab_strip_model()->GetWebContentsAt(0); 316 browser()->tab_strip_model()->GetWebContentsAt(0);
307 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) 317 EXPECT_EQ(test.expected_result, IsInstantNTP(contents))
308 << test.url << " " << test.comment; 318 << test.url << " " << test.comment;
309 } 319 }
310 } 320 }
311 321
312 TEST_F(SearchTest, InstantNTPExtendedDisabled) { 322 TEST_F(SearchTest, InstantNTPExtendedDisabled) {
313 AddTab(browser(), GURL("chrome://blank")); 323 AddTab(browser(), GURL("chrome://blank"));
314 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 324 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
315 const SearchTestCase& test = kInstantNTPTestCases[i]; 325 const SearchTestCase& test = kInstantNTPTestCases[i];
316 NavigateAndCommitActiveTab(GURL(test.url)); 326 NavigateAndCommitActiveTab(GURL(test.url));
317 const content::WebContents* contents = 327 const content::WebContents* contents =
318 browser()->tab_strip_model()->GetWebContentsAt(0); 328 browser()->tab_strip_model()->GetWebContentsAt(0);
319 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment; 329 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment;
320 } 330 }
321 } 331 }
322 332
323 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { 333 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
324 EnableInstantExtendedAPIForTesting(); 334 EnableInstantExtendedAPIForTesting();
325 AddTab(browser(), GURL("chrome://blank")); 335 AddTab(browser(), GURL("chrome://blank"));
326 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 336 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
327 const SearchTestCase& test = kInstantNTPTestCases[i]; 337 const SearchTestCase& test = kInstantNTPTestCases[i];
328 NavigateAndCommitActiveTab(GURL(test.url)); 338 NavigateAndCommitActiveTab(GURL(test.url));
339 SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl);
329 content::WebContents* contents = 340 content::WebContents* contents =
330 browser()->tab_strip_model()->GetWebContentsAt(0); 341 browser()->tab_strip_model()->GetWebContentsAt(0);
331 content::NavigationController& controller = contents->GetController(); 342 content::NavigationController& controller = contents->GetController();
332 controller.SetTransientEntry( 343 controller.SetTransientEntry(
333 controller.CreateNavigationEntry(GURL("chrome://blank"), 344 controller.CreateNavigationEntry(GURL("chrome://blank"),
334 content::Referrer(), 345 content::Referrer(),
335 content::PAGE_TRANSITION_LINK, 346 content::PAGE_TRANSITION_LINK,
336 false, 347 false,
337 std::string(), 348 std::string(),
338 contents->GetBrowserContext())); 349 contents->GetBrowserContext()));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 TemplateURL* template_url = new TemplateURL(profile(), data); 509 TemplateURL* template_url = new TemplateURL(profile(), data);
499 // Takes ownership of |template_url|. 510 // Takes ownership of |template_url|.
500 template_url_service->Add(template_url); 511 template_url_service->Add(template_url);
501 template_url_service->SetDefaultSearchProvider(template_url); 512 template_url_service->SetDefaultSearchProvider(template_url);
502 } 513 }
503 514
504 EXPECT_FALSE(DefaultSearchProviderSupportsInstant(profile())); 515 EXPECT_FALSE(DefaultSearchProviderSupportsInstant(profile()));
505 } 516 }
506 517
507 } // namespace chrome 518 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/ui/search/instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698