Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/chrome_elf_init_unittest_win.cc

Issue 120963002: Use a Finch Experiment to control the Browser Blacklist (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/string16.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/test_reg_util_win.h"
9 #include "chrome/browser/chrome_elf_init_win.h"
Alexei Svitkine (slow) 2014/01/06 20:43:05 This should be the first include. (For a while bot
csharp 2014/01/07 20:04:02 Done.
10 #include "chrome/common/chrome_version_info.h"
11 #include "chrome_elf/blacklist/blacklist.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 class ChromeBlacklistTrialTest : public testing::Test {
15 protected:
16 ChromeBlacklistTrialTest() : blacklist_registry_key_(
17 HKEY_CURRENT_USER,
18 blacklist::kRegistryBeaconPath,
19 KEY_QUERY_VALUE | KEY_SET_VALUE) {}
20
21 virtual void SetUp() {
Alexei Svitkine (slow) 2014/01/06 20:43:05 Nit: OVERRIDE
csharp 2014/01/07 20:04:02 Done.
22 testing::Test::SetUp();
23
24 registry_util::RegistryOverrideManager override_manager;
25 override_manager.OverrideRegistry(HKEY_CURRENT_USER,
26 L"browser_blacklist_test");
27
28
29 }
30
31 DWORD GetBlacklistState() {
32 DWORD blacklist_state = 0;
33 blacklist_registry_key_.ReadValueDW(blacklist::kBeaconState,
34 &blacklist_state);
35
36 return blacklist_state;
37 }
38
39 base::string16 GetBlacklistVersion() {
40 base::string16 blacklist_version;
41 blacklist_registry_key_.ReadValue(blacklist::kBeaconVersion,
42 &blacklist_version);
43
44 return blacklist_version;
45 }
46
47 base::win::RegKey blacklist_registry_key_;
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest);
51 };
52
53
54 // Ensure that the default trial deletes any existing blacklist beacons.
55 TEST_F(ChromeBlacklistTrialTest, DefaultRun) {
56 // Set some dummy values as beacons.
57 blacklist_registry_key_.WriteValue(blacklist::kBeaconState,
58 blacklist::BLACKLIST_ENABLED);
59 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion, L"Data");
60
61 // This setup code should result in the default group, which should remove
62 // all the beacon values.
63 InitializeChromeElf();
64
65 // Ensure that all the beacon values are gone.
66 DWORD state = blacklist::BLACKLIST_STATE_MAX;
67 ASSERT_NE(ERROR_SUCCESS,
68 blacklist_registry_key_.ReadValueDW(blacklist::kBeaconState,
Alexei Svitkine (slow) 2014/01/06 20:43:05 Why do you both have helpers in the test class (Ge
csharp 2014/01/07 20:04:02 Modified this code to use the test helpers. The te
69 &state));
70 ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, state);
71
72 base::string16 version;
73 ASSERT_NE(ERROR_SUCCESS,
74 blacklist_registry_key_.ReadValue(blacklist::kBeaconVersion,
75 &version));
76 ASSERT_EQ(L"", version);
77 }
78
79 TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) {
80 BrowserBlacklistBeaconSetup();
81
82 // Verify the state is properly set after the first run.
83 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
84
85 chrome::VersionInfo version_info;
86 base::string16 version(base::UTF8ToUTF16(version_info.Version()));
87 ASSERT_EQ(version, GetBlacklistVersion());
88 }
89
90 TEST_F(ChromeBlacklistTrialTest, SetupFailed) {
91 // Set the registry to indicate that the blacklist setup is running,
92 // which means it failed to run correctly last time.
93 blacklist_registry_key_.WriteValue(blacklist::kBeaconState,
94 blacklist::BLACKLIST_SETUP_RUNNING);
95
96 BrowserBlacklistBeaconSetup();
97
98 // Since the blacklist setup failed, it should now be disabled.
99 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
100 }
101
102 TEST_F(ChromeBlacklistTrialTest, VersionChanged) {
103 // Mark the blacklist as disabled for an older version, so it should
104 // get enabled for this new version.
105 blacklist_registry_key_.WriteValue(blacklist::kBeaconVersion,
106 L"old_version");
107 blacklist_registry_key_.WriteValue(blacklist::kBeaconState,
108 blacklist::BLACKLIST_DISABLED);
109
110 BrowserBlacklistBeaconSetup();
111
112 // The beacon should now be marked as enabled for the current version.
113 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
114
115 chrome::VersionInfo version_info;
116 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version()));
117 ASSERT_EQ(expected_version, GetBlacklistVersion());
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698