| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/feature_engagement_tracker/internal/chrome_variations_confi
guration.h" | 5 #include "components/feature_engagement_tracker/internal/chrome_variations_confi
guration.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/field_trial_param_associator.h" | 13 #include "base/metrics/field_trial_param_associator.h" |
| 14 #include "base/metrics/field_trial_params.h" | 14 #include "base/metrics/field_trial_params.h" |
| 15 #include "base/test/histogram_tester.h" |
| 15 #include "base/test/scoped_feature_list.h" | 16 #include "base/test/scoped_feature_list.h" |
| 16 #include "components/feature_engagement_tracker/internal/configuration.h" | 17 #include "components/feature_engagement_tracker/internal/configuration.h" |
| 18 #include "components/feature_engagement_tracker/internal/stats.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace feature_engagement_tracker { | 21 namespace feature_engagement_tracker { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 const base::Feature kTestFeatureFoo{"test_foo", | 25 const base::Feature kTestFeatureFoo{"test_foo", |
| 24 base::FEATURE_DISABLED_BY_DEFAULT}; | 26 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 25 const base::Feature kTestFeatureBar{"test_bar", | 27 const base::Feature kTestFeatureBar{"test_bar", |
| 26 base::FEATURE_DISABLED_BY_DEFAULT}; | 28 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 27 const base::Feature kTestFeatureQux{"test_qux", | 29 const base::Feature kTestFeatureQux{"test_qux", |
| 28 base::FEATURE_DISABLED_BY_DEFAULT}; | 30 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 29 | 31 |
| 30 const char kFooTrialName[] = "FooTrial"; | 32 const char kFooTrialName[] = "FooTrial"; |
| 31 const char kBarTrialName[] = "BarTrial"; | 33 const char kBarTrialName[] = "BarTrial"; |
| 32 const char kQuxTrialName[] = "QuxTrial"; | 34 const char kQuxTrialName[] = "QuxTrial"; |
| 33 const char kGroupName[] = "Group1"; | 35 const char kGroupName[] = "Group1"; |
| 36 const char kConfigParseEventName[] = "InProductHelp.Config.ParsingEvent"; |
| 34 | 37 |
| 35 class ChromeVariationsConfigurationTest : public ::testing::Test { | 38 class ChromeVariationsConfigurationTest : public ::testing::Test { |
| 36 public: | 39 public: |
| 37 ChromeVariationsConfigurationTest() : field_trials_(nullptr) { | 40 ChromeVariationsConfigurationTest() : field_trials_(nullptr) { |
| 38 base::FieldTrial* foo_trial = | 41 base::FieldTrial* foo_trial = |
| 39 base::FieldTrialList::CreateFieldTrial(kFooTrialName, kGroupName); | 42 base::FieldTrialList::CreateFieldTrial(kFooTrialName, kGroupName); |
| 40 base::FieldTrial* bar_trial = | 43 base::FieldTrial* bar_trial = |
| 41 base::FieldTrialList::CreateFieldTrial(kBarTrialName, kGroupName); | 44 base::FieldTrialList::CreateFieldTrial(kBarTrialName, kGroupName); |
| 42 base::FieldTrial* qux_trial = | 45 base::FieldTrial* qux_trial = |
| 43 base::FieldTrialList::CreateFieldTrial(kQuxTrialName, kGroupName); | 46 base::FieldTrialList::CreateFieldTrial(kQuxTrialName, kGroupName); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 108 |
| 106 } // namespace | 109 } // namespace |
| 107 | 110 |
| 108 TEST_F(ChromeVariationsConfigurationTest, | 111 TEST_F(ChromeVariationsConfigurationTest, |
| 109 DisabledFeatureShouldHaveInvalidConfig) { | 112 DisabledFeatureShouldHaveInvalidConfig) { |
| 110 base::test::ScopedFeatureList scoped_feature_list; | 113 base::test::ScopedFeatureList scoped_feature_list; |
| 111 scoped_feature_list.InitWithFeatures({}, {kTestFeatureFoo}); | 114 scoped_feature_list.InitWithFeatures({}, {kTestFeatureFoo}); |
| 112 | 115 |
| 113 FeatureVector features; | 116 FeatureVector features; |
| 114 features.push_back(&kTestFeatureFoo); | 117 features.push_back(&kTestFeatureFoo); |
| 118 base::HistogramTester histogram_tester; |
| 115 | 119 |
| 116 configuration_.ParseFeatureConfigs(features); | 120 configuration_.ParseFeatureConfigs(features); |
| 117 | 121 |
| 118 FeatureConfig foo_config = configuration_.GetFeatureConfig(kTestFeatureFoo); | 122 FeatureConfig foo_config = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 119 EXPECT_FALSE(foo_config.valid); | 123 EXPECT_FALSE(foo_config.valid); |
| 124 histogram_tester.ExpectBucketCount( |
| 125 kConfigParseEventName, |
| 126 static_cast<int>(stats::ConfigParsingEvent::FAILURE_NO_FIELD_TRIAL), 1); |
| 127 histogram_tester.ExpectTotalCount(kConfigParseEventName, 1); |
| 120 } | 128 } |
| 121 | 129 |
| 122 TEST_F(ChromeVariationsConfigurationTest, ParseSingleFeature) { | 130 TEST_F(ChromeVariationsConfigurationTest, ParseSingleFeature) { |
| 123 std::map<std::string, std::string> foo_params; | 131 std::map<std::string, std::string> foo_params; |
| 124 foo_params["event_used"] = | 132 foo_params["event_used"] = |
| 125 "name:page_download_started;comparator:any;window:0;storage:360"; | 133 "name:page_download_started;comparator:any;window:0;storage:360"; |
| 126 foo_params["event_trigger"] = | 134 foo_params["event_trigger"] = |
| 127 "name:opened_chrome_home;comparator:any;window:0;storage:360"; | 135 "name:opened_chrome_home;comparator:any;window:0;storage:360"; |
| 128 foo_params["event_1"] = | 136 foo_params["event_1"] = |
| 129 "name:user_has_seen_dino;comparator:>=1;window:120;storage:180"; | 137 "name:user_has_seen_dino;comparator:>=1;window:120;storage:180"; |
| 130 foo_params["event_2"] = | 138 foo_params["event_2"] = |
| 131 "name:user_opened_app_menu;comparator:<=0;window:120;storage:180"; | 139 "name:user_opened_app_menu;comparator:<=0;window:120;storage:180"; |
| 132 foo_params["event_3"] = | 140 foo_params["event_3"] = |
| 133 "name:user_opened_downloads_home;comparator:any;window:0;storage:360"; | 141 "name:user_opened_downloads_home;comparator:any;window:0;storage:360"; |
| 134 SetFeatureParams(kTestFeatureFoo, foo_params); | 142 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 135 | 143 |
| 144 base::HistogramTester histogram_tester; |
| 136 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 145 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 137 configuration_.ParseFeatureConfigs(features); | 146 configuration_.ParseFeatureConfigs(features); |
| 138 | 147 |
| 139 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 148 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 140 EXPECT_TRUE(foo.valid); | 149 EXPECT_TRUE(foo.valid); |
| 150 histogram_tester.ExpectBucketCount( |
| 151 kConfigParseEventName, |
| 152 static_cast<int>(stats::ConfigParsingEvent::SUCCESS), 1); |
| 153 histogram_tester.ExpectTotalCount(kConfigParseEventName, 1); |
| 141 | 154 |
| 142 FeatureConfig expected_foo; | 155 FeatureConfig expected_foo; |
| 143 expected_foo.valid = true; | 156 expected_foo.valid = true; |
| 144 expected_foo.used = | 157 expected_foo.used = |
| 145 EventConfig("page_download_started", Comparator(ANY, 0), 0, 360); | 158 EventConfig("page_download_started", Comparator(ANY, 0), 0, 360); |
| 146 expected_foo.trigger = | 159 expected_foo.trigger = |
| 147 EventConfig("opened_chrome_home", Comparator(ANY, 0), 0, 360); | 160 EventConfig("opened_chrome_home", Comparator(ANY, 0), 0, 360); |
| 148 expected_foo.event_configs.insert(EventConfig( | 161 expected_foo.event_configs.insert(EventConfig( |
| 149 "user_has_seen_dino", Comparator(GREATER_THAN_OR_EQUAL, 1), 120, 180)); | 162 "user_has_seen_dino", Comparator(GREATER_THAN_OR_EQUAL, 1), 120, 180)); |
| 150 expected_foo.event_configs.insert(EventConfig( | 163 expected_foo.event_configs.insert(EventConfig( |
| 151 "user_opened_app_menu", Comparator(LESS_THAN_OR_EQUAL, 0), 120, 180)); | 164 "user_opened_app_menu", Comparator(LESS_THAN_OR_EQUAL, 0), 120, 180)); |
| 152 expected_foo.event_configs.insert( | 165 expected_foo.event_configs.insert( |
| 153 EventConfig("user_opened_downloads_home", Comparator(ANY, 0), 0, 360)); | 166 EventConfig("user_opened_downloads_home", Comparator(ANY, 0), 0, 360)); |
| 154 EXPECT_EQ(expected_foo, foo); | 167 EXPECT_EQ(expected_foo, foo); |
| 155 } | 168 } |
| 156 | 169 |
| 157 TEST_F(ChromeVariationsConfigurationTest, MissingUsedIsInvalid) { | 170 TEST_F(ChromeVariationsConfigurationTest, MissingUsedIsInvalid) { |
| 158 std::map<std::string, std::string> foo_params; | 171 std::map<std::string, std::string> foo_params; |
| 159 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 172 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 160 SetFeatureParams(kTestFeatureFoo, foo_params); | 173 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 161 | 174 |
| 175 base::HistogramTester histogram_tester; |
| 162 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 176 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 163 configuration_.ParseFeatureConfigs(features); | 177 configuration_.ParseFeatureConfigs(features); |
| 164 | 178 |
| 165 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 179 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 166 EXPECT_FALSE(foo.valid); | 180 EXPECT_FALSE(foo.valid); |
| 181 histogram_tester.ExpectBucketCount( |
| 182 kConfigParseEventName, |
| 183 static_cast<int>(stats::ConfigParsingEvent::FAILURE_USED_EVENT_MISSING), |
| 184 1); |
| 185 histogram_tester.ExpectBucketCount( |
| 186 kConfigParseEventName, |
| 187 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 188 histogram_tester.ExpectTotalCount(kConfigParseEventName, 2); |
| 167 } | 189 } |
| 168 | 190 |
| 169 TEST_F(ChromeVariationsConfigurationTest, MissingTriggerIsInvalid) { | 191 TEST_F(ChromeVariationsConfigurationTest, MissingTriggerIsInvalid) { |
| 170 std::map<std::string, std::string> foo_params; | 192 std::map<std::string, std::string> foo_params; |
| 171 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; | 193 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; |
| 172 SetFeatureParams(kTestFeatureFoo, foo_params); | 194 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 173 | 195 |
| 196 base::HistogramTester histogram_tester; |
| 174 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 197 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 175 configuration_.ParseFeatureConfigs(features); | 198 configuration_.ParseFeatureConfigs(features); |
| 176 | 199 |
| 177 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 200 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 178 EXPECT_FALSE(foo.valid); | 201 EXPECT_FALSE(foo.valid); |
| 202 histogram_tester.ExpectBucketCount( |
| 203 kConfigParseEventName, |
| 204 static_cast<int>( |
| 205 stats::ConfigParsingEvent::FAILURE_TRIGGER_EVENT_MISSING), |
| 206 1); |
| 207 histogram_tester.ExpectBucketCount( |
| 208 kConfigParseEventName, |
| 209 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 210 histogram_tester.ExpectTotalCount(kConfigParseEventName, 2); |
| 179 } | 211 } |
| 180 | 212 |
| 181 TEST_F(ChromeVariationsConfigurationTest, OnlyTriggerAndUsedIsValid) { | 213 TEST_F(ChromeVariationsConfigurationTest, OnlyTriggerAndUsedIsValid) { |
| 182 std::map<std::string, std::string> foo_params; | 214 std::map<std::string, std::string> foo_params; |
| 183 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; | 215 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; |
| 184 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 216 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 185 SetFeatureParams(kTestFeatureFoo, foo_params); | 217 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 186 | 218 |
| 219 base::HistogramTester histogram_tester; |
| 187 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 220 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 188 configuration_.ParseFeatureConfigs(features); | 221 configuration_.ParseFeatureConfigs(features); |
| 189 | 222 |
| 190 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 223 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 191 EXPECT_TRUE(foo.valid); | 224 EXPECT_TRUE(foo.valid); |
| 192 | 225 |
| 193 FeatureConfig expected_foo; | 226 FeatureConfig expected_foo; |
| 194 expected_foo.valid = true; | 227 expected_foo.valid = true; |
| 195 expected_foo.used = EventConfig("eu", Comparator(ANY, 0), 0, 360); | 228 expected_foo.used = EventConfig("eu", Comparator(ANY, 0), 0, 360); |
| 196 expected_foo.trigger = EventConfig("et", Comparator(ANY, 0), 0, 360); | 229 expected_foo.trigger = EventConfig("et", Comparator(ANY, 0), 0, 360); |
| 197 EXPECT_EQ(expected_foo, foo); | 230 EXPECT_EQ(expected_foo, foo); |
| 231 histogram_tester.ExpectBucketCount( |
| 232 kConfigParseEventName, |
| 233 static_cast<int>(stats::ConfigParsingEvent::SUCCESS), 1); |
| 234 histogram_tester.ExpectTotalCount(kConfigParseEventName, 1); |
| 198 } | 235 } |
| 199 | 236 |
| 200 TEST_F(ChromeVariationsConfigurationTest, WhitespaceIsValid) { | 237 TEST_F(ChromeVariationsConfigurationTest, WhitespaceIsValid) { |
| 201 std::map<std::string, std::string> foo_params; | 238 std::map<std::string, std::string> foo_params; |
| 202 foo_params["event_used"] = | 239 foo_params["event_used"] = |
| 203 " name : eu ; comparator : any ; window : 1 ; storage : 320 "; | 240 " name : eu ; comparator : any ; window : 1 ; storage : 320 "; |
| 204 foo_params["event_trigger"] = | 241 foo_params["event_trigger"] = |
| 205 " name:et;comparator : any ;window: 2;storage:330 "; | 242 " name:et;comparator : any ;window: 2;storage:330 "; |
| 206 foo_params["event_0"] = "name:e0;comparator: <1 ;window:3\n;storage:340"; | 243 foo_params["event_0"] = "name:e0;comparator: <1 ;window:3\n;storage:340"; |
| 207 foo_params["event_1"] = "name:e1;comparator: > 2 ;window:4;\rstorage:350"; | 244 foo_params["event_1"] = "name:e1;comparator: > 2 ;window:4;\rstorage:350"; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 366 } |
| 330 | 367 |
| 331 TEST_F(ChromeVariationsConfigurationTest, | 368 TEST_F(ChromeVariationsConfigurationTest, |
| 332 InvalidSessionRateCausesInvalidConfig) { | 369 InvalidSessionRateCausesInvalidConfig) { |
| 333 std::map<std::string, std::string> foo_params; | 370 std::map<std::string, std::string> foo_params; |
| 334 foo_params["event_used"] = "name:eu;comparator:any;window:1;storage:360"; | 371 foo_params["event_used"] = "name:eu;comparator:any;window:1;storage:360"; |
| 335 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 372 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 336 foo_params["session_rate"] = "bogus value"; | 373 foo_params["session_rate"] = "bogus value"; |
| 337 SetFeatureParams(kTestFeatureFoo, foo_params); | 374 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 338 | 375 |
| 376 base::HistogramTester histogram_tester; |
| 339 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 377 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 340 configuration_.ParseFeatureConfigs(features); | 378 configuration_.ParseFeatureConfigs(features); |
| 341 | 379 |
| 342 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 380 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 343 EXPECT_FALSE(foo.valid); | 381 EXPECT_FALSE(foo.valid); |
| 382 histogram_tester.ExpectBucketCount( |
| 383 kConfigParseEventName, |
| 384 static_cast<int>(stats::ConfigParsingEvent::FAILURE_SESSION_RATE_PARSE), |
| 385 1); |
| 386 histogram_tester.ExpectBucketCount( |
| 387 kConfigParseEventName, |
| 388 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 389 histogram_tester.ExpectTotalCount(kConfigParseEventName, 2); |
| 344 } | 390 } |
| 345 | 391 |
| 346 TEST_F(ChromeVariationsConfigurationTest, | 392 TEST_F(ChromeVariationsConfigurationTest, |
| 347 InvalidAvailabilityCausesInvalidConfig) { | 393 InvalidAvailabilityCausesInvalidConfig) { |
| 348 std::map<std::string, std::string> foo_params; | 394 std::map<std::string, std::string> foo_params; |
| 349 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; | 395 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; |
| 350 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 396 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 351 foo_params["availability"] = "bogus value"; | 397 foo_params["availability"] = "bogus value"; |
| 352 SetFeatureParams(kTestFeatureFoo, foo_params); | 398 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 353 | 399 |
| 400 base::HistogramTester histogram_tester; |
| 354 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 401 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 355 configuration_.ParseFeatureConfigs(features); | 402 configuration_.ParseFeatureConfigs(features); |
| 356 | 403 |
| 357 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 404 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 358 EXPECT_FALSE(foo.valid); | 405 EXPECT_FALSE(foo.valid); |
| 406 histogram_tester.ExpectBucketCount( |
| 407 kConfigParseEventName, |
| 408 static_cast<int>(stats::ConfigParsingEvent::FAILURE_AVAILABILITY_PARSE), |
| 409 1); |
| 410 histogram_tester.ExpectBucketCount( |
| 411 kConfigParseEventName, |
| 412 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 413 histogram_tester.ExpectTotalCount(kConfigParseEventName, 2); |
| 359 } | 414 } |
| 360 | 415 |
| 361 TEST_F(ChromeVariationsConfigurationTest, InvalidUsedCausesInvalidConfig) { | 416 TEST_F(ChromeVariationsConfigurationTest, InvalidUsedCausesInvalidConfig) { |
| 362 std::map<std::string, std::string> foo_params; | 417 std::map<std::string, std::string> foo_params; |
| 363 foo_params["event_used"] = "bogus value"; | 418 foo_params["event_used"] = "bogus value"; |
| 364 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 419 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 365 SetFeatureParams(kTestFeatureFoo, foo_params); | 420 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 366 | 421 |
| 422 base::HistogramTester histogram_tester; |
| 367 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 423 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 368 configuration_.ParseFeatureConfigs(features); | 424 configuration_.ParseFeatureConfigs(features); |
| 369 | 425 |
| 370 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 426 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 371 EXPECT_FALSE(foo.valid); | 427 EXPECT_FALSE(foo.valid); |
| 428 histogram_tester.ExpectBucketCount( |
| 429 kConfigParseEventName, |
| 430 static_cast<int>(stats::ConfigParsingEvent::FAILURE_USED_EVENT_PARSE), 1); |
| 431 histogram_tester.ExpectBucketCount( |
| 432 kConfigParseEventName, |
| 433 static_cast<int>(stats::ConfigParsingEvent::FAILURE_USED_EVENT_MISSING), |
| 434 1); |
| 435 histogram_tester.ExpectBucketCount( |
| 436 kConfigParseEventName, |
| 437 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 438 histogram_tester.ExpectTotalCount(kConfigParseEventName, 3); |
| 372 } | 439 } |
| 373 | 440 |
| 374 TEST_F(ChromeVariationsConfigurationTest, InvalidTriggerCausesInvalidConfig) { | 441 TEST_F(ChromeVariationsConfigurationTest, InvalidTriggerCausesInvalidConfig) { |
| 375 std::map<std::string, std::string> foo_params; | 442 std::map<std::string, std::string> foo_params; |
| 376 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; | 443 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; |
| 377 foo_params["event_trigger"] = "bogus value"; | 444 foo_params["event_trigger"] = "bogus value"; |
| 378 SetFeatureParams(kTestFeatureFoo, foo_params); | 445 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 379 | 446 |
| 447 base::HistogramTester histogram_tester; |
| 380 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; | 448 std::vector<const base::Feature*> features = {&kTestFeatureFoo}; |
| 381 configuration_.ParseFeatureConfigs(features); | 449 configuration_.ParseFeatureConfigs(features); |
| 382 | 450 |
| 383 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); | 451 FeatureConfig foo = configuration_.GetFeatureConfig(kTestFeatureFoo); |
| 384 EXPECT_FALSE(foo.valid); | 452 EXPECT_FALSE(foo.valid); |
| 453 histogram_tester.ExpectBucketCount( |
| 454 kConfigParseEventName, |
| 455 static_cast<int>(stats::ConfigParsingEvent::FAILURE_TRIGGER_EVENT_PARSE), |
| 456 1); |
| 457 histogram_tester.ExpectBucketCount( |
| 458 kConfigParseEventName, |
| 459 static_cast<int>( |
| 460 stats::ConfigParsingEvent::FAILURE_TRIGGER_EVENT_MISSING), |
| 461 1); |
| 462 histogram_tester.ExpectBucketCount( |
| 463 kConfigParseEventName, |
| 464 static_cast<int>(stats::ConfigParsingEvent::FAILURE), 1); |
| 465 histogram_tester.ExpectTotalCount(kConfigParseEventName, 3); |
| 385 } | 466 } |
| 386 | 467 |
| 387 TEST_F(ChromeVariationsConfigurationTest, | 468 TEST_F(ChromeVariationsConfigurationTest, |
| 388 InvalidEventConfigCausesInvalidConfig) { | 469 InvalidEventConfigCausesInvalidConfig) { |
| 389 std::map<std::string, std::string> foo_params; | 470 std::map<std::string, std::string> foo_params; |
| 390 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; | 471 foo_params["event_used"] = "name:eu;comparator:any;window:0;storage:360"; |
| 391 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; | 472 foo_params["event_trigger"] = "name:et;comparator:any;window:0;storage:360"; |
| 392 foo_params["event_used_0"] = "bogus value"; | 473 foo_params["event_used_0"] = "bogus value"; |
| 393 SetFeatureParams(kTestFeatureFoo, foo_params); | 474 SetFeatureParams(kTestFeatureFoo, foo_params); |
| 394 | 475 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 expected_qux.event_configs.insert( | 613 expected_qux.event_configs.insert( |
| 533 EventConfig("q4", Comparator(EQUAL, 14), 24, 34)); | 614 EventConfig("q4", Comparator(EQUAL, 14), 24, 34)); |
| 534 expected_qux.event_configs.insert( | 615 expected_qux.event_configs.insert( |
| 535 EventConfig("q5", Comparator(NOT_EQUAL, 15), 25, 35)); | 616 EventConfig("q5", Comparator(NOT_EQUAL, 15), 25, 35)); |
| 536 expected_qux.session_rate = Comparator(NOT_EQUAL, 13); | 617 expected_qux.session_rate = Comparator(NOT_EQUAL, 13); |
| 537 expected_qux.availability = Comparator(EQUAL, 0); | 618 expected_qux.availability = Comparator(EQUAL, 0); |
| 538 EXPECT_EQ(expected_qux, qux); | 619 EXPECT_EQ(expected_qux, qux); |
| 539 } | 620 } |
| 540 | 621 |
| 541 } // namespace feature_engagement_tracker | 622 } // namespace feature_engagement_tracker |
| OLD | NEW |