Index: chrome/browser/chrome_elf_init_unittest_win.cc |
diff --git a/chrome/browser/chrome_elf_init_unittest_win.cc b/chrome/browser/chrome_elf_init_unittest_win.cc |
index 441f73665707f1f8dbc3bddc08729fb3ef70f91c..d01c0e107b89e98644460d3689f1d3330e177cd1 100644 |
--- a/chrome/browser/chrome_elf_init_unittest_win.cc |
+++ b/chrome/browser/chrome_elf_init_unittest_win.cc |
@@ -113,7 +113,14 @@ TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { |
ASSERT_EQ(version, GetBlacklistVersion()); |
} |
+// This test assumes that kBeaconAttemps (the number of startup retries we |
+// allow) is at least 2. |
TEST_F(ChromeBlacklistTrialTest, SetupFailed) { |
+ // Ensure the setup failure counter is low enough that even a new failure |
+ // would leave the blacklist enabled. |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount, |
+ kBeaconAttempts - 2); |
+ |
// Set the registry to indicate that the blacklist setup is running, |
// which means it failed to run correctly last time for this version. |
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
@@ -121,13 +128,50 @@ TEST_F(ChromeBlacklistTrialTest, SetupFailed) { |
blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
blacklist::BLACKLIST_SETUP_RUNNING); |
- BrowserBlacklistBeaconSetup(); |
+ BrowserBlacklistBeaconSetup(); |
+ |
+ // The blacklist has now failed kBeaconAttempts - 1 times, the beacon should |
+ // reflect this and the blacklist state be set to enabled. |
+ DWORD failed_attempt_count = kBeaconAttempts; |
+ GetBlacklistFailedCount(&failed_attempt_count); |
+ ASSERT_EQ(kBeaconAttempts - 1, failed_attempt_count); |
+ ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
+ |
+ // Force a second 'failure', this should disable the blacklist. |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
+ TEXT(CHROME_VERSION_STRING)); |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
+ blacklist::BLACKLIST_SETUP_RUNNING); |
- // Since the blacklist setup failed, it should now be disabled. |
+ BrowserBlacklistBeaconSetup(); |
ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
} |
+TEST_F(ChromeBlacklistTrialTest, SetupSucceeded) { |
+ // Write a non-zero value to the registry so that we can check it gets reset. |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount, |
+ kBeaconAttempts); |
+ |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
+ TEXT(CHROME_VERSION_STRING)); |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
+ blacklist::BLACKLIST_ENABLED); |
+ |
+ BrowserBlacklistBeaconSetup(); |
+ |
+ // Because the set up was successful the counter should be reset. |
+ DWORD attempt_count = kBeaconAttempts; |
+ GetBlacklistFailedCount(&attempt_count); |
+ ASSERT_EQ(static_cast<DWORD>(0), attempt_count); |
+ ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
+} |
+ |
TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { |
+ // Set the setup failure counter so that one more failure should disable the |
+ // blacklist. |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount, |
+ kBeaconAttempts - 1); |
+ |
// Set the registry to indicate that the blacklist thunk setup is running, |
// which means it failed to run correctly last time for this version. |
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
@@ -142,6 +186,11 @@ TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { |
} |
TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { |
+ // Set the setup failure counter so that one more failure should disable the |
+ // blacklist. |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount, |
+ kBeaconAttempts - 1); |
+ |
// Set the registry to indicate that an interception is running, |
// which means it failed to run correctly last time for this version. |
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
@@ -157,11 +206,14 @@ TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { |
TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
// Mark the blacklist as disabled for an older version, so it should |
- // get enabled for this new version. |
+ // get enabled for this new version. Also record a non-zero number of |
+ // setup failures, this should be reset to zero. |
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
L"old_version"); |
blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
blacklist::BLACKLIST_DISABLED); |
+ blacklist_registry_key_->WriteValue(blacklist::kBeaconFailedCount, |
+ kBeaconAttempts); |
BrowserBlacklistBeaconSetup(); |
@@ -171,4 +223,9 @@ TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
chrome::VersionInfo version_info; |
base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
ASSERT_EQ(expected_version, GetBlacklistVersion()); |
+ |
+ // The counter should be reset. |
+ DWORD attempt_count = kBeaconAttempts; |
+ GetBlacklistFailedCount(&attempt_count); |
+ ASSERT_EQ(static_cast<DWORD>(0), attempt_count); |
} |