| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 histogram_ = base::StatisticsRecorder::FindHistogram( | 225 histogram_ = base::StatisticsRecorder::FindHistogram( |
| 226 "InstantExtended.OptInState"); | 226 "InstantExtended.OptInState"); |
| 227 } | 227 } |
| 228 return histogram_; | 228 return histogram_; |
| 229 } | 229 } |
| 230 base::HistogramBase* histogram_; | 230 base::HistogramBase* histogram_; |
| 231 scoped_ptr<base::FieldTrialList> field_trial_list_; | 231 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 232 std::vector<int> previous_metrics_count_; | 232 std::vector<int> previous_metrics_count_; |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) { | |
| 236 GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI); | |
| 237 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 238 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 239 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); | |
| 240 #else | |
| 241 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 242 #endif | |
| 243 ValidateMetrics(INSTANT_EXTENDED_OPT_IN); | |
| 244 } | |
| 245 | |
| 246 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) { | 235 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) { |
| 247 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | 236 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 248 "Group1 espv:42")); | 237 "Group1 espv:42")); |
| 249 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 238 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 250 EXPECT_EQ(42ul, EmbeddedSearchPageVersion()); | 239 EXPECT_EQ(42ul, EmbeddedSearchPageVersion()); |
| 251 ValidateMetrics(INSTANT_EXTENDED_NOT_SET); | 240 ValidateMetrics(INSTANT_EXTENDED_NOT_SET); |
| 252 } | 241 } |
| 253 | 242 |
| 254 TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) { | |
| 255 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 256 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | |
| 257 "Group1 espv:2")); | |
| 258 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); | |
| 259 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | |
| 260 ValidateMetrics(INSTANT_EXTENDED_OPT_OUT); | |
| 261 } | |
| 262 | |
| 263 typedef InstantExtendedAPIEnabledTest ShouldHideTopVerbatimTest; | 243 typedef InstantExtendedAPIEnabledTest ShouldHideTopVerbatimTest; |
| 264 | 244 |
| 265 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) { | 245 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) { |
| 266 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | 246 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 267 "Control")); | 247 "Control")); |
| 268 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); | 248 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); |
| 269 } | 249 } |
| 270 | 250 |
| 271 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) { | 251 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) { |
| 272 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | 252 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| (...skipping 12 matching lines...) Expand all Loading... |
| 285 "EmbeddedSearch", "Controll1 hide_verbatim:1")); | 265 "EmbeddedSearch", "Controll1 hide_verbatim:1")); |
| 286 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); | 266 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); |
| 287 } | 267 } |
| 288 | 268 |
| 289 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { | 269 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { |
| 290 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | 270 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 291 "Group1 hide_verbatim:0")); | 271 "Group1 hide_verbatim:0")); |
| 292 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); | 272 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); |
| 293 } | 273 } |
| 294 | 274 |
| 295 typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest; | |
| 296 | |
| 297 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) { | |
| 298 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", | |
| 299 "Group1 espv:2")); | |
| 300 EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP()); | |
| 301 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 302 EXPECT_FALSE(IsQueryExtractionEnabled()); | |
| 303 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 304 } | |
| 305 | |
| 306 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) { | |
| 307 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 308 "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:0")); | |
| 309 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP()); | |
| 310 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 311 EXPECT_TRUE(IsQueryExtractionEnabled()); | |
| 312 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 313 } | |
| 314 | |
| 315 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) { | |
| 316 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 317 "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:1")); | |
| 318 EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP()); | |
| 319 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 320 EXPECT_FALSE(IsQueryExtractionEnabled()); | |
| 321 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 322 } | |
| 323 | |
| 324 typedef InstantExtendedAPIEnabledTest DisplaySearchButtonTest; | 275 typedef InstantExtendedAPIEnabledTest DisplaySearchButtonTest; |
| 325 | 276 |
| 326 TEST_F(DisplaySearchButtonTest, NotSet) { | 277 TEST_F(DisplaySearchButtonTest, NotSet) { |
| 327 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 278 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 328 "EmbeddedSearch", "Group1 espv:2")); | 279 "EmbeddedSearch", "Group1 espv:2")); |
| 329 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 280 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
| 330 } | 281 } |
| 331 | 282 |
| 332 TEST_F(DisplaySearchButtonTest, Never) { | 283 TEST_F(DisplaySearchButtonTest, Never) { |
| 333 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 284 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 scoped_ptr<base::FieldTrialList> field_trial_list_; | 400 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 450 }; | 401 }; |
| 451 | 402 |
| 452 struct SearchTestCase { | 403 struct SearchTestCase { |
| 453 const char* url; | 404 const char* url; |
| 454 bool expected_result; | 405 bool expected_result; |
| 455 const char* comment; | 406 const char* comment; |
| 456 }; | 407 }; |
| 457 | 408 |
| 458 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { | 409 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { |
| 459 EnableInstantExtendedAPIForTesting(); | 410 EnableQueryExtractionForTesting(); |
| 460 | 411 |
| 461 const SearchTestCase kTestCases[] = { | 412 const SearchTestCase kTestCases[] = { |
| 462 {chrome::kChromeSearchLocalNtpUrl, true, ""}, | 413 {chrome::kChromeSearchLocalNtpUrl, true, ""}, |
| 463 {"https://foo.com/instant?strk", true, ""}, | 414 {"https://foo.com/instant?strk", true, ""}, |
| 464 {"https://foo.com/instant#strk", true, ""}, | 415 {"https://foo.com/instant#strk", true, ""}, |
| 465 {"https://foo.com/instant?strk=0", true, ""}, | 416 {"https://foo.com/instant?strk=0", true, ""}, |
| 466 {"https://foo.com/url?strk", true, ""}, | 417 {"https://foo.com/url?strk", true, ""}, |
| 467 {"https://foo.com/alt?strk", true, ""}, | 418 {"https://foo.com/alt?strk", true, ""}, |
| 468 {"http://foo.com/instant", false, "Non-HTTPS"}, | 419 {"http://foo.com/instant", false, "Non-HTTPS"}, |
| 469 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, | 420 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 500 | 451 |
| 501 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 452 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 502 const SearchTestCase& test = kTestCases[i]; | 453 const SearchTestCase& test = kTestCases[i]; |
| 503 EXPECT_EQ(test.expected_result, | 454 EXPECT_EQ(test.expected_result, |
| 504 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | 455 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) |
| 505 << test.url << " " << test.comment; | 456 << test.url << " " << test.comment; |
| 506 } | 457 } |
| 507 } | 458 } |
| 508 | 459 |
| 509 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { | 460 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { |
| 510 EnableInstantExtendedAPIForTesting(); | 461 EnableQueryExtractionForTesting(); |
| 511 | 462 |
| 512 const SearchTestCase kTestCases[] = { | 463 const SearchTestCase kTestCases[] = { |
| 513 {"chrome-search://local-ntp", true, "Local NTP"}, | 464 {"chrome-search://local-ntp", true, "Local NTP"}, |
| 514 {"chrome-search://online-ntp", true, "Online NTP"}, | 465 {"chrome-search://online-ntp", true, "Online NTP"}, |
| 515 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, | 466 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, |
| 516 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, | 467 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, |
| 517 {"chrome-search://foo.com", false, "Search result page"}, | 468 {"chrome-search://foo.com", false, "Search result page"}, |
| 518 {"https://foo.com/instant?strk", false, ""}, | 469 {"https://foo.com/instant?strk", false, ""}, |
| 519 {"https://foo.com/instant#strk", false, ""}, | 470 {"https://foo.com/instant#strk", false, ""}, |
| 520 {"https://foo.com/instant?strk=0", false, ""}, | 471 {"https://foo.com/instant?strk=0", false, ""}, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 "https://foo.com/url?strk", true, true }, | 515 "https://foo.com/url?strk", true, true }, |
| 565 {"SRP -> Regular", | 516 {"SRP -> Regular", |
| 566 "https://foo.com/url?strk", true, | 517 "https://foo.com/url?strk", true, |
| 567 "https://foo.com/other", false, false }, | 518 "https://foo.com/other", false, false }, |
| 568 {"Regular -> SRP", | 519 {"Regular -> SRP", |
| 569 "https://foo.com/other", false, | 520 "https://foo.com/other", false, |
| 570 "https://foo.com/url?strk", true, false }, | 521 "https://foo.com/url?strk", true, false }, |
| 571 }; | 522 }; |
| 572 | 523 |
| 573 TEST_F(SearchTest, ProcessIsolation) { | 524 TEST_F(SearchTest, ProcessIsolation) { |
| 574 EnableInstantExtendedAPIForTesting(); | 525 EnableQueryExtractionForTesting(); |
| 575 | 526 |
| 576 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 527 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
| 577 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 528 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
| 578 AddTab(browser(), GURL("chrome://blank")); | 529 AddTab(browser(), GURL("chrome://blank")); |
| 579 const content::WebContents* contents = | 530 const content::WebContents* contents = |
| 580 browser()->tab_strip_model()->GetActiveWebContents(); | 531 browser()->tab_strip_model()->GetActiveWebContents(); |
| 581 | 532 |
| 582 // Navigate to start URL. | 533 // Navigate to start URL. |
| 583 NavigateAndCommitActiveTab(GURL(test.start_url)); | 534 NavigateAndCommitActiveTab(GURL(test.start_url)); |
| 584 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 535 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 603 EXPECT_EQ(test.same_site_instance, | 554 EXPECT_EQ(test.same_site_instance, |
| 604 start_rvh == contents->GetRenderViewHost()) | 555 start_rvh == contents->GetRenderViewHost()) |
| 605 << test.description; | 556 << test.description; |
| 606 EXPECT_EQ(test.same_site_instance, | 557 EXPECT_EQ(test.same_site_instance, |
| 607 start_rph == contents->GetRenderProcessHost()) | 558 start_rph == contents->GetRenderProcessHost()) |
| 608 << test.description; | 559 << test.description; |
| 609 } | 560 } |
| 610 } | 561 } |
| 611 | 562 |
| 612 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { | 563 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { |
| 613 EnableInstantExtendedAPIForTesting(); | 564 EnableQueryExtractionForTesting(); |
| 614 | 565 |
| 615 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 566 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
| 616 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 567 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
| 617 AddTab(browser(), GURL("chrome://blank")); | 568 AddTab(browser(), GURL("chrome://blank")); |
| 618 content::WebContents* contents = | 569 content::WebContents* contents = |
| 619 browser()->tab_strip_model()->GetActiveWebContents(); | 570 browser()->tab_strip_model()->GetActiveWebContents(); |
| 620 | 571 |
| 621 // Navigate to start URL. | 572 // Navigate to start URL. |
| 622 NavigateAndCommitActiveTab(GURL(test.start_url)); | 573 NavigateAndCommitActiveTab(GURL(test.start_url)); |
| 623 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 574 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, | 619 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, |
| 669 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, | 620 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, |
| 670 {"https://foo.com/instant", false, "No search term replacement"}, | 621 {"https://foo.com/instant", false, "No search term replacement"}, |
| 671 {"chrome://blank/", false, "Chrome scheme"}, | 622 {"chrome://blank/", false, "Chrome scheme"}, |
| 672 {"chrome-search://foo", false, "Chrome-search scheme"}, | 623 {"chrome-search://foo", false, "Chrome-search scheme"}, |
| 673 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, | 624 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, |
| 674 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, | 625 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, |
| 675 }; | 626 }; |
| 676 | 627 |
| 677 TEST_F(SearchTest, InstantNTPExtendedEnabled) { | 628 TEST_F(SearchTest, InstantNTPExtendedEnabled) { |
| 678 EnableInstantExtendedAPIForTesting(); | 629 EnableQueryExtractionForTesting(); |
| 679 // TODO(samarth): update test cases to use cacheable NTP URLs and remove this. | 630 // TODO(samarth): update test cases to use cacheable NTP URLs and remove this. |
| 680 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 631 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 681 "InstantExtended", "Group1 use_cacheable_ntp:0")); | 632 "InstantExtended", "Group1 use_cacheable_ntp:0")); |
| 682 AddTab(browser(), GURL("chrome://blank")); | 633 AddTab(browser(), GURL("chrome://blank")); |
| 683 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 634 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
| 684 const SearchTestCase& test = kInstantNTPTestCases[i]; | 635 const SearchTestCase& test = kInstantNTPTestCases[i]; |
| 685 NavigateAndCommitActiveTab(GURL(test.url)); | 636 NavigateAndCommitActiveTab(GURL(test.url)); |
| 686 const content::WebContents* contents = | 637 const content::WebContents* contents = |
| 687 browser()->tab_strip_model()->GetWebContentsAt(0); | 638 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 688 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) | 639 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) |
| 689 << test.url << " " << test.comment; | 640 << test.url << " " << test.comment; |
| 690 } | 641 } |
| 691 } | 642 } |
| 692 | 643 |
| 693 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { | 644 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { |
| 694 EnableInstantExtendedAPIForTesting(); | 645 EnableQueryExtractionForTesting(); |
| 695 // TODO(samarth): update test cases to use cacheable NTP URLs and remove this. | 646 // TODO(samarth): update test cases to use cacheable NTP URLs and remove this. |
| 696 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 647 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 697 "InstantExtended", "Group1 use_cacheable_ntp:0")); | 648 "InstantExtended", "Group1 use_cacheable_ntp:0")); |
| 698 AddTab(browser(), GURL("chrome://blank")); | 649 AddTab(browser(), GURL("chrome://blank")); |
| 699 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 650 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
| 700 const SearchTestCase& test = kInstantNTPTestCases[i]; | 651 const SearchTestCase& test = kInstantNTPTestCases[i]; |
| 701 NavigateAndCommitActiveTab(GURL(test.url)); | 652 NavigateAndCommitActiveTab(GURL(test.url)); |
| 702 content::WebContents* contents = | 653 content::WebContents* contents = |
| 703 browser()->tab_strip_model()->GetWebContentsAt(0); | 654 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 704 content::NavigationController& controller = contents->GetController(); | 655 content::NavigationController& controller = contents->GetController(); |
| 705 controller.SetTransientEntry( | 656 controller.SetTransientEntry( |
| 706 controller.CreateNavigationEntry(GURL("chrome://blank"), | 657 controller.CreateNavigationEntry(GURL("chrome://blank"), |
| 707 content::Referrer(), | 658 content::Referrer(), |
| 708 content::PAGE_TRANSITION_LINK, | 659 content::PAGE_TRANSITION_LINK, |
| 709 false, | 660 false, |
| 710 std::string(), | 661 std::string(), |
| 711 contents->GetBrowserContext())); | 662 contents->GetBrowserContext())); |
| 712 // The active entry is chrome://blank and not an NTP. | 663 // The active entry is chrome://blank and not an NTP. |
| 713 EXPECT_FALSE(IsInstantNTP(contents)); | 664 EXPECT_FALSE(IsInstantNTP(contents)); |
| 714 EXPECT_EQ(test.expected_result, | 665 EXPECT_EQ(test.expected_result, |
| 715 NavEntryIsInstantNTP(contents, | 666 NavEntryIsInstantNTP(contents, |
| 716 controller.GetLastCommittedEntry())) | 667 controller.GetLastCommittedEntry())) |
| 717 << test.url << " " << test.comment; | 668 << test.url << " " << test.comment; |
| 718 } | 669 } |
| 719 } | 670 } |
| 720 | 671 |
| 721 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { | 672 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { |
| 722 EnableInstantExtendedAPIForTesting(); | |
| 723 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 673 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 724 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 674 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 725 | 675 |
| 726 AddTab(browser(), GURL("chrome://blank")); | 676 AddTab(browser(), GURL("chrome://blank")); |
| 727 content::WebContents* contents = | 677 content::WebContents* contents = |
| 728 browser()->tab_strip_model()->GetWebContentsAt(0); | 678 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 729 content::NavigationController& controller = contents->GetController(); | 679 content::NavigationController& controller = contents->GetController(); |
| 730 // Local NTP. | 680 // Local NTP. |
| 731 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 681 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 732 EXPECT_TRUE(NavEntryIsInstantNTP(contents, | 682 EXPECT_TRUE(NavEntryIsInstantNTP(contents, |
| 733 controller.GetLastCommittedEntry())); | 683 controller.GetLastCommittedEntry())); |
| 734 // Instant page is not cacheable NTP. | 684 // Instant page is not cacheable NTP. |
| 735 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin, | 685 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin, |
| 736 false)); | 686 false)); |
| 737 EXPECT_FALSE(NavEntryIsInstantNTP(contents, | 687 EXPECT_FALSE(NavEntryIsInstantNTP(contents, |
| 738 controller.GetLastCommittedEntry())); | 688 controller.GetLastCommittedEntry())); |
| 739 // Test Cacheable NTP | 689 // Test Cacheable NTP |
| 740 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); | 690 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); |
| 741 EXPECT_TRUE(NavEntryIsInstantNTP(contents, | 691 EXPECT_TRUE(NavEntryIsInstantNTP(contents, |
| 742 controller.GetLastCommittedEntry())); | 692 controller.GetLastCommittedEntry())); |
| 743 } | 693 } |
| 744 | 694 |
| 745 TEST_F(SearchTest, UseLocalNTPInIncognito) { | 695 TEST_F(SearchTest, UseLocalNTPInIncognito) { |
| 746 EnableInstantExtendedAPIForTesting(); | |
| 747 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 696 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 748 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 697 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 749 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( | 698 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( |
| 750 profile()->GetOffTheRecordProfile())); | 699 profile()->GetOffTheRecordProfile())); |
| 751 } | 700 } |
| 752 | 701 |
| 753 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) { | 702 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) { |
| 754 EnableInstantExtendedAPIForTesting(); | |
| 755 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 703 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 756 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 704 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 757 // Set an insecure new tab page URL and verify that it's ignored. | 705 // Set an insecure new tab page URL and verify that it's ignored. |
| 758 SetSearchProvider(true, true); | 706 SetSearchProvider(true, true); |
| 759 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 707 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
| 760 chrome::GetNewTabPageURL(profile())); | 708 chrome::GetNewTabPageURL(profile())); |
| 761 } | 709 } |
| 762 | 710 |
| 763 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { | 711 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { |
| 764 EnableInstantExtendedAPIForTesting(); | |
| 765 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 712 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 766 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 713 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 767 // Set an insecure new tab page URL and verify that it's ignored. | 714 // Set an insecure new tab page URL and verify that it's ignored. |
| 768 SetSearchProvider(false, true); | 715 SetSearchProvider(false, true); |
| 769 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 716 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
| 770 chrome::GetNewTabPageURL(profile())); | 717 chrome::GetNewTabPageURL(profile())); |
| 771 } | 718 } |
| 772 | 719 |
| 773 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { | 720 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { |
| 774 EnableInstantExtendedAPIForTesting(); | |
| 775 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 721 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 776 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 722 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 777 | 723 |
| 778 // Block access to foo.com in the URL filter. | 724 // Block access to foo.com in the URL filter. |
| 779 ManagedUserService* managed_user_service = | 725 ManagedUserService* managed_user_service = |
| 780 ManagedUserServiceFactory::GetForProfile(profile()); | 726 ManagedUserServiceFactory::GetForProfile(profile()); |
| 781 ManagedModeURLFilter* url_filter = | 727 ManagedModeURLFilter* url_filter = |
| 782 managed_user_service->GetURLFilterForUIThread(); | 728 managed_user_service->GetURLFilterForUIThread(); |
| 783 std::map<std::string, bool> hosts; | 729 std::map<std::string, bool> hosts; |
| 784 hosts["foo.com"] = false; | 730 hosts["foo.com"] = false; |
| 785 url_filter->SetManualHosts(&hosts); | 731 url_filter->SetManualHosts(&hosts); |
| 786 | 732 |
| 787 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 733 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
| 788 chrome::GetNewTabPageURL(profile())); | 734 chrome::GetNewTabPageURL(profile())); |
| 789 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); | 735 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); |
| 790 } | 736 } |
| 791 | 737 |
| 792 TEST_F(SearchTest, GetInstantURL) { | 738 TEST_F(SearchTest, GetInstantURL) { |
| 793 // Enable Instant. Still no Instant URL because "strk" is missing. | 739 // No Instant URL because "strk" is missing. |
| 794 EnableInstantExtendedAPIForTesting(); | |
| 795 SetDefaultInstantTemplateUrl(false); | 740 SetDefaultInstantTemplateUrl(false); |
| 796 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); | 741 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); |
| 797 | 742 |
| 798 // Set an Instant URL with a valid search terms replacement key. | 743 // Set an Instant URL with a valid search terms replacement key. |
| 799 SetDefaultInstantTemplateUrl(true); | 744 SetDefaultInstantTemplateUrl(true); |
| 800 | 745 |
| 801 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". | 746 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". |
| 802 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 747 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 803 GetInstantURL(profile(), kDisableStartMargin, false)); | 748 GetInstantURL(profile(), kDisableStartMargin, false)); |
| 804 | 749 |
| 805 // Enable suggest. No difference. | 750 // Enable suggest. No difference. |
| 806 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 751 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 807 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 752 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 808 GetInstantURL(profile(), kDisableStartMargin, false)); | 753 GetInstantURL(profile(), kDisableStartMargin, false)); |
| 809 | 754 |
| 810 // Disable suggest. No Instant URL. | 755 // Disable suggest. No Instant URL. |
| 811 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | 756 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); |
| 812 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); | 757 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); |
| 813 } | 758 } |
| 814 | 759 |
| 815 TEST_F(SearchTest, StartMarginCGI) { | 760 TEST_F(SearchTest, StartMarginCGI) { |
| 816 // No margin. | 761 // No margin. |
| 817 EnableInstantExtendedAPIForTesting(); | |
| 818 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 762 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 819 | 763 |
| 820 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 764 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 821 GetInstantURL(profile(), kDisableStartMargin, false)); | 765 GetInstantURL(profile(), kDisableStartMargin, false)); |
| 822 | 766 |
| 823 // With start margin. | 767 // With start margin. |
| 824 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), | 768 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), |
| 825 GetInstantURL(profile(), 10, false)); | 769 GetInstantURL(profile(), 10, false)); |
| 826 } | 770 } |
| 827 | 771 |
| 828 TEST_F(SearchTest, InstantSearchEnabledCGI) { | 772 TEST_F(SearchTest, InstantSearchEnabledCGI) { |
| 829 EnableInstantExtendedAPIForTesting(); | |
| 830 | |
| 831 // Disable Instant Search. | 773 // Disable Instant Search. |
| 832 // Make sure {google:forceInstantResults} is not set in the Instant URL. | 774 // Make sure {google:forceInstantResults} is not set in the Instant URL. |
| 833 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 775 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 834 GetInstantURL(profile(), kDisableStartMargin, false)); | 776 GetInstantURL(profile(), kDisableStartMargin, false)); |
| 835 | 777 |
| 836 // Enable Instant Search. | 778 // Enable Instant Search. |
| 837 // Make sure {google:forceInstantResults} is set in the Instant URL. | 779 // Make sure {google:forceInstantResults} is set in the Instant URL. |
| 838 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), | 780 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), |
| 839 GetInstantURL(profile(), kDisableStartMargin, true)); | 781 GetInstantURL(profile(), kDisableStartMargin, true)); |
| 840 } | 782 } |
| 841 | 783 |
| 842 TEST_F(SearchTest, CommandLineOverrides) { | 784 TEST_F(SearchTest, CommandLineOverrides) { |
| 843 EnableInstantExtendedAPIForTesting(); | |
| 844 | |
| 845 GURL local_instant_url(GetLocalInstantURL(profile())); | 785 GURL local_instant_url(GetLocalInstantURL(profile())); |
| 846 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); | 786 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); |
| 847 | 787 |
| 848 TemplateURLService* template_url_service = | 788 TemplateURLService* template_url_service = |
| 849 TemplateURLServiceFactory::GetForProfile(profile()); | 789 TemplateURLServiceFactory::GetForProfile(profile()); |
| 850 TemplateURLData data; | 790 TemplateURLData data; |
| 851 data.SetURL("{google:baseURL}search?q={searchTerms}"); | 791 data.SetURL("{google:baseURL}search?q={searchTerms}"); |
| 852 data.instant_url = "{google:baseURL}webhp?strk"; | 792 data.instant_url = "{google:baseURL}webhp?strk"; |
| 853 data.search_terms_replacement_key = "strk"; | 793 data.search_terms_replacement_key = "strk"; |
| 854 TemplateURL* template_url = new TemplateURL(profile(), data); | 794 TemplateURL* template_url = new TemplateURL(profile(), data); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 881 // If we specify extra search query params, they should be inserted into the | 821 // If we specify extra search query params, they should be inserted into the |
| 882 // query portion of the instant URL. | 822 // query portion of the instant URL. |
| 883 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 823 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 884 switches::kExtraSearchQueryParams, "a=b"); | 824 switches::kExtraSearchQueryParams, "a=b"); |
| 885 instant_url = GetInstantURL(profile(), kDisableStartMargin, false); | 825 instant_url = GetInstantURL(profile(), kDisableStartMargin, false); |
| 886 ASSERT_TRUE(instant_url.is_valid()); | 826 ASSERT_TRUE(instant_url.is_valid()); |
| 887 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); | 827 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); |
| 888 } | 828 } |
| 889 | 829 |
| 890 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { | 830 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { |
| 891 EnableInstantExtendedAPIForTesting(); | |
| 892 EXPECT_FALSE(ShouldShowInstantNTP()); | 831 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 893 } | 832 } |
| 894 | 833 |
| 895 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { | 834 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { |
| 896 EnableInstantExtendedAPIForTesting(); | |
| 897 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 835 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 898 "EmbeddedSearch", "Group1 show_ntp:0")); | 836 "EmbeddedSearch", "Group1 show_ntp:0")); |
| 899 EXPECT_FALSE(ShouldShowInstantNTP()); | 837 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 900 } | 838 } |
| 901 | 839 |
| 902 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { | 840 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { |
| 903 EnableInstantExtendedAPIForTesting(); | |
| 904 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 841 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 905 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 842 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 906 EXPECT_FALSE(ShouldShowInstantNTP()); | 843 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 907 } | 844 } |
| 908 | 845 |
| 909 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) { | 846 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) { |
| 910 EnableInstantExtendedAPIForTesting(); | |
| 911 EXPECT_TRUE(ShouldUseCacheableNTP()); | 847 EXPECT_TRUE(ShouldUseCacheableNTP()); |
| 912 } | 848 } |
| 913 | 849 |
| 914 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) { | 850 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) { |
| 915 EnableInstantExtendedAPIForTesting(); | |
| 916 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 851 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 917 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 852 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
| 918 EXPECT_TRUE(ShouldUseCacheableNTP()); | 853 EXPECT_TRUE(ShouldUseCacheableNTP()); |
| 919 } | 854 } |
| 920 | 855 |
| 921 TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) { | 856 TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) { |
| 922 EXPECT_FALSE(ShouldPrefetchSearchResults()); | 857 EXPECT_FALSE(ShouldPrefetchSearchResults()); |
| 923 } | 858 } |
| 924 | 859 |
| 925 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { | 860 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { |
| 926 EnableInstantExtendedAPIForTesting(); | |
| 927 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 861 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 928 "EmbeddedSearch", | 862 "EmbeddedSearch", |
| 929 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1")); | 863 "Group1 espv:2 use_cacheable_ntp:1 prefetch_results:1")); |
| 930 EXPECT_TRUE(ShouldPrefetchSearchResults()); | 864 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
| 931 #if defined(OS_IOS) || defined(OS_ANDROID) | 865 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 932 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); | 866 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); |
| 933 #else | 867 #else |
| 934 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 868 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 935 #endif | 869 #endif |
| 936 } | 870 } |
| 937 | 871 |
| 938 TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) { | 872 TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) { |
| 939 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 873 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 951 EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); | 885 EXPECT_EQ(80ul, EmbeddedSearchPageVersion()); |
| 952 } | 886 } |
| 953 | 887 |
| 954 TEST_F(SearchTest, IsNTPURL) { | 888 TEST_F(SearchTest, IsNTPURL) { |
| 955 GURL invalid_url; | 889 GURL invalid_url; |
| 956 GURL ntp_url(chrome::kChromeUINewTabURL); | 890 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 957 GURL local_ntp_url(GetLocalInstantURL(profile())); | 891 GURL local_ntp_url(GetLocalInstantURL(profile())); |
| 958 | 892 |
| 959 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); | 893 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); |
| 960 // No margin. | 894 // No margin. |
| 961 EnableInstantExtendedAPIForTesting(); | 895 EnableQueryExtractionForTesting(); |
| 962 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 896 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 963 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false)); | 897 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false)); |
| 964 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); | 898 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); |
| 965 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); | 899 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); |
| 966 | 900 |
| 967 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); | 901 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); |
| 968 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); | 902 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); |
| 969 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); | 903 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); |
| 970 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); | 904 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); |
| 971 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); | 905 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 991 // "prefetch_results" flag is enabled via field trials. | 925 // "prefetch_results" flag is enabled via field trials. |
| 992 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 926 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 993 "EmbeddedSearch", | 927 "EmbeddedSearch", |
| 994 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1")); | 928 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1")); |
| 995 EXPECT_TRUE(ShouldPrefetchSearchResults()); | 929 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
| 996 | 930 |
| 997 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), | 931 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), |
| 998 GetSearchResultPrefetchBaseURL(profile())); | 932 GetSearchResultPrefetchBaseURL(profile())); |
| 999 } | 933 } |
| 1000 | 934 |
| 935 typedef SearchTest IsQueryExtractionEnabledTest; |
| 936 |
| 937 TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
| 938 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 939 "EmbeddedSearch", "Group1 espv:2")); |
| 940 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 941 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 942 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 943 } |
| 944 |
| 945 TEST_F(IsQueryExtractionEnabledTest, EnabledViaFinch) { |
| 946 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 947 "EmbeddedSearch", "Group1 espv:2 query_extraction:1")); |
| 948 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 949 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 950 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 951 } |
| 952 |
| 953 TEST_F(IsQueryExtractionEnabledTest, DisabledViaFinch) { |
| 954 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 955 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
| 956 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 957 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 958 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 959 } |
| 960 |
| 961 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { |
| 962 EnableQueryExtractionForTesting(); |
| 963 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 964 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
| 965 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 966 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 967 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 968 } |
| 969 |
| 1001 } // namespace chrome | 970 } // namespace chrome |
| OLD | NEW |