OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/test/test_reg_util_win.h" |
| 8 #include "chrome/browser/chrome_elf_init_win.h" |
| 9 #include "chrome/common/chrome_version_info.h" |
| 10 #include "chrome_elf/blacklist/blacklist.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 class ChromeBlacklistTrialTest : public testing::Test { |
| 14 protected: |
| 15 ChromeBlacklistTrialTest() : blacklist_registry_key_( |
| 16 HKEY_CURRENT_USER, |
| 17 blacklist::kRegistryBeaconPath, |
| 18 KEY_READ | KEY_WRITE) {} |
| 19 |
| 20 virtual void SetUp() { |
| 21 testing::Test::SetUp(); |
| 22 |
| 23 registry_util::RegistryOverrideManager override_manager; |
| 24 override_manager.OverrideRegistry(HKEY_CURRENT_USER, |
| 25 L"browser_blacklist_test"); |
| 26 |
| 27 |
| 28 } |
| 29 |
| 30 DWORD GetBlacklistState() { |
| 31 DWORD blacklist_state = 0; |
| 32 blacklist_registry_key_.ReadValueDW(blacklist::kBeaconState, |
| 33 &blacklist_state); |
| 34 |
| 35 return blacklist_state; |
| 36 } |
| 37 |
| 38 base::string16 GetBlacklistVersion() { |
| 39 std::wstring blacklist_version(L""); |
| 40 blacklist_registry_key_.ReadValue(blacklist::kBeaconVersion, |
| 41 &blacklist_version); |
| 42 |
| 43 return blacklist_version; |
| 44 } |
| 45 |
| 46 base::win::RegKey blacklist_registry_key_; |
| 47 |
| 48 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest); |
| 50 }; |
| 51 |
| 52 |
| 53 // Ensure that the default trial deletes any existing blacklist beacons. |
| 54 TEST_F(ChromeBlacklistTrialTest, DefaultRun) { |
| 55 // Set some dummy values as beacons. |
| 56 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, |
| 57 blacklist::BLACKLIST_ENABLED); |
| 58 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion, L"Data"); |
| 59 |
| 60 // This setup code should result in the default group, which should remove |
| 61 // all the beacon values. |
| 62 SetupChromeElfInitialization(); |
| 63 |
| 64 // Ensure that all the beacon values are gone. |
| 65 DWORD state = -1; |
| 66 ASSERT_NE(ERROR_SUCCESS, |
| 67 blacklist_registry_key_.ReadValueDW(blacklist::kBeaconState, |
| 68 &state)); |
| 69 ASSERT_EQ(-1, state); |
| 70 |
| 71 std::wstring version(L""); |
| 72 ASSERT_NE(ERROR_SUCCESS, |
| 73 blacklist_registry_key_.ReadValue(blacklist::kBeaconVersion, |
| 74 &version)); |
| 75 ASSERT_EQ(L"", version); |
| 76 } |
| 77 |
| 78 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) { |
| 79 BrowserBlacklistBeaconSetup(); |
| 80 |
| 81 // Verify the state is properly set after the first run. |
| 82 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 83 |
| 84 chrome::VersionInfo version_info; |
| 85 base::string16 version = base::UTF8ToUTF16(version_info.Version()); |
| 86 ASSERT_EQ(version, GetBlacklistVersion()); |
| 87 } |
| 88 |
| 89 TEST_F(ChromeBlacklistTrialTest, SetupFailed) { |
| 90 // Set the registry to indicate that the blacklist setup is running, |
| 91 // which means it failed to run correctly last time. |
| 92 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, |
| 93 blacklist::BLACKLIST_SETUP_RUNNING); |
| 94 |
| 95 BrowserBlacklistBeaconSetup(); |
| 96 |
| 97 // Since the blacklist setup failed, it should now be disabled. |
| 98 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState()); |
| 99 } |
| 100 |
| 101 TEST_F(ChromeBlacklistTrialTest, VersionChanged) { |
| 102 // Mark the blacklist as disabled for an older version, so it should |
| 103 // get enabled for this new version. |
| 104 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion, |
| 105 L"old_version"); |
| 106 blacklist_registry_key_.WriteValue(blacklist::kBeaconState, |
| 107 blacklist::BLACKLIST_DISABLED); |
| 108 |
| 109 BrowserBlacklistBeaconSetup(); |
| 110 |
| 111 // The beacon should now be marked as enabled for the current version. |
| 112 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
| 113 |
| 114 chrome::VersionInfo version_info; |
| 115 base::string16 expected_version = base::UTF8ToUTF16(version_info.Version()); |
| 116 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
| 117 } |
OLD | NEW |