Release version 0.15.33
[platform/core/appfw/wgt-backend.git] / test / smoke_tests / smoke_test.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest-death-test.h>
6
7 #include <common/utils/subprocess.h>
8 #include <common/utils/file_util.h>
9 #include <common/utils/pkgmgr_query.h>
10 #include <smoke_tests/common/smoke_utils.h>
11
12 #include <memory>
13
14 #include "smoke_tests/wgt_smoke_utils.h"
15
16 namespace st = smoke_test;
17 namespace bf = boost::filesystem;
18 namespace bs = boost::system;
19 namespace ci = common_installer;
20 namespace bo = boost::program_options;
21
22 namespace smoke_test {
23
24 class SmokeEnvironment : public testing::Environment {
25  public:
26   explicit SmokeEnvironment(ci::RequestMode mode) {\
27     request_mode_ = mode;
28   }
29   void SetUp() override {
30     if (request_mode_ == ci::RequestMode::USER)
31       ASSERT_TRUE(AddTestUser(&test_user));
32     backups_ = SetupBackupDirectories(test_user.uid);
33     for (auto& path : backups_)
34       ASSERT_TRUE(BackupPath(path));
35     CreateDatabase();
36   }
37   void TearDown() override {
38     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
39                 (request_mode_ == ci::RequestMode::USER &&
40                 kGlobalUserUid != test_user.uid));
41     WgtBackendInterface backend(std::to_string(test_user.uid));
42     UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
43     for (auto& path : backups_)
44       ASSERT_TRUE(RestorePath(path));
45     if (request_mode_ == ci::RequestMode::USER)
46       ASSERT_TRUE(DeleteTestUser());
47   }
48   User test_user;
49
50  private:
51   ci::RequestMode request_mode_;
52   std::vector<bf::path> backups_;
53 };
54
55 }  // namespace smoke_test
56
57 namespace {
58
59 smoke_test::SmokeEnvironment* env = nullptr;
60 void signalHandler(int signum) {
61   env->TearDown();
62   exit(signum);
63 }
64
65 }  // namespace
66
67 namespace smoke_test {
68
69 class SmokeTest : public testing::Test {
70  public:
71   SmokeTest() : backend(std::to_string(env->test_user.uid)),
72       params{PackageType::WGT, false} {
73     params.test_user.uid = env->test_user.uid;
74     params.test_user.gid = env->test_user.gid;
75   }
76  protected:
77   WgtBackendInterface backend;
78   TestParameters params;
79 };
80
81 class RollbackSmokeTest : public testing::Test {
82  public:
83   RollbackSmokeTest() : backend(std::to_string(env->test_user.uid),
84       RequestResult::FAIL), params{PackageType::WGT, false} {
85     params.test_user.uid = env->test_user.uid;
86     params.test_user.gid = env->test_user.gid;
87   }
88  protected:
89   WgtBackendInterface backend;
90   TestParameters params;
91 };
92
93 class HybridSmokeTest : public testing::Test {
94  public:
95   HybridSmokeTest() : backend(std::to_string(env->test_user.uid)),
96       params{PackageType::HYBRID, false} {
97     params.test_user.uid = env->test_user.uid;
98     params.test_user.gid = env->test_user.gid;
99   }
100  protected:
101   HybridBackendInterface backend;
102   TestParameters params;
103 };
104
105 class RollbackHybridSmokeTest : public testing::Test {
106  public:
107   RollbackHybridSmokeTest() : backend(std::to_string(env->test_user.uid),
108       RequestResult::FAIL), params{PackageType::HYBRID, false} {
109     params.test_user.uid = env->test_user.uid;
110     params.test_user.gid = env->test_user.gid;
111   }
112  protected:
113   HybridBackendInterface backend;
114   TestParameters params;
115 };
116
117 class PreloadSmokeTest : public testing::Test {
118  public:
119   PreloadSmokeTest() : backend(std::to_string(env->test_user.uid)),
120       params{PackageType::WGT, true}  {
121     params.test_user.uid = env->test_user.uid;
122     params.test_user.gid = env->test_user.gid;
123   }
124  protected:
125   WgtBackendInterface backend;
126   TestParameters params;
127 };
128
129 class HybridPreloadSmokeTest : public testing::Test {
130  public:
131   HybridPreloadSmokeTest() : backend(std::to_string(env->test_user.uid)),
132       params{PackageType::HYBRID, true} {
133     params.test_user.uid = env->test_user.uid;
134     params.test_user.gid = env->test_user.gid;
135   }
136  protected:
137   HybridBackendInterface backend;
138   TestParameters params;
139 };
140
141 TEST_F(SmokeTest, InstallationMode) {
142   bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
143   std::string pkgid = "smokewgt03";
144   std::string appid = "smokewgt03.InstallationMode";
145   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
146   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
147 }
148
149 TEST_F(SmokeTest, UpdateMode) {
150   bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
151   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
152   std::string pkgid = "smokewgt04";
153   std::string appid = "smokewgt04.UpdateMode";
154   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
155   AddDataFiles(pkgid, params.test_user.uid);
156   ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK);
157   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
158
159   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n",
160       params));
161   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
162 }
163
164 TEST_F(SmokeTest, DeinstallationMode) {
165   bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
166   std::string pkgid = "smokewgt05";
167   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
168   ASSERT_EQ(backend.Uninstall(pkgid), ci::AppInstaller::Result::OK);
169   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
170 }
171
172 TEST_F(SmokeTest, RDSMode) {
173   bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
174   std::string pkgid = "smokewgt11";
175   std::string appid = "smokewgt11.RDSMode";
176   bf::path delta_directory = kSmokePackagesDirectory / "delta_dir";
177   bf::path sdk_expected_directory = kSdkDirectory / "tmp" / pkgid;
178   ASSERT_TRUE(ci::CopyDir(delta_directory, sdk_expected_directory));
179   ASSERT_EQ(backend.RDSUpdate(path, pkgid),
180             ci::AppInstaller::Result::OK);
181   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
182   // Check delta modifications
183   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
184       "res" / "wgt" / "DELETED"));
185   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
186       "res" / "wgt" / "ADDED"));
187   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n",
188       params));
189 }
190
191 TEST_F(SmokeTest, EnablePkg) {
192   bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
193   std::string pkgid = "smokewgt22";
194   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
195   ASSERT_EQ(backend.DisablePackage(pkgid), ci::AppInstaller::Result::OK);
196   ASSERT_EQ(backend.EnablePackage(pkgid), ci::AppInstaller::Result::OK);
197
198   ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
199   ASSERT_TRUE(pkg_query.IsPackageInstalled(
200       ci::GetRequestMode(params.test_user.uid)));
201 }
202
203 TEST_F(SmokeTest, DisablePkg) {
204   bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
205   std::string pkgid = "smokewgt21";
206   std::string appid = "smokewgt21.DisablePkg";
207   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
208   ASSERT_EQ(backend.DisablePackage(pkgid), ci::AppInstaller::Result::OK);
209   ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, params.test_user.uid));
210   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
211 }
212
213 TEST_F(SmokeTest, DeltaMode) {
214   bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
215   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
216   std::string pkgid = "smokewgt17";
217   std::string appid = "smokewgt17.DeltaMode";
218   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
219   ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::OK);
220   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
221
222   // Check delta modifications
223   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
224       "res" / "wgt" / "DELETED"));
225   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
226       "res" / "wgt" / "ADDED"));
227   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
228       "res" / "wgt" / "css" / "style.css"));
229   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
230       "res" / "wgt" / "images" / "tizen_32.png"));
231   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
232       "res" / "wgt" / "js" / "main.js"));
233   ASSERT_TRUE(ValidateFileContentInPackage(
234       pkgid, "res/wgt/MODIFIED", "version 2\n", params));
235 }
236
237 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
238   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
239   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
240   std::string test_uid_str = std::to_string(params.test_user.uid);
241   backend_crash.Run("-i", path.string(), "-u", test_uid_str.c_str());
242   ASSERT_NE(backend_crash.Wait(), 0);
243
244   std::string pkgid = "smokewgt09";
245   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
246                                             params.test_user.uid);
247   ASSERT_FALSE(recovery_file.empty());
248   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
249   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
250 }
251
252 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
253   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
254   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
255   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
256   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
257   std::string pkgid = "smokewgt10";
258   std::string appid = "smokewgt10.RecoveryModeForUpdate";
259   AddDataFiles(pkgid, params.test_user.uid);
260   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
261   std::string test_uid_str = std::to_string(params.test_user.uid);
262   backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
263   ASSERT_NE(backend_crash.Wait(), 0);
264
265   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
266                                             params.test_user.uid);
267   ASSERT_FALSE(recovery_file.empty());
268   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
269   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
270
271   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
272       params));
273   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
274 }
275
276 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
277   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
278   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
279   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
280   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
281   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
282   std::string test_uid_str = std::to_string(params.test_user.uid);
283   backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
284   ASSERT_NE(backend_crash.Wait(), 0);
285
286   std::string pkgid = "smokewgt30";
287   std::string appid = "smokewgt30.RecoveryModeForDelta";
288   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
289                                             params.test_user.uid);
290   ASSERT_FALSE(recovery_file.empty());
291   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
292   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
293
294   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
295       params));
296 }
297
298 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
299   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
300   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
301   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
302   std::string test_uid_str = std::to_string(params.test_user.uid);
303   backend_crash.Run("-w", path.string(), "-u", test_uid_str.c_str());
304   ASSERT_NE(backend_crash.Wait(), 0);
305
306   std::string pkgid = "smokewgt31";
307   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
308                                             params.test_user.uid);
309   ASSERT_FALSE(recovery_file.empty());
310   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
311   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
312 }
313
314 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
315   bf::path path_old =
316       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
317   bf::path path_new =
318       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
319   std::string pkgid = "smokewgt32";
320   std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
321   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
322   ASSERT_EQ(backend.MountInstallSuccess(path_old),
323             ci::AppInstaller::Result::OK);
324   AddDataFiles(pkgid, params.test_user.uid);
325   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
326   std::string test_uid_str = std::to_string(params.test_user.uid);
327   backend_crash.Run("-w", path_new.string(), "-u", test_uid_str.c_str());
328   ASSERT_NE(backend_crash.Wait(), 0);
329
330   // Filesystem may be mounted after crash
331   ScopedTzipInterface poweroff_unmount_interface(pkgid, params.test_user.uid);
332   poweroff_unmount_interface.Release();
333
334   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
335                            params.test_user.uid);
336   ASSERT_FALSE(recovery_file.empty());
337   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
338
339   ScopedTzipInterface interface(pkgid, params.test_user.uid);
340   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
341   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
342       params));
343   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
344 }
345
346 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
347   // pkgid: smokewgt08
348   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
349   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
350 }
351
352 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
353   // pkgid: smokewgt12
354   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
355   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
356 }
357
358 TEST_F(RollbackSmokeTest, InstallationMode) {
359   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
360   std::string pkgid = "smokewgt06";
361   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
362   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
363 }
364
365 TEST_F(RollbackSmokeTest, UpdateMode) {
366   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
367   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
368   std::string pkgid = "smokewgt07";
369   std::string appid = "smokewgt07.UpdateModeRollback";
370   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
371   AddDataFiles(pkgid, params.test_user.uid);
372   ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::ERROR);
373   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
374
375   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
376       params));
377   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
378 }
379
380 TEST_F(RollbackSmokeTest, DeltaMode) {
381   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
382   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
383   std::string pkgid = "smokewgt01";
384   std::string appid = "smokewgt01.DeltaMode";
385   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
386   AddDataFiles(pkgid, params.test_user.uid);
387   ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::ERROR);
388
389   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
390   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
391                                            "version 1\n", params));
392   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
393   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
394                          "res/wgt/DELETED"));
395   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, params.test_user.uid) /
396                           "res/wgt/ADDED"));
397 }
398
399 TEST_F(HybridSmokeTest, InstallationMode) {
400   bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
401   std::string pkgid = "smokehyb01";
402   // Excutable for native app doesn't create symlink
403   std::string appid1 = "smokehyb01.Web";
404   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
405   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
406 }
407
408 TEST_F(HybridSmokeTest, UpdateMode) {
409   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
410   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
411   std::string pkgid = "smokehyb02";
412   std::string appid1 = "smokehyb02.Web";
413   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
414   AddDataFiles(pkgid, params.test_user.uid);
415   ASSERT_EQ(backend.Install(path_new),
416             ci::AppInstaller::Result::OK);
417   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
418
419   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n",
420       params));
421   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n", params));
422   ValidateDataFiles(pkgid, params.test_user.uid);
423 }
424
425 TEST_F(HybridSmokeTest, DeinstallationMode) {
426   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
427   std::string pkgid = "smokehyb03";
428   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
429   ASSERT_EQ(backend.Uninstall(pkgid), ci::AppInstaller::Result::OK);
430   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
431 }
432
433 TEST_F(HybridSmokeTest, DeltaMode) {
434   bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
435   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
436   std::string pkgid = "smokehyb04";
437   std::string appid1 = "smokehyb04.Web";
438   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
439   ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::OK);
440   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
441
442   // Check delta modifications
443   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
444   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
445   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
446   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
447   ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
448   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
449   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
450   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
451   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n", params));  // NOLINT
452   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n", params));  // NOLINT
453 }
454
455 TEST_F(HybridSmokeTest, MountInstallationMode) {
456   bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
457   std::string pkgid = "smokehyb05";
458   std::string appid1 = "smokehyb05.web";
459   ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
460   ScopedTzipInterface interface(pkgid, params.test_user.uid);
461   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
462 }
463
464 TEST_F(HybridSmokeTest, MountUpdateMode) {
465   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
466   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
467   std::string pkgid = "smokehyb06";
468   std::string appid1 = "smokehyb06.web";
469   ASSERT_EQ(backend.MountInstallSuccess(path_old),
470       ci::AppInstaller::Result::OK);
471   AddDataFiles(pkgid, params.test_user.uid);
472   ASSERT_EQ(backend.MountInstall(path_new), ci::AppInstaller::Result::OK);
473   ScopedTzipInterface interface(pkgid, params.test_user.uid);
474   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
475
476   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n",
477       params));
478   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n",
479       params));
480   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
481 }
482
483 TEST_F(RollbackHybridSmokeTest, InstallationMode) {
484   bf::path path = kSmokePackagesDirectory /
485       "InstallationMode_Rollback_Hybrid.wgt";
486   std::string pkgid = "smokehyb07";
487   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
488   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
489 }
490
491 TEST_F(RollbackHybridSmokeTest, UpdateMode) {
492   bf::path path_old = kSmokePackagesDirectory /
493       "UpdateMode_Rollback_Hybrid.wgt";
494   bf::path path_new = kSmokePackagesDirectory /
495       "UpdateMode_Rollback_Hybrid_2.wgt";
496   std::string pkgid = "smokehyb08";
497   std::string appid1 = "smokehyb08.web";
498   ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
499   AddDataFiles(pkgid, params.test_user.uid);
500   ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::ERROR);
501   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
502
503   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
504       params));
505   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n",
506       params));
507   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
508 }
509
510 TEST_F(RollbackHybridSmokeTest, DeltaMode) {
511   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
512   bf::path delta_package = kSmokePackagesDirectory /
513       "DeltaMode_Rollback_Hybrid.delta";
514   std::string pkgid = "smokehyb11";
515   std::string appid1 = "smokehyb11.web";
516   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
517   AddDataFiles(pkgid, params.test_user.uid);
518   ASSERT_EQ(backend.Install(delta_package),
519             ci::AppInstaller::Result::ERROR);
520
521   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
522   // Check delta modifications
523   bf::path root_path = GetPackageRoot(pkgid, params.test_user.uid);
524   ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
525   ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
526   ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
527   ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
528   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
529                                            "version 1\n", params));
530   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
531                                            "version 1\n", params));
532   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
533 }
534
535 TEST_F(RollbackHybridSmokeTest, MountInstallationMode) {
536   bf::path path = kSmokePackagesDirectory /
537       "MountInstallationMode_Rollback_Hybrid.wgt";
538   std::string pkgid = "smokehyb09";
539   ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::ERROR);
540   ScopedTzipInterface interface(pkgid, params.test_user.uid);
541   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
542 }
543
544 TEST_F(RollbackHybridSmokeTest, MountUpdateMode) {
545   bf::path path_old = kSmokePackagesDirectory /
546       "MountUpdateMode_Rollback_Hybrid.wgt";
547   bf::path path_new = kSmokePackagesDirectory /
548       "MountUpdateMode_Rollback_Hybrid_2.wgt";
549   std::string pkgid = "smokehyb10";
550   std::string appid1 = "smokehyb10.web";
551   ASSERT_EQ(backend.MountInstallSuccess(path_old),
552             ci::AppInstaller::Result::OK);
553   AddDataFiles(pkgid, params.test_user.uid);
554   ASSERT_EQ(backend.MountInstall(path_new), ci::AppInstaller::Result::ERROR);
555   ScopedTzipInterface interface(pkgid, params.test_user.uid);
556   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
557
558   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
559       params));
560   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n",
561       params));
562   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
563 }
564
565 TEST_F(SmokeTest, MountInstallationMode) {
566   bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
567   std::string pkgid = "smokewgt28";
568   std::string appid = "smokewgt28.InstallationMode";
569   ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
570   ScopedTzipInterface interface(pkgid, params.test_user.uid);
571   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
572 }
573
574 TEST_F(SmokeTest, MountUpdateMode) {
575   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
576   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
577   std::string pkgid = "smokewgt29";
578   std::string appid = "smokewgt29.UpdateMode";
579   ASSERT_EQ(backend.MountInstallSuccess(path_old),
580       ci::AppInstaller::Result::OK);
581   AddDataFiles(pkgid, params.test_user.uid);
582   ASSERT_EQ(backend.MountInstall(path_new), ci::AppInstaller::Result::OK);
583   ScopedTzipInterface interface(pkgid, params.test_user.uid);
584   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
585
586   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n",
587       params));
588   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
589 }
590
591 TEST_F(RollbackSmokeTest, MountInstallationMode) {
592   bf::path path =
593       kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
594   std::string pkgid = "smokewgt33";
595   ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::ERROR);
596   ScopedTzipInterface interface(pkgid, params.test_user.uid);
597   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
598 }
599
600 TEST_F(RollbackSmokeTest, MountUpdateMode) {
601   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
602   bf::path path_new =
603       kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
604   std::string pkgid = "smokewgt34";
605   std::string appid = "smokewgt34.web";
606   ASSERT_EQ(backend.MountInstallSuccess(path_old),
607             ci::AppInstaller::Result::OK);
608   AddDataFiles(pkgid, params.test_user.uid);
609   ASSERT_EQ(backend.MountInstall(path_new), ci::AppInstaller::Result::ERROR);
610   ScopedTzipInterface interface(pkgid, params.test_user.uid);
611   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
612
613   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
614       params));
615   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
616 }
617
618 TEST_F(SmokeTest, UserDefinedPlugins) {
619   bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
620   std::string pkgid = "smokewgt02";
621   std::string appid = "smokewgt02.SimpleEcho";
622   std::string call_privilege = "http://tizen.org/privilege/call";
623   std::string location_privilege = "http://tizen.org/privilege/location";
624   std::string power_privilege = "http://tizen.org/privilege/power";
625
626   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
627   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
628   std::vector<std::string> res;
629   ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
630   ASSERT_TRUE(pkg_query.PrivilegesForPkgId(&res));
631   ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
632   ASSERT_TRUE(std::find(res.begin(), res.end(), location_privilege)
633           != res.end());
634   ASSERT_TRUE(std::find(res.begin(), res.end(), power_privilege) != res.end());
635 }
636
637 TEST_F(SmokeTest, InstallExternalMode) {
638   ASSERT_TRUE(CheckAvailableExternalPath());
639   bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
640   std::string pkgid = "smokewgt35";
641   std::string appid = "smokewgt35.web";
642   ASSERT_EQ(backend.InstallWithStorage(path, StorageType::EXTERNAL),
643       ci::AppInstaller::Result::OK);
644   ValidateExternalPackage(pkgid, {appid}, params);
645 }
646
647 TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
648   ASSERT_TRUE(CheckAvailableExternalPath());
649   bf::path path =
650       kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
651   std::string pkgid = "smokewgt36";
652   std::string appid = "smokewgt36.web";
653   bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
654   std::string test_uid_str = std::to_string(params.test_user.uid);
655   if (test_uid_str == kDefaultUserIdStr ||
656       params.test_user.uid == kGlobalUserUid) {
657     ASSERT_EQ(backend.MigrateLegacyExternalImage(pkgid, path, legacy_path),
658         ci::AppInstaller::Result::OK);
659     ValidateExternalPackage(pkgid, {appid}, params);
660   } else {
661     ASSERT_EQ(backend.MigrateLegacyExternalImage(pkgid, path, legacy_path),
662         ci::AppInstaller::Result::ERROR);
663   }
664 }
665
666 TEST_F(PreloadSmokeTest, InstallationMode) {
667   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
668   bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
669   std::string pkgid = "smokewgt37";
670   std::string appid = "smokewgt37.InstallationModePreload";
671   ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
672   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
673 }
674
675 TEST_F(PreloadSmokeTest, UpdateMode) {
676   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
677   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
678   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
679   std::string pkgid = "smokewgt38";
680   std::string appid = "smokewgt38.UpdateModePreload";
681   ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
682   AddDataFiles(pkgid, params.test_user.uid);
683   ASSERT_EQ(backend.InstallPreload(path_new), ci::AppInstaller::Result::OK);
684   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
685
686   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
687                                            params));
688   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
689 }
690
691 TEST_F(PreloadSmokeTest, DeinstallationMode) {
692   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
693   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
694   std::string pkgid = "smokewgt39";
695   ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
696   ASSERT_EQ(backend.UninstallPreload(pkgid), ci::AppInstaller::Result::OK);
697   CheckPackageReadonlyNonExistance(pkgid, params);
698 }
699
700 TEST_F(SmokeTest, ManifestDirectInstallMode) {
701   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
702   bf::path src_path = kSmokePackagesDirectory / "ManifestDirectInstallMode";
703   std::string pkgid = "smokewgt40";
704   std::string appid = "smokewgt40.ManifestDirectInstallMode";
705   bf::path pkg_path = ci::GetRootAppPath(false, params.test_user.uid);
706
707   ci::CopyDir(src_path / pkgid, pkg_path / pkgid);
708   ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
709   ASSERT_FALSE(pkg_query.IsPackageInstalled(
710       ci::GetRequestMode(params.test_user.uid)));
711   ASSERT_EQ(backend.ManifestDirectInstall(pkgid),
712             ci::AppInstaller::Result::OK);
713   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
714 }
715
716 TEST_F(SmokeTest, ManifestDirectUpdateMode) {
717   bf::path path = kSmokePackagesDirectory / "ManifestDirectUpdateMode.wgt";
718   std::string pkgid = "smokewgt41";
719   std::string appid = "smokewgt41.ManifestDirectUpdateMode";
720
721   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
722   int install_time = GetAppInstalledTime(appid.c_str(), params.test_user.uid);
723   sleep(1);
724   ASSERT_EQ(backend.ManifestDirectInstall(pkgid),
725             ci::AppInstaller::Result::OK);
726   ASSERT_GT(
727       GetAppInstalledTime(appid.c_str(), params.test_user.uid), install_time)
728           << "Package is not updated (app installed time didn't change).";
729   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
730 }
731
732 TEST_F(PreloadSmokeTest, ReadonlyUpdateInstallMode) {
733   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
734   bf::path path = kSmokePackagesDirectory / "ReadonlyUpdateInstallMode.wgt";
735   std::string pkgid = "smokewgt42";
736   std::string appid = "smokewgt42.ReadonlyUpdateInstallMode";
737
738   ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
739   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
740   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
741 }
742
743 TEST_F(PreloadSmokeTest, ReadonlyUpdateUninstallMode) {
744   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
745   bf::path path = kSmokePackagesDirectory / "ReadonlyUpdateUninstallMode.wgt";
746   std::string pkgid = "smokewgt43";
747   std::string appid = "smokewgt43.ReadonlyUpdateUninstallMode";
748
749   ASSERT_EQ(backend.InstallPreload(path),
750             ci::AppInstaller::Result::OK);
751   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
752   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
753   ASSERT_EQ(backend.Uninstall(pkgid), ci::AppInstaller::Result::OK);
754   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
755 }
756
757 TEST_F(HybridSmokeTest, ManifestDirectInstallMode) {
758   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
759   bf::path src_path = kSmokePackagesDirectory /
760       "ManifestDirectInstallMode_Hybrid";
761   std::string pkgid = "smokehyb12";
762   std::string appid = "smokehyb12.ManifestDirectInstallModeHybrid";
763   bf::path pkg_path = ci::GetRootAppPath(false, params.test_user.uid);
764
765   ci::CopyDir(src_path / pkgid, pkg_path / pkgid);
766   ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
767   ASSERT_FALSE(pkg_query.IsPackageInstalled(
768       ci::GetRequestMode(params.test_user.uid)));
769   ASSERT_EQ(backend.ManifestDirectInstall(pkgid),
770             ci::AppInstaller::Result::OK);
771   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
772 }
773
774 TEST_F(HybridSmokeTest, ManifestDirectUpdateMode) {
775   bf::path path = kSmokePackagesDirectory /
776       "ManifestDirectUpdateMode_Hybrid.wgt";
777   std::string pkgid = "smokehyb13";
778   std::string appid = "smokehyb13.ManifestDirectUpdateModeHybrid";
779
780   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
781   int install_time = GetAppInstalledTime(appid.c_str(), params.test_user.uid);
782   sleep(1);
783   ASSERT_EQ(backend.ManifestDirectInstall(pkgid), ci::AppInstaller::Result::OK);
784   ASSERT_GT(
785       GetAppInstalledTime(appid.c_str(), params.test_user.uid), install_time)
786           << "Package is not updated (app installed time didn't change).";
787   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
788 }
789
790 TEST_F(SmokeTest, SharedRes24) {
791   bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
792   std::string pkgid = "smokeSh2xx";
793   std::string appid = "smokeSh2xx.SharedRes24";
794   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
795   ValidatePackage(pkgid, {appid}, params);
796   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
797   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
798   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
799 }
800
801 TEST_F(SmokeTest, SharedRes30) {
802   bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
803   std::string pkgid = "smokeSh3xx";
804   std::string appid = "smokeSh3xx.SharedRes30";
805   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
806   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
807   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
808   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
809   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
810 }
811
812 TEST_F(SmokeTest, SharedRes30Delta) {
813   bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
814   bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
815   std::string pkgid = "smokeSh3De";
816   std::string appid = "smokeSh3De.SharedRes30Delta";
817   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
818   ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::OK);
819   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
820   // Check delta modifications
821   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
822   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
823   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
824   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
825   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
826 }
827
828 TEST_F(HybridSmokeTest, SharedRes30Hybrid) {
829   bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
830   std::string pkgid = "smokeSh3Hy";
831   std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
832   std::string appid2 = "sharedres30hybridserivce";
833   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
834   ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}, params));
835   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
836   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
837   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
838   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK"));  // NOLINT
839 }
840
841 TEST_F(HybridSmokeTest, SharedRes30HybridDelta) {
842   bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
843   bf::path delta_package = kSmokePackagesDirectory /
844       "SharedRes30HybridDelta.delta";
845   std::string pkgid = "smokeSh3HD";
846   std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
847   std::string appid2 = "sharedres30hybriddeltaserivce";
848   ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
849   ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::OK);
850   ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}, params));
851   // Check delta modifications
852   bf::path root_path = ci::GetRootAppPath(false, params.test_user.uid);
853   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
854   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
855   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
856   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
857   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
858 }
859
860 TEST_F(SmokeTest, InstallExtendedMode) {
861   ASSERT_TRUE(CheckAvailableExtendedPath());
862   bf::path path = kSmokePackagesDirectory / "InstallExtendedMode.wgt";
863   std::string pkgid = "smokewgt44";
864   std::string appid = "smokewgt44.web";
865   ASSERT_EQ(backend.InstallWithStorage(path, StorageType::EXTENDED),
866       ci::AppInstaller::Result::OK);
867   ASSERT_TRUE(ValidateExtendedPackage(pkgid, {appid}, params));
868 }
869
870 TEST_F(SmokeTest, RecoveryMode_CrashAfterUnzip) {
871   bf::path path = kSmokePackagesDirectory / "RecoveryMode_CrashAfterUnzip.wgt";
872   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
873   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
874   std::string test_uid_str = std::to_string(params.test_user.uid);
875   backend_crash.Run("-i", path.string(), "-u", test_uid_str.c_str(),
876       "-step_name", "Unzip");
877   ASSERT_NE(backend_crash.Wait(), 0);
878
879   std::string pkgid = "smokewgt45";
880   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
881       params.test_user.uid);
882   ASSERT_FALSE(recovery_file.empty());
883   std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
884       GetRecoverFileInfo(recovery_file);
885   ASSERT_TRUE(recovery_info ? true : false);
886   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
887   ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
888   ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
889 }
890
891 TEST_F(SmokeTest, InstallationMode_GlobalServiceAppWithUiAppId) {
892   bf::path path = kSmokePackagesDirectory /
893       "InstallationMode_GlobalServiceAppWithUiAppId.wgt";
894   std::string pkgid = "smokewgt46";
895   std::string ui_appid = "smokewgt46.uiapp";
896   std::string service_appid = "smokewgt46.serviceapp";
897   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
898   ASSERT_TRUE(ValidatePackage(pkgid, {ui_appid, service_appid}, params));
899 }
900
901 TEST_F(SmokeTest, InstallationMode_GlobalServiceAppWithoutUiAppId) {
902   bf::path path = kSmokePackagesDirectory /
903       "InstallationMode_GlobalServiceAppWithoutUiAppId.wgt";
904   std::string pkgid = "smokewgt47";
905   std::string service_appid = "smokewgt47.serviceapp";
906   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
907   ASSERT_TRUE(ValidatePackage(pkgid, {service_appid}, params));
908 }
909
910 TEST_F(SmokeTest, InstallationMode_UIServiceAppWithUiAppId) {
911   bf::path path = kSmokePackagesDirectory /
912       "InstallationMode_UIServiceAppWithUiAppId.wgt";
913   std::string pkgid = "smokewgt48";
914   std::string ui_appid = "smokewgt48.uiapp";
915   std::string service_appid = "smokewgt48.serviceapp";
916   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
917   ASSERT_TRUE(ValidatePackage(pkgid, {ui_appid, service_appid}, params));
918 }
919
920 TEST_F(SmokeTest, InstallationMode_UIServiceAppWithoutUiAppId) {
921   bf::path path = kSmokePackagesDirectory /
922       "InstallationMode_UIServiceAppWithoutUiAppId.wgt";
923   std::string pkgid = "smokewgt49";
924   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
925 }
926
927 TEST_F(SmokeTest, InstallationMode_UIAppWithoutUiAppId) {
928   bf::path path = kSmokePackagesDirectory /
929       "InstallationMode_UIAppWithoutUiAppId.wgt";
930   std::string pkgid = "smokewgt50";
931   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
932 }
933
934 TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
935   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
936   bf::path path_old = kSmokePackagesDirectory /
937       "RecoveryMode_ForReadonlyUpdateInstall.wgt";
938   bf::path path_new = kSmokePackagesDirectory /
939       "RecoveryMode_ForReadonlyUpdateInstall_2.wgt";
940   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
941   ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
942   std::string pkgid = "smokewgt51";
943   std::string appid = "smokewgt51.RecoveryModeForReadonlyUpdateInstall";
944   AddDataFiles(pkgid, params.test_user.uid);
945   ci::Subprocess backend_crash("/usr/bin/wgt-installer-ut/smoke-test-helper");
946   std::string test_uid_str = std::to_string(params.test_user.uid);
947   backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
948   ASSERT_NE(backend_crash.Wait(), 0);
949
950   bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
951                                             params.test_user.uid);
952   ASSERT_FALSE(recovery_file.empty());
953   ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
954   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
955
956   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
957       params));
958   ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
959 }
960
961 }  // namespace smoke_test
962
963 int main(int argc,  char** argv) {
964   try {
965     ci::RequestMode request_mode = st::ParseRequestMode(argc, argv);
966     if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
967       std::cout << "Skip tests for preload request" << std::endl;
968       ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
969     }
970     testing::InitGoogleTest(&argc, argv);
971     ::env = static_cast<smoke_test::SmokeEnvironment*>(
972         testing::AddGlobalTestEnvironment(
973             new smoke_test::SmokeEnvironment(request_mode)));
974     signal(SIGINT, ::signalHandler);
975     signal(SIGSEGV, ::signalHandler);
976     return RUN_ALL_TESTS();
977   } catch (...) {
978     std::cout << "Exception occurred during testing" << std::endl;
979     return 1;
980   }
981 }