Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/autocomplete/autocomplete_field_trial.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/metrics/field_trial.h" | |
| 9 #include "base/string16.h" | |
| 10 #include "chrome/common/metrics/entropy_provider.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 class AutocompleteFieldTrialTest : public testing::Test { | |
| 14 public: | |
| 15 AutocompleteFieldTrialTest() {} | |
| 16 | |
| 17 static void SetUpTestCase() { | |
| 18 field_trial_list_ = new base::FieldTrialList( | |
| 19 new metrics::SHA1EntropyProvider("foo")); | |
| 20 AutocompleteFieldTrial::ActivateDynamicTrials(); | |
| 21 } | |
| 22 | |
| 23 static void TearDownTestCase() { | |
| 24 delete field_trial_list_; | |
| 25 } | |
| 26 | |
| 27 // Creates and activates a field trial. | |
| 28 static base::FieldTrial* CreateTestTrial(const std::string& name, | |
| 29 const std::string& group_name) { | |
| 30 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( | |
| 31 name, group_name); | |
| 32 trial->group(); | |
| 33 return trial; | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 // Needed for Activate{Static/Dynamic}Trials(). | |
| 38 static base::FieldTrialList* field_trial_list_; | |
|
Mark P
2013/02/11 22:39:46
Consider making this a non-pointer, non-static mem
Bart N.
2013/02/12 01:18:19
As discussed offline, I wanted to avoid initializa
| |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(AutocompleteFieldTrialTest); | |
| 41 }; | |
| 42 | |
| 43 // static | |
| 44 base::FieldTrialList* AutocompleteFieldTrialTest::field_trial_list_ = NULL; | |
| 45 | |
| 46 // Test if GetDisabledProviderTypes() properly parses various field trial | |
| 47 // group names. | |
| 48 // Note: Unfortunately, it's not possible to disable an already reported | |
| 49 // field trial group, so the following test gradually adds more field trials | |
| 50 // as it goes. | |
|
Mark P
2013/02/11 22:39:46
If you want to disable already reported groups, yo
Bart N.
2013/02/12 01:18:19
I actually found a better way. I've added ResetFie
Mark P
2013/02/12 17:53:31
Nice.
| |
| 51 TEST_F(AutocompleteFieldTrialTest, GetDisabledProviderTypes) { | |
| 52 EXPECT_EQ(0, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 53 | |
| 54 // Invalid groups. | |
| 55 base::FieldTrial* trial = CreateTestTrial("AutocompleteDynamicTrial_0", | |
| 56 "Group1 DisabledProviders_"); | |
| 57 EXPECT_EQ(0, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 58 trial = CreateTestTrial("AutocompleteDynamicTrial_1", | |
| 59 "Group1 DisabledProviders_XXX"); | |
| 60 EXPECT_EQ(0, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 61 | |
| 62 // Valid group name, unsupported trial name. | |
| 63 trial = CreateTestTrial("UnsupportedTrialName", | |
| 64 "Group1 DisabledProviders_20"); | |
| 65 EXPECT_EQ(0, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 66 | |
| 67 // Valid field and group name. | |
| 68 trial = CreateTestTrial("AutocompleteDynamicTrial_2", | |
| 69 "Group1 DisabledProviders_3"); | |
| 70 EXPECT_EQ(3, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 71 // Two groups should be OR-ed together. | |
| 72 trial = CreateTestTrial("AutocompleteDynamicTrial_3", | |
| 73 "Group1 DisabledProviders_6"); | |
| 74 EXPECT_EQ(7, AutocompleteFieldTrial::GetDisabledProviderTypes()); | |
| 75 } | |
| OLD | NEW |