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

Side by Side Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 1851213002: Remove sandbox on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nacl compile issues Created 4 years, 8 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
« no previous file with comments | « chrome_elf/chrome_elf_util.cc ('k') | chrome_elf/dll_hash.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <tuple>
8
9 #include "base/test/test_reg_util_win.h"
10 #include "base/win/registry.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
13
14 namespace {
15
16 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
17 const wchar_t kRegPathClientStateMedium[] =
18 L"Software\\Google\\Update\\ClientStateMedium";
19 const wchar_t kRegValueUsageStats[] = L"usagestats";
20 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
21
22 const wchar_t kAppGuidCanary[] =
23 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
24 const wchar_t kAppGuidGoogleChrome[] =
25 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
26 const wchar_t kAppGuidGoogleBinaries[] =
27 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
28
29 const wchar_t kCanaryExePath[] =
30 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application"
31 L"\\chrome.exe";
32 const wchar_t kChromeSystemExePath[] =
33 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
34 const wchar_t kChromeUserExePath[] =
35 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
36 const wchar_t kChromiumExePath[] =
37 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
38
39
40 TEST(ChromeElfUtilTest, CanaryTest) {
41 EXPECT_TRUE(IsCanary(kCanaryExePath));
42 EXPECT_FALSE(IsCanary(kChromeUserExePath));
43 EXPECT_FALSE(IsCanary(kChromiumExePath));
44 }
45
46 TEST(ChromeElfUtilTest, SystemInstallTest) {
47 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
48 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
49 }
50
51 TEST(ChromeElfUtilTest, BrowserProcessTest) {
52 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
53 InitializeProcessType();
54 EXPECT_FALSE(IsNonBrowserProcess());
55 }
56
57 // Parameterized test with paramters:
58 // 1: product: "canary" or "google"
59 // 2: install level: "user" or "system"
60 // 3: install mode: "single" or "multi"
61 class ChromeElfUtilTest :
62 public testing::TestWithParam<std::tuple<const char*,
63 const char*,
64 const char*> > {
65 protected:
66 void SetUp() override {
67 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
68 override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
69 const char* app;
70 const char* level;
71 const char* mode;
72 std::tie(app, level, mode) = GetParam();
73 is_canary_ = (std::string(app) == "canary");
74 system_level_ = (std::string(level) != "user");
75 multi_install_ = (std::string(mode) != "single");
76 if (is_canary_) {
77 ASSERT_FALSE(system_level_);
78 ASSERT_FALSE(multi_install_);
79 app_guid_ = kAppGuidCanary;
80 chrome_path_ = kCanaryExePath;
81 } else {
82 app_guid_ = kAppGuidGoogleChrome;
83 chrome_path_ = (system_level_ ? kChromeSystemExePath :
84 kChromeUserExePath);
85 }
86 if (multi_install_) {
87 SetMultiInstallStateInRegistry(system_level_, true);
88 app_guid_ = kAppGuidGoogleBinaries;
89 }
90 }
91
92 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) {
93 base::string16 full_key_path(path);
94 full_key_path.append(1, L'\\');
95 full_key_path.append(guid);
96 return full_key_path;
97 }
98
99 void SetUsageStat(DWORD value, bool state_medium) {
100 LONG result = base::win::RegKey(
101 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
102 BuildKey(state_medium ? kRegPathClientStateMedium : kRegPathClientState,
103 app_guid_).c_str(),
104 KEY_SET_VALUE).WriteValue(kRegValueUsageStats, value);
105 ASSERT_EQ(ERROR_SUCCESS, result);
106 }
107
108 void SetMultiInstallStateInRegistry(bool system_install, bool multi) {
109 base::win::RegKey key(
110 system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
111 BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(),
112 KEY_SET_VALUE);
113 LONG result;
114 if (multi) {
115 result = key.WriteValue(kUninstallArgumentsField,
116 L"yadda yadda --multi-install yadda yadda");
117 } else {
118 result = key.DeleteValue(kUninstallArgumentsField);
119 }
120 ASSERT_EQ(ERROR_SUCCESS, result);
121 }
122
123 const wchar_t* app_guid_;
124 const wchar_t* chrome_path_;
125 bool system_level_;
126 bool multi_install_;
127 bool is_canary_;
128 registry_util::RegistryOverrideManager override_manager_;
129 };
130
131 TEST_P(ChromeElfUtilTest, MultiInstallTest) {
132 if (is_canary_)
133 return;
134 SetMultiInstallStateInRegistry(system_level_, true);
135 EXPECT_TRUE(IsMultiInstall(system_level_));
136
137 SetMultiInstallStateInRegistry(system_level_, false);
138 EXPECT_FALSE(IsMultiInstall(system_level_));
139 }
140
141 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
142 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
143 }
144
145 TEST_P(ChromeElfUtilTest, UsageStatsZero) {
146 SetUsageStat(0, false);
147 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
148 }
149
150 TEST_P(ChromeElfUtilTest, UsageStatsOne) {
151 SetUsageStat(1, false);
152 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_));
153 if (is_canary_) {
154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
155 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath));
156 } else if (system_level_) {
157 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
158 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
159 } else {
160 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
161 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath));
162 }
163 }
164
165 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
166 if (!system_level_)
167 return;
168 SetUsageStat(0, true);
169 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
170 }
171
172 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
173 if (!system_level_)
174 return;
175 SetUsageStat(1, true);
176 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_));
177 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
178 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
179 }
180
181 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest,
182 testing::Combine(testing::Values("canary"),
183 testing::Values("user"),
184 testing::Values("single")));
185 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest,
186 testing::Combine(testing::Values("google"),
187 testing::Values("user", "system"),
188 testing::Values("single", "multi")));
189
190 } // namespace
OLDNEW
« no previous file with comments | « chrome_elf/chrome_elf_util.cc ('k') | chrome_elf/dll_hash.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698