Add WidgetUpdate tests
[platform/framework/web/wrt-installer.git] / tests / general / WidgetUpdateTests.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    WidgetUpdateTests.cpp
18  * @author  Grzegorz Rynkowski (g.rynkowski@samsung.com)
19  * @version 1.0
20  * @brief   Test a process of updating web applications.
21  */
22
23 #include <string>
24 #include <dpl/test/test_runner.h>
25 #include <InstallerWrapper.h>
26 #include <fstream>
27
28 using namespace InstallerWrapper;
29
30 #define RUNNER_ASSERT_MSG_SAFE(test, message)                                  \
31     {                                                                          \
32         DPL::Test::TestRunnerSingleton::Instance().MarkAssertion();            \
33                                                                                \
34         if (!(test))                                                           \
35         {                                                                      \
36             uninstall(tizenId);                                                \
37             std::ostringstream assertMsg;                                      \
38             assertMsg << message;                                              \
39             throw DPL::Test::TestRunner::TestFailed(#test,                     \
40                                                     __FILE__,                  \
41                                                     __LINE__,                  \
42                                                     assertMsg.str());          \
43         }                                                                      \
44     }
45
46 RUNNER_TEST_GROUP_INIT(WidgetUpdate)
47
48 /*
49 Name: validUpdateOfSigned
50 Description: Tests update the web app where origin and a new one are signed.
51 Expected: Widget should be successfully installed.
52 */
53 RUNNER_TEST(validUpdateOfSigned)
54 {
55     std::string tizenId;
56     std::string wgtPath;
57
58     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
59     RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
60             "Failed to install widget");
61
62     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
63     RUNNER_ASSERT_MSG_SAFE(install(wgtPath, tizenId) == InstallerWrapper::Success,
64             "Failed update in case both programs are signed");
65     uninstall(tizenId);
66 }
67
68 /*
69 Name: validUpdateOfUnsigned
70 Description: Tests update the web app where origin and a new one are unsigned.
71 Expected: Widget should be successfully updated.
72 */
73 RUNNER_TEST(validUpdateOfUnsigned)
74 {
75     std::string tizenId;
76     std::string wgtPath;
77
78     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
79     RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
80             "Failed to install widget");
81
82     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
83     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
84                 "Failed update in case both programs are signed");
85     uninstall(tizenId);
86 }
87
88 /*
89 Name: unupdateOfSigned
90 Description: Tests update that signed web app could be downgraded.
91 Expected: Widget should not be updated.
92 */
93 RUNNER_TEST(unupdateOfSigned)
94 {
95     std::string tizenId;
96     std::string wgtPath;
97
98     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
99     RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
100             "Failed to install widget");
101
102     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
103     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
104             "Unupdate should be prohibited.");
105     uninstall(tizenId);
106 }
107
108 /*
109 Name: unupdateOfSigned
110 Description: Tests update that unsigned web app could be downgraded.
111 Expected: Widget should not be updated.
112 */
113 RUNNER_TEST(unupdateOfUnsigned)
114 {
115     std::string tizenId;
116     std::string wgtPath;
117
118     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
119     RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
120             "Failed to install widget");
121
122     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
123     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
124             "Unupdate should be prohibited.");
125     uninstall(tizenId);
126 }
127
128 /*
129 Name: validUpdateOfCrossSigned
130 Description: Tests update the web app where one of widgets are signed and second not.
131 Expected: Widget should not be updated.
132 */
133 RUNNER_TEST(updateOfCrossSignedWidgets)
134 {
135     std::string tizenId;
136     std::string wgtPath;
137
138     {
139         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
140         RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
141                 "Failed to install widget");
142
143         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
144         RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
145                 "The update unsigned app by the signed app should not be possible");
146         uninstall(tizenId);
147     }
148     {
149         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
150         RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
151                 "Failed to install widget");
152
153         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
154         RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
155                 "The update signed app by the unsigned app should not be possible");
156         uninstall(tizenId);
157     }
158 }
159
160
161 /*
162 Name: updateAnotherAuthor
163 Description: Tests update the web app by the widget signed by another author.
164 Expected: Widget should not be updated.
165 */
166 RUNNER_TEST(updateAnotherAuthor)
167 {
168     std::string tizenId;
169     std::string wgtPath;
170
171     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
172     RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
173             "Failed to install widget");
174
175     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220SignedAnotherAuthor.wgt";
176     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
177             "The update by another author should not be possible");
178     uninstall(tizenId);
179 }
180
181
182 /*
183 Name: updateWidgetDataRemember
184 Description: Tests of keeping app data during widget updating.
185 Expected: App data should be kept.
186 */
187 RUNNER_TEST(updateWidgetDataRemember)
188 {
189     std::string tizenId;
190     std::string wgtPath;
191
192     // Installation of the widget
193     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
194     RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
195             "Failed to install widget");
196
197     // Creating a file
198     std::string filePath = "/opt/usr/apps/HAdisUJ4Kn/data/test";
199     std::string text = "slonce swieci dzisiaj wyjatkowo wysoko";
200     std::string command = "echo " + text + " > " + filePath;
201     system(command.c_str());
202
203     // Second installation of the widget
204     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
205     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
206             "Failed update in case both programs are signed");
207
208
209     // Checking of the file created before
210     std::stringstream ss;
211     std::ifstream file(filePath);
212     RUNNER_ASSERT_MSG_SAFE(file.good(), "File is gone");
213
214     for( std::string line; getline( file, line ); ss << line);
215     file.close();
216     RUNNER_ASSERT_MSG_SAFE(text == ss.str(), "Content of file is not the same");
217     uninstall(tizenId);
218 }