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