| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { | 116 TEST_F(ChromeBlacklistTrialTest, BlacklistFailed) { |
| 117 // Set the registry to indicate that the blacklist setup is running, | 117 // Ensure when the blacklist set up failed we set the state to disabled for |
| 118 // which means it failed to run correctly last time for this version. | 118 // future runs. |
| 119 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 119 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 120 TEXT(CHROME_VERSION_STRING)); | 120 TEXT(CHROME_VERSION_STRING)); |
| 121 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 121 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 122 blacklist::BLACKLIST_SETUP_RUNNING); | 122 blacklist::BLACKLIST_SETUP_FAILED); |
| 123 | |
| 124 BrowserBlacklistBeaconSetup(); | |
| 125 | |
| 126 // Since the blacklist setup failed, it should now be disabled. | |
| 127 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | |
| 128 } | |
| 129 | |
| 130 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { | |
| 131 // 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. | |
| 133 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | |
| 134 TEXT(CHROME_VERSION_STRING)); | |
| 135 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 136 blacklist::BLACKLIST_THUNK_SETUP); | |
| 137 | 123 |
| 138 BrowserBlacklistBeaconSetup(); | 124 BrowserBlacklistBeaconSetup(); |
| 139 | 125 |
| 140 // Since the blacklist thunk setup failed, it should now be disabled. | 126 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX; |
| 141 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | 127 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconState, |
| 142 } | 128 &blacklist_state); |
| 143 | 129 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, blacklist_state); |
| 144 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { | |
| 145 // Set the registry to indicate that an interception is running, | |
| 146 // which means it failed to run correctly last time for this version. | |
| 147 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | |
| 148 TEXT(CHROME_VERSION_STRING)); | |
| 149 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 150 blacklist::BLACKLIST_INTERCEPTING); | |
| 151 | |
| 152 BrowserBlacklistBeaconSetup(); | |
| 153 | |
| 154 // Since an interception failed, the blacklist should now be disabled. | |
| 155 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | |
| 156 } | 130 } |
| 157 | 131 |
| 158 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { | 132 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
| 159 // Mark the blacklist as disabled for an older version, so it should | 133 // Mark the blacklist as disabled for an older version, it should |
| 160 // get enabled for this new version. | 134 // get enabled for this new version. Also record a non-zero number of |
| 135 // setup failures, which should be reset to zero. |
| 161 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 136 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 162 L"old_version"); | 137 L"old_version"); |
| 163 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 138 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 164 blacklist::BLACKLIST_DISABLED); | 139 blacklist::BLACKLIST_DISABLED); |
| 140 blacklist_registry_key_->WriteValue(blacklist::kBeaconAttemptCount, |
| 141 blacklist::kBeaconMaxAttempts); |
| 165 | 142 |
| 166 BrowserBlacklistBeaconSetup(); | 143 BrowserBlacklistBeaconSetup(); |
| 167 | 144 |
| 168 // The beacon should now be marked as enabled for the current version. | 145 // The beacon should now be marked as enabled for the current version. |
| 169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 146 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 170 | 147 |
| 171 chrome::VersionInfo version_info; | 148 chrome::VersionInfo version_info; |
| 172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 149 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
| 173 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 150 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
| 151 |
| 152 // The counter should be reset. |
| 153 DWORD attempt_count = blacklist::kBeaconMaxAttempts; |
| 154 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, |
| 155 &attempt_count); |
| 156 ASSERT_EQ(static_cast<DWORD>(0), attempt_count); |
| 174 } | 157 } |
| OLD | NEW |