Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chrome_elf_init_unittest_win.cc
blobb7cee8af896a99a6487b227ea91689dc24c476e9
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/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/test_reg_util_win.h"
12 #include "chrome/common/chrome_version_info.h"
13 #include "chrome_elf/chrome_elf_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "version.h" // NOLINT
17 class ChromeBlacklistTrialTest : public testing::Test {
18 protected:
19 ChromeBlacklistTrialTest() {}
20 virtual ~ChromeBlacklistTrialTest() {}
22 virtual void SetUp() OVERRIDE {
23 testing::Test::SetUp();
25 override_manager_.OverrideRegistry(HKEY_CURRENT_USER,
26 L"browser_blacklist_test");
28 blacklist_registry_key_.reset(
29 new base::win::RegKey(HKEY_CURRENT_USER,
30 blacklist::kRegistryBeaconPath,
31 KEY_QUERY_VALUE | KEY_SET_VALUE));
34 DWORD GetBlacklistState() {
35 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
36 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconState,
37 &blacklist_state);
39 return blacklist_state;
42 base::string16 GetBlacklistVersion() {
43 base::string16 blacklist_version;
44 blacklist_registry_key_->ReadValue(blacklist::kBeaconVersion,
45 &blacklist_version);
47 return blacklist_version;
50 scoped_ptr<base::win::RegKey> blacklist_registry_key_;
51 registry_util::RegistryOverrideManager override_manager_;
53 private:
54 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest);
58 // Ensure that the default trial deletes any existing blacklist beacons.
59 TEST_F(ChromeBlacklistTrialTest, DefaultRun) {
60 // Set some dummy values as beacons.
61 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
62 blacklist::BLACKLIST_ENABLED);
63 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data");
65 // This setup code should result in the default group, which should remove
66 // all the beacon values.
67 InitializeChromeElf();
69 // Ensure that invalid values are returned to indicate that the
70 // beacon values are gone.
71 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState());
72 ASSERT_EQ(base::string16(), GetBlacklistVersion());
75 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) {
76 BrowserBlacklistBeaconSetup();
78 // Verify the state is properly set after the first run.
79 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
81 chrome::VersionInfo version_info;
82 base::string16 version(base::UTF8ToUTF16(version_info.Version()));
83 ASSERT_EQ(version, GetBlacklistVersion());
86 TEST_F(ChromeBlacklistTrialTest, SetupFailed) {
87 // Set the registry to indicate that the blacklist setup is running,
88 // which means it failed to run correctly last time for this version.
89 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
90 TEXT(CHROME_VERSION_STRING));
91 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
92 blacklist::BLACKLIST_SETUP_RUNNING);
94 BrowserBlacklistBeaconSetup();
96 // Since the blacklist setup failed, it should now be disabled.
97 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
100 TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) {
101 // Set the registry to indicate that the blacklist thunk setup is running,
102 // which means it failed to run correctly last time for this version.
103 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
104 TEXT(CHROME_VERSION_STRING));
105 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
106 blacklist::BLACKLIST_THUNK_SETUP);
108 BrowserBlacklistBeaconSetup();
110 // Since the blacklist thunk setup failed, it should now be disabled.
111 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
114 TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) {
115 // Set the registry to indicate that an interception is running,
116 // which means it failed to run correctly last time for this version.
117 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
118 TEXT(CHROME_VERSION_STRING));
119 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
120 blacklist::BLACKLIST_INTERCEPTING);
122 BrowserBlacklistBeaconSetup();
124 // Since an interception failed, the blacklist should now be disabled.
125 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
128 TEST_F(ChromeBlacklistTrialTest, VersionChanged) {
129 // Mark the blacklist as disabled for an older version, so it should
130 // get enabled for this new version.
131 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
132 L"old_version");
133 blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
134 blacklist::BLACKLIST_DISABLED);
136 BrowserBlacklistBeaconSetup();
138 // The beacon should now be marked as enabled for the current version.
139 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
141 chrome::VersionInfo version_info;
142 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version()));
143 ASSERT_EQ(expected_version, GetBlacklistVersion());