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/metrics/field_trial.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/test/test_reg_util_win.h" | 12 #include "base/test/test_reg_util_win.h" |
13 #include "chrome/common/chrome_version_info.h" | |
14 #include "chrome_elf/chrome_elf_constants.h" | 13 #include "chrome_elf/chrome_elf_constants.h" |
15 #include "components/variations/entropy_provider.h" | 14 #include "components/variations/entropy_provider.h" |
16 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
| 16 #include "components/version_info/version_info.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "version.h" // NOLINT | 19 #include "version.h" // NOLINT |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; | 23 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; |
24 | 24 |
25 class ChromeBlacklistTrialTest : public testing::Test { | 25 class ChromeBlacklistTrialTest : public testing::Test { |
26 protected: | 26 protected: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 blacklist::BLACKLIST_DISABLED); | 69 blacklist::BLACKLIST_DISABLED); |
70 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 70 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
71 | 71 |
72 // This setup code should result in the default group, which should have | 72 // This setup code should result in the default group, which should have |
73 // the blacklist set up. | 73 // the blacklist set up. |
74 InitializeChromeElf(); | 74 InitializeChromeElf(); |
75 | 75 |
76 // Ensure the beacon values are now correct, indicating the | 76 // Ensure the beacon values are now correct, indicating the |
77 // blacklist beacon was setup. | 77 // blacklist beacon was setup. |
78 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 78 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
79 chrome::VersionInfo version_info; | 79 base::string16 version(base::UTF8ToUTF16(version_info::GetVersionNumber())); |
80 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | |
81 ASSERT_EQ(version, GetBlacklistVersion()); | 80 ASSERT_EQ(version, GetBlacklistVersion()); |
82 } | 81 } |
83 | 82 |
84 // Ensure that the blacklist is disabled for any users in the | 83 // Ensure that the blacklist is disabled for any users in the |
85 // "BlacklistDisabled" finch group. | 84 // "BlacklistDisabled" finch group. |
86 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { | 85 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { |
87 // Set the beacons to enabled values. | 86 // Set the beacons to enabled values. |
88 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 87 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
89 blacklist::BLACKLIST_ENABLED); | 88 blacklist::BLACKLIST_ENABLED); |
90 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 89 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
(...skipping 14 matching lines...) Expand all Loading... |
105 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); | 104 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); |
106 ASSERT_EQ(base::string16(), GetBlacklistVersion()); | 105 ASSERT_EQ(base::string16(), GetBlacklistVersion()); |
107 } | 106 } |
108 | 107 |
109 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { | 108 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { |
110 BrowserBlacklistBeaconSetup(); | 109 BrowserBlacklistBeaconSetup(); |
111 | 110 |
112 // Verify the state is properly set after the first run. | 111 // Verify the state is properly set after the first run. |
113 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 112 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
114 | 113 |
115 chrome::VersionInfo version_info; | 114 base::string16 version(base::UTF8ToUTF16(version_info::GetVersionNumber())); |
116 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | |
117 ASSERT_EQ(version, GetBlacklistVersion()); | 115 ASSERT_EQ(version, GetBlacklistVersion()); |
118 } | 116 } |
119 | 117 |
120 TEST_F(ChromeBlacklistTrialTest, BlacklistFailed) { | 118 TEST_F(ChromeBlacklistTrialTest, BlacklistFailed) { |
121 // Ensure when the blacklist set up failed we set the state to disabled for | 119 // Ensure when the blacklist set up failed we set the state to disabled for |
122 // future runs. | 120 // future runs. |
123 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 121 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
124 TEXT(CHROME_VERSION_STRING)); | 122 TEXT(CHROME_VERSION_STRING)); |
125 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 123 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
126 blacklist::BLACKLIST_SETUP_FAILED); | 124 blacklist::BLACKLIST_SETUP_FAILED); |
(...skipping 12 matching lines...) Expand all Loading... |
139 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 137 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
140 blacklist::BLACKLIST_DISABLED); | 138 blacklist::BLACKLIST_DISABLED); |
141 blacklist_registry_key_->WriteValue(blacklist::kBeaconAttemptCount, | 139 blacklist_registry_key_->WriteValue(blacklist::kBeaconAttemptCount, |
142 blacklist::kBeaconMaxAttempts); | 140 blacklist::kBeaconMaxAttempts); |
143 | 141 |
144 BrowserBlacklistBeaconSetup(); | 142 BrowserBlacklistBeaconSetup(); |
145 | 143 |
146 // The beacon should now be marked as enabled for the current version. | 144 // The beacon should now be marked as enabled for the current version. |
147 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 145 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
148 | 146 |
149 chrome::VersionInfo version_info; | 147 base::string16 expected_version( |
150 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 148 base::UTF8ToUTF16(version_info::GetVersionNumber())); |
151 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 149 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
152 | 150 |
153 // The counter should be reset. | 151 // The counter should be reset. |
154 DWORD attempt_count = blacklist::kBeaconMaxAttempts; | 152 DWORD attempt_count = blacklist::kBeaconMaxAttempts; |
155 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, | 153 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, |
156 &attempt_count); | 154 &attempt_count); |
157 ASSERT_EQ(static_cast<DWORD>(0), attempt_count); | 155 ASSERT_EQ(static_cast<DWORD>(0), attempt_count); |
158 } | 156 } |
159 | 157 |
160 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { | 158 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { |
(...skipping 28 matching lines...) Expand all Loading... |
189 | 187 |
190 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); | 188 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); |
191 it != desired_params.end(); | 189 it != desired_params.end(); |
192 ++it) { | 190 ++it) { |
193 std::wstring name = base::UTF8ToWide(it->first); | 191 std::wstring name = base::UTF8ToWide(it->first); |
194 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); | 192 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); |
195 } | 193 } |
196 } | 194 } |
197 | 195 |
198 } // namespace | 196 } // namespace |
OLD | NEW |