| 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" | |
| 8 #include "base/metrics/histogram_samples.h" | |
| 9 #include "base/metrics/statistics_recorder.h" | 7 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/search/instant_service.h" | 9 #include "chrome/browser/search/instant_service.h" |
| 12 #include "chrome/browser/search/instant_service_factory.h" | 10 #include "chrome/browser/search/instant_service_factory.h" |
| 13 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/browser/search_engines/search_terms_data.h" | 12 #include "chrome/browser/search_engines/search_terms_data.h" |
| 15 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 30 | 28 |
| 31 namespace chrome { | 29 namespace chrome { |
| 32 | 30 |
| 33 class EmbeddedSearchFieldTrialTest : public testing::Test { | 31 class EmbeddedSearchFieldTrialTest : public testing::Test { |
| 34 protected: | 32 protected: |
| 35 virtual void SetUp() { | 33 virtual void SetUp() { |
| 36 field_trial_list_.reset(new base::FieldTrialList( | 34 field_trial_list_.reset(new base::FieldTrialList( |
| 37 new metrics::SHA1EntropyProvider("42"))); | 35 new metrics::SHA1EntropyProvider("42"))); |
| 38 base::StatisticsRecorder::Initialize(); | 36 base::StatisticsRecorder::Initialize(); |
| 39 ResetInstantExtendedOptInStateGateForTest(); | |
| 40 } | 37 } |
| 41 | 38 |
| 42 private: | 39 private: |
| 43 scoped_ptr<base::FieldTrialList> field_trial_list_; | 40 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 44 }; | 41 }; |
| 45 | 42 |
| 46 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) { | 43 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) { |
| 47 FieldTrialFlags flags; | 44 FieldTrialFlags flags; |
| 48 uint64 group_number = 0; | |
| 49 | 45 |
| 50 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 46 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 51 EXPECT_EQ(0ul, group_number); | |
| 52 EXPECT_EQ(0ul, flags.size()); | 47 EXPECT_EQ(0ul, flags.size()); |
| 53 | 48 |
| 54 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 49 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 55 "InstantExtended", "Group77")); | 50 "InstantExtended", "Group77")); |
| 56 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 51 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 57 EXPECT_EQ(77ul, group_number); | |
| 58 EXPECT_EQ(0ul, flags.size()); | 52 EXPECT_EQ(0ul, flags.size()); |
| 59 } | 53 } |
| 60 | 54 |
| 61 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) { | 55 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) { |
| 62 FieldTrialFlags flags; | 56 FieldTrialFlags flags; |
| 63 uint64 group_number = 0; | |
| 64 | 57 |
| 65 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 58 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 66 "InstantExtended", "Group77.2")); | 59 "InstantExtended", "Group77.2")); |
| 67 EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number)); | 60 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 68 EXPECT_EQ(0ul, group_number); | |
| 69 EXPECT_EQ(0ul, flags.size()); | 61 EXPECT_EQ(0ul, flags.size()); |
| 70 } | 62 } |
| 71 | 63 |
| 72 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) { | 64 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) { |
| 73 FieldTrialFlags flags; | 65 FieldTrialFlags flags; |
| 74 uint64 group_number = 0; | |
| 75 | 66 |
| 76 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 67 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 77 "InstantExtended", "Invalid77")); | 68 "InstantExtended", "Invalid77")); |
| 78 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 69 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 79 EXPECT_EQ(0ul, group_number); | |
| 80 EXPECT_EQ(0ul, flags.size()); | 70 EXPECT_EQ(0ul, flags.size()); |
| 81 } | 71 } |
| 82 | 72 |
| 83 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) { | 73 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) { |
| 84 FieldTrialFlags flags; | 74 FieldTrialFlags flags; |
| 85 uint64 group_number = 0; | |
| 86 | 75 |
| 87 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 76 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 88 "InstantExtended", "Group77")); | 77 "InstantExtended", "Group77")); |
| 89 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 78 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 90 EXPECT_EQ(77ul, group_number); | |
| 91 EXPECT_EQ(0ul, flags.size()); | 79 EXPECT_EQ(0ul, flags.size()); |
| 92 } | 80 } |
| 93 | 81 |
| 94 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) { | 82 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) { |
| 95 FieldTrialFlags flags; | 83 FieldTrialFlags flags; |
| 96 uint64 group_number = 0; | |
| 97 | 84 |
| 98 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 85 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 99 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 86 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 100 "InstantExtended", "Group77 foo:6")); | 87 "InstantExtended", "Group77 foo:6")); |
| 101 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 88 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 102 EXPECT_EQ(77ul, group_number); | |
| 103 EXPECT_EQ(1ul, flags.size()); | 89 EXPECT_EQ(1ul, flags.size()); |
| 104 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 90 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 105 } | 91 } |
| 106 | 92 |
| 107 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) { | 93 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) { |
| 108 FieldTrialFlags flags; | 94 FieldTrialFlags flags; |
| 109 uint64 group_number = 0; | |
| 110 | 95 |
| 111 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 96 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 112 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 97 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 113 "EmbeddedSearch", "Group77 foo:6")); | 98 "EmbeddedSearch", "Group77 foo:6")); |
| 114 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 99 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 115 EXPECT_EQ(77ul, group_number); | |
| 116 EXPECT_EQ(1ul, flags.size()); | 100 EXPECT_EQ(1ul, flags.size()); |
| 117 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 101 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 118 } | 102 } |
| 119 | 103 |
| 120 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) { | 104 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) { |
| 121 FieldTrialFlags flags; | 105 FieldTrialFlags flags; |
| 122 uint64 group_number = 0; | |
| 123 | 106 |
| 124 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 107 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 125 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 108 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 126 "EmbeddedSearch", "Group77 foo:6")); | 109 "EmbeddedSearch", "Group77 foo:6")); |
| 127 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 110 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 128 "InstantExtended", "Group78 foo:5")); | 111 "InstantExtended", "Group78 foo:5")); |
| 129 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 112 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 130 EXPECT_EQ(77ul, group_number); | |
| 131 EXPECT_EQ(1ul, flags.size()); | 113 EXPECT_EQ(1ul, flags.size()); |
| 132 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); | 114 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); |
| 133 } | 115 } |
| 134 | 116 |
| 135 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) { | 117 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) { |
| 136 FieldTrialFlags flags; | 118 FieldTrialFlags flags; |
| 137 uint64 group_number = 0; | |
| 138 | 119 |
| 139 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 120 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 140 "InstantExtended", "Group77 bar:1 baz:7 cat:dogs")); | 121 "InstantExtended", "Group77 bar:1 baz:7 cat:dogs")); |
| 141 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 122 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 142 EXPECT_EQ(77ul, group_number); | |
| 143 EXPECT_EQ(3ul, flags.size()); | 123 EXPECT_EQ(3ul, flags.size()); |
| 144 EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags)); | 124 EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags)); |
| 145 EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags)); | 125 EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags)); |
| 146 EXPECT_EQ("dogs", | 126 EXPECT_EQ("dogs", |
| 147 GetStringValueForFlagWithDefault("cat", std::string(), flags)); | 127 GetStringValueForFlagWithDefault("cat", std::string(), flags)); |
| 148 EXPECT_EQ("default", | 128 EXPECT_EQ("default", |
| 149 GetStringValueForFlagWithDefault("moose", "default", flags)); | 129 GetStringValueForFlagWithDefault("moose", "default", flags)); |
| 150 } | 130 } |
| 151 | 131 |
| 152 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) { | 132 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) { |
| 153 FieldTrialFlags flags; | 133 FieldTrialFlags flags; |
| 154 uint64 group_number = 0; | |
| 155 | 134 |
| 156 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 135 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 157 "InstantExtended", "Group77 bar:1 baz:7 cat:dogs DISABLED")); | 136 "InstantExtended", "Group77 bar:1 baz:7 cat:dogs DISABLED")); |
| 158 EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number)); | 137 EXPECT_FALSE(GetFieldTrialInfo(&flags)); |
| 159 EXPECT_EQ(0ul, group_number); | |
| 160 EXPECT_EQ(0ul, flags.size()); | 138 EXPECT_EQ(0ul, flags.size()); |
| 161 } | 139 } |
| 162 | 140 |
| 163 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { | 141 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { |
| 164 FieldTrialFlags flags; | 142 FieldTrialFlags flags; |
| 165 uint64 group_number = 0; | |
| 166 | 143 |
| 167 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 144 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 168 "InstantExtended", "Control77 bar:1 baz:7 cat:dogs")); | 145 "InstantExtended", "Control77 bar:1 baz:7 cat:dogs")); |
| 169 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); | 146 EXPECT_TRUE(GetFieldTrialInfo(&flags)); |
| 170 EXPECT_EQ(0ul, group_number); | |
| 171 EXPECT_EQ(3ul, flags.size()); | 147 EXPECT_EQ(3ul, flags.size()); |
| 172 } | 148 } |
| 173 | 149 |
| 174 class InstantExtendedAPIEnabledTest : public testing::Test { | |
| 175 public: | |
| 176 InstantExtendedAPIEnabledTest() : histogram_(NULL) { | |
| 177 } | |
| 178 protected: | |
| 179 virtual void SetUp() { | |
| 180 field_trial_list_.reset(new base::FieldTrialList( | |
| 181 new metrics::SHA1EntropyProvider("42"))); | |
| 182 base::StatisticsRecorder::Initialize(); | |
| 183 ResetInstantExtendedOptInStateGateForTest(); | |
| 184 previous_metrics_count_.resize(INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT, 0); | |
| 185 base::HistogramBase* histogram = GetHistogram(); | |
| 186 if (histogram) { | |
| 187 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | |
| 188 if (samples.get()) { | |
| 189 for (int state = INSTANT_EXTENDED_NOT_SET; | |
| 190 state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) { | |
| 191 previous_metrics_count_[state] = samples->GetCount(state); | |
| 192 } | |
| 193 } | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 virtual CommandLine* GetCommandLine() const { | |
| 198 return CommandLine::ForCurrentProcess(); | |
| 199 } | |
| 200 | |
| 201 void ValidateMetrics(base::HistogramBase::Sample value) { | |
| 202 base::HistogramBase* histogram = GetHistogram(); | |
| 203 if (histogram) { | |
| 204 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | |
| 205 if (samples.get()) { | |
| 206 for (int state = INSTANT_EXTENDED_NOT_SET; | |
| 207 state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) { | |
| 208 if (state == value) { | |
| 209 EXPECT_EQ(previous_metrics_count_[state] + 1, | |
| 210 samples->GetCount(state)); | |
| 211 } else { | |
| 212 EXPECT_EQ(previous_metrics_count_[state], samples->GetCount(state)); | |
| 213 } | |
| 214 } | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 private: | |
| 220 base::HistogramBase* GetHistogram() { | |
| 221 if (!histogram_) { | |
| 222 histogram_ = base::StatisticsRecorder::FindHistogram( | |
| 223 "InstantExtended.OptInState"); | |
| 224 } | |
| 225 return histogram_; | |
| 226 } | |
| 227 base::HistogramBase* histogram_; | |
| 228 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 229 std::vector<int> previous_metrics_count_; | |
| 230 }; | |
| 231 | |
| 232 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) { | |
| 233 GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI); | |
| 234 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 235 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 236 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); | |
| 237 #else | |
| 238 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 239 #endif | |
| 240 ValidateMetrics(INSTANT_EXTENDED_OPT_IN); | |
| 241 } | |
| 242 | |
| 243 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) { | |
| 244 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 245 "Group1 espv:42")); | |
| 246 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 247 EXPECT_EQ(42ul, EmbeddedSearchPageVersion()); | |
| 248 ValidateMetrics(INSTANT_EXTENDED_NOT_SET); | |
| 249 } | |
| 250 | |
| 251 TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) { | |
| 252 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 253 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 254 "Group1 espv:2")); | |
| 255 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); | |
| 256 EXPECT_EQ(0ul, EmbeddedSearchPageVersion()); | |
| 257 ValidateMetrics(INSTANT_EXTENDED_OPT_OUT); | |
| 258 } | |
| 259 | |
| 260 typedef InstantExtendedAPIEnabledTest ShouldHideTopVerbatimTest; | |
| 261 | |
| 262 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) { | |
| 263 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 264 "InstantExtended", "Control")); | |
| 265 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); | |
| 266 } | |
| 267 | |
| 268 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) { | |
| 269 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 270 "InstantExtended", "Group1")); | |
| 271 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); | |
| 272 } | |
| 273 | |
| 274 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) { | |
| 275 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 276 "InstantExtended", "Group1 hide_verbatim:1")); | |
| 277 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); | |
| 278 } | |
| 279 | |
| 280 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) { | |
| 281 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 282 "InstantExtended", "Controll1 hide_verbatim:1")); | |
| 283 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); | |
| 284 } | |
| 285 | |
| 286 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { | |
| 287 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 288 "InstantExtended", "Group1 hide_verbatim:0")); | |
| 289 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); | |
| 290 } | |
| 291 | |
| 292 typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest; | |
| 293 | |
| 294 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) { | |
| 295 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 296 "InstantExtended", "Group1 espv:2")); | |
| 297 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP()); | |
| 298 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 299 EXPECT_TRUE(IsQueryExtractionEnabled()); | |
| 300 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 301 } | |
| 302 | |
| 303 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) { | |
| 304 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 305 "InstantExtended", "Group1 espv:2 suppress_on_srp:0")); | |
| 306 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP()); | |
| 307 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 308 EXPECT_TRUE(IsQueryExtractionEnabled()); | |
| 309 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 310 } | |
| 311 | |
| 312 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) { | |
| 313 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 314 "InstantExtended", "Group1 espv:2 suppress_on_srp:1")); | |
| 315 EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP()); | |
| 316 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | |
| 317 EXPECT_FALSE(IsQueryExtractionEnabled()); | |
| 318 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | |
| 319 } | |
| 320 | |
| 321 class SearchTest : public BrowserWithTestWindowTest { | 150 class SearchTest : public BrowserWithTestWindowTest { |
| 322 protected: | 151 protected: |
| 323 virtual void SetUp() OVERRIDE { | 152 virtual void SetUp() OVERRIDE { |
| 324 BrowserWithTestWindowTest::SetUp(); | 153 BrowserWithTestWindowTest::SetUp(); |
| 325 field_trial_list_.reset(new base::FieldTrialList( | 154 field_trial_list_.reset(new base::FieldTrialList( |
| 326 new metrics::SHA1EntropyProvider("42"))); | 155 new metrics::SHA1EntropyProvider("42"))); |
| 327 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 156 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 328 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 157 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 329 TemplateURLService* template_url_service = | 158 TemplateURLService* template_url_service = |
| 330 TemplateURLServiceFactory::GetForProfile(profile()); | 159 TemplateURLServiceFactory::GetForProfile(profile()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 bool InInstantProcess(const content::WebContents* contents) { | 205 bool InInstantProcess(const content::WebContents* contents) { |
| 377 InstantService* instant_service = | 206 InstantService* instant_service = |
| 378 InstantServiceFactory::GetForProfile(profile()); | 207 InstantServiceFactory::GetForProfile(profile()); |
| 379 return instant_service->IsInstantProcess( | 208 return instant_service->IsInstantProcess( |
| 380 contents->GetRenderProcessHost()->GetID()); | 209 contents->GetRenderProcessHost()->GetID()); |
| 381 } | 210 } |
| 382 | 211 |
| 383 scoped_ptr<base::FieldTrialList> field_trial_list_; | 212 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 384 }; | 213 }; |
| 385 | 214 |
| 215 typedef SearchTest ShouldHideTopVerbatimTest; |
| 216 |
| 217 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) { |
| 218 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 219 "InstantExtended", "Control")); |
| 220 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); |
| 221 } |
| 222 |
| 223 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) { |
| 224 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 225 "InstantExtended", "Group1")); |
| 226 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); |
| 227 } |
| 228 |
| 229 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) { |
| 230 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 231 "InstantExtended", "Group1 hide_verbatim:1")); |
| 232 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); |
| 233 } |
| 234 |
| 235 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) { |
| 236 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 237 "InstantExtended", "Controll1 hide_verbatim:1")); |
| 238 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); |
| 239 } |
| 240 |
| 241 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { |
| 242 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 243 "InstantExtended", "Group1 hide_verbatim:0")); |
| 244 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); |
| 245 } |
| 246 |
| 247 typedef SearchTest IsQueryExtractionEnabledTest; |
| 248 |
| 249 TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
| 250 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 251 "InstantExtended", "Group1 espv:2")); |
| 252 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 253 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 254 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 255 } |
| 256 |
| 257 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaFinch) { |
| 258 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 259 "InstantExtended", "Group1 espv:2 query_extraction:1")); |
| 260 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 261 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 262 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 263 } |
| 264 |
| 265 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaCommandLine) { |
| 266 EnableQueryExtractionForTesting(); |
| 267 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 268 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 269 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 270 } |
| 271 |
| 272 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionDisabledViaFinch) { |
| 273 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 274 "InstantExtended", "Group1 espv:2 query_extraction:0")); |
| 275 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 276 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 277 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 278 } |
| 279 |
| 386 struct SearchTestCase { | 280 struct SearchTestCase { |
| 387 const char* url; | 281 const char* url; |
| 388 bool expected_result; | 282 bool expected_result; |
| 389 const char* comment; | 283 const char* comment; |
| 390 }; | 284 }; |
| 391 | 285 |
| 392 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) { | 286 TEST_F(SearchTest, ShouldAssignURLToInstantRendererSRPEnabled) { |
| 393 DisableInstantExtendedAPIForTesting(); | 287 EnableQueryExtractionForTesting(); |
| 394 | |
| 395 const SearchTestCase kTestCases[] = { | |
| 396 {"chrome-search://foo/bar", false, ""}, | |
| 397 {"http://foo.com/instant", false, ""}, | |
| 398 {"http://foo.com/instant?foo=bar", false, ""}, | |
| 399 {"https://foo.com/instant", false, ""}, | |
| 400 {"https://foo.com/instant#foo=bar", false, ""}, | |
| 401 {"HtTpS://fOo.CoM/instant", false, ""}, | |
| 402 {"http://foo.com:80/instant", false, ""}, | |
| 403 {"invalid URL", false, "Invalid URL"}, | |
| 404 {"unknown://scheme/path", false, "Unknown scheme"}, | |
| 405 {"ftp://foo.com/instant", false, "Non-HTTP scheme"}, | |
| 406 {"http://sub.foo.com/instant", false, "Non-exact host"}, | |
| 407 {"http://foo.com:26/instant", false, "Non-default port"}, | |
| 408 {"http://foo.com/instant/bar", false, "Non-exact path"}, | |
| 409 {"http://foo.com/Instant", false, "Case sensitive path"}, | |
| 410 {"http://foo.com/", false, "Non-exact path"}, | |
| 411 {"https://foo.com/", false, "Non-exact path"}, | |
| 412 {"https://foo.com/url?strk", false, "Non-extended mode"}, | |
| 413 {"https://foo.com/alt?strk", false, "Non-extended mode"}, | |
| 414 }; | |
| 415 | |
| 416 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 417 const SearchTestCase& test = kTestCases[i]; | |
| 418 EXPECT_EQ(test.expected_result, | |
| 419 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | |
| 420 << test.url << " " << test.comment; | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { | |
| 425 EnableInstantExtendedAPIForTesting(); | |
| 426 | 288 |
| 427 const SearchTestCase kTestCases[] = { | 289 const SearchTestCase kTestCases[] = { |
| 428 {chrome::kChromeSearchLocalNtpUrl, true, ""}, | 290 {chrome::kChromeSearchLocalNtpUrl, true, ""}, |
| 429 {"https://foo.com/instant?strk", true, ""}, | 291 {"https://foo.com/instant?strk", true, ""}, |
| 430 {"https://foo.com/instant#strk", true, ""}, | 292 {"https://foo.com/instant#strk", true, ""}, |
| 431 {"https://foo.com/instant?strk=0", true, ""}, | 293 {"https://foo.com/instant?strk=0", true, ""}, |
| 432 {"https://foo.com/url?strk", true, ""}, | 294 {"https://foo.com/url?strk", true, ""}, |
| 433 {"https://foo.com/alt?strk", true, ""}, | 295 {"https://foo.com/alt?strk", true, ""}, |
| 434 {"http://foo.com/instant", false, "Non-HTTPS"}, | 296 {"http://foo.com/instant", false, "Non-HTTPS"}, |
| 435 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, | 297 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, |
| 436 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, | 298 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, |
| 437 {"https://foo.com/instant", false, "No search terms replacement"}, | 299 {"https://foo.com/instant", false, "No search terms replacement"}, |
| 438 {"https://foo.com/?strk", false, "Non-exact path"}, | 300 {"https://foo.com/?strk", false, "Non-exact path"}, |
| 439 }; | 301 }; |
| 440 | 302 |
| 441 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 303 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 442 const SearchTestCase& test = kTestCases[i]; | 304 const SearchTestCase& test = kTestCases[i]; |
| 443 EXPECT_EQ(test.expected_result, | 305 EXPECT_EQ(test.expected_result, |
| 444 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | 306 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) |
| 445 << test.url << " " << test.comment; | 307 << test.url << " " << test.comment; |
| 446 } | 308 } |
| 447 } | 309 } |
| 448 | 310 |
| 449 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) { | 311 TEST_F(SearchTest, ShouldAssignURLToInstantRenderer) { |
| 450 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 451 "InstantExtended", "Group1 espv:2 suppress_on_srp:1")); | |
| 452 | |
| 453 const SearchTestCase kTestCases[] = { | 312 const SearchTestCase kTestCases[] = { |
| 454 {chrome::kChromeSearchLocalNtpUrl, true, ""}, | 313 {chrome::kChromeSearchLocalNtpUrl, true, ""}, |
| 455 {"https://foo.com/instant?strk", true, ""}, | 314 {"https://foo.com/instant?strk", true, ""}, |
| 456 {"https://foo.com/instant#strk", true, ""}, | 315 {"https://foo.com/instant#strk", true, ""}, |
| 457 {"https://foo.com/instant?strk=0", true, ""}, | 316 {"https://foo.com/instant?strk=0", true, ""}, |
| 458 {"https://foo.com/url?strk", false, "Disabled on SRP"}, | 317 {"https://foo.com/url?strk", false, "Disabled on SRP"}, |
| 459 {"https://foo.com/alt?strk", false, "Disabled ON SRP"}, | 318 {"https://foo.com/alt?strk", false, "Disabled ON SRP"}, |
| 460 {"http://foo.com/instant", false, "Non-HTTPS"}, | 319 {"http://foo.com/instant", false, "Non-HTTPS"}, |
| 461 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, | 320 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, |
| 462 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, | 321 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, |
| 463 {"https://foo.com/instant", false, "No search terms replacement"}, | 322 {"https://foo.com/instant", false, "No search terms replacement"}, |
| 464 {"https://foo.com/?strk", false, "Non-exact path"}, | 323 {"https://foo.com/?strk", false, "Non-exact path"}, |
| 465 }; | 324 }; |
| 466 | 325 |
| 467 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 326 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 468 const SearchTestCase& test = kTestCases[i]; | 327 const SearchTestCase& test = kTestCases[i]; |
| 469 EXPECT_EQ(test.expected_result, | 328 EXPECT_EQ(test.expected_result, |
| 470 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) | 329 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) |
| 471 << test.url << " " << test.comment; | 330 << test.url << " " << test.comment; |
| 472 } | 331 } |
| 473 } | 332 } |
| 474 | 333 |
| 475 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { | 334 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { |
| 476 EnableInstantExtendedAPIForTesting(); | |
| 477 | |
| 478 const SearchTestCase kTestCases[] = { | 335 const SearchTestCase kTestCases[] = { |
| 479 {"chrome-search://local-ntp", true, "Local NTP"}, | 336 {"chrome-search://local-ntp", true, "Local NTP"}, |
| 480 {"chrome-search://online-ntp", true, "Online NTP"}, | 337 {"chrome-search://online-ntp", true, "Online NTP"}, |
| 481 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, | 338 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, |
| 482 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, | 339 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, |
| 483 {"chrome-search://foo.com", false, "Search result page"}, | 340 {"chrome-search://foo.com", false, "Search result page"}, |
| 484 {"https://foo.com/instant?strk", false, ""}, | 341 {"https://foo.com/instant?strk", false, ""}, |
| 485 {"https://foo.com/instant#strk", false, ""}, | 342 {"https://foo.com/instant#strk", false, ""}, |
| 486 {"https://foo.com/instant?strk=0", false, ""}, | 343 {"https://foo.com/instant?strk=0", false, ""}, |
| 487 {"https://foo.com/url?strk", false, ""}, | 344 {"https://foo.com/url?strk", false, ""}, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 "https://foo.com/url?strk", true, true }, | 387 "https://foo.com/url?strk", true, true }, |
| 531 {"SRP -> Regular", | 388 {"SRP -> Regular", |
| 532 "https://foo.com/url?strk", true, | 389 "https://foo.com/url?strk", true, |
| 533 "https://foo.com/other", false, false }, | 390 "https://foo.com/other", false, false }, |
| 534 {"Regular -> SRP", | 391 {"Regular -> SRP", |
| 535 "https://foo.com/other", false, | 392 "https://foo.com/other", false, |
| 536 "https://foo.com/url?strk", true, false }, | 393 "https://foo.com/url?strk", true, false }, |
| 537 }; | 394 }; |
| 538 | 395 |
| 539 TEST_F(SearchTest, ProcessIsolation) { | 396 TEST_F(SearchTest, ProcessIsolation) { |
| 540 EnableInstantExtendedAPIForTesting(); | 397 EnableQueryExtractionForTesting(); |
| 541 | 398 |
| 542 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 399 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
| 543 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 400 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
| 544 AddTab(browser(), GURL("chrome://blank")); | 401 AddTab(browser(), GURL("chrome://blank")); |
| 545 const content::WebContents* contents = | 402 const content::WebContents* contents = |
| 546 browser()->tab_strip_model()->GetActiveWebContents(); | 403 browser()->tab_strip_model()->GetActiveWebContents(); |
| 547 | 404 |
| 548 // Navigate to start URL. | 405 // Navigate to start URL. |
| 549 NavigateAndCommitActiveTab(GURL(test.start_url)); | 406 NavigateAndCommitActiveTab(GURL(test.start_url)); |
| 550 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 407 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 569 EXPECT_EQ(test.same_site_instance, | 426 EXPECT_EQ(test.same_site_instance, |
| 570 start_rvh == contents->GetRenderViewHost()) | 427 start_rvh == contents->GetRenderViewHost()) |
| 571 << test.description; | 428 << test.description; |
| 572 EXPECT_EQ(test.same_site_instance, | 429 EXPECT_EQ(test.same_site_instance, |
| 573 start_rph == contents->GetRenderProcessHost()) | 430 start_rph == contents->GetRenderProcessHost()) |
| 574 << test.description; | 431 << test.description; |
| 575 } | 432 } |
| 576 } | 433 } |
| 577 | 434 |
| 578 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { | 435 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { |
| 579 EnableInstantExtendedAPIForTesting(); | 436 EnableQueryExtractionForTesting(); |
| 580 | 437 |
| 581 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { | 438 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { |
| 582 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; | 439 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; |
| 583 AddTab(browser(), GURL("chrome://blank")); | 440 AddTab(browser(), GURL("chrome://blank")); |
| 584 content::WebContents* contents = | 441 content::WebContents* contents = |
| 585 browser()->tab_strip_model()->GetActiveWebContents(); | 442 browser()->tab_strip_model()->GetActiveWebContents(); |
| 586 | 443 |
| 587 // Navigate to start URL. | 444 // Navigate to start URL. |
| 588 NavigateAndCommitActiveTab(GURL(test.start_url)); | 445 NavigateAndCommitActiveTab(GURL(test.start_url)); |
| 589 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) | 446 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, | 491 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, |
| 635 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, | 492 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, |
| 636 {"https://foo.com/instant", false, "No search term replacement"}, | 493 {"https://foo.com/instant", false, "No search term replacement"}, |
| 637 {"chrome://blank/", false, "Chrome scheme"}, | 494 {"chrome://blank/", false, "Chrome scheme"}, |
| 638 {"chrome-search://foo", false, "Chrome-search scheme"}, | 495 {"chrome-search://foo", false, "Chrome-search scheme"}, |
| 639 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, | 496 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, |
| 640 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, | 497 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, |
| 641 }; | 498 }; |
| 642 | 499 |
| 643 TEST_F(SearchTest, InstantNTPExtendedEnabled) { | 500 TEST_F(SearchTest, InstantNTPExtendedEnabled) { |
| 644 EnableInstantExtendedAPIForTesting(); | 501 EnableQueryExtractionForTesting(); |
| 645 AddTab(browser(), GURL("chrome://blank")); | 502 AddTab(browser(), GURL("chrome://blank")); |
| 646 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 503 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
| 647 const SearchTestCase& test = kInstantNTPTestCases[i]; | 504 const SearchTestCase& test = kInstantNTPTestCases[i]; |
| 648 NavigateAndCommitActiveTab(GURL(test.url)); | 505 NavigateAndCommitActiveTab(GURL(test.url)); |
| 649 const content::WebContents* contents = | 506 const content::WebContents* contents = |
| 650 browser()->tab_strip_model()->GetWebContentsAt(0); | 507 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 651 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) | 508 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) |
| 652 << test.url << " " << test.comment; | 509 << test.url << " " << test.comment; |
| 653 } | 510 } |
| 654 } | 511 } |
| 655 | 512 |
| 656 TEST_F(SearchTest, InstantNTPExtendedDisabled) { | |
| 657 AddTab(browser(), GURL("chrome://blank")); | |
| 658 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | |
| 659 const SearchTestCase& test = kInstantNTPTestCases[i]; | |
| 660 NavigateAndCommitActiveTab(GURL(test.url)); | |
| 661 const content::WebContents* contents = | |
| 662 browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 663 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment; | |
| 664 } | |
| 665 } | |
| 666 | |
| 667 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { | 513 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { |
| 668 EnableInstantExtendedAPIForTesting(); | 514 EnableQueryExtractionForTesting(); |
| 669 AddTab(browser(), GURL("chrome://blank")); | 515 AddTab(browser(), GURL("chrome://blank")); |
| 670 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { | 516 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { |
| 671 const SearchTestCase& test = kInstantNTPTestCases[i]; | 517 const SearchTestCase& test = kInstantNTPTestCases[i]; |
| 672 NavigateAndCommitActiveTab(GURL(test.url)); | 518 NavigateAndCommitActiveTab(GURL(test.url)); |
| 673 content::WebContents* contents = | 519 content::WebContents* contents = |
| 674 browser()->tab_strip_model()->GetWebContentsAt(0); | 520 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 675 content::NavigationController& controller = contents->GetController(); | 521 content::NavigationController& controller = contents->GetController(); |
| 676 controller.SetTransientEntry( | 522 controller.SetTransientEntry( |
| 677 controller.CreateNavigationEntry(GURL("chrome://blank"), | 523 controller.CreateNavigationEntry(GURL("chrome://blank"), |
| 678 content::Referrer(), | 524 content::Referrer(), |
| 679 content::PAGE_TRANSITION_LINK, | 525 content::PAGE_TRANSITION_LINK, |
| 680 false, | 526 false, |
| 681 std::string(), | 527 std::string(), |
| 682 contents->GetBrowserContext())); | 528 contents->GetBrowserContext())); |
| 683 // The active entry is chrome://blank and not an NTP. | 529 // The active entry is chrome://blank and not an NTP. |
| 684 EXPECT_FALSE(IsInstantNTP(contents)); | 530 EXPECT_FALSE(IsInstantNTP(contents)); |
| 685 EXPECT_EQ(test.expected_result, | 531 EXPECT_EQ(test.expected_result, |
| 686 NavEntryIsInstantNTP(contents, | 532 NavEntryIsInstantNTP(contents, |
| 687 controller.GetLastCommittedEntry())) | 533 controller.GetLastCommittedEntry())) |
| 688 << test.url << " " << test.comment; | 534 << test.url << " " << test.comment; |
| 689 } | 535 } |
| 690 } | 536 } |
| 691 | 537 |
| 692 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { | 538 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { |
| 693 EnableInstantExtendedAPIForTesting(); | |
| 694 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 539 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 695 "Group1 use_cacheable_ntp:1")); | 540 "Group1 use_cacheable_ntp:1")); |
| 696 | 541 |
| 697 AddTab(browser(), GURL("chrome://blank")); | 542 AddTab(browser(), GURL("chrome://blank")); |
| 698 content::WebContents* contents = | 543 content::WebContents* contents = |
| 699 browser()->tab_strip_model()->GetWebContentsAt(0); | 544 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 700 content::NavigationController& controller = contents->GetController(); | 545 content::NavigationController& controller = contents->GetController(); |
| 701 // Local NTP. | 546 // Local NTP. |
| 702 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 547 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 703 EXPECT_TRUE(NavEntryIsInstantNTP(contents, | 548 EXPECT_TRUE(NavEntryIsInstantNTP(contents, |
| 704 controller.GetLastCommittedEntry())); | 549 controller.GetLastCommittedEntry())); |
| 705 // Instant page is not cacheable NTP. | 550 // Instant page is not cacheable NTP. |
| 706 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin)); | 551 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin)); |
| 707 EXPECT_FALSE(NavEntryIsInstantNTP(contents, | 552 EXPECT_FALSE(NavEntryIsInstantNTP(contents, |
| 708 controller.GetLastCommittedEntry())); | 553 controller.GetLastCommittedEntry())); |
| 709 // Test Cacheable NTP | 554 // Test Cacheable NTP |
| 710 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); | 555 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); |
| 711 EXPECT_TRUE(NavEntryIsInstantNTP(contents, | 556 EXPECT_TRUE(NavEntryIsInstantNTP(contents, |
| 712 controller.GetLastCommittedEntry())); | 557 controller.GetLastCommittedEntry())); |
| 713 } | 558 } |
| 714 | 559 |
| 715 TEST_F(SearchTest, UseLocalNTPInIncognito) { | 560 TEST_F(SearchTest, UseLocalNTPInIncognito) { |
| 716 EnableInstantExtendedAPIForTesting(); | |
| 717 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 561 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 718 "Group1 use_cacheable_ntp:1")); | 562 "Group1 use_cacheable_ntp:1")); |
| 719 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( | 563 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( |
| 720 profile()->GetOffTheRecordProfile())); | 564 profile()->GetOffTheRecordProfile())); |
| 721 } | 565 } |
| 722 | 566 |
| 723 TEST_F(SearchTest, GetInstantURLExtendedEnabled) { | 567 TEST_F(SearchTest, GetInstantURL) { |
| 724 // Instant is disabled, so no Instant URL. | 568 // No Instant URL because "strk" is missing. |
| 725 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | |
| 726 | |
| 727 // Enable Instant. Still no Instant URL because "strk" is missing. | |
| 728 EnableInstantExtendedAPIForTesting(); | |
| 729 SetDefaultInstantTemplateUrl(false); | 569 SetDefaultInstantTemplateUrl(false); |
| 730 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | 570 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); |
| 731 | 571 |
| 732 // Set an Instant URL with a valid search terms replacement key. | 572 // Set an Instant URL with a valid search terms replacement key. |
| 733 SetDefaultInstantTemplateUrl(true); | 573 SetDefaultInstantTemplateUrl(true); |
| 734 | 574 |
| 735 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". | 575 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". |
| 736 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 576 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 737 GetInstantURL(profile(), kDisableStartMargin)); | 577 GetInstantURL(profile(), kDisableStartMargin)); |
| 738 | 578 |
| 739 // Enable suggest. No difference. | 579 // Enable suggest. No difference. |
| 740 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 580 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 741 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 581 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 742 GetInstantURL(profile(), kDisableStartMargin)); | 582 GetInstantURL(profile(), kDisableStartMargin)); |
| 743 | 583 |
| 744 // Disable suggest. No Instant URL. | 584 // Disable suggest. No Instant URL. |
| 745 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | 585 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); |
| 746 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | 586 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); |
| 747 } | 587 } |
| 748 | 588 |
| 749 TEST_F(SearchTest, StartMarginCGI) { | 589 TEST_F(SearchTest, StartMarginCGI) { |
| 750 // Instant is disabled, so no Instant URL. | 590 // No margin. |
| 751 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); | |
| 752 | |
| 753 // Enable Instant. No margin. | |
| 754 EnableInstantExtendedAPIForTesting(); | |
| 755 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 591 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 756 | |
| 757 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), | 592 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), |
| 758 GetInstantURL(profile(), kDisableStartMargin)); | 593 GetInstantURL(profile(), kDisableStartMargin)); |
| 759 | 594 |
| 760 // With start margin. | 595 // With start margin. |
| 761 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), | 596 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), |
| 762 GetInstantURL(profile(), 10)); | 597 GetInstantURL(profile(), 10)); |
| 763 } | 598 } |
| 764 | 599 |
| 765 TEST_F(SearchTest, CommandLineOverrides) { | 600 TEST_F(SearchTest, CommandLineOverrides) { |
| 766 EnableInstantExtendedAPIForTesting(); | 601 EnableQueryExtractionForTesting(); |
| 767 | 602 |
| 768 GURL local_instant_url(GetLocalInstantURL(profile())); | 603 GURL local_instant_url(GetLocalInstantURL(profile())); |
| 769 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); | 604 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); |
| 770 | 605 |
| 771 TemplateURLService* template_url_service = | 606 TemplateURLService* template_url_service = |
| 772 TemplateURLServiceFactory::GetForProfile(profile()); | 607 TemplateURLServiceFactory::GetForProfile(profile()); |
| 773 TemplateURLData data; | 608 TemplateURLData data; |
| 774 data.SetURL("{google:baseURL}search?q={searchTerms}"); | 609 data.SetURL("{google:baseURL}search?q={searchTerms}"); |
| 775 data.instant_url = "{google:baseURL}webhp?strk"; | 610 data.instant_url = "{google:baseURL}webhp?strk"; |
| 776 data.search_terms_replacement_key = "strk"; | 611 data.search_terms_replacement_key = "strk"; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 804 // If we specify extra search query params, they should be inserted into the | 639 // If we specify extra search query params, they should be inserted into the |
| 805 // query portion of the instant URL. | 640 // query portion of the instant URL. |
| 806 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 641 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 807 switches::kExtraSearchQueryParams, "a=b"); | 642 switches::kExtraSearchQueryParams, "a=b"); |
| 808 instant_url = GetInstantURL(profile(), kDisableStartMargin); | 643 instant_url = GetInstantURL(profile(), kDisableStartMargin); |
| 809 ASSERT_TRUE(instant_url.is_valid()); | 644 ASSERT_TRUE(instant_url.is_valid()); |
| 810 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); | 645 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); |
| 811 } | 646 } |
| 812 | 647 |
| 813 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { | 648 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { |
| 814 EnableInstantExtendedAPIForTesting(); | |
| 815 EXPECT_TRUE(ShouldShowInstantNTP()); | 649 EXPECT_TRUE(ShouldShowInstantNTP()); |
| 816 } | 650 } |
| 817 | 651 |
| 818 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { | 652 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { |
| 819 EnableInstantExtendedAPIForTesting(); | |
| 820 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 653 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 821 "Group1 show_ntp:0")); | 654 "Group1 show_ntp:0")); |
| 822 EXPECT_FALSE(ShouldShowInstantNTP()); | 655 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 823 } | 656 } |
| 824 | 657 |
| 825 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { | 658 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { |
| 826 EnableInstantExtendedAPIForTesting(); | |
| 827 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 659 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 828 "Group1 use_cacheable_ntp:1")); | 660 "Group1 use_cacheable_ntp:1")); |
| 829 EXPECT_FALSE(ShouldShowInstantNTP()); | 661 EXPECT_FALSE(ShouldShowInstantNTP()); |
| 830 } | 662 } |
| 831 | 663 |
| 832 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) { | 664 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) { |
| 833 EnableInstantExtendedAPIForTesting(); | |
| 834 EXPECT_FALSE(ShouldUseCacheableNTP()); | 665 EXPECT_FALSE(ShouldUseCacheableNTP()); |
| 835 } | 666 } |
| 836 | 667 |
| 837 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) { | 668 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) { |
| 838 EnableInstantExtendedAPIForTesting(); | |
| 839 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 669 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 840 "Group1 use_cacheable_ntp:1")); | 670 "Group1 use_cacheable_ntp:1")); |
| 841 EXPECT_TRUE(ShouldUseCacheableNTP()); | 671 EXPECT_TRUE(ShouldUseCacheableNTP()); |
| 842 } | 672 } |
| 843 | 673 |
| 844 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaCommandLine) { | 674 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaCommandLine) { |
| 845 EnableInstantExtendedAPIForTesting(); | |
| 846 CommandLine::ForCurrentProcess()-> | 675 CommandLine::ForCurrentProcess()-> |
| 847 AppendSwitch(switches::kUseCacheableNewTabPage); | 676 AppendSwitch(switches::kUseCacheableNewTabPage); |
| 848 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 677 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 849 "Group1 use_cacheable_ntp:0")); | 678 "Group1 use_cacheable_ntp:0")); |
| 850 EXPECT_TRUE(ShouldUseCacheableNTP()); | 679 EXPECT_TRUE(ShouldUseCacheableNTP()); |
| 851 } | 680 } |
| 852 | 681 |
| 853 TEST_F(SearchTest, IsNTPURL) { | 682 TEST_F(SearchTest, IsNTPURL) { |
| 854 GURL invalid_url; | 683 GURL invalid_url; |
| 855 GURL ntp_url(chrome::kChromeUINewTabURL); | 684 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 856 GURL local_ntp_url(GetLocalInstantURL(profile())); | 685 GURL local_ntp_url(GetLocalInstantURL(profile())); |
| 857 | 686 |
| 858 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); | 687 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); |
| 859 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, profile())); | |
| 860 | 688 |
| 861 EXPECT_TRUE(chrome::IsNTPURL(ntp_url, NULL)); | 689 EnableQueryExtractionForTesting(); |
| 862 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); | |
| 863 | |
| 864 // Enable Instant. No margin. | |
| 865 EnableInstantExtendedAPIForTesting(); | |
| 866 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 690 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 867 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin)); | 691 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin)); |
| 868 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); | 692 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); |
| 869 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); | 693 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); |
| 870 | 694 |
| 871 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); | 695 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); |
| 872 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); | 696 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); |
| 873 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); | 697 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); |
| 874 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); | 698 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); |
| 875 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); | 699 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); |
| 876 | 700 |
| 877 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); | 701 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); |
| 878 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); | 702 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); |
| 879 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL)); | 703 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL)); |
| 880 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL)); | 704 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL)); |
| 881 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL)); | 705 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL)); |
| 882 } | 706 } |
| 883 | 707 |
| 884 TEST_F(SearchTest, GetSearchURLs) { | 708 TEST_F(SearchTest, GetSearchURLs) { |
| 885 std::vector<GURL> search_urls = GetSearchURLs(profile()); | 709 std::vector<GURL> search_urls = GetSearchURLs(profile()); |
| 886 EXPECT_EQ(2U, search_urls.size()); | 710 EXPECT_EQ(2U, search_urls.size()); |
| 887 EXPECT_EQ("http://foo.com/alt#quux=", search_urls[0].spec()); | 711 EXPECT_EQ("http://foo.com/alt#quux=", search_urls[0].spec()); |
| 888 EXPECT_EQ("http://foo.com/url?bar=", search_urls[1].spec()); | 712 EXPECT_EQ("http://foo.com/url?bar=", search_urls[1].spec()); |
| 889 } | 713 } |
| 890 | 714 |
| 891 } // namespace chrome | 715 } // namespace chrome |
| OLD | NEW |