Remove two tests from WidgetUpdate test group
[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  * Information:
90  * These tests are incompatible to the specification 2.1
91  *      (but compatible to the specification 3.0).
92  */
93 ///*
94 //Name: unupdateOfSigned
95 //Description: Tests update that signed web app could be downgraded.
96 //Expected: Widget should not be updated.
97 //*/
98 //RUNNER_TEST(unupdateOfSigned)
99 //{
100 //    std::string tizenId;
101 //    std::string wgtPath;
102 //
103 //    wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
104 //    RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
105 //            "Failed to install widget");
106 //
107 //    wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
108 //    RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
109 //            "Unupdate should be prohibited.");
110 //    uninstall(tizenId);
111 //}
112 //
113 ///*
114 //Name: unupdateOfSigned
115 //Description: Tests update that unsigned web app could be downgraded.
116 //Expected: Widget should not be updated.
117 //*/
118 //RUNNER_TEST(unupdateOfUnsigned)
119 //{
120 //    std::string tizenId;
121 //    std::string wgtPath;
122 //
123 //    wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
124 //    RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
125 //            "Failed to install widget");
126 //
127 //    wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
128 //    RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
129 //            "Unupdate should be prohibited.");
130 //    uninstall(tizenId);
131 //}
132
133 /*
134 Name: validUpdateOfCrossSigned
135 Description: Tests update the web app where one of widgets are signed and second not.
136 Expected: Widget should not be updated.
137 */
138 RUNNER_TEST(updateOfCrossSignedWidgets)
139 {
140     std::string tizenId;
141     std::string wgtPath;
142
143     {
144         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
145         RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
146                 "Failed to install widget");
147
148         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
149         RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
150                 "The update unsigned app by the signed app should not be possible");
151         uninstall(tizenId);
152     }
153     {
154         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
155         RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
156                 "Failed to install widget");
157
158         wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
159         RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
160                 "The update signed app by the unsigned app should not be possible");
161         uninstall(tizenId);
162     }
163 }
164
165
166 /*
167 Name: updateAnotherAuthor
168 Description: Tests update the web app by the widget signed by another author.
169 Expected: Widget should not be updated.
170 */
171 RUNNER_TEST(updateAnotherAuthor)
172 {
173     std::string tizenId;
174     std::string wgtPath;
175
176     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
177     RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
178             "Failed to install widget");
179
180     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220SignedAnotherAuthor.wgt";
181     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
182             "The update by another author should not be possible");
183     uninstall(tizenId);
184 }
185
186
187 /*
188 Name: updateWidgetDataRemember
189 Description: Tests of keeping app data during widget updating.
190 Expected: App data should be kept.
191 */
192 RUNNER_TEST(updateWidgetDataRemember)
193 {
194     std::string tizenId;
195     std::string wgtPath;
196
197     // Installation of the widget
198     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
199     RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
200             "Failed to install widget");
201
202     // Creating a file
203     std::string filePath = "/opt/usr/apps/HAdisUJ4Kn/data/test";
204     std::string text = "slonce swieci dzisiaj wyjatkowo wysoko";
205     std::string command = "echo " + text + " > " + filePath;
206     system(command.c_str());
207
208     // Second installation of the widget
209     wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
210     RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
211             "Failed update in case both programs are signed");
212
213
214     // Checking of the file created before
215     std::stringstream ss;
216     std::ifstream file(filePath);
217     RUNNER_ASSERT_MSG_SAFE(file.good(), "File is gone");
218
219     for( std::string line; getline( file, line ); ss << line);
220     file.close();
221     RUNNER_ASSERT_MSG_SAFE(text == ss.str(), "Content of file is not the same");
222     uninstall(tizenId);
223 }