| 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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/search/search.cc" |
| 8 #include "chrome/browser/search/search.h" | 9 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| 10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/metrics/entropy_provider.h" | 14 #include "chrome/common/metrics/entropy_provider.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/base/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 scoped_ptr<base::FieldTrialList> field_trial_list_; | 93 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) { | 96 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) { |
| 96 GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI); | 97 GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI); |
| 97 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 98 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 98 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 99 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 99 #if defined(OS_IOS) || defined(OS_ANDROID) | 100 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 100 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); | 101 EXPECT_EQ(1ul, EmbeddedSearchPageVersion(NULL)); |
| 101 #else | 102 #else |
| 102 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 103 EXPECT_EQ(2ul, EmbeddedSearchPageVersion(NULL)); |
| 103 #endif | 104 #endif |
| 104 } | 105 } |
| 105 | 106 |
| 106 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) { | 107 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) { |
| 107 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 108 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 108 "InstantExtended/Group1 espv:42/")); | 109 "InstantExtended/Group1 espv:42/")); |
| 109 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 110 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 110 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 111 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 111 EXPECT_EQ(42ul, EmbeddedSearchPageVersion()); | 112 EXPECT_EQ(42ul, EmbeddedSearchPageVersion(NULL)); |
| 112 } | 113 } |
| 113 | 114 |
| 114 TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) { | 115 TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) { |
| 115 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); | 116 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); |
| 116 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 117 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 117 "InstantExtended/Group1 espv:2/")); | 118 "InstantExtended/Group1 espv:2/")); |
| 118 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); | 119 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); |
| 119 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 120 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 120 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 121 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaCommandLineFlag) { | 124 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaCommandLineFlag) { |
| 124 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); | 125 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); |
| 125 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 126 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 126 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); | 127 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 127 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 128 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 128 } | 129 } |
| 129 | 130 |
| 130 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaFinch) { | 131 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaFinch) { |
| 131 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 132 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 132 "InstantExtended/Group1 local_only:1/")); | 133 "InstantExtended/Group1 local_only:1/")); |
| 133 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 134 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 134 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); | 135 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 135 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 136 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 136 } | 137 } |
| 137 | 138 |
| 138 TEST_F(InstantExtendedAPIEnabledTest, | 139 TEST_F(InstantExtendedAPIEnabledTest, |
| 139 LocalOnlyCommandLineTrumpedByCommandLine) { | 140 LocalOnlyCommandLineTrumpedByCommandLine) { |
| 140 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); | 141 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); |
| 141 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); | 142 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); |
| 142 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); | 143 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); |
| 143 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 144 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 144 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 145 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyCommandLineTrumpsFinch) { | 148 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyCommandLineTrumpsFinch) { |
| 148 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); | 149 GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI); |
| 149 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 150 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 150 "InstantExtended/Group1 espv:2/")); | 151 "InstantExtended/Group1 espv:2/")); |
| 151 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 152 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 152 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); | 153 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 153 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 154 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 154 } | 155 } |
| 155 | 156 |
| 156 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpedByCommandLine) { | 157 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpedByCommandLine) { |
| 157 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 158 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 158 "InstantExtended/Group1 local_only:1/")); | 159 "InstantExtended/Group1 local_only:1/")); |
| 159 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); | 160 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); |
| 160 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); | 161 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); |
| 161 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 162 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 162 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 163 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpsFinch) { | 166 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpsFinch) { |
| 166 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 167 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 167 "InstantExtended/Group1 espv:1 local_only:1/")); | 168 "InstantExtended/Group1 espv:1 local_only:1/")); |
| 168 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 169 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 169 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); | 170 EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 170 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | 171 EXPECT_EQ(0ul, EmbeddedSearchPageVersion(NULL)); |
| 171 } | 172 } |
| 172 | 173 |
| 173 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyDisabledViaCommandLineFlag) { | 174 TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyDisabledViaCommandLineFlag) { |
| 174 GetCommandLine()->AppendSwitch(switches::kDisableLocalOnlyInstantExtendedAPI); | 175 GetCommandLine()->AppendSwitch(switches::kDisableLocalOnlyInstantExtendedAPI); |
| 175 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( | 176 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 176 "InstantExtended/Group1 espv:2/")); | 177 "InstantExtended/Group1 espv:2/")); |
| 177 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 178 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 178 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); | 179 EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled()); |
| 179 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 180 EXPECT_EQ(2ul, EmbeddedSearchPageVersion(NULL)); |
| 180 } | 181 } |
| 181 | 182 |
| 182 class SearchTest : public BrowserWithTestWindowTest { | 183 class SearchTest : public BrowserWithTestWindowTest { |
| 183 protected: | 184 protected: |
| 184 virtual void SetUp() OVERRIDE { | 185 virtual void SetUp() OVERRIDE { |
| 185 BrowserWithTestWindowTest::SetUp(); | 186 BrowserWithTestWindowTest::SetUp(); |
| 186 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 187 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 187 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 188 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 188 TemplateURLService* template_url_service = | 189 TemplateURLService* template_url_service = |
| 189 TemplateURLServiceFactory::GetForProfile(profile()); | 190 TemplateURLServiceFactory::GetForProfile(profile()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 {"https://foo.com/url#strk", true, "Valid search URL"}, | 318 {"https://foo.com/url#strk", true, "Valid search URL"}, |
| 318 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, | 319 {"https://foo.com/alt?strk", true, "Valid alternative URL"}, |
| 319 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, | 320 {"https://foo.com/alt#strk", true, "Valid alternative URL"}, |
| 320 {"https://foo.com/url?strk&bar=", true, "No query terms"}, | 321 {"https://foo.com/url?strk&bar=", true, "No query terms"}, |
| 321 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, | 322 {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, |
| 322 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, | 323 {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, |
| 323 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, | 324 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, |
| 324 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, | 325 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, |
| 325 {"https://foo.com/instant", false, "No search term replacement"}, | 326 {"https://foo.com/instant", false, "No search term replacement"}, |
| 326 {"chrome://blank/", false, "Chrome scheme"}, | 327 {"chrome://blank/", false, "Chrome scheme"}, |
| 327 {"chrome-search://foo", false, "Chrome-search scheme"}, | 328 {"chrome-search://foo", false, "Chrome-search scheme"}, |
| 328 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, | 329 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, |
| 329 {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"}, | 330 {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"}, |
| 330 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, | 331 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, |
| 331 }; | 332 }; |
| 332 | 333 |
| 334 TEST_F(SearchTest, InstantExtendedEmbeddedSearchDisabledForIncognito) { |
| 335 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 336 EnableInstantExtendedAPIForTesting(); |
| 337 profile()->set_incognito(true); |
| 338 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 339 EXPECT_EQ( |
| 340 kEmbeddedPageVersionDisabled, EmbeddedSearchPageVersion(profile())); |
| 341 EXPECT_FALSE(IsQueryExtractionEnabled(profile())); |
| 342 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) |
| 343 } |
| 344 |
| 333 TEST_F(SearchTest, InstantNTPExtendedEnabled) { | 345 TEST_F(SearchTest, InstantNTPExtendedEnabled) { |
| 334 EnableInstantExtendedAPIForTesting(); | 346 EnableInstantExtendedAPIForTesting(); |
| 335 AddTab(browser(), GURL("chrome://blank")); | 347 AddTab(browser(), GURL("chrome://blank")); |
| 336 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 348 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
| 337 const SearchTestCase& test = kInstantNTPTestCases[i]; | 349 const SearchTestCase& test = kInstantNTPTestCases[i]; |
| 338 NavigateAndCommitActiveTab(GURL(test.url)); | 350 NavigateAndCommitActiveTab(GURL(test.url)); |
| 339 SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl); | 351 SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl); |
| 340 const content::WebContents* contents = | 352 const content::WebContents* contents = |
| 341 browser()->tab_strip_model()->GetWebContentsAt(0); | 353 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 342 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) | 354 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 578 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 567 | 579 |
| 568 // Now that suggest is back on and the instant url is good, the checkbox | 580 // Now that suggest is back on and the instant url is good, the checkbox |
| 569 // should be enabled and checked again. | 581 // should be enabled and checked again. |
| 570 EXPECT_TRUE(IsInstantCheckboxEnabled(profile())); | 582 EXPECT_TRUE(IsInstantCheckboxEnabled(profile())); |
| 571 EXPECT_TRUE(IsInstantCheckboxChecked(profile())); | 583 EXPECT_TRUE(IsInstantCheckboxChecked(profile())); |
| 572 } | 584 } |
| 573 | 585 |
| 574 | 586 |
| 575 } // namespace chrome | 587 } // namespace chrome |
| OLD | NEW |