| 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 "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/metrics/histogram_base.h" | 7 #include "base/metrics/histogram_base.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 391 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 392 const SearchTestCase& test = kTestCases[i]; | 392 const SearchTestCase& test = kTestCases[i]; |
| 393 EXPECT_EQ(test.expected_result, | 393 EXPECT_EQ(test.expected_result, |
| 394 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | 394 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) |
| 395 << test.url << " " << test.comment; | 395 << test.url << " " << test.comment; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 TEST_F(SearchTest, CoerceCommandLineURLToTemplateURL) { | |
| 400 TemplateURL* template_url = | |
| 401 TemplateURLServiceFactory::GetForProfile(profile())-> | |
| 402 GetDefaultSearchProvider(); | |
| 403 EXPECT_EQ( | |
| 404 GURL("https://foo.com/dev?bar=bar#bar=bar"), | |
| 405 CoerceCommandLineURLToTemplateURL( | |
| 406 GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), | |
| 407 template_url->instant_url_ref(), kDisableStartMargin)); | |
| 408 } | |
| 409 | |
| 410 const SearchTestCase kInstantNTPTestCases[] = { | 399 const SearchTestCase kInstantNTPTestCases[] = { |
| 411 {"https://foo.com/instant?strk", true, "Valid Instant URL"}, | 400 {"https://foo.com/instant?strk", true, "Valid Instant URL"}, |
| 412 {"https://foo.com/instant#strk", true, "Valid Instant URL"}, | 401 {"https://foo.com/instant#strk", true, "Valid Instant URL"}, |
| 413 {"https://foo.com/url?strk", true, "Valid search URL"}, | 402 {"https://foo.com/url?strk", true, "Valid search URL"}, |
| 414 {"https://foo.com/url#strk", true, "Valid search URL"}, | 403 {"https://foo.com/url#strk", true, "Valid search URL"}, |
| 415 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, | 404 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, |
| 416 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, | 405 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, |
| 417 {"https://foo.com/url?strk&bar=", true, "No query terms"}, | 406 {"https://foo.com/url?strk&bar=", true, "No query terms"}, |
| 418 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, | 407 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, |
| 419 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, | 408 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 // Enable suggest. No difference. | 497 // Enable suggest. No difference. |
| 509 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 498 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 510 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 499 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 511 GetInstantURL(profile(), kDisableStartMargin)); | 500 GetInstantURL(profile(), kDisableStartMargin)); |
| 512 | 501 |
| 513 // Disable Instant. No difference, because suggest is still enabled. | 502 // Disable Instant. No difference, because suggest is still enabled. |
| 514 profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, false); | 503 profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, false); |
| 515 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 504 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 516 GetInstantURL(profile(), kDisableStartMargin)); | 505 GetInstantURL(profile(), kDisableStartMargin)); |
| 517 | 506 |
| 518 // Override the Instant URL on the commandline. Oops, forgot "strk". | |
| 519 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 520 switches::kInstantURL, | |
| 521 "http://myserver.com:9000/dev?bar=bar#bar=bar"); | |
| 522 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | |
| 523 | |
| 524 // Override with "strk". For fun, put it in the query, instead of the ref. | |
| 525 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 526 switches::kInstantURL, | |
| 527 "http://myserver.com:9000/dev?bar=bar&strk#bar=bar"); | |
| 528 EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar&strk#bar=bar"), | |
| 529 GetInstantURL(profile(), kDisableStartMargin)); | |
| 530 | |
| 531 // Disable suggest. No Instant URL. | 507 // Disable suggest. No Instant URL. |
| 532 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | 508 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); |
| 533 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | 509 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); |
| 534 } | 510 } |
| 535 | 511 |
| 536 TEST_F(SearchTest, StartMarginCGI) { | 512 TEST_F(SearchTest, StartMarginCGI) { |
| 537 // Instant is disabled, so no Instant URL. | 513 // Instant is disabled, so no Instant URL. |
| 538 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | 514 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); |
| 539 | 515 |
| 540 // Enable Instant. No margin. | 516 // Enable Instant. No margin. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 564 // Default search provider should now support instant. | 540 // Default search provider should now support instant. |
| 565 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); | 541 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); |
| 566 // Enable suggest. No difference. | 542 // Enable suggest. No difference. |
| 567 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 543 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 568 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); | 544 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); |
| 569 | 545 |
| 570 // Disable Instant. No difference. | 546 // Disable Instant. No difference. |
| 571 profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, false); | 547 profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, false); |
| 572 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); | 548 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); |
| 573 | 549 |
| 574 // Override the Instant URL on the commandline. Oops, forgot "strk". | |
| 575 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 576 switches::kInstantURL, | |
| 577 "http://myserver.com:9000/dev?bar=bar#bar=bar"); | |
| 578 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | |
| 579 | |
| 580 // Check that command line overrides don't affect the default search provider. | |
| 581 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); | |
| 582 | |
| 583 // Disable suggest. No Instant URL. | 550 // Disable suggest. No Instant URL. |
| 584 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | 551 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); |
| 585 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | 552 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); |
| 586 // Even with suggest disabled, the default search provider still supports | 553 // Even with suggest disabled, the default search provider still supports |
| 587 // instant. | 554 // instant. |
| 588 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); | 555 EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile())); |
| 589 | 556 |
| 590 // Set an Instant URL with no valid search terms replacement key. | 557 // Set an Instant URL with no valid search terms replacement key. |
| 591 SetDefaultInstantTemplateUrl(false); | 558 SetDefaultInstantTemplateUrl(false); |
| 592 | 559 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 651 |
| 685 // Now that suggest is back on and the instant url is good, the checkbox | 652 // Now that suggest is back on and the instant url is good, the checkbox |
| 686 // should be enabled and checked again, but still invisible. | 653 // should be enabled and checked again, but still invisible. |
| 687 EXPECT_FALSE(IsInstantCheckboxVisible()); | 654 EXPECT_FALSE(IsInstantCheckboxVisible()); |
| 688 EXPECT_TRUE(IsInstantCheckboxEnabled(profile())); | 655 EXPECT_TRUE(IsInstantCheckboxEnabled(profile())); |
| 689 EXPECT_FALSE(IsInstantCheckboxChecked(profile())); | 656 EXPECT_FALSE(IsInstantCheckboxChecked(profile())); |
| 690 } | 657 } |
| 691 | 658 |
| 692 | 659 |
| 693 } // namespace chrome | 660 } // namespace chrome |
| OLD | NEW |