Chromium Code Reviews| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 SetSearchProvider(); | 238 SetSearchProvider(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void SetSearchProvider() { | 241 void SetSearchProvider() { |
| 242 TemplateURLService* template_url_service = | 242 TemplateURLService* template_url_service = |
| 243 TemplateURLServiceFactory::GetForProfile(profile()); | 243 TemplateURLServiceFactory::GetForProfile(profile()); |
| 244 TemplateURLData data; | 244 TemplateURLData data; |
| 245 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 245 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 246 data.instant_url = "http://foo.com/instant?" | 246 data.instant_url = "http://foo.com/instant?" |
| 247 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; | 247 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; |
| 248 data.new_tab_url = "http://foo.com/newtab?strk"; | |
|
Anuj
2013/08/13 22:54:33
Should this change for all tests testing NTP?
(We
Jered
2013/08/14 15:41:49
Not right now (emailed response).
| |
| 248 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | 249 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); |
| 249 data.search_terms_replacement_key = "strk"; | 250 data.search_terms_replacement_key = "strk"; |
| 250 | 251 |
| 251 TemplateURL* template_url = new TemplateURL(profile(), data); | 252 TemplateURL* template_url = new TemplateURL(profile(), data); |
| 252 // Takes ownership of |template_url|. | 253 // Takes ownership of |template_url|. |
| 253 template_url_service->Add(template_url); | 254 template_url_service->Add(template_url); |
| 254 template_url_service->SetDefaultSearchProvider(template_url); | 255 template_url_service->SetDefaultSearchProvider(template_url); |
| 255 } | 256 } |
| 256 | 257 |
| 257 // Build an Instant URL with or without a valid search terms replacement key | 258 // Build an Instant URL with or without a valid search terms replacement key |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 } | 660 } |
| 660 | 661 |
| 661 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { | 662 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { |
| 662 EnableInstantExtendedAPIForTesting(); | 663 EnableInstantExtendedAPIForTesting(); |
| 663 EXPECT_TRUE(ShouldShowInstantNTP()); | 664 EXPECT_TRUE(ShouldShowInstantNTP()); |
| 664 } | 665 } |
| 665 | 666 |
| 666 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { | 667 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { |
| 667 EnableInstantExtendedAPIForTesting(); | 668 EnableInstantExtendedAPIForTesting(); |
| 668 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 669 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 669 "Group1 show_ntp:0")); | 670 "Group1 show_ntp:0")); |
| 670 EXPECT_FALSE(ShouldShowInstantNTP()); | 671 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 671 } | 672 } |
| 672 | 673 |
| 673 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByInstantNewTabURLSwitch) { | 674 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { |
| 674 EnableInstantExtendedAPIForTesting(); | 675 EnableInstantExtendedAPIForTesting(); |
| 675 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 676 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 676 switches::kInstantNewTabURL, "http://example.com/newtab"); | 677 "Group1 use_cacheable_ntp:1")); |
| 677 EXPECT_FALSE(ShouldShowInstantNTP()); | 678 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 678 } | 679 } |
| 679 | 680 |
| 680 TEST_F(SearchTest, IsNTPURL) { | 681 TEST_F(SearchTest, IsNTPURL) { |
| 681 GURL invalid_url; | 682 GURL invalid_url; |
| 682 GURL ntp_url(chrome::kChromeUINewTabURL); | 683 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 683 GURL local_ntp_url(GetLocalInstantURL(profile())); | 684 GURL local_ntp_url(GetLocalInstantURL(profile())); |
| 684 | 685 |
| 685 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); | 686 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); |
| 686 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, profile())); | 687 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, profile())); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 702 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); | 703 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); |
| 703 | 704 |
| 704 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); | 705 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); |
| 705 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); | 706 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); |
| 706 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL)); | 707 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL)); |
| 707 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL)); | 708 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL)); |
| 708 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL)); | 709 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL)); |
| 709 } | 710 } |
| 710 | 711 |
| 711 } // namespace chrome | 712 } // namespace chrome |
| OLD | NEW |