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

Side by Side Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 154653002: Breakpad coverage for chrome_elf start up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests and Greg's comments Created 6 years, 10 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 | Annotate | Revision Log
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 "chrome_elf/chrome_elf_util.h"
6
7 #include "base/test/test_reg_util_win.h"
8 #include "base/win/registry.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h"
11
12 namespace {
13
14 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
15 const wchar_t kRegPathClientStateMedium[] =
16 L"Software\\Google\\Update\\ClientStateMedium";
17 const wchar_t kRegValueUsageStats[] = L"usagestats";
18 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
19
20 const wchar_t kAppGuidCanary[] =
21 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
22 const wchar_t kAppGuidGoogleChrome[] =
23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
24 const wchar_t kAppGuidGoogleBinaries[] =
25 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
26
27 const wchar_t kCanaryExePath[] =
28 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.e xe";
29 const wchar_t kChromeSystemExePath[] =
30 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
31 const wchar_t kChromeUserExePath[] =
32 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
33 const wchar_t kChromiumExePath[] =
34 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
35
36 class ChromeElfUtilTest : public testing::Test {
37 public:
38 virtual void SetUp() OVERRIDE {
grt (UTC plus 2) 2014/02/14 16:37:33 SetUp should be protected, too
Cait (Slow) 2014/02/14 23:12:04 Done.
39 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE,
40 L"chrome_elf_test_local");
grt (UTC plus 2) 2014/02/14 16:37:33 indentation
Cait (Slow) 2014/02/14 23:12:04 Done.
41 override_manager_.OverrideRegistry(HKEY_CURRENT_USER,
42 L"chrome_elf_test_current");
43 }
44
45 protected:
46 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) {
47 base::string16 full_key_path(path);
48 full_key_path.append(1, L'\\');
49 full_key_path.append(guid);
50 return full_key_path;
51 }
52
53 void SetMultiInstall(bool is_multi, bool is_system) {
54 base::win::RegKey key;
55 key.Create(is_system? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/14 16:37:33 space after ?
Cait (Slow) 2014/02/14 23:12:04 Done.
56 BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(),
grt (UTC plus 2) 2014/02/14 16:37:33 align with the open paren of Create(
Cait (Slow) 2014/02/14 23:12:04 Done.
57 KEY_ALL_ACCESS);
grt (UTC plus 2) 2014/02/14 16:37:33 only request the access you need: KEY_SET_VALUE
Cait (Slow) 2014/02/14 23:12:04 Done.
58 if (is_multi) {
59 key.WriteValue(kUninstallArgumentsField,
60 L"yadda yadda --multi-install yadda yadda");
61 } else {
62 key.DeleteValue(kUninstallArgumentsField);
63 }
64 key.Close();
grt (UTC plus 2) 2014/02/14 16:37:33 RegKey's dtor does this for you
Cait (Slow) 2014/02/14 23:12:04 Done.
65 }
66
67 void SetStatsEnabled(const wchar_t* path, const wchar_t* guid,
68 bool enabled, bool is_system) {
69 base::win::RegKey key;
70 key.Create(is_system? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/14 16:37:33 use RegKey's ctor rather than calling Create here
Cait (Slow) 2014/02/14 23:12:04 Done.
71 BuildKey(path, guid).c_str(),
grt (UTC plus 2) 2014/02/14 16:37:33 align with the open paren above
Cait (Slow) 2014/02/14 23:12:04 Done.
72 KEY_ALL_ACCESS);
grt (UTC plus 2) 2014/02/14 16:37:33 KEY_SET_VALUE
Cait (Slow) 2014/02/14 23:12:04 Done.
73 key.WriteValue(kRegValueUsageStats, enabled ? 1 : 0);
74 key.Close();
grt (UTC plus 2) 2014/02/14 16:37:33 remove
Cait (Slow) 2014/02/14 23:12:04 Done.
75 }
76
77 void TestUsageStats(bool canary, bool chrome_system, bool chrome_user) {
78 EXPECT_EQ(canary, AreUsageStatsEnabled(kCanaryExePath));
79 EXPECT_EQ(chrome_system, AreUsageStatsEnabled(kChromeSystemExePath));
80 EXPECT_EQ(chrome_user, AreUsageStatsEnabled(kChromeUserExePath));
81 }
82
83 registry_util::RegistryOverrideManager override_manager_;
84
85 };
86
87 TEST_F(ChromeElfUtilTest, CanaryTest) {
88 EXPECT_TRUE(IsCanary(kCanaryExePath));
89 EXPECT_FALSE(IsCanary(kChromeUserExePath));
90 EXPECT_FALSE(IsCanary(kChromiumExePath));
91 }
92
93 TEST_F(ChromeElfUtilTest, SystemInstallTest) {
94 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
95 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
96 }
97
98 TEST_F(ChromeElfUtilTest, MultiInstallTest_SingleUser) {
99 bool system_install = false;
100 SetMultiInstall(true, system_install);
101 EXPECT_TRUE(IsMultiInstall(system_install));
102
103 SetMultiInstall(false, system_install);
104 EXPECT_FALSE(IsMultiInstall(system_install));
105 }
106
107 TEST_F(ChromeElfUtilTest, MultiInstallTest_System) {
108 bool system_install = true;
109 SetMultiInstall(true, system_install);
110 EXPECT_TRUE(IsMultiInstall(system_install));
111
112 SetMultiInstall(false, system_install);
113 EXPECT_FALSE(IsMultiInstall(system_install));
114 }
115
116 TEST_F(ChromeElfUtilTest, UsageStatsTest_Canary) {
grt (UTC plus 2) 2014/02/14 16:37:33 i think this is a good case for a parameterized te
Cait (Slow) 2014/02/14 23:12:04 Done -- wow! I had no idea these existed. They mak
117 SetStatsEnabled(kRegPathClientState, kAppGuidCanary, true, false);
118 TestUsageStats(true, false, false);
119 SetStatsEnabled(kRegPathClientState, kAppGuidCanary, false, false);
120 TestUsageStats(false, false, false);
121 }
122
123 TEST_F(ChromeElfUtilTest, UsageStatsTest_Chrome_System) {
124 bool system_install = true;
125 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, true,
126 system_install);
127 TestUsageStats(false, true, false);
128 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, false,
129 system_install);
130 TestUsageStats(false, false, false);
131
132 SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleChrome, true,
133 system_install);
134 TestUsageStats(false, true, false);
135 SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleChrome, false,
136 system_install);
137 TestUsageStats(false, false, false);
138
139 SetMultiInstall(true, system_install);
140
141 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, true,
142 system_install);
143 TestUsageStats(false, true, false);
144 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, false,
145 system_install);
146 TestUsageStats(false, false, false);
147
148 SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleBinaries, true,
149 system_install);
150 TestUsageStats(false, true, false);
151 SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleBinaries, false,
152 system_install);
153 TestUsageStats(false, false, false);
154 }
155
156 TEST_F(ChromeElfUtilTest, UsageStatsTest_Chrome_User) {
157 bool system_install = false;
158 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, true,
159 system_install);
160 TestUsageStats(false, false, true);
161 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, false,
162 system_install);
163 TestUsageStats(false, false, false);
164
165 SetMultiInstall(true, system_install);
166
167 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, true,
168 system_install);
169 TestUsageStats(false, false, true);
170 SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, false,
171 system_install);
172 TestUsageStats(false, false, false);
173 }
174
175 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698