Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: chrome/browser/chrome_elf_init_unittest_win.cc

Issue 311893005: Can now adjust the number of retries before the blacklist is disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding setup failure counter, UMA recording and unit tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 BrowserBlacklistBeaconSetup(); 106 BrowserBlacklistBeaconSetup();
107 107
108 // Verify the state is properly set after the first run. 108 // Verify the state is properly set after the first run.
109 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); 109 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
110 110
111 chrome::VersionInfo version_info; 111 chrome::VersionInfo version_info;
112 base::string16 version(base::UTF8ToUTF16(version_info.Version())); 112 base::string16 version(base::UTF8ToUTF16(version_info.Version()));
113 ASSERT_EQ(version, GetBlacklistVersion()); 113 ASSERT_EQ(version, GetBlacklistVersion());
114 } 114 }
115 115
116 // This test assumes that kBeaconAttemps (the number of startup retries we
117 // allow) is at least 2.
116 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { 118 TEST_F(ChromeBlacklistTrialTest, SetupFailed) {
119 // Ensure the setup failure counter is low enough that even a new failure
120 // would leave the blacklist enabled.
121 blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount,
122 kBeaconAttempts - 2);
123
117 // Set the registry to indicate that the blacklist setup is running, 124 // Set the registry to indicate that the blacklist setup is running,
118 // which means it failed to run correctly last time for this version. 125 // which means it failed to run correctly last time for this version.
119 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, 126 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
120 TEXT(CHROME_VERSION_STRING)); 127 TEXT(CHROME_VERSION_STRING));
121 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, 128 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
122 blacklist::BLACKLIST_SETUP_RUNNING); 129 blacklist::BLACKLIST_SETUP_RUNNING);
123 130
124 BrowserBlacklistBeaconSetup(); 131 BrowserBlacklistBeaconSetup();
125 132
126 // Since the blacklist setup failed, it should now be disabled. 133 // The blacklist has now failed kBeaconAttempts - 1 times, the beacon should
134 // reflect this and the blacklist state be set to enabled.
135 DWORD failed_attempt_count = kBeaconAttempts;
136 GetBlacklistFailedCount(&failed_attempt_count);
137 ASSERT_EQ(kBeaconAttempts - 1, failed_attempt_count);
138 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
139
140 // Force a second 'failure', this should disable the blacklist.
141 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
142 TEXT(CHROME_VERSION_STRING));
143 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
144 blacklist::BLACKLIST_SETUP_RUNNING);
145
146 BrowserBlacklistBeaconSetup();
127 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); 147 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
128 } 148 }
129 149
150 TEST_F(ChromeBlacklistTrialTest, SetupSucceeded) {
151 // Write a non-zero value to the registry so that we can check it gets reset.
152 blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount,
153 kBeaconAttempts);
154
155 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
156 TEXT(CHROME_VERSION_STRING));
157 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
158 blacklist::BLACKLIST_ENABLED);
159
160 BrowserBlacklistBeaconSetup();
161
162 // Because the set up was successful the counter should be reset.
163 DWORD attempt_count = kBeaconAttempts;
164 GetBlacklistFailedCount(&attempt_count);
165 ASSERT_EQ(static_cast<DWORD>(0), attempt_count);
166 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
167 }
168
130 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { 169 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) {
170 // Set the setup failure counter so that one more failure should disable the
171 // blacklist.
172 blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount,
173 kBeaconAttempts - 1);
174
131 // Set the registry to indicate that the blacklist thunk setup is running, 175 // Set the registry to indicate that the blacklist thunk setup is running,
132 // which means it failed to run correctly last time for this version. 176 // which means it failed to run correctly last time for this version.
133 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, 177 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
134 TEXT(CHROME_VERSION_STRING)); 178 TEXT(CHROME_VERSION_STRING));
135 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, 179 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
136 blacklist::BLACKLIST_THUNK_SETUP); 180 blacklist::BLACKLIST_THUNK_SETUP);
137 181
138 BrowserBlacklistBeaconSetup(); 182 BrowserBlacklistBeaconSetup();
139 183
140 // Since the blacklist thunk setup failed, it should now be disabled. 184 // Since the blacklist thunk setup failed, it should now be disabled.
141 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); 185 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
142 } 186 }
143 187
144 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { 188 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) {
189 // Set the setup failure counter so that one more failure should disable the
190 // blacklist.
191 blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount,
192 kBeaconAttempts - 1);
193
145 // Set the registry to indicate that an interception is running, 194 // Set the registry to indicate that an interception is running,
146 // which means it failed to run correctly last time for this version. 195 // which means it failed to run correctly last time for this version.
147 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, 196 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
148 TEXT(CHROME_VERSION_STRING)); 197 TEXT(CHROME_VERSION_STRING));
149 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, 198 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
150 blacklist::BLACKLIST_INTERCEPTING); 199 blacklist::BLACKLIST_INTERCEPTING);
151 200
152 BrowserBlacklistBeaconSetup(); 201 BrowserBlacklistBeaconSetup();
153 202
154 // Since an interception failed, the blacklist should now be disabled. 203 // Since an interception failed, the blacklist should now be disabled.
155 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); 204 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
156 } 205 }
157 206
158 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { 207 TEST_F(ChromeBlacklistTrialTest, VersionChanged) {
159 // Mark the blacklist as disabled for an older version, so it should 208 // Mark the blacklist as disabled for an older version, so it should
160 // get enabled for this new version. 209 // get enabled for this new version. Also record a non-zero number of
210 // setup failures, this should be reset to zero.
161 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, 211 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
162 L"old_version"); 212 L"old_version");
163 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, 213 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
164 blacklist::BLACKLIST_DISABLED); 214 blacklist::BLACKLIST_DISABLED);
215 blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount,
216 kBeaconAttempts);
165 217
166 BrowserBlacklistBeaconSetup(); 218 BrowserBlacklistBeaconSetup();
167 219
168 // The beacon should now be marked as enabled for the current version. 220 // The beacon should now be marked as enabled for the current version.
169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); 221 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
170 222
171 chrome::VersionInfo version_info; 223 chrome::VersionInfo version_info;
172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); 224 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version()));
173 ASSERT_EQ(expected_version, GetBlacklistVersion()); 225 ASSERT_EQ(expected_version, GetBlacklistVersion());
226
227 // The counter should be reset.
228 DWORD attempt_count = kBeaconAttempts;
229 GetBlacklistFailedCount(&attempt_count);
230 ASSERT_EQ(static_cast<DWORD>(0), attempt_count);
174 } 231 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_elf_init_win.h » ('j') | chrome/browser/chrome_elf_init_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698