| 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" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 BrowserBlacklistBeaconSetup(); | 110 BrowserBlacklistBeaconSetup(); |
| 111 | 111 |
| 112 // Verify the state is properly set after the first run. | 112 // Verify the state is properly set after the first run. |
| 113 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 113 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 114 | 114 |
| 115 chrome::VersionInfo version_info; | 115 chrome::VersionInfo version_info; |
| 116 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | 116 base::string16 version(base::UTF8ToUTF16(version_info.Version())); |
| 117 ASSERT_EQ(version, GetBlacklistVersion()); | 117 ASSERT_EQ(version, GetBlacklistVersion()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { | 120 TEST_F(ChromeBlacklistTrialTest, BlacklistFailed) { |
| 121 // Set the registry to indicate that the blacklist setup is running, | 121 // Ensure when the blacklist set up failed we set the state to disabled for |
| 122 // which means it failed to run correctly last time for this version. | 122 // future runs. |
| 123 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 123 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 124 TEXT(CHROME_VERSION_STRING)); | 124 TEXT(CHROME_VERSION_STRING)); |
| 125 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 125 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 126 blacklist::BLACKLIST_SETUP_RUNNING); | 126 blacklist::BLACKLIST_SETUP_FAILED); |
| 127 | |
| 128 BrowserBlacklistBeaconSetup(); | |
| 129 | |
| 130 // Since the blacklist setup failed, it should now be disabled. | |
| 131 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | |
| 132 } | |
| 133 | |
| 134 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { | |
| 135 // Set the registry to indicate that the blacklist thunk setup is running, | |
| 136 // which means it failed to run correctly last time for this version. | |
| 137 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | |
| 138 TEXT(CHROME_VERSION_STRING)); | |
| 139 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 140 blacklist::BLACKLIST_THUNK_SETUP); | |
| 141 | 127 |
| 142 BrowserBlacklistBeaconSetup(); | 128 BrowserBlacklistBeaconSetup(); |
| 143 | 129 |
| 144 // Since the blacklist thunk setup failed, it should now be disabled. | |
| 145 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | |
| 146 } | |
| 147 | |
| 148 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { | |
| 149 // Set the registry to indicate that an interception is running, | |
| 150 // which means it failed to run correctly last time for this version. | |
| 151 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | |
| 152 TEXT(CHROME_VERSION_STRING)); | |
| 153 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 154 blacklist::BLACKLIST_INTERCEPTING); | |
| 155 | |
| 156 BrowserBlacklistBeaconSetup(); | |
| 157 | |
| 158 // Since an interception failed, the blacklist should now be disabled. | |
| 159 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | 130 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
| 160 } | 131 } |
| 161 | 132 |
| 162 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { | 133 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
| 163 // Mark the blacklist as disabled for an older version, so it should | 134 // Mark the blacklist as disabled for an older version, it should |
| 164 // get enabled for this new version. | 135 // get enabled for this new version. Also record a non-zero number of |
| 136 // setup failures, which should be reset to zero. |
| 165 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 137 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 166 L"old_version"); | 138 L"old_version"); |
| 167 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 139 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 168 blacklist::BLACKLIST_DISABLED); | 140 blacklist::BLACKLIST_DISABLED); |
| 141 blacklist_registry_key_->WriteValue(blacklist::kBeaconAttemptCount, |
| 142 blacklist::kBeaconMaxAttempts); |
| 169 | 143 |
| 170 BrowserBlacklistBeaconSetup(); | 144 BrowserBlacklistBeaconSetup(); |
| 171 | 145 |
| 172 // The beacon should now be marked as enabled for the current version. | 146 // The beacon should now be marked as enabled for the current version. |
| 173 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 147 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 174 | 148 |
| 175 chrome::VersionInfo version_info; | 149 chrome::VersionInfo version_info; |
| 176 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 150 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
| 177 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 151 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
| 152 |
| 153 // The counter should be reset. |
| 154 DWORD attempt_count = blacklist::kBeaconMaxAttempts; |
| 155 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, |
| 156 &attempt_count); |
| 157 ASSERT_EQ(static_cast<DWORD>(0), attempt_count); |
| 178 } | 158 } |
| 179 | 159 |
| 180 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { | 160 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { |
| 181 // Create the field trial with the blacklist enabled group. | 161 // Create the field trial with the blacklist enabled group. |
| 182 base::FieldTrialList field_trial_list( | 162 base::FieldTrialList field_trial_list( |
| 183 new metrics::SHA1EntropyProvider("test")); | 163 new metrics::SHA1EntropyProvider("test")); |
| 184 | 164 |
| 185 scoped_refptr<base::FieldTrial> trial(base::FieldTrialList::CreateFieldTrial( | 165 scoped_refptr<base::FieldTrial> trial(base::FieldTrialList::CreateFieldTrial( |
| 186 kBrowserBlacklistTrialName, kBrowserBlacklistTrialEnabledGroupName)); | 166 kBrowserBlacklistTrialName, kBrowserBlacklistTrialEnabledGroupName)); |
| 187 | 167 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 209 | 189 |
| 210 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); | 190 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); |
| 211 it != desired_params.end(); | 191 it != desired_params.end(); |
| 212 ++it) { | 192 ++it) { |
| 213 std::wstring name = base::UTF8ToWide(it->first); | 193 std::wstring name = base::UTF8ToWide(it->first); |
| 214 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); | 194 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); |
| 215 } | 195 } |
| 216 } | 196 } |
| 217 | 197 |
| 218 } // namespace | 198 } // namespace |
| OLD | NEW |