[Release] wrt-commons_0.2.145
[framework/web/wrt-commons.git] / tests / dao / TestCases_WidgetDAO.cpp
1 /*
2  * Copyright (c) 2011 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_WidgetDAO.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @version 1.0
20  * @brief   This file contains tests for widget dao class.
21  */
22
23 #include <list>
24 #include <cstdlib>
25 #include <cstdio>
26 #include <string>
27 #include <algorithm>
28 #include <dpl/test/test_runner.h>
29 #include <dpl/foreach.h>
30 #include <dpl/exception.h>
31 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/wrt-dao-ro/wrt_db_types.h>
33 #include <dpl/string.h>
34 #include <wrt_plugin_export.h>
35
36 using namespace WrtDB;
37
38 namespace {
39 class WacSecurityMock : public WrtDB::IWidgetSecurity
40 {
41   public:
42     WacSecurityMock() :
43         mRecognized(false),
44         mDistributorSigned(false)
45     {}
46
47     virtual const WidgetCertificateDataList& getCertificateList() const
48     {
49         return mList;
50     }
51
52     virtual bool isRecognized() const
53     {
54         return mRecognized;
55     }
56     virtual bool isDistributorSigned() const
57     {
58         return mDistributorSigned;
59     }
60     virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {}
61     virtual void getCertificateChainList(CertificateChainList& /*lst*/,
62                                          CertificateSource /*source*/) const {}
63
64     WrtDB::WidgetCertificateDataList& getCertificateListRef()
65     {
66         return mList;
67     }
68
69     void setRecognized(bool recognized)
70     {
71         mRecognized = recognized;
72     }
73     void setDistributorSigned(bool distributorSigned)
74     {
75         mDistributorSigned = distributorSigned;
76     }
77
78   private:
79     WrtDB::WidgetCertificateDataList mList;
80     // author signature verified
81     bool mRecognized;
82     // known distribuor
83     bool mDistributorSigned;
84     // distributor is wac
85 };
86
87 TizenAppId _registerWidget(const WidgetRegisterInfo& regInfo,
88                            const IWidgetSecurity& sec,
89                            int line)
90 {
91     TizenAppId tizenAppId;
92     Try {
93         auto previous = WidgetDAO::getTizenAppidList();
94
95         // register widget
96         tizenAppId = WidgetDAO::registerWidgetGeneratePkgId(regInfo, sec);
97
98         RUNNER_ASSERT_MSG(!tizenAppId.empty(),
99                           "(called from line " << line << ")");
100
101         auto current = WidgetDAO::getTizenAppidList();
102         RUNNER_ASSERT_MSG(previous.size() + 1 == current.size(),
103                           "(called from line " << line << ")");
104
105         RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
106                               tizenAppId),
107                           "(called from line " << line << " tizenAppId: " <<
108                           tizenAppId << ")");
109     }
110     Catch(WidgetDAO::Exception::AlreadyRegistered) {
111         RUNNER_ASSERT_MSG(
112             false,
113             "Unexpected exception (called from line " << line << ")");
114     }
115     return tizenAppId;
116 }
117
118 #define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo), \
119                                                       (sec), \
120                                                       __LINE__)
121 } // namespace
122
123 // Widgets used <2300,2500), 2000, 2001, 2002, 2003
124
125 #define RUNNER_ASSERT_WHAT_EQUALS(in, test)                   \
126     { std::string tmp(in);                                     \
127       RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
128
129 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test)          \
130     {                                                     \
131         if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
132         else { RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in), test); } \
133     }
134
135 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test)                   \
136     {                                                                 \
137         if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); }             \
138         else { RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); } \
139     }
140
141 RUNNER_TEST_GROUP_INIT(DAO)
142
143 //2300
144 /*
145  * Name: widget_dao_test_register_widget_empty_strings
146  * Description: Tests registeration of new widget with empty values
147  * Expected: widget should be registered in database
148  */
149 RUNNER_TEST(widget_dao_test_register_widget_empty_strings)
150 {
151     WidgetRegisterInfo regInfo;
152
153     //ext info
154     regInfo.shareHref = "";
155
156     //info
157     regInfo.configInfo.widget_id = DPL::FromUTF8String("");
158     regInfo.configInfo.version = DPL::FromUTF8String("");
159     regInfo.configInfo.width = 10;
160     regInfo.configInfo.height = 10;
161     regInfo.configInfo.authorName = DPL::FromUTF8String("");
162     regInfo.configInfo.authorEmail = DPL::FromUTF8String("");
163     regInfo.configInfo.authorHref = DPL::FromUTF8String("");
164     regInfo.baseFolder = "";
165     //TODO authenticated, etc...
166     regInfo.configInfo.flashNeeded = false;
167     regInfo.configInfo.minVersionRequired = DPL::FromUTF8String("1.0");
168     regInfo.configInfo.backSupported = true;
169
170     //loc info
171     ConfigParserData::LocalizedData locData;
172     locData.name = DPL::FromUTF8String("");
173     locData.shortName = DPL::FromUTF8String("");
174     locData.description = DPL::FromUTF8String("");
175     locData.license = DPL::FromUTF8String("");
176     locData.licenseFile = DPL::FromUTF8String("");
177     locData.licenseHref = DPL::FromUTF8String("");
178     regInfo.configInfo.localizedDataSet.insert(
179         std::make_pair(DPL::FromUTF8String("en"), locData));
180
181     //userAgentLoc
182
183     //icons
184     ConfigParserData::Icon icon(DPL::FromUTF8String(""));
185     icon.width = 10;
186     icon.height = 10;
187     LocaleSet locs;
188     locs.insert(DPL::FromUTF8String("en"));
189     WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
190     regInfo.localizationData.icons.push_back(locIcon);
191
192     //start file
193     WidgetRegisterInfo::StartFileProperties prop;
194     prop.encoding = DPL::FromUTF8String("");
195     prop.type = DPL::FromUTF8String("");
196     WidgetRegisterInfo::LocalizedStartFile file;
197     file.path = DPL::FromUTF8String("");
198     file.propertiesForLocales.insert(
199         std::make_pair(DPL::FromUTF8String("en"), prop));
200     regInfo.localizationData.startFiles.push_back(file);
201
202     //widget pref
203     ConfigParserData::Preference pref(DPL::FromUTF8String(""), false);
204     pref.value = DPL::FromUTF8String("");
205     regInfo.configInfo.preferencesList.insert(pref);
206
207     //widget feature
208     ConfigParserData::Feature feat(DPL::FromUTF8String(""));
209     regInfo.configInfo.featuresList.insert(feat);
210
211     //win modes
212     regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
213
214     //WARP info
215     ConfigParserData::AccessInfo access(DPL::FromUTF8String(""), true);
216     regInfo.configInfo.accessInfoSet.insert(access);
217
218     //certificates
219     WidgetCertificateData cert;
220     cert.owner = WidgetCertificateData::AUTHOR;
221     cert.type = WidgetCertificateData::ROOT;
222     cert.chainId = 1;
223     cert.strMD5Fingerprint = "";
224     cert.strSHA1Fingerprint = "";
225     cert.strCommonName = DPL::FromUTF8String("");
226
227     WacSecurityMock security;
228     security.getCertificateListRef().push_back(cert);
229
230     REGISTER_WIDGET(regInfo, security);
231 }
232
233 /*
234  * Name: widget_dao_test_register_widget_empty_strings
235  * Description: Tests possiblity of registering twice same content (different
236  * tizenId)
237  * Expected: it should be possible
238  */
239 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
240 {
241     WacSecurityMock sec;
242     {
243         WidgetRegisterInfo regInfo;
244         REGISTER_WIDGET(regInfo, sec);
245     }
246     {
247         WidgetRegisterInfo regInfo;
248         REGISTER_WIDGET(regInfo, sec);
249     }
250 }
251
252 /*
253  * Name: widget_dao_test_register_widget_minimum_info
254  * Description: Tests simplest registeration of new widget
255  * Expected: widget should be registered in database
256  */
257 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
258 {
259     WacSecurityMock sec;
260     const std::size_t NUMBER_OF_WIDGETS = 5;
261
262     TizenAppId lastTizenAppId;
263
264     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
265         WidgetRegisterInfo regInfo;
266         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
267
268         lastTizenAppId = tizenAppId;
269
270         WidgetDAO dao(tizenAppId);
271         //TODO check nulls
272     }
273 }
274
275 /*
276  * Name: widget_dao_test_register_widget_info
277  * Description: Tests registeration of many widgets
278  * Expected: all widgets should be registered in database
279  */
280 RUNNER_TEST(widget_dao_test_register_widget_info)
281 {
282     WacSecurityMock sec;
283     const std::size_t NUMBER_OF_WIDGETS = 5;
284
285     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
286         std::ostringstream str;
287         str << "register_info_test_" << number;
288
289         WidgetRegisterInfo regInfo;
290         regInfo.configInfo.widget_id = DPL::FromUTF8String(str.str());
291         regInfo.configInfo.version = DPL::FromUTF8String(str.str());
292         regInfo.configInfo.width = 10;
293         regInfo.configInfo.height = 10;
294         regInfo.configInfo.authorName = DPL::FromUTF8String(str.str());
295         regInfo.configInfo.authorEmail = DPL::FromUTF8String(str.str());
296         regInfo.configInfo.authorHref = DPL::FromUTF8String(str.str());
297         regInfo.baseFolder = str.str(); //base folder at the end has /
298         regInfo.configInfo.flashNeeded = false;
299         //TODO authenticated, etc...
300         //in wrt-installer: TaskWidgetConfig::fillWidgetConfig:
301         //regInfo.minVersion = regInfo.configInfo.minVersionRequired
302         regInfo.minVersion = DPL::FromUTF8String("1.0");
303         regInfo.configInfo.backSupported = true;
304
305         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
306
307         WidgetDAO dao(tizenAppId);
308         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), str.str());
309         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), str.str());
310         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), str.str());
311         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), str.str());
312         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), str.str());
313         RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), str.str() + "/");
314         RUNNER_ASSERT(dao.getWebkitPluginsRequired() == false);
315         //        RUNNER_ASSERT(
316         //            dao.GetWidgetSecurityDomain() == WacSecurity::Trusted);
317         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
318     }
319 }
320
321 /*
322  * Name: widget_dao_test_register_widget_extended_info
323  * Description: Tests registeration of widget_extended_info
324  * Expected: registeration of extended inforamtion is checked
325  * via existence of backgroudn page value
326  */
327 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
328 {
329     WacSecurityMock sec;
330     const std::size_t NUMBER_OF_WIDGETS = 5;
331
332     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
333         std::ostringstream str;
334         str << "register_ext_info_test_" << number;
335
336         WidgetRegisterInfo regInfo;
337
338         //        regInfo.shareHref = str.str();
339         regInfo.configInfo.backgroundPage = L"background.html";
340
341         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
342
343         WidgetDAO dao(tizenAppId);
344         //        RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
345
346         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
347                                            "background.html");
348     }
349 }
350
351 /*
352  * Name: widget_dao_test_register_widget_localized_info
353  * Description: Tests registeration of localized widgets information
354  * Expected: values received by dao should match those which were registered
355  */
356 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
357 {
358     WacSecurityMock sec;
359     const std::size_t NUMBER_OF_WIDGETS = 5;
360
361     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
362         WidgetRegisterInfo regInfo;
363         std::ostringstream str_en;
364         std::ostringstream str_pl;
365         str_en << "register_loc_info_test_en_" << number;
366         str_pl << "register_loc_info_test_pl_" << number;
367         { //EN
368             ConfigParserData::LocalizedData locDataEn;
369             locDataEn.name = DPL::FromUTF8String(str_en.str());
370             locDataEn.shortName = DPL::FromUTF8String(str_en.str());
371             locDataEn.description = DPL::FromUTF8String(str_en.str());
372             locDataEn.license = DPL::FromUTF8String(str_en.str());
373             locDataEn.licenseFile = DPL::FromUTF8String(str_en.str());
374             locDataEn.licenseHref = DPL::FromUTF8String(str_en.str());
375             regInfo.configInfo.localizedDataSet.insert(
376                 std::make_pair(DPL::FromUTF8String("en"), locDataEn));
377         }
378
379         { //PL
380             ConfigParserData::LocalizedData locDataPl;
381             locDataPl.name = DPL::FromUTF8String(str_pl.str());
382             locDataPl.shortName = DPL::FromUTF8String(str_pl.str());
383             locDataPl.description = DPL::FromUTF8String(str_pl.str());
384             locDataPl.license = DPL::FromUTF8String(str_pl.str());
385             locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str());
386             locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str());
387             regInfo.configInfo.localizedDataSet.insert(
388                 std::make_pair(DPL::FromUTF8String("pl"), locDataPl));
389         }
390
391         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
392
393         WidgetDAO dao(tizenAppId);
394         RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
395                           "language tags list invalid");
396
397         { //EN
398             WidgetLocalizedInfo locInfo =
399                 dao.getLocalizedInfo(DPL::FromUTF8String("en"));
400
401             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
402                                                str_en.str());
403             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
404                                                str_en.str());
405             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
406                                                str_en.str());
407             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
408                                                str_en.str());
409             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
410                                                str_en.str());
411         }
412
413         { //PL
414             WidgetLocalizedInfo locInfo =
415                 dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
416
417             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
418                                                str_pl.str());
419             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
420                                                str_pl.str());
421             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
422                                                str_pl.str());
423             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
424                                                str_pl.str());
425             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
426                                                str_pl.str());
427         }
428     }
429 }
430
431 /*
432  * Name: widget_dao_test_register_widget_icons
433  * Description: Tests registeration of localized icons information
434  * Expected: values received by dao should match those which were registered
435  * for icon
436  */
437 RUNNER_TEST(widget_dao_test_register_widget_icons)
438 {
439     WacSecurityMock sec;
440     WidgetRegisterInfo regInfo;
441
442     ConfigParserData::Icon icon(L"icon1");
443     icon.width = 10;
444     icon.height = 10;
445     LocaleSet locs;
446     locs.insert(DPL::FromUTF8String("en"));
447     WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
448     regInfo.localizationData.icons.push_back(locIcon);
449
450     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
451
452     WidgetDAO dao(tizenAppId);
453     WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
454
455     RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size());
456     WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin();
457     WidgetRegisterInfo::LocalizedIconList::const_iterator it2 =
458         regInfo.localizationData.icons.begin();
459     for (; it1 != list.end() && it2 != regInfo.localizationData.icons.end();
460          ++it1, ++it2)
461     {
462         RUNNER_ASSERT(it2->height == it1->iconHeight);
463         RUNNER_ASSERT(it2->width == it1->iconWidth);
464         RUNNER_ASSERT(it2->src == it1->iconSrc);
465         RUNNER_ASSERT(it2->availableLocales == locs);
466     }
467 }
468
469 /*
470  * Name: widget_dao_test_register_widget_start_files
471  * Description: Tests registeration of localized start files
472  * Expected: no expectations as it should be removed
473  */
474 RUNNER_TEST(widget_dao_test_register_widget_start_files)
475 {
476     WacSecurityMock sec;
477
478     WidgetRegisterInfo::LocalizedStartFileList files;
479     WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
480     WidgetRegisterInfo::StartFileProperties prop1;
481     prop1.encoding = DPL::FromUTF8String("enc1");
482     prop1.type = DPL::FromUTF8String("type1");
483
484     map1.insert(std::make_pair(DPL::FromUTF8String("en"), prop1));
485     map1.insert(std::make_pair(DPL::FromUTF8String("pl"), prop1));
486
487     WidgetRegisterInfo::LocalizedStartFile file1;
488     WidgetRegisterInfo::LocalizedStartFile file2;
489     file1.path = DPL::FromUTF8String("path1");
490     file1.propertiesForLocales = map1;
491     file2.path = DPL::FromUTF8String("path2");
492     file2.propertiesForLocales = map1;
493
494     files.push_back(file1);
495     files.push_back(file1);
496
497     WidgetRegisterInfo regInfo;
498     regInfo.localizationData.startFiles = files;
499
500     REGISTER_WIDGET(regInfo, sec);
501
502     //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
503     // but it will be removed
504 }
505
506 /*
507  * Name: widget_dao_test_register_widget_features
508  * Description: Tests registeration of features of widget
509  * Expected: number of features should match (for given widget reginfo)
510  */
511 RUNNER_TEST(widget_dao_test_register_widget_features)
512 {
513     WacSecurityMock sec;
514     ConfigParserData::FeaturesList features;
515     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1")));
516     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2")));
517     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3")));
518
519     WidgetRegisterInfo regInfo;
520     FOREACH(it, features)
521     regInfo.configInfo.featuresList.insert(*it);
522
523     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
524
525     WidgetDAO dao(tizenAppId);
526     WidgetFeatureSet out = dao.getFeaturesList();
527     RUNNER_ASSERT_MSG(out.size() == features.size(),
528                       "wrong number of features");
529     //    FOREACH(it, out)
530     //        RUNNER_ASSERT(features.find(*it) != features.end());
531 }
532
533 /*
534  * Name: widget_dao_test_register_widget_security_settings
535  * Description: Tests registeration of dafault values of security settings
536  * Expected: widget should be registered in database.
537  * Returned values should match dafault.
538  */
539 RUNNER_TEST(widget_dao_test_register_widget_security_settings)
540 {
541     WacSecurityMock sec;
542     WidgetRegisterInfo regInfo;
543     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
544
545     WidgetDAO dao(tizenAppId);
546     RUNNER_ASSERT_MSG(
547         dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_ON,
548         "SecurityPopupUsage is not deafult on");
549     RUNNER_ASSERT_MSG(
550         dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
551         "GeolocationUsage is not deafult on");
552     RUNNER_ASSERT_MSG(
553         dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
554         "WebNotificationUsage is not deafult on");
555     RUNNER_ASSERT_MSG(
556         dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
557         "WebDatabaseUsage is not deafult on");
558
559     dao.setSecurityPopupUsage(WrtDB::SETTINGS_TYPE_OFF);
560     RUNNER_ASSERT_MSG(
561         dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
562         "SecurityPopupUsage - wrong value");
563     RUNNER_ASSERT_MSG(
564         dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
565         "GeolocationUsage - wrong value");
566     RUNNER_ASSERT_MSG(
567         dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
568         "WebNotificationUsage - wrong value");
569     RUNNER_ASSERT_MSG(
570         dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
571         "WebDatabaseUsage - wrong value");
572
573     dao.setGeolocationUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
574     RUNNER_ASSERT_MSG(
575         dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
576         "SecurityPopupUsage - wrong value");
577     RUNNER_ASSERT_MSG(
578         dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
579         "GeolocationUsage - wrong value");
580     RUNNER_ASSERT_MSG(
581         dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
582         "WebNotificationUsage - wrong value");
583     RUNNER_ASSERT_MSG(
584         dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
585         "WebDatabaseUsage - wrong value");
586
587     dao.setWebNotificationUsage(WrtDB::SETTINGS_TYPE_OFF);
588     RUNNER_ASSERT_MSG(
589         dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
590         "SecurityPopupUsage - wrong value");
591     RUNNER_ASSERT_MSG(
592         dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
593         "GeolocationUsage - wrong value");
594     RUNNER_ASSERT_MSG(
595         dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
596         "WebNotificationUsage - wrong value");
597     RUNNER_ASSERT_MSG(
598         dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
599         "WebDatabaseUsage - wrong value");
600
601     dao.setWebDatabaseUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
602     RUNNER_ASSERT_MSG(
603         dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
604         "SecurityPopupUsage - wrong value");
605     RUNNER_ASSERT_MSG(
606         dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
607         "GeolocationUsage - wrong value");
608     RUNNER_ASSERT_MSG(
609         dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
610         "WebNotificationUsage - wrong value");
611     RUNNER_ASSERT_MSG(
612         dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
613         "WebDatabaseUsage - wrong value");
614 }
615
616 /*
617  * Name: widget_dao_test_register_widget_win_modes
618  * Description: Tests registeration of window modes
619  * Expected: all modes should be returned from dao
620  */
621 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
622 {
623     WacSecurityMock sec;
624     std::set<DPL::String> modes;
625     modes.insert(DPL::FromUTF8String("full"));
626     modes.insert(DPL::FromUTF8String("window"));
627
628     WidgetRegisterInfo regInfo;
629
630     FOREACH(it, modes)
631     regInfo.configInfo.windowModes.insert(*it);
632
633     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
634
635     WidgetDAO dao(tizenAppId);
636     std::list<DPL::String> wins = dao.getWindowModes();
637     RUNNER_ASSERT_MSG(modes.size() == wins.size(),
638                       "wrong number of window modes");
639     FOREACH(it, wins)
640     RUNNER_ASSERT(modes.find(*it) != modes.end());
641 }
642
643 /*
644  * Name: widget_dao_test_register_widget_warp_info
645  * Description: Tests registeration of access info iris
646  * Expected: all access info iris should be returned from dao
647  */
648 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
649 {
650     WacSecurityMock sec;
651     ConfigParserData::AccessInfoSet orig;
652     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
653                                              true));
654     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
655                                              false));
656     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
657                                              true));
658
659     WidgetRegisterInfo regInfo;
660     FOREACH(it, orig)
661     regInfo.configInfo.accessInfoSet.insert(*it);
662
663     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
664
665     WidgetDAO dao(tizenAppId);
666
667     WidgetAccessInfoList out;
668     dao.getWidgetAccessInfo(out);
669     RUNNER_ASSERT_MSG(out.size() == orig.size(),
670                       "wrong number of access info elem");
671     FOREACH(it, out){
672         ConfigParserData::AccessInfo tmp(it->strIRI, it->bSubDomains);
673         RUNNER_ASSERT(orig.find(tmp) != orig.end());
674     }
675 }
676
677 /*
678  * Name: widget_dao_test_register_widget_certificates
679  * Description: Tests registeration of widget certificates
680  * Expected: all certificates should be returned from dao
681  * and should contain inserted data
682  */
683 RUNNER_TEST(widget_dao_test_register_widget_certificates)
684 {
685     WacSecurityMock sec;
686     WidgetRegisterInfo regInfo;
687
688     WidgetCertificateData cert;
689     cert.owner = WidgetCertificateData::AUTHOR;
690     cert.type = WidgetCertificateData::ROOT;
691     cert.chainId = 1;
692     cert.strMD5Fingerprint = "md5";
693     cert.strSHA1Fingerprint = "sha1";
694     cert.strCommonName = DPL::FromUTF8String("common name");
695
696     WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
697     certListRef.push_back(cert);
698
699     // register widget
700     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
701
702     WidgetDAO dao(tizenAppId);
703
704     // certificates
705     WidgetCertificateDataList recList = dao.getCertificateDataList();
706     RUNNER_ASSERT(recList.size() == certListRef.size());
707
708     auto recListIt = recList.begin();
709     auto certListIt = certListRef.begin();
710     for (; recListIt != recList.end() && certListIt != certListRef.end();
711          ++recListIt, ++certListIt)
712     {
713         RUNNER_ASSERT(recListIt->chainId == certListIt->chainId);
714         RUNNER_ASSERT(recListIt->owner == certListIt->owner);
715         RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName);
716         RUNNER_ASSERT(recListIt->strMD5Fingerprint ==
717                       certListIt->strMD5Fingerprint);
718         RUNNER_ASSERT(recListIt->strSHA1Fingerprint ==
719                       certListIt->strSHA1Fingerprint);
720         RUNNER_ASSERT(recListIt->type == certListIt->type);
721     }
722
723     // fingerprints
724     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
725                                          WidgetCertificateData::ENDENTITY).
726                       empty());
727     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
728                                          WidgetCertificateData::ENDENTITY).
729                       empty());
730     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
731                                          WidgetCertificateData::ROOT).empty());
732
733     FingerPrintList fingerprints = dao.getKeyFingerprints(
734             WidgetCertificateData::AUTHOR,
735             WidgetCertificateData::ROOT);
736
737     RUNNER_ASSERT(fingerprints.size() == certListRef.size() * 2);
738     FOREACH(it, certListRef)
739     {
740         auto md5 = std::find(fingerprints.begin(),
741                              fingerprints.end(),
742                              it->strMD5Fingerprint);
743         RUNNER_ASSERT(md5 != fingerprints.end());
744
745         auto sha = std::find(fingerprints.begin(),
746                              fingerprints.end(),
747                              it->strSHA1Fingerprint);
748         RUNNER_ASSERT(sha != fingerprints.end());
749     }
750
751     // common names
752     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
753                                            WidgetCertificateData::ENDENTITY).
754                       empty());
755     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
756                                            WidgetCertificateData::ENDENTITY).
757                       empty());
758     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
759                                            WidgetCertificateData::ROOT).empty());
760
761     FingerPrintList commonNames = dao.getKeyCommonNameList(
762             WidgetCertificateData::AUTHOR,
763             WidgetCertificateData::ROOT);
764
765     RUNNER_ASSERT(commonNames.size() == certListRef.size());
766     FOREACH(it, certListRef)
767     {
768         auto cn = std::find(commonNames.begin(),
769                             commonNames.end(),
770                             DPL::ToUTF8String(it->strCommonName));
771         RUNNER_ASSERT(cn != commonNames.end());
772     }
773 }
774
775 /*
776  * Name: widget_dao_test_register_widget_privileges
777  * Description: Tests registration of widget privileges
778  */
779 RUNNER_TEST(widget_dao_test_register_widget_privileges)
780 {
781
782     WacSecurityMock sec;
783     WidgetRegisterInfo regInfo;
784
785     ConfigParserData::PrivilegeList& privilegeList =
786             regInfo.configInfo.privilegeList;
787     privilegeList.insert(DPL::FromUTF8String("name"));
788     privilegeList.insert(DPL::FromUTF8String("name2"));
789
790     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
791     WidgetDAO dao(tizenAppId);
792
793     WrtDB::PrivilegeList privListFromDB;
794     privListFromDB = dao.getWidgetPrivilege();
795
796     RUNNER_ASSERT(privilegeList.size() == privListFromDB.size());
797
798     auto privListIt = privilegeList.begin();
799     auto privDBIt = privListFromDB.begin();
800     for(; privListIt != privilegeList.end() && privDBIt != privListFromDB.end();
801             ++privListIt, ++privDBIt)
802     {
803         RUNNER_ASSERT(*privDBIt == privListIt->name);
804     }
805 }
806
807 /*
808  * Name: widget_dao_test_register_app_control
809  * Description: Tests app control
810  */
811 RUNNER_TEST(widget_dao_test_register_app_control)
812 {
813     WacSecurityMock sec;
814     WidgetRegisterInfo regInfo;
815
816     ConfigParserData::AppControlInfo appControl(DPL::FromUTF8String("operation"));
817     appControl.m_disposition
818             = ConfigParserData::AppControlInfo::Disposition::WINDOW;
819     appControl.m_mimeList.insert(DPL::FromUTF8String("mime"));
820     appControl.m_src = DPL::FromUTF8String("src");
821     appControl.m_uriList.insert(DPL::FromUTF8String("uri"));
822
823     ConfigParserData::AppControlInfoList& appControlListRef
824             = regInfo.configInfo.appControlList;
825     appControlListRef.push_back(appControl);
826
827     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
828
829     WidgetDAO dao(tizenAppId);
830
831     WrtDB::WidgetAppControlList appControlInfoListDB;
832     dao.getAppControlList(appControlInfoListDB);
833     RUNNER_ASSERT(appControlInfoListDB.size() == appControlListRef.size());
834     auto appDBIt = appControlInfoListDB.begin();
835     auto appRefIt = appControlListRef.begin();
836
837     for (;appDBIt != appControlInfoListDB.end()
838             && appRefIt != appControlListRef.end();
839             ++appDBIt, ++appRefIt)
840     {
841         RUNNER_ASSERT((WidgetAppControl::Disposition)
842                 appRefIt->m_disposition == appDBIt->disposition);
843         RUNNER_ASSERT(appRefIt->m_index == appDBIt->index);
844         RUNNER_ASSERT(appRefIt->m_operation == appDBIt->operation);
845         RUNNER_ASSERT(appRefIt->m_src == appDBIt->src);
846         for(auto it = appRefIt->m_mimeList.begin();
847                 it != appRefIt->m_mimeList.end();
848                 ++it)
849         {
850             RUNNER_ASSERT((*it) == appDBIt->mime);
851         }
852         for(auto it = appRefIt->m_uriList.begin();
853                 it != appRefIt->m_uriList.end();
854                 ++it)
855         {
856             RUNNER_ASSERT((*it) == appDBIt->uri);
857         }
858     }
859 }
860
861 /*
862  * Name: widget_dao_test_is_widget_installed
863  * Description: Tests checking if widgets are installed
864  * Expected: installed widgets should be stated as installed
865  */
866 RUNNER_TEST(widget_dao_test_is_widget_installed)
867 {
868     RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
869
870     WacSecurityMock sec;
871     WidgetRegisterInfo regInfo;
872
873     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
874
875     RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(tizenAppId));
876 }
877
878 /*
879  * Name: widget_dao_test_unregister_widget
880  * Description: Tests unregistering widgets
881  * Expected: widget register informations should be successfully removed
882  */
883 RUNNER_TEST(widget_dao_test_unregister_widget)
884 {
885     WacSecurityMock sec;
886     WidgetHandleList handles = WidgetDAO::getHandleList();
887
888     WidgetRegisterInfo regInfo;
889
890     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
891
892     WidgetDAO::unregisterWidget(tizenAppId);
893
894     RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
895                       "Widget unregister failed");
896 }
897
898 /*
899  * Name: widget_dao_test_register_or_update_widget
900  * Description: Tests reregistering widgets
901  * Expected: widget should be successfully replaced
902  */
903 RUNNER_TEST(widget_dao_test_register_or_update_widget)
904 {
905     WacSecurityMock sec;
906
907     WidgetRegisterInfo regInfo;
908     regInfo.configInfo.version = L"1.0";
909     regInfo.configInfo.authorName = L"AAA";
910
911     WidgetRegisterInfo regInfo2;
912     regInfo2.configInfo.version = L"1.1";
913     regInfo2.configInfo.authorName = L"BBB";
914
915     WrtDB::TizenAppId tizenAppId(L"abcdefghij");
916
917     //first installation
918     WidgetDAO::registerWidget(tizenAppId, regInfo, sec);
919     RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
920                           tizenAppId), "Widget is not registered");
921
922     //success full update
923     WidgetDAO::updateTizenAppId(tizenAppId, L"backup");
924     WidgetDAO::registerWidget(tizenAppId, regInfo2, sec);
925     WidgetDAO::unregisterWidget(L"backup");
926     RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
927                           tizenAppId), "Widget is not reregistered");
928     WidgetDAO dao(tizenAppId);
929     RUNNER_ASSERT_MSG(
930         *dao.getVersion() == L"1.1", "Data widget was not updated");
931     RUNNER_ASSERT_MSG(
932         *dao.getAuthorName() == L"BBB", "Data widget was not updated");
933
934
935     WidgetDAO::unregisterWidget(tizenAppId);
936 }
937
938 /*
939  * Name: widget_dao_test_get_widget_tizenAppId_list
940  * Description: Tests getTizenAppidList API for backendlib
941  * Expected: For all position in database should be returned one item in list
942  */
943 RUNNER_TEST(widget_dao_test_get_widget_tizenAppId_list)
944 {
945     TizenAppIdList tizenAppIds = WidgetDAO::getTizenAppidList();
946     RUNNER_ASSERT(tizenAppIds.size() >= 3);
947 }
948
949 /*
950  * Name: widget_dao_test_get_widget_list
951  * Description: Tests getTizenAppidList API for backendlib
952  * Expected: For all position in database should be returned one item in list
953  * Those item should contain valid tizenAppId
954  */
955 RUNNER_TEST(widget_dao_test_get_widget_list)
956 {
957     WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList();
958     RUNNER_ASSERT(list.size() >= 3);
959     RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists");
960     WidgetDAOReadOnlyPtr dao = list.front();
961 }
962
963 /*
964  * Name: widget_dao_test_get_widget_attributes
965  * Description: Tests returning basic widget attributes by dao
966  * Expected: Attributes should match values inserted into database
967  */
968 RUNNER_TEST(widget_dao_test_get_widget_attributes)
969 {
970     {
971         TizenAppId tizenAppId = L"tizenid201";
972         WidgetDAO dao(tizenAppId);
973
974         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000");
975         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0");
976         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000");
977         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(),
978                                            "a_email_2000");
979         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000");
980         RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/");
981         RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true);
982         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
983     }
984 }
985
986 /*
987  * Name: widget_dao_test_localization
988  * Description: Tests inserting and returning localization info
989  * Expected: Values inserted into database should match values received from
990  * database
991  */
992 RUNNER_TEST(widget_dao_test_localization)
993 {
994     WacSecurityMock sec;
995
996     // icon
997     WidgetRegisterInfo regInfo;
998     ConfigParserData::Icon icon(L"icon1");
999     icon.width = 10;
1000     icon.height = 10;
1001     LocaleSet locs;
1002     locs.insert(DPL::FromUTF8String("en"));
1003     locs.insert(DPL::FromUTF8String("pl"));
1004     WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
1005     regInfo.localizationData.icons.push_back(locIcon);
1006
1007     //start file
1008     WidgetRegisterInfo::StartFileProperties prop_en;
1009     prop_en.encoding = DPL::FromUTF8String("encoding_en");
1010     prop_en.type = DPL::FromUTF8String("type_en");
1011
1012     WidgetRegisterInfo::StartFileProperties prop_pl;
1013     prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
1014     prop_pl.type = DPL::FromUTF8String("type_pl");
1015
1016     WidgetRegisterInfo::LocalizedStartFile file;
1017     file.path = DPL::FromUTF8String("path");
1018     file.propertiesForLocales.insert(
1019         std::make_pair(DPL::FromUTF8String("en"), prop_en));
1020     file.propertiesForLocales.insert(
1021         std::make_pair(DPL::FromUTF8String("pl"), prop_pl));
1022     regInfo.localizationData.startFiles.push_back(file);
1023
1024     // register widget
1025     TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1026
1027     WidgetDAO dao(tizenAppId);
1028
1029     // check localized icons
1030     WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
1031     RUNNER_ASSERT(locList.size() == locs.size());
1032
1033     // non-localized icon
1034     WidgetDAO::WidgetIconList list = dao.getIconList();
1035     int iconId = list.front().iconId;
1036
1037     // compare every icon with the origin
1038     auto locsIt = locs.begin();
1039     auto iconIt = locList.begin();
1040     for (; locsIt != locs.end() && iconIt != locList.end(); ++locsIt,
1041          ++iconIt)
1042     {
1043         RUNNER_ASSERT(iconIt->appId == dao.getHandle());
1044         RUNNER_ASSERT(iconIt->iconId == iconId);
1045         RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
1046     }
1047
1048     // localized start file list
1049     WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
1050     RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
1051
1052     int startFileId = dao.getStartFileList().front().startFileId;
1053
1054     FOREACH(it, fList)
1055     {
1056         RUNNER_ASSERT(it->appId == dao.getHandle());
1057         auto propIt = file.propertiesForLocales.find(it->widgetLocale);
1058         RUNNER_ASSERT(propIt != file.propertiesForLocales.end());
1059         RUNNER_ASSERT(it->encoding == propIt->second.encoding);
1060         RUNNER_ASSERT(it->type == propIt->second.type);
1061         RUNNER_ASSERT(it->startFileId == startFileId);
1062     }
1063 }
1064
1065 /*
1066  * Name: widget_dao_test_wac_security
1067  * Description: Tests inserting and returning wac security information
1068  * Expected: Values inserted into database should match values received from
1069  * database
1070  */
1071 RUNNER_TEST(widget_dao_test_wac_security)
1072 {
1073     WacSecurityMock sec;
1074     WidgetRegisterInfo regInfo;
1075     {
1076         // register widget
1077         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1078         WidgetDAO dao(tizenAppId);
1079
1080         RUNNER_ASSERT(!dao.isDistributorSigned());
1081         RUNNER_ASSERT(!dao.isRecognized());
1082     }
1083     sec.setDistributorSigned(true);
1084     sec.setRecognized(true);
1085     {
1086         // register widget
1087         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1088         WidgetDAO dao(tizenAppId);
1089
1090         RUNNER_ASSERT(dao.isDistributorSigned());
1091         RUNNER_ASSERT(dao.isRecognized());
1092     }
1093 }
1094
1095 /*
1096  * Name: widget_dao_test_register_scp
1097  * Description: Tests inserting and returning scp policy information
1098  * Expected: Value inserted into database should match values received from
1099  * database
1100  */
1101 RUNNER_TEST(widget_dao_test_register_scp)
1102 {
1103     WacSecurityMock sec;
1104     WidgetRegisterInfo regInfo;
1105     DPL::OptionalString policy = DPL::FromUTF8String("Some awesome csp policy");
1106     regInfo.configInfo.cspPolicy = policy;
1107     {
1108         // register widget
1109         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1110         WidgetDAO dao(tizenAppId);
1111
1112         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
1113             dao.getCspPolicy(), DPL::ToUTF8String(*policy));
1114     }
1115 }
1116
1117 /*
1118  * Name: widget_dao_test_register_csp_empty
1119  * Description: Tests inserting and returning empty csp policy
1120  * Expected: Value inserted into database should match values received from
1121  * database
1122  */
1123 RUNNER_TEST(widget_dao_test_register_csp_empty)
1124 {
1125     WacSecurityMock sec;
1126     WidgetRegisterInfo regInfo;
1127     {
1128         // register widget
1129         TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1130         WidgetDAO dao(tizenAppId);
1131
1132         RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
1133     }
1134 }
1135 #undef RUNNER_ASSERT_WHAT_EQUALS