Tizen appservice 'disposition' attribute added.
[framework/web/wrt-installer.git] / tests / general / TestCases.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    TestCases.cpp
18  * @author  Karol Pawlowski (k.pawlowski@samsung.com)
19  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
20  * @version 1.0
21  * @brief   Miscellaneous test's bodies
22  */
23
24 #include <string>
25 #include <algorithm>
26 #include <dpl/utils/wrt_utility.h>
27 #include <dpl/test/test_runner.h>
28 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
29 #include <dpl/log/log.h>
30 #include <InstallerWrapper.h>
31 #include <ManifestFile.h>
32
33 using namespace InstallerWrapper;
34
35 namespace {
36
37 const std::string miscWidgetsStuff = "/opt/share/widget/tests/installer/";
38
39 struct Result {
40     bool m_exc;
41     bool m_exd;
42     bool m_exs;
43     std::string message;
44     Result(bool exc = false, bool exd = false, bool exs = false)
45         : m_exc(exc), m_exd(exd), m_exs(exs) {}
46 };
47
48 }
49
50 ////////////////////////////////////////////////////////////////////////////////
51
52 RUNNER_TEST_GROUP_INIT(Manifest)
53
54 /*
55 Name: creatingManifestFile
56 Description: Creation of manifest file by wrt-installer test
57 Expected: file should be created and installed by wrt-installer. Content should
58  match expected values
59 */
60 RUNNER_TEST(creatingManifestFile)
61 {
62     const char * manifestPath = "/opt/share/packages/manifest01.xml";
63     /* This widget removal should stay here in case previous test run failed
64      * (so widget has not been uninstalled) */
65     uninstallByGuid("http://test.samsung.com/widget/manifestTest");
66     std::string tizenId;
67     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/manifest.wgt", tizenId)
68             == InstallerWrapper::Success);
69     RUNNER_ASSERT(WrtUtilFileExists(manifestPath));
70     ManifestFile mf(manifestPath);
71
72     Try
73     {
74         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@package")
75                       == "manifest01");
76         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@type")
77                       == "wgt");
78         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@version")
79                       == "1.0");
80         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:label")
81                       == "Manifest Example");
82
83         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@email")
84                       == "manifest@misc.test.create.desktop.com");
85         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@href")
86                       == "http://misc.test.create.desktop.com");
87         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author")
88                       == "Manifest");
89
90         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@appid")
91                       == "manifest01");
92         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@nodisplay")
93                       == "false");
94         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@type")
95                       == "webapp");
96         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@extraid")
97                       == "http://test.samsung.com/widget/manifestTest");
98         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@taskmanage")
99                       == "true");
100
101         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:icon")
102                       == "manifest01.png");
103
104         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[not(@xml:lang)]")
105                       == "Manifest Example");
106         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='de_DE']")
107                       == "Manifest Beispiel");
108         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='en_US']")
109                       == "Manifest Example");
110         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pl']")
111                       == "PrzykĹ‚ad Manifest");
112         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pt_PT']")
113                       == "Exemplo manifesto");
114     }
115     Catch(ManifestFile::ManifestParseError)
116     {
117         RUNNER_ASSERT_MSG(false,DPL::Exception::KnownExceptionToString(_rethrown_exception));
118     }
119     /* If test finished sucessfully than uninstall test widget */
120     uninstall(tizenId);
121 }
122
123 ////////////////////////////////////////////////////////////////////////////////
124
125 RUNNER_TEST_GROUP_INIT(BackgroundPage)
126
127 /*
128 Name: widgetWithBackgroundPage
129 Description: Tests if widget with background page is installed correctly
130 Expected: widget should be installed correctly
131 */
132 RUNNER_TEST(widgetWithBackgroundPage)
133 {
134     std::string tizenId;
135     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-00-with_bg.wgt",
136             tizenId) == InstallerWrapper::Success);
137     uninstall(tizenId);
138 }
139
140 /*
141 Name: missingBackgroundFile
142 Description: Tests if widget with declared in conifg background page
143  but missing background file will be installed correctly.
144 Expected: widget should NOT be installed
145 */
146 RUNNER_TEST(missingBackgroundFile)
147 {
148     std::string tizenId;
149     if(install(miscWidgetsStuff + "widgets/bg-01-missing_file.wgt",
150             tizenId) == InstallerWrapper::Success) {
151         uninstall(tizenId);
152         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
153     }
154 }
155
156 /*
157 Name: widgetWithoutBackgroundPage
158 Description: Complementary test to check if normal widget\
159  without background page is successfully installed
160 Expected: widget should be installed
161 */
162 RUNNER_TEST(widgetWithoutBackgroundPage)
163 {
164     std::string tizenId;
165     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-02-without_bg.wgt",
166             tizenId) == InstallerWrapper::Success);
167     uninstall(tizenId);
168 }
169
170 ////////////////////////////////////////////////////////////////////////////////
171
172 RUNNER_TEST_GROUP_INIT(NonRootUser)
173
174 /*
175 Name: widgetNonRootInstallation
176 Description: Check installation from other user than root
177 Expected: widget should be installed
178 */
179 RUNNER_TEST(widgetNonRootInstallation)
180 {
181     std::string tizenId;
182     RUNNER_ASSERT(install(
183                 miscWidgetsStuff + "widgets/nonroot.wgt",
184                 tizenId,
185                 "app") == InstallerWrapper::Success);
186     uninstall(tizenId);
187 }
188
189 ////////////////////////////////////////////////////////////////////////////////
190
191 RUNNER_TEST_GROUP_INIT(NPluginsInstall)
192
193 /*
194 Name: pluginFilesAdded
195 Description: Tests installation of plugins attached to widget
196 Expected: widget should be succesfully installed
197 */
198 RUNNER_TEST(pluginFilesAdded)
199 {
200     std::string tizenId;
201     RUNNER_ASSERT(install(miscWidgetsStuff
202             + "widgets/inst_nplug_1.wgt", tizenId) == InstallerWrapper::Success);
203     uninstall(tizenId);
204 }
205
206 /*
207 Name: emptyPluginsDir
208 Description: Tests installation with empty 'plugins' directory
209 Expected: widget should be not installed
210 */
211 RUNNER_TEST(emptyPluginsDir)
212 {
213     std::string tizenId;
214     if(install(miscWidgetsStuff + "widgets/inst_nplug_2.wgt",
215             tizenId) == InstallerWrapper::Success) {
216         uninstall(tizenId);
217         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
218     }
219 }
220
221 /*
222 Name: pluginFileAndOtherFile
223 Description: Tests installation with plugins directory and data files
224 Expected: widget should be installed
225 */
226 RUNNER_TEST(pluginFileAndOtherFile)
227 {
228     std::string tizenId;
229     RUNNER_ASSERT(install(miscWidgetsStuff
230             + "widgets/inst_nplug_3.wgt", tizenId) == InstallerWrapper::Success);
231     uninstall(tizenId);
232 }
233
234 /*
235 Name: pluginFileAndSubdir
236 Description: Tests installation with 'plugins' directory and subdirectories
237  inside plugin directory
238 Expected: widget should be not installed
239 */
240 RUNNER_TEST(pluginFileAndSubdir)
241 {
242     std::string tizenId;
243     if(install(miscWidgetsStuff + "widgets/inst_nplug_4.wgt",
244             tizenId) == InstallerWrapper::Success) {
245         uninstall(tizenId);
246         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
247     }
248 }
249
250 RUNNER_TEST_GROUP_INIT(ParsingTizenAppservice)
251 namespace {
252
253 }
254
255 /*
256 Name: correct_csp_policy
257 Description: Tests if widget policy is correctly parsed from config file
258              and stored into database
259 Expected: widget should be installed and policy should mach
260 */
261 RUNNER_TEST(tizen_appservice_disposition)
262 {
263     std::string tizenId;
264     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/appservice_dispos.wgt",
265             tizenId) == InstallerWrapper::Success);
266
267     WrtDB::WidgetDAOReadOnly dao(DPL::FromASCIIString(tizenId));
268     WidgetApplicationServiceList appsvcList;
269     dao.getAppServiceList(appsvcList);
270     uninstall(tizenId);
271
272     RUNNER_ASSERT_MSG(appsvcList.size() == 4, "Incorrect list size");
273     WidgetApplicationService s;
274     s.src = DPL::FromUTF8String("edit1.html");
275     s.operation = DPL::FromUTF8String("http://tizen.org/appsvc/operation/edit");
276     s.mime = DPL::FromUTF8String("image/jpg");      /* mime type */
277     s.disposition = WidgetApplicationService::Disposition::WINDOW;
278     RUNNER_ASSERT_MSG(
279         std::find(appsvcList.begin(), appsvcList.end(), s) != appsvcList.end(),
280         "Unable to find service #");
281
282     s.src = DPL::FromUTF8String("edit2.html");
283     s.operation = DPL::FromUTF8String("http://tizen.org/appsvc/operation/view");
284     s.mime = DPL::FromUTF8String("audio/ogg");      /* mime type */
285     s.disposition = WidgetApplicationService::Disposition::WINDOW;
286     RUNNER_ASSERT_MSG(
287         std::find(appsvcList.begin(), appsvcList.end(), s) != appsvcList.end(),
288         "Unable to find service ##");
289
290     s.src = DPL::FromUTF8String("edit3.html");
291     s.operation = DPL::FromUTF8String("http://tizen.org/appsvc/operation/call");
292     s.mime = DPL::FromUTF8String("image/png");      /* mime type */
293     s.disposition = WidgetApplicationService::Disposition::INLINE;
294     RUNNER_ASSERT_MSG(
295         std::find(appsvcList.begin(), appsvcList.end(), s) != appsvcList.end(),
296         "Unable to find service ###");
297
298     s.src = DPL::FromUTF8String("edit4.html");
299     s.operation = DPL::FromUTF8String("http://tizen.org/appsvc/operation/send");
300     s.mime = DPL::FromUTF8String("text/css");      /* mime type */
301     s.disposition = WidgetApplicationService::Disposition::WINDOW;
302     RUNNER_ASSERT_MSG(
303         std::find(appsvcList.begin(), appsvcList.end(), s) != appsvcList.end(),
304         "Unable to find service ####");
305 }