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

Side by Side Diff: client/bundle_creator_test.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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 | « client/bundle_creator.cc ('k') | client/bundle_installer.h » ('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 2011 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/base/app_util.h"
17 #include "omaha/base/browser_utils.h"
18 #include "omaha/base/omaha_version.h"
19 #include "omaha/base/path.h"
20 #include "omaha/base/reg_key.h"
21 #include "omaha/base/system.h"
22 #include "omaha/base/utils.h"
23 #include "omaha/base/vistautil.h"
24 #include "omaha/client/bundle_creator.h"
25 #include "omaha/client/client_utils.h"
26 #include "omaha/common/command_line.h"
27 #include "omaha/common/command_line_builder.h"
28 #include "omaha/common/config_manager.h"
29 #include "omaha/common/const_goopdate.h"
30 #include "omaha/common/goopdate_utils.h"
31 #include "omaha/common/update3_utils.h"
32 #include "omaha/goopdate/goopdate.h"
33 #include "omaha/goopdate/resource_manager.h"
34 #include "omaha/goopdate/worker.h"
35 #include "omaha/testing/unit_test.h"
36
37 namespace omaha {
38
39 namespace {
40
41 const TCHAR kUpdateDevKey[] = MACHINE_REG_UPDATE;
42 const TCHAR kMachineGoopdateClientsKey[] = MACHINE_REG_CLIENTS_GOOPDATE;
43 const TCHAR kMachineGoopdateStateKey[] = MACHINE_REG_CLIENT_STATE_GOOPDATE;
44
45 } // namespace
46
47 class BundleCreatorTest : public testing::Test {
48 protected:
49 BundleCreatorTest() {}
50
51 static void SetUpTestCase() {
52 // Goopdate instance is required by Worker instance.
53 goopdates_.reset(new Goopdate(true));
54
55 EXPECT_SUCCEEDED(ResourceManager::Create(
56 true, app_util::GetCurrentModuleDirectory(), _T("en")));
57
58 const CString shell_path = goopdate_utils::BuildGoogleUpdateExePath(true);
59 EXPECT_SUCCEEDED(RegKey::SetValue(kUpdateDevKey,
60 kRegValueInstalledPath,
61 shell_path));
62
63 EXPECT_SUCCEEDED(RegKey::SetValue(kUpdateDevKey,
64 kRegValueInstalledVersion,
65 GetVersionString()));
66
67 EXPECT_SUCCEEDED(RegKey::SetValue(kMachineGoopdateClientsKey,
68 kRegValueProductVersion,
69 GetVersionString()));
70
71 EXPECT_SUCCEEDED(RegKey::SetValue(kMachineGoopdateStateKey,
72 kRegValueProductVersion,
73 GetVersionString()));
74
75 CopyGoopdateFiles(GetGoogleUpdateMachinePath(), GetVersionString());
76 }
77
78 static void TearDownTestCase() {
79 ResourceManager::Delete();
80
81 // bundle_creator::Create*() methods indirectly creates Worker instance,
82 // delete it here (to avoid interference with other tests).
83 Worker::DeleteInstance();
84
85 goopdates_.reset();
86 }
87
88 virtual void SetUp() {
89 RegisterOrUnregisterGoopdateLocalServer(true);
90 }
91
92 virtual void TearDown() {
93 RegisterOrUnregisterGoopdateLocalServer(false);
94 }
95
96 static void VerifyAppMatchesCommandLineArguments(
97 const CommandLineExtraArgs extra_arg,
98 const CommandLineAppArgs& app_arg,
99 IApp* app) {
100 // Verify common data.
101 CComBSTR language;
102 EXPECT_SUCCEEDED(app->get_language(&language));
103 EXPECT_STREQ(extra_arg.language, language);
104
105 CComBSTR iid;
106 EXPECT_SUCCEEDED(app->get_iid(&iid));
107
108 GUID installation_id = {0};
109 EXPECT_SUCCEEDED(StringToGuidSafe(CString(iid), &installation_id));
110 EXPECT_TRUE(extra_arg.installation_id == installation_id);
111
112 CComBSTR brand_code;
113 EXPECT_SUCCEEDED(app->get_brandCode(&brand_code));
114 EXPECT_STREQ(extra_arg.brand_code, brand_code);
115
116 CComBSTR client_id;
117 EXPECT_SUCCEEDED(app->get_clientId(&client_id));
118 EXPECT_STREQ(extra_arg.client_id, client_id);
119
120 CComBSTR referral_id;
121 EXPECT_SUCCEEDED(app->get_referralId(&referral_id));
122 EXPECT_STREQ(extra_arg.referral_id, referral_id);
123
124 UINT browser_type = 0;
125 EXPECT_SUCCEEDED(app->get_browserType(&browser_type));
126 EXPECT_EQ(extra_arg.browser_type, browser_type);
127
128 // Verify app specific data.
129 CComBSTR app_name;
130 EXPECT_SUCCEEDED(app->get_displayName(&app_name));
131 EXPECT_STREQ(app_arg.app_name, app_name);
132
133 CComBSTR tt_token;
134 EXPECT_SUCCEEDED(app->get_ttToken(&tt_token));
135 EXPECT_STREQ(app_arg.tt_token, tt_token);
136
137 CComBSTR ap;
138 EXPECT_SUCCEEDED(app->get_ap(&ap));
139 EXPECT_STREQ(app_arg.ap, ap);
140 }
141
142 static void CreateAppRegistryState(const CString& app_id, bool is_machine) {
143 CString clients_key_name = AppendRegKeyPath(
144 ConfigManager::Instance()->registry_clients(is_machine),
145 app_id);
146 RegKey client_key;
147 ASSERT_SUCCEEDED(client_key.Create(clients_key_name));
148
149 CString current_version(_T("1.0.0.0"));
150 ASSERT_SUCCEEDED(client_key.SetValue(kRegValueProductVersion,
151 current_version));
152 }
153
154 static void RemoveAppRegistryState(const CString& app_id, bool is_machine) {
155 CString clients_key_name = AppendRegKeyPath(
156 ConfigManager::Instance()->registry_clients(is_machine),
157 app_id);
158 EXPECT_SUCCEEDED(RegKey::DeleteKey(clients_key_name));
159 }
160
161 static scoped_ptr<Goopdate> goopdates_;
162 };
163
164 scoped_ptr<Goopdate> BundleCreatorTest::goopdates_;
165
166 TEST_F(BundleCreatorTest, Create) {
167 const CString kDisplayLanguage = _T("en");
168 const CString kInstallSource = _T("TestInstallSource");
169 const CString kSessionId = _T("{6cb069db-b073-4a40-9983-846a3819876a}");
170 const bool is_machine = true;
171 const bool is_interactive = false;
172
173 CComPtr<IAppBundle> app_bundle;
174 ASSERT_SUCCEEDED(bundle_creator::Create(is_machine,
175 kDisplayLanguage,
176 kInstallSource,
177 kSessionId,
178 is_interactive,
179 &app_bundle));
180 CComBSTR display_name;
181 EXPECT_SUCCEEDED(app_bundle->get_displayName(&display_name));
182 EXPECT_STREQ(client_utils::GetUpdateAllAppsBundleName(), display_name);
183
184 CComBSTR install_source;
185 EXPECT_SUCCEEDED(app_bundle->get_installSource(&install_source));
186 EXPECT_STREQ(kInstallSource, install_source);
187
188 CComBSTR session_id;
189 EXPECT_SUCCEEDED(app_bundle->get_sessionId(&session_id));
190 EXPECT_STREQ(kSessionId, session_id);
191
192 long num_apps = 0; // NOLINT(runtime/int)
193 EXPECT_SUCCEEDED(app_bundle->get_Count(&num_apps));
194 EXPECT_EQ(0, num_apps);
195
196 long priority = INSTALL_PRIORITY_LOW; // NOLINT(runtime/int)
197 EXPECT_SUCCEEDED(app_bundle->get_priority(&priority));
198 EXPECT_EQ(is_interactive ? INSTALL_PRIORITY_HIGH : INSTALL_PRIORITY_LOW,
199 priority);
200
201 CComBSTR display_language;
202 EXPECT_SUCCEEDED(app_bundle->get_displayLanguage(&display_language));
203 EXPECT_STREQ(kDisplayLanguage, display_language);
204 }
205
206 TEST_F(BundleCreatorTest, CreateFromCommandLine) {
207 const CString kDisplayLanguage = _T("en");
208 const CString kTestBundleName = _T("CommandLineTestBundle");
209 const GUID kInstallationId = {
210 0x9a67c0e6, 0xe6f6, 0x400d,
211 {0xa4, 0x30, 0xe3, 0xfe, 0x54, 0xcc, 0x10, 0x43}
212 };
213 const CString kBrandCode = _T("GOOG");
214 const CString kClientId = _T("TestClient");
215 const CString kReferralId = _T("TestReferral");
216 const BrowserType kBrowserType = BROWSER_CHROME;
217
218 const CString kInstallSource = _T("TestInstallSourceCmdLine");
219 const CString kSessionId = _T("{6cb069db-b073-4a40-9983-846a3819876a}");
220 const bool is_machine = true;
221 const bool is_interactive = true;
222 const bool is_eula_accepted = true;
223 const bool is_offline = true;
224 const CString offline_directory = _T("C:\\GoogleUpdateUnitTest");
225
226 const GUID kApp1Id = {
227 0x433bd902, 0x6c0d, 0x4115,
228 {0x97, 0xe8, 0x4f, 0xa8, 0x2e, 0x1f, 0x4b, 0x8f}
229 };
230 const CString kApp1Name = _T("Test App1");
231 const CString kApp1AdditionalParameter = _T("App1 AP");
232 const CString kApp1Tttoken = _T("T1");
233
234 const GUID kApp2Id = {
235 0x83ed8a95, 0xc4e2, 0x4da8,
236 {0xbd, 0x0c, 0x00, 0xb9, 0xdf, 0xac, 0x6c, 0x88}
237 };
238 const CString kApp2Name = _T("Test App2");
239 const CString kApp2AdditionalParameter = _T("App2 AP");
240 const CString kApp2Tttoken = _T("T2");
241
242 CommandLineAppArgs app1;
243 app1.app_guid = kApp1Id;
244 app1.app_name = kApp1Name;
245 app1.needs_admin = NEEDS_ADMIN_YES;
246 app1.ap = kApp1AdditionalParameter;
247 app1.tt_token = kApp1Tttoken;
248
249 CommandLineAppArgs app2;
250 app2.app_guid = kApp2Id;
251 app2.app_name = kApp2Name;
252 app2.needs_admin = NEEDS_ADMIN_NO;
253 app2.ap = kApp2AdditionalParameter;
254 app2.tt_token = kApp2Tttoken;
255
256 CommandLineExtraArgs extra_args;
257 extra_args.bundle_name = kTestBundleName;
258 extra_args.installation_id = kInstallationId;
259 extra_args.brand_code = kBrandCode;
260 extra_args.client_id = kClientId;
261 extra_args.referral_id = kReferralId;
262 extra_args.language = kDisplayLanguage;
263 extra_args.browser_type = kBrowserType;
264 extra_args.apps.push_back(app1);
265 extra_args.apps.push_back(app2);
266
267 CComPtr<IAppBundle> app_bundle;
268 ASSERT_SUCCEEDED(bundle_creator::CreateFromCommandLine(
269 is_machine,
270 is_eula_accepted,
271 is_offline,
272 offline_directory,
273 extra_args,
274 kInstallSource,
275 kSessionId,
276 is_interactive,
277 &app_bundle));
278
279 CComBSTR display_name;
280 EXPECT_SUCCEEDED(app_bundle->get_displayName(&display_name));
281 EXPECT_STREQ(kTestBundleName, display_name);
282
283 CComBSTR install_source;
284 EXPECT_SUCCEEDED(app_bundle->get_installSource(&install_source));
285 EXPECT_STREQ(kInstallSource, install_source);
286
287 CComBSTR session_id;
288 EXPECT_SUCCEEDED(app_bundle->get_sessionId(&session_id));
289 EXPECT_STREQ(kSessionId, session_id);
290
291 long priority = INSTALL_PRIORITY_LOW; // NOLINT(runtime/int)
292 EXPECT_SUCCEEDED(app_bundle->get_priority(&priority));
293 EXPECT_EQ(is_interactive ? INSTALL_PRIORITY_HIGH : INSTALL_PRIORITY_LOW,
294 priority);
295
296 CComBSTR display_language;
297 EXPECT_SUCCEEDED(app_bundle->get_displayLanguage(&display_language));
298 EXPECT_STREQ(kDisplayLanguage, display_language);
299
300 long num_apps = 0; // NOLINT(runtime/int)
301 EXPECT_SUCCEEDED(app_bundle->get_Count(&num_apps));
302 EXPECT_EQ(2, num_apps);
303
304 for (long i = 0; i < num_apps; ++i) { // NOLINT(runtime/int)
305 CComPtr<IApp> app;
306 EXPECT_SUCCEEDED(update3_utils::GetApp(app_bundle, i, &app));
307
308 CComBSTR app_id;
309 EXPECT_SUCCEEDED(app->get_appId(&app_id));
310 GUID app_guid = {0};
311 EXPECT_SUCCEEDED(StringToGuidSafe(CString(app_id), &app_guid));
312
313 if (app_guid == kApp1Id) {
314 VerifyAppMatchesCommandLineArguments(extra_args, app1, app);
315 } else {
316 EXPECT_TRUE(kApp2Id == app_guid);
317 VerifyAppMatchesCommandLineArguments(extra_args, app2, app);
318 }
319 }
320 }
321
322 TEST_F(BundleCreatorTest, CreateForOnDemand) {
323 const CString& kAppId = _T("{5dace97e-9d8f-430b-acc7-ef04708b4725}");
324 const CString kInstallSource = _T("TestInstallSourceOnDemand");
325 const CString kSessionId = _T("{6cb069db-b073-4a40-9983-846a3819876a}");
326 const bool is_machine = true;
327
328 // Create app registry key to make it "installed".
329 CreateAppRegistryState(kAppId, is_machine);
330
331 CAccessToken process_token;
332 if (is_machine) {
333 process_token.GetEffectiveToken(TOKEN_ALL_ACCESS);
334 }
335
336 CComPtr<IAppBundle> app_bundle;
337 HRESULT hr = bundle_creator::CreateForOnDemand(is_machine,
338 kAppId,
339 kInstallSource,
340 kSessionId,
341 process_token.GetHandle(),
342 process_token.GetHandle(),
343 &app_bundle);
344 RemoveAppRegistryState(kAppId, is_machine);
345 ASSERT_SUCCEEDED(hr);
346
347 CComBSTR install_source;
348 EXPECT_SUCCEEDED(app_bundle->get_installSource(&install_source));
349 EXPECT_STREQ(kInstallSource, install_source);
350
351 CComBSTR session_id;
352 EXPECT_SUCCEEDED(app_bundle->get_sessionId(&session_id));
353 EXPECT_STREQ(kSessionId, session_id);
354
355 long num_apps = 0; // NOLINT(runtime/int)
356 EXPECT_SUCCEEDED(app_bundle->get_Count(&num_apps));
357 EXPECT_EQ(1, num_apps);
358
359 long priority = INSTALL_PRIORITY_LOW; // NOLINT(runtime/int)
360 EXPECT_SUCCEEDED(app_bundle->get_priority(&priority));
361 EXPECT_EQ(INSTALL_PRIORITY_HIGH, priority);
362 }
363
364 TEST_F(BundleCreatorTest, CreateForOnDemand_NonExistApp) {
365 const CString& kAppId = _T("{52e24bf9-d7d0-4b6e-b12d-9cef51fa45f2}");
366 const CString kInstallSource = _T("TestInstallSourceOnDemand");
367 const CString kSessionId = _T("{6cb069db-b073-4a40-9983-846a3819876a}");
368 const bool is_machine = true;
369
370 CAccessToken process_token;
371 if (is_machine) {
372 process_token.GetEffectiveToken(TOKEN_ALL_ACCESS);
373 }
374
375 CComPtr<IAppBundle> app_bundle;
376 EXPECT_FAILED(bundle_creator::CreateForOnDemand(
377 is_machine,
378 kAppId,
379 kInstallSource,
380 kSessionId,
381 process_token.GetHandle(),
382 process_token.GetHandle(),
383 &app_bundle));
384 }
385
386 } // namespace omaha
OLDNEW
« no previous file with comments | « client/bundle_creator.cc ('k') | client/bundle_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698