OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chrome_elf_init_win.h" | 5 #include "chrome/browser/chrome_elf_init_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "base/test/test_reg_util_win.h" | 13 #include "base/test/test_reg_util_win.h" |
12 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
13 #include "chrome_elf/chrome_elf_constants.h" | 15 #include "chrome_elf/chrome_elf_constants.h" |
| 16 #include "components/variations/entropy_provider.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "version.h" // NOLINT | 18 #include "version.h" // NOLINT |
16 | 19 |
17 class ChromeBlacklistTrialTest : public testing::Test { | 20 class ChromeBlacklistTrialTest : public testing::Test { |
18 protected: | 21 protected: |
19 ChromeBlacklistTrialTest() {} | 22 ChromeBlacklistTrialTest() {} |
20 virtual ~ChromeBlacklistTrialTest() {} | 23 virtual ~ChromeBlacklistTrialTest() {} |
21 | 24 |
22 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() OVERRIDE { |
23 testing::Test::SetUp(); | 26 testing::Test::SetUp(); |
(...skipping 23 matching lines...) Expand all Loading... |
47 return blacklist_version; | 50 return blacklist_version; |
48 } | 51 } |
49 | 52 |
50 scoped_ptr<base::win::RegKey> blacklist_registry_key_; | 53 scoped_ptr<base::win::RegKey> blacklist_registry_key_; |
51 registry_util::RegistryOverrideManager override_manager_; | 54 registry_util::RegistryOverrideManager override_manager_; |
52 | 55 |
53 private: | 56 private: |
54 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest); | 57 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest); |
55 }; | 58 }; |
56 | 59 |
57 | 60 // Ensure that the default trial sets up the blacklist beacons. |
58 // Ensure that the default trial deletes any existing blacklist beacons. | |
59 TEST_F(ChromeBlacklistTrialTest, DefaultRun) { | 61 TEST_F(ChromeBlacklistTrialTest, DefaultRun) { |
60 // Set some dummy values as beacons. | 62 // Set some dummy values as beacons. |
61 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 63 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 64 blacklist::BLACKLIST_DISABLED); |
| 65 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
| 66 |
| 67 // This setup code should result in the default group, which should have |
| 68 // the blacklist set up. |
| 69 InitializeChromeElf(); |
| 70 |
| 71 // Ensure the beacon values are now correct, indicating the |
| 72 // blacklist beacon was setup. |
| 73 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 74 chrome::VersionInfo version_info; |
| 75 base::string16 version(base::UTF8ToUTF16(version_info.Version())); |
| 76 ASSERT_EQ(version, GetBlacklistVersion()); |
| 77 } |
| 78 |
| 79 |
| 80 // Ensure that the blacklist is disabled for any users in the |
| 81 // "BlacklistDisabled" finch group. |
| 82 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { |
| 83 // Set the beacons to enabled values. |
| 84 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
62 blacklist::BLACKLIST_ENABLED); | 85 blacklist::BLACKLIST_ENABLED); |
63 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 86 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
64 | 87 |
65 // This setup code should result in the default group, which should remove | 88 // Create the field trial with the blacklist disabled group. |
66 // all the beacon values. | 89 base::FieldTrialList field_trial_list( |
| 90 new metrics::SHA1EntropyProvider("test")); |
| 91 |
| 92 scoped_refptr<base::FieldTrial> trial( |
| 93 base::FieldTrialList::CreateFieldTrial( |
| 94 kBrowserBlacklistTrialName, kBrowserBlacklistTrialDisabledGroupName)); |
| 95 |
| 96 // This setup code should now delete any existing blacklist beacons. |
67 InitializeChromeElf(); | 97 InitializeChromeElf(); |
68 | 98 |
69 // Ensure that invalid values are returned to indicate that the | 99 // Ensure invalid values are returned to indicate that the beacon |
70 // beacon values are gone. | 100 // values are indeed gone. |
71 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); | 101 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); |
72 ASSERT_EQ(base::string16(), GetBlacklistVersion()); | 102 ASSERT_EQ(base::string16(), GetBlacklistVersion()); |
73 } | 103 } |
74 | 104 |
75 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { | 105 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { |
76 BrowserBlacklistBeaconSetup(); | 106 BrowserBlacklistBeaconSetup(); |
77 | 107 |
78 // Verify the state is properly set after the first run. | 108 // Verify the state is properly set after the first run. |
79 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 109 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
80 | 110 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 165 |
136 BrowserBlacklistBeaconSetup(); | 166 BrowserBlacklistBeaconSetup(); |
137 | 167 |
138 // The beacon should now be marked as enabled for the current version. | 168 // The beacon should now be marked as enabled for the current version. |
139 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
140 | 170 |
141 chrome::VersionInfo version_info; | 171 chrome::VersionInfo version_info; |
142 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
143 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 173 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
144 } | 174 } |
OLD | NEW |