Chromium Code Reviews| 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/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_reg_util_win.h" | 11 #include "base/test/test_reg_util_win.h" |
| 11 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
| 12 #include "chrome_elf/chrome_elf_constants.h" | 13 #include "chrome_elf/chrome_elf_constants.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "version.h" // NOLINT | |
| 14 | 16 |
| 15 class ChromeBlacklistTrialTest : public testing::Test { | 17 class ChromeBlacklistTrialTest : public testing::Test { |
| 16 protected: | 18 protected: |
| 17 ChromeBlacklistTrialTest() : | 19 ChromeBlacklistTrialTest() {} |
| 18 blacklist_registry_key_(HKEY_CURRENT_USER, | 20 virtual ~ChromeBlacklistTrialTest() {} |
| 19 blacklist::kRegistryBeaconPath, | |
| 20 KEY_QUERY_VALUE | KEY_SET_VALUE) {} | |
| 21 | 21 |
| 22 virtual void SetUp() OVERRIDE { | 22 virtual void SetUp() OVERRIDE { |
| 23 testing::Test::SetUp(); | 23 testing::Test::SetUp(); |
| 24 | 24 |
| 25 registry_util::RegistryOverrideManager override_manager; | 25 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, |
| 26 override_manager.OverrideRegistry(HKEY_CURRENT_USER, | 26 L"browser_blacklist_test"); |
| 27 L"browser_blacklist_test"); | |
| 28 | 27 |
| 29 | 28 blacklist_registry_key_.reset(new base::win::RegKey(HKEY_CURRENT_USER, |
| 29 blacklist::kRegistryBeaconPath, | |
| 30 KEY_QUERY_VALUE | KEY_SET_VALUE)); | |
|
robertshield
2014/03/03 13:51:46
nit: indent
csharp
2014/03/03 14:17:38
Done.
| |
| 30 } | 31 } |
| 31 | 32 |
| 32 DWORD GetBlacklistState() { | 33 DWORD GetBlacklistState() { |
| 33 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX; | 34 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX; |
| 34 blacklist_registry_key_.ReadValueDW(blacklist::kBeaconState, | 35 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconState, |
| 35 &blacklist_state); | 36 &blacklist_state); |
| 36 | 37 |
| 37 return blacklist_state; | 38 return blacklist_state; |
| 38 } | 39 } |
| 39 | 40 |
| 40 base::string16 GetBlacklistVersion() { | 41 base::string16 GetBlacklistVersion() { |
| 41 base::string16 blacklist_version; | 42 base::string16 blacklist_version; |
| 42 blacklist_registry_key_.ReadValue(blacklist::kBeaconVersion, | 43 blacklist_registry_key_->ReadValue(blacklist::kBeaconVersion, |
| 43 &blacklist_version); | 44 &blacklist_version); |
| 44 | 45 |
| 45 return blacklist_version; | 46 return blacklist_version; |
| 46 } | 47 } |
| 47 | 48 |
| 48 base::win::RegKey blacklist_registry_key_; | 49 scoped_ptr<base::win::RegKey> blacklist_registry_key_; |
| 50 registry_util::RegistryOverrideManager override_manager_; | |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest); | 53 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest); |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 | 56 |
| 55 // Ensure that the default trial deletes any existing blacklist beacons. | 57 // Ensure that the default trial deletes any existing blacklist beacons. |
| 56 TEST_F(ChromeBlacklistTrialTest, DefaultRun) { | 58 TEST_F(ChromeBlacklistTrialTest, DefaultRun) { |
| 57 // Set some dummy values as beacons. | 59 // Set some dummy values as beacons. |
| 58 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, | 60 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 59 blacklist::BLACKLIST_ENABLED); | 61 blacklist::BLACKLIST_ENABLED); |
| 60 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion, L"Data"); | 62 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
| 61 | 63 |
| 62 // This setup code should result in the default group, which should remove | 64 // This setup code should result in the default group, which should remove |
| 63 // all the beacon values. | 65 // all the beacon values. |
| 64 InitializeChromeElf(); | 66 InitializeChromeElf(); |
| 65 | 67 |
| 66 // Ensure that invalid values are returned to indicate that the | 68 // Ensure that invalid values are returned to indicate that the |
| 67 // beacon values are gone. | 69 // beacon values are gone. |
| 68 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); | 70 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState()); |
| 69 ASSERT_EQ(base::string16(), GetBlacklistVersion()); | 71 ASSERT_EQ(base::string16(), GetBlacklistVersion()); |
| 70 } | 72 } |
| 71 | 73 |
| 72 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { | 74 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { |
| 73 BrowserBlacklistBeaconSetup(); | 75 BrowserBlacklistBeaconSetup(); |
| 74 | 76 |
| 75 // Verify the state is properly set after the first run. | 77 // Verify the state is properly set after the first run. |
| 76 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 78 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 77 | 79 |
| 78 chrome::VersionInfo version_info; | 80 chrome::VersionInfo version_info; |
| 79 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | 81 base::string16 version(base::UTF8ToUTF16(version_info.Version())); |
| 80 ASSERT_EQ(version, GetBlacklistVersion()); | 82 ASSERT_EQ(version, GetBlacklistVersion()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { | 85 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { |
| 84 // Set the registry to indicate that the blacklist setup is running, | 86 // Set the registry to indicate that the blacklist setup is running, |
| 85 // which means it failed to run correctly last time. | 87 // which means it failed to run correctly last time for this version. |
| 86 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, | 88 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 87 blacklist::BLACKLIST_SETUP_RUNNING); | 89 TEXT(CHROME_VERSION_STRING)); |
| 90 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 91 blacklist::BLACKLIST_SETUP_RUNNING); | |
| 88 | 92 |
| 89 BrowserBlacklistBeaconSetup(); | 93 BrowserBlacklistBeaconSetup(); |
| 90 | 94 |
| 91 // Since the blacklist setup failed, it should now be disabled. | 95 // Since the blacklist setup failed, it should now be disabled. |
| 92 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | 96 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
| 93 } | 97 } |
| 94 | 98 |
| 95 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { | 99 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) { |
| 96 // Set the registry to indicate that the blacklist thunk setup is running, | 100 // Set the registry to indicate that the blacklist thunk setup is running, |
| 97 // which means it failed to run correctly last time. | 101 // which means it failed to run correctly last time for this version. |
| 98 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, | 102 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 99 blacklist::BLACKLIST_THUNK_SETUP); | 103 TEXT(CHROME_VERSION_STRING)); |
| 104 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 105 blacklist::BLACKLIST_THUNK_SETUP); | |
| 100 | 106 |
| 101 BrowserBlacklistBeaconSetup(); | 107 BrowserBlacklistBeaconSetup(); |
| 102 | 108 |
| 103 // Since the blacklist thunk setup failed, it should now be disabled. | 109 // Since the blacklist thunk setup failed, it should now be disabled. |
| 104 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | 110 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
| 105 } | 111 } |
| 106 | 112 |
| 107 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { | 113 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) { |
| 108 // Set the registry to indicate that an interception is running, | 114 // Set the registry to indicate that an interception is running, |
| 109 // which means it failed to run correctly last time. | 115 // which means it failed to run correctly last time for this version. |
| 110 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, | 116 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 111 blacklist::BLACKLIST_INTERCEPTING); | 117 TEXT(CHROME_VERSION_STRING)); |
| 118 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | |
| 119 blacklist::BLACKLIST_INTERCEPTING); | |
| 112 | 120 |
| 113 BrowserBlacklistBeaconSetup(); | 121 BrowserBlacklistBeaconSetup(); |
| 114 | 122 |
| 115 // Since an interception failed, the blacklist should now be disabled. | 123 // Since an interception failed, the blacklist should now be disabled. |
| 116 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); | 124 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
| 117 } | 125 } |
| 118 | 126 |
| 119 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { | 127 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
| 120 // Mark the blacklist as disabled for an older version, so it should | 128 // Mark the blacklist as disabled for an older version, so it should |
| 121 // get enabled for this new version. | 129 // get enabled for this new version. |
| 122 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion, | 130 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
| 123 L"old_version"); | 131 L"old_version"); |
| 124 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, | 132 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
| 125 blacklist::BLACKLIST_DISABLED); | 133 blacklist::BLACKLIST_DISABLED); |
| 126 | 134 |
| 127 BrowserBlacklistBeaconSetup(); | 135 BrowserBlacklistBeaconSetup(); |
| 128 | 136 |
| 129 // The beacon should now be marked as enabled for the current version. | 137 // The beacon should now be marked as enabled for the current version. |
| 130 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 138 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 131 | 139 |
| 132 chrome::VersionInfo version_info; | 140 chrome::VersionInfo version_info; |
| 133 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 141 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
| 134 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 142 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
| 135 } | 143 } |
| OLD | NEW |