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.
5 #include "chrome/browser/chrome_elf_init_win.h"
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"
15 class ChromeBlacklistTrialTest
: public testing::Test
{
17 ChromeBlacklistTrialTest() :
18 blacklist_registry_key_(HKEY_CURRENT_USER
,
19 blacklist::kRegistryBeaconPath
,
20 KEY_QUERY_VALUE
| KEY_SET_VALUE
) {}
22 virtual void SetUp() OVERRIDE
{
23 testing::Test::SetUp();
25 registry_util::RegistryOverrideManager override_manager
;
26 override_manager
.OverrideRegistry(HKEY_CURRENT_USER
,
27 L
"browser_blacklist_test");
32 DWORD
GetBlacklistState() {
33 DWORD blacklist_state
= blacklist::BLACKLIST_STATE_MAX
;
34 blacklist_registry_key_
.ReadValueDW(blacklist::kBeaconState
,
37 return blacklist_state
;
40 base::string16
GetBlacklistVersion() {
41 base::string16 blacklist_version
;
42 blacklist_registry_key_
.ReadValue(blacklist::kBeaconVersion
,
45 return blacklist_version
;
48 base::win::RegKey blacklist_registry_key_
;
51 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest
);
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");
62 // This setup code should result in the default group, which should remove
63 // all the beacon values.
64 InitializeChromeElf();
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(base::string16(), GetBlacklistVersion());
72 TEST_F(ChromeBlacklistTrialTest
, VerifyFirstRun
) {
73 BrowserBlacklistBeaconSetup();
75 // Verify the state is properly set after the first run.
76 ASSERT_EQ(blacklist::BLACKLIST_ENABLED
, GetBlacklistState());
78 chrome::VersionInfo version_info
;
79 base::string16
version(base::UTF8ToUTF16(version_info
.Version()));
80 ASSERT_EQ(version
, GetBlacklistVersion());
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
);
89 BrowserBlacklistBeaconSetup();
91 // Since the blacklist setup failed, it should now be disabled.
92 ASSERT_EQ(blacklist::BLACKLIST_DISABLED
, GetBlacklistState());
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
,
100 blacklist_registry_key_
.WriteValue(blacklist::kBeaconState
,
101 blacklist::BLACKLIST_DISABLED
);
103 BrowserBlacklistBeaconSetup();
105 // The beacon should now be marked as enabled for the current version.
106 ASSERT_EQ(blacklist::BLACKLIST_ENABLED
, GetBlacklistState());
108 chrome::VersionInfo version_info
;
109 base::string16
expected_version(base::UTF8ToUTF16(version_info
.Version()));
110 ASSERT_EQ(expected_version
, GetBlacklistVersion());