c04752ab3a89fe689055ca8cae4ba1cfeb5d37c7
[platform/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
40 class WacSecurityMock : public WrtDB::IWacSecurity
41 {
42 public:
43     WacSecurityMock() :
44         mRecognized(false),
45         mDistributorSigned(false),
46         mWacSigned(false)
47     {
48     }
49
50     virtual const WidgetCertificateDataList& getCertificateList() const
51     {
52         return mList;
53     }
54
55     virtual bool isRecognized() const { return mRecognized; }
56     virtual bool isDistributorSigned() const { return mDistributorSigned; }
57     virtual bool isWacSigned() const { return mWacSigned; }
58     virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {}
59     virtual void getCertificateChainList(CertificateChainList& /*lst*/,
60         CertificateSource source) const {}
61
62     WrtDB::WidgetCertificateDataList& getCertificateListRef()
63     {
64         return mList;
65     }
66
67     void setRecognized(bool recognized) { mRecognized = recognized; }
68     void setDistributorSigned(bool distributorSigned)
69     {
70         mDistributorSigned = distributorSigned;
71     }
72     void setWacSigned(bool wacSigned) { mWacSigned = wacSigned; }
73
74 private:
75     WrtDB::WidgetCertificateDataList mList;
76     // author signature verified
77     bool mRecognized;
78     // known distribuor
79     bool mDistributorSigned;
80     // distributor is wac
81     bool mWacSigned;
82
83 };
84
85 WidgetPkgName _registerWidget(const WidgetRegisterInfo& regInfo,
86                              const IWacSecurity& sec,
87                              int line)
88 {
89     WidgetPkgName pkgname;
90     Try {
91         auto previous = WidgetDAO::getPkgnameList();
92
93         // register widget
94         pkgname = WidgetDAO::registerWidgetGenerateTizenId(regInfo, sec);
95
96         RUNNER_ASSERT_MSG(!pkgname.empty(),
97                           "(called from line " << line << ")");
98
99         auto current = WidgetDAO::getPkgnameList();
100         RUNNER_ASSERT_MSG(previous.size()+1 == current.size(),
101                           "(called from line " << line << ")");
102
103         RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname),
104                           "(called from line " << line << " pkgname: " << pkgname << ")");
105     }
106     Catch (WidgetDAO::Exception::AlreadyRegistered) {
107         RUNNER_ASSERT_MSG(
108                 false,
109                 "Unexpected exception (called from line " << line << ")");
110     }
111     return pkgname;
112 }
113
114 #define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo),(sec), __LINE__)
115
116 } // namespace
117
118 // Widgets used <2300,2500), 2000, 2001, 2002, 2003
119
120 #define RUNNER_ASSERT_WHAT_EQUALS(in, test)                   \
121     {std::string tmp(in);                                     \
122     RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");}
123
124 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test)          \
125         {                                                     \
126             if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \
127             else RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in),test);\
128         }
129
130 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test)                   \
131         {                                                                 \
132             if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL");             \
133             else RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); \
134         }
135
136 RUNNER_TEST_GROUP_INIT(DAO)
137
138 //2300
139 /*
140 Name: widget_dao_test_register_widget_empty_strings
141 Description: Tests registeration of new widget with empty values
142 Expected: widget should be registered in database
143 */
144 RUNNER_TEST(widget_dao_test_register_widget_empty_strings)
145 {
146     WidgetRegisterInfo regInfo;
147
148     //ext info
149     regInfo.shareHref = "";
150
151     //info
152     regInfo.configInfo.widget_id = DPL::FromUTF8String("");
153     regInfo.configInfo.version = DPL::FromUTF8String("");
154     regInfo.configInfo.width = 10;
155     regInfo.configInfo.height = 10;
156     regInfo.configInfo.authorName = DPL::FromUTF8String("");
157     regInfo.configInfo.authorEmail = DPL::FromUTF8String("");
158     regInfo.configInfo.authorHref = DPL::FromUTF8String("");
159     regInfo.baseFolder = "";
160     //TODO authenticated, etc...
161     regInfo.configInfo.flashNeeded = false;
162     regInfo.configInfo.minVersionRequired = DPL::FromUTF8String("1.0");
163     regInfo.configInfo.backSupported = true;
164
165     //loc info
166     ConfigParserData::LocalizedData locData;
167     locData.name = DPL::FromUTF8String("");
168     locData.shortName = DPL::FromUTF8String("");
169     locData.description = DPL::FromUTF8String("");
170     locData.license = DPL::FromUTF8String("");
171     locData.licenseFile = DPL::FromUTF8String("");
172     locData.licenseHref = DPL::FromUTF8String("");
173     regInfo.configInfo.localizedDataSet.insert(
174             std::make_pair(DPL::FromUTF8String("en"),locData));
175
176     //userAgentLoc
177
178     //icons
179     ConfigParserData::Icon icon(DPL::FromUTF8String(""));
180     icon.width = 10;
181     icon.height = 10;
182     LocaleSet locs;
183     locs.insert(DPL::FromUTF8String("en"));
184     WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
185     regInfo.localizationData.icons.push_back(locIcon);
186
187     //start file
188     WidgetRegisterInfo::StartFileProperties prop;
189     prop.encoding = DPL::FromUTF8String("");
190     prop.type = DPL::FromUTF8String("");
191     WidgetRegisterInfo::LocalizedStartFile file;
192     file.path = DPL::FromUTF8String("");
193     file.propertiesForLocales.insert(
194             std::make_pair(DPL::FromUTF8String("en"), prop));
195     regInfo.localizationData.startFiles.push_back(file);
196
197     //widget pref
198     ConfigParserData::Preference pref(DPL::FromUTF8String(""),false);
199     pref.value = DPL::FromUTF8String("");
200     regInfo.configInfo.preferencesList.insert(pref);
201
202     //widget feature
203     ConfigParserData::Feature feat(DPL::FromUTF8String(""),false);
204     ConfigParserData::Param par(DPL::FromUTF8String(("")));
205     par.value = DPL::FromUTF8String("");
206     feat.paramsList.insert(par);
207     regInfo.configInfo.featuresList.insert(feat);
208
209     //win modes
210     regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
211
212     //WARP info
213     ConfigParserData::AccessInfo access(DPL::FromUTF8String(""),true);
214     regInfo.configInfo.accessInfoSet.insert(access);
215
216     //certificates
217     WidgetCertificateData cert;
218     cert.owner = WidgetCertificateData::AUTHOR;
219     cert.type = WidgetCertificateData::ROOT;
220     cert.chainId = 1;
221     cert.strMD5Fingerprint = "";
222     cert.strSHA1Fingerprint = "";
223     cert.strCommonName = DPL::FromUTF8String("");
224
225     WacSecurityMock security;
226     security.getCertificateListRef().push_back(cert);
227
228     REGISTER_WIDGET(regInfo,security);
229 }
230
231 /*
232 Name: widget_dao_test_register_widget_empty_strings
233 Description: Tests possiblity of registering twice same content (different tizenId)
234 Expected: it should be possible
235 */
236 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
237 {
238     WacSecurityMock sec;
239     {
240         WidgetRegisterInfo regInfo;
241         REGISTER_WIDGET(regInfo, sec);
242     }
243     {
244         WidgetRegisterInfo regInfo;
245         REGISTER_WIDGET(regInfo, sec);
246     }
247
248 }
249
250 /*
251 Name: widget_dao_test_register_widget_minimum_info
252 Description: Tests simplest registeration of new widget
253 Expected: widget should be registered in database
254 */
255 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
256 {
257     WacSecurityMock sec;
258     const std::size_t NUMBER_OF_WIDGETS = 5;
259
260     DPL::Optional<WidgetPkgName> lastPkgname;
261
262     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
263     {
264         WidgetRegisterInfo regInfo;
265         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
266
267         lastPkgname = pkgname;
268
269         WidgetDAO dao(pkgname);
270         //TODO check nulls
271     }
272 }
273
274 /*
275 Name: widget_dao_test_register_widget_info
276 Description: Tests registeration of many widgets
277 Expected: all widgets should be registered in database
278 */
279 RUNNER_TEST(widget_dao_test_register_widget_info)
280 {
281     WacSecurityMock sec;
282     const std::size_t NUMBER_OF_WIDGETS = 5;
283
284     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
285     {
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         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
306
307         WidgetDAO dao(pkgname);
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 /*
323 Name: widget_dao_test_register_widget_extended_info
324 Description: Tests registeration of widget_extended_info
325 Expected: registeration of extended inforamtion is checked
326  via existence of backgroudn page value
327 */
328 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
329 {
330     WacSecurityMock sec;
331     const std::size_t NUMBER_OF_WIDGETS = 5;
332
333     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
334     {
335         std::ostringstream str;
336         str << "register_ext_info_test_" << number;
337
338         WidgetRegisterInfo regInfo;
339
340 //        regInfo.shareHref = str.str();
341         regInfo.configInfo.backgroundPage = L"background.html";
342
343         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
344
345         WidgetDAO dao(pkgname);
346 //        RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
347
348         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
349                 "background.html");
350     }
351 }
352
353 /*
354 Name: widget_dao_test_register_widget_localized_info
355 Description: Tests registeration of localized widgets information
356 Expected: values received by dao should match those which were registered
357 */
358 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
359 {
360     WacSecurityMock sec;
361     const std::size_t NUMBER_OF_WIDGETS = 5;
362
363     for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
364     {
365         WidgetRegisterInfo regInfo;
366         std::ostringstream str_en;
367         std::ostringstream str_pl;
368         str_en << "register_loc_info_test_en_" << number;
369         str_pl<< "register_loc_info_test_pl_"  << number;
370         {//EN
371             ConfigParserData::LocalizedData locDataEn;
372             locDataEn.name = DPL::FromUTF8String(str_en.str());
373             locDataEn.shortName = DPL::FromUTF8String(str_en.str());
374             locDataEn.description = DPL::FromUTF8String(str_en.str());
375             locDataEn.license = DPL::FromUTF8String(str_en.str());
376             locDataEn.licenseFile = DPL::FromUTF8String(str_en.str());
377             locDataEn.licenseHref = DPL::FromUTF8String(str_en.str());
378             regInfo.configInfo.localizedDataSet.insert(
379                     std::make_pair(DPL::FromUTF8String("en"),locDataEn));
380         }
381
382         {//PL
383             ConfigParserData::LocalizedData locDataPl;
384             locDataPl.name = DPL::FromUTF8String(str_pl.str());
385             locDataPl.shortName = DPL::FromUTF8String(str_pl.str());
386             locDataPl.description = DPL::FromUTF8String(str_pl.str());
387             locDataPl.license = DPL::FromUTF8String(str_pl.str());
388             locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str());
389             locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str());
390             regInfo.configInfo.localizedDataSet.insert(
391                     std::make_pair(DPL::FromUTF8String("pl"),locDataPl));
392         }
393
394         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
395
396         WidgetDAO dao(pkgname);
397         RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
398                           "language tags list invalid");
399
400         {//EN
401             WidgetLocalizedInfo locInfo =
402                     dao.getLocalizedInfo(DPL::FromUTF8String("en"));
403
404             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
405                                                str_en.str());
406             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
407                                                str_en.str());
408             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
409                                                str_en.str());
410             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
411                                                str_en.str());
412             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
413                                                str_en.str());
414         }
415
416         {//PL
417             WidgetLocalizedInfo locInfo =
418                     dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
419
420             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
421                                                str_pl.str());
422             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
423                                                str_pl.str());
424             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
425                                                str_pl.str());
426             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
427                                                str_pl.str());
428             RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
429                                                str_pl.str());
430         }
431     }
432 }
433
434 /*
435 Name: widget_dao_test_register_widget_icons
436 Description: Tests registeration of localized icons information
437 Expected: values received by dao should match those which were registered
438  for icon
439 */
440 RUNNER_TEST(widget_dao_test_register_widget_icons)
441 {
442     WacSecurityMock sec;
443     WidgetRegisterInfo regInfo;
444
445     ConfigParserData::Icon icon(L"icon1");
446     icon.width = 10;
447     icon.height = 10;
448     LocaleSet locs;
449     locs.insert(DPL::FromUTF8String("en"));
450     WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
451     regInfo.localizationData.icons.push_back(locIcon);
452
453     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
454
455     WidgetDAO dao(pkgname);
456     WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
457
458     RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size());
459     WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin();
460     WidgetRegisterInfo::LocalizedIconList::const_iterator it2 =
461             regInfo.localizationData.icons.begin();
462     for(;it1!=list.end() && it2!=regInfo.localizationData.icons.end();
463         ++it1,++it2)
464     {
465         RUNNER_ASSERT(it2->height == it1->iconHeight);
466         RUNNER_ASSERT(it2->width == it1->iconWidth);
467         RUNNER_ASSERT(it2->src == it1->iconSrc);
468         RUNNER_ASSERT(it2->availableLocales == locs);
469     }
470 }
471
472 /*
473 Name: widget_dao_test_register_widget_start_files
474 Description: Tests registeration of localized start files
475 Expected: no expectations as it should be removed
476 */
477 RUNNER_TEST(widget_dao_test_register_widget_start_files)
478 {
479     WacSecurityMock sec;
480
481     WidgetRegisterInfo::LocalizedStartFileList files;
482     WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
483     WidgetRegisterInfo::StartFileProperties prop1;
484     prop1.encoding = DPL::FromUTF8String("enc1");
485     prop1.type = DPL::FromUTF8String("type1");
486
487     map1.insert(std::make_pair(DPL::FromUTF8String("en"),prop1));
488     map1.insert(std::make_pair(DPL::FromUTF8String("pl"),prop1));
489
490     WidgetRegisterInfo::LocalizedStartFile file1;
491     WidgetRegisterInfo::LocalizedStartFile file2;
492     file1.path = DPL::FromUTF8String("path1");
493     file1.propertiesForLocales = map1;
494     file2.path = DPL::FromUTF8String("path2");
495     file2.propertiesForLocales = map1;
496
497     files.push_back(file1);
498     files.push_back(file1);
499
500     WidgetRegisterInfo regInfo;
501     regInfo.localizationData.startFiles = files;
502
503     REGISTER_WIDGET(regInfo, sec);
504
505     //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
506     // but it will be removed
507 }
508
509 /*
510 Name: widget_dao_test_register_widget_features
511 Description: Tests registeration of features of widget
512 Expected: number of features should match (for given widget reginfo)
513 */
514 RUNNER_TEST(widget_dao_test_register_widget_features)
515 {
516     WacSecurityMock sec;
517     ConfigParserData::FeaturesList features;
518     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1"),true));
519     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2")));
520     features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3"),
521                                               false));
522
523     WidgetRegisterInfo regInfo;
524     FOREACH(it, features)
525         regInfo.configInfo.featuresList.insert(*it);
526
527     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
528
529     WidgetDAO dao(pkgname);
530     WidgetFeatureSet out = dao.getFeaturesList();
531     RUNNER_ASSERT_MSG(out.size() == features.size(),
532                       "wrong number of features");
533 //    FOREACH(it, out)
534 //        RUNNER_ASSERT(features.find(*it) != features.end());
535 }
536
537 /*
538 Name: widget_dao_test_register_widget_win_modes
539 Description: Tests registeration of window modes
540 Expected: all modes should be returned from dao
541 */
542 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
543 {
544     WacSecurityMock sec;
545     std::set<DPL::String> modes;
546     modes.insert(DPL::FromUTF8String("full"));
547     modes.insert(DPL::FromUTF8String("window"));
548
549     WidgetRegisterInfo regInfo;
550
551     FOREACH(it, modes)
552         regInfo.configInfo.windowModes.insert(*it);
553
554     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
555
556     WidgetDAO dao(pkgname);
557     std::list<DPL::String> wins = dao.getWindowModes();
558     RUNNER_ASSERT_MSG(modes.size() == wins.size(),
559                       "wrong number of window modes");
560     FOREACH(it, wins)
561         RUNNER_ASSERT(modes.find(*it) != modes.end());
562 }
563
564 /*
565 Name: widget_dao_test_register_widget_warp_info
566 Description: Tests registeration of access info iris
567 Expected: all access info iris should be returned from dao
568 */
569 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
570 {
571     WacSecurityMock sec;
572     ConfigParserData::AccessInfoSet orig;
573     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
574                                              true));
575     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
576                                              false));
577     orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
578                                              true));
579
580     WidgetRegisterInfo regInfo;
581     FOREACH(it, orig)
582         regInfo.configInfo.accessInfoSet.insert(*it);
583
584     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
585
586     WidgetDAO dao(pkgname);
587
588     WidgetAccessInfoList out;
589     dao.getWidgetAccessInfo(out);
590     RUNNER_ASSERT_MSG(out.size() == orig.size(),
591                       "wrong number of access info elem");
592     FOREACH(it, out){
593         ConfigParserData::AccessInfo tmp(it->strIRI,it->bSubDomains);
594         RUNNER_ASSERT(orig.find(tmp) != orig.end());
595     }
596 }
597
598 /*
599 Name: widget_dao_test_register_widget_certificates
600 Description: Tests registeration of widget certificates
601 Expected: all certificates should be returned from dao
602  and should contain inserted data
603 */
604 RUNNER_TEST(widget_dao_test_register_widget_certificates)
605 {
606     WacSecurityMock sec;
607     WidgetRegisterInfo regInfo;
608
609     WidgetCertificateData cert;
610     cert.owner = WidgetCertificateData::AUTHOR;
611     cert.type = WidgetCertificateData::ROOT;
612     cert.chainId = 1;
613     cert.strMD5Fingerprint = "md5";
614     cert.strSHA1Fingerprint = "sha1";
615     cert.strCommonName = DPL::FromUTF8String("common name");
616
617     WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
618     certListRef.push_back(cert);
619
620     // register widget
621     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
622
623     WidgetDAO dao(pkgname);
624
625     // certificates
626     WidgetCertificateDataList recList = dao.getCertificateDataList();
627     RUNNER_ASSERT(recList.size() == certListRef.size());
628
629     auto recListIt = recList.begin();
630     auto certListIt = certListRef.begin();
631     for(;recListIt != recList.end() && certListIt != certListRef.end();
632         ++recListIt,++certListIt)
633     {
634         RUNNER_ASSERT(recListIt->chainId == certListIt->chainId);
635         RUNNER_ASSERT(recListIt->owner == certListIt->owner);
636         RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName);
637         RUNNER_ASSERT(recListIt->strMD5Fingerprint ==
638                 certListIt->strMD5Fingerprint);
639         RUNNER_ASSERT(recListIt->strSHA1Fingerprint ==
640                 certListIt->strSHA1Fingerprint);
641         RUNNER_ASSERT(recListIt->type == certListIt->type);
642     }
643
644     // fingerprints
645     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
646             WidgetCertificateData::ENDENTITY).empty());
647     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
648             WidgetCertificateData::ENDENTITY).empty());
649     RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
650             WidgetCertificateData::ROOT).empty());
651
652     FingerPrintList fingerprints = dao.getKeyFingerprints(
653             WidgetCertificateData::AUTHOR,
654             WidgetCertificateData::ROOT);
655
656     RUNNER_ASSERT(fingerprints.size() == certListRef.size()*2);
657     FOREACH(it, certListRef)
658     {
659         auto md5 = std::find(fingerprints.begin(),
660                              fingerprints.end(),
661                              it->strMD5Fingerprint);
662         RUNNER_ASSERT(md5 != fingerprints.end());
663
664         auto sha = std::find(fingerprints.begin(),
665                              fingerprints.end(),
666                              it->strSHA1Fingerprint);
667         RUNNER_ASSERT(sha != fingerprints.end());
668     }
669
670     // common names
671     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
672             WidgetCertificateData::ENDENTITY).empty());
673     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
674             WidgetCertificateData::ENDENTITY).empty());
675     RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
676             WidgetCertificateData::ROOT).empty());
677
678     FingerPrintList commonNames = dao.getKeyCommonNameList(
679             WidgetCertificateData::AUTHOR,
680             WidgetCertificateData::ROOT);
681
682     RUNNER_ASSERT(commonNames.size() == certListRef.size());
683     FOREACH(it, certListRef)
684     {
685         auto cn = std::find(commonNames.begin(),
686                             commonNames.end(),
687                             DPL::ToUTF8String(it->strCommonName));
688         RUNNER_ASSERT(cn != commonNames.end());
689     }
690 }
691
692 /*
693 Name: widget_dao_test_is_widget_installed
694 Description: Tests checking if widgets are installed
695 Expected: installed widgets should be stated as installed
696 */
697 RUNNER_TEST(widget_dao_test_is_widget_installed)
698 {
699     RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
700
701     WacSecurityMock sec;
702     WidgetRegisterInfo regInfo;
703
704     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
705
706     RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(pkgname));
707 }
708
709 /*
710 Name: widget_dao_test_unregister_widget
711 Description: Tests unregistering widgets
712 Expected: widget register informations should be successfully removed
713 */
714 RUNNER_TEST(widget_dao_test_unregister_widget)
715 {
716     WacSecurityMock sec;
717     WidgetHandleList handles = WidgetDAO::getHandleList();
718
719     WidgetRegisterInfo regInfo;
720
721     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
722
723     WidgetDAO::unregisterWidget(pkgname);
724
725     RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
726                       "Widget unregister failed");
727 }
728
729 /*
730 Name: widget_dao_test_register_or_update_widget
731 Description: Tests reregistering widgets
732 Expected: widget should be successfully replaced
733 */
734 RUNNER_TEST(widget_dao_test_register_or_update_widget)
735 {
736     WacSecurityMock sec;
737
738     WidgetRegisterInfo regInfo;
739     regInfo.configInfo.version = L"1.0";
740     regInfo.configInfo.authorName = L"AAA";
741
742     WidgetRegisterInfo regInfo2;
743     regInfo2.configInfo.version = L"1.1";
744     regInfo2.configInfo.authorName = L"BBB";
745
746     WrtDB::WidgetPkgName pkgname(L"abcdefghij");
747
748     //first installation
749     WidgetDAO::registerWidget(pkgname, regInfo, sec);
750     RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not registered");
751
752     //success full update
753     WidgetDAO::registerOrUpdateWidget(pkgname, regInfo2, sec);
754     RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not reregistered");
755     WidgetDAO dao(pkgname);
756     RUNNER_ASSERT_MSG(*dao.getVersion() == L"1.1", "Data widget was not updated");
757     RUNNER_ASSERT_MSG(*dao.getAuthorName() == L"BBB", "Data widget was not updated");
758
759     WidgetDAO::unregisterWidget(pkgname);
760 }
761
762 /*
763 Name: widget_dao_test_get_widget_pkgname_list
764 Description: Tests getPkgnameList API for backendlib
765 Expected: For all position in database should be returned one item in list
766 */
767 RUNNER_TEST(widget_dao_test_get_widget_pkgname_list)
768 {
769     WidgetPkgNameList pkgnames = WidgetDAO::getPkgnameList();
770     RUNNER_ASSERT(pkgnames.size() >= 3);
771 }
772
773 /*
774 Name: widget_dao_test_get_widget_list
775 Description: Tests getPkgnameList API for backendlib
776 Expected: For all position in database should be returned one item in list
777  Those item should contain valid pkgname
778 */
779 RUNNER_TEST(widget_dao_test_get_widget_list)
780 {
781     WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList();
782     RUNNER_ASSERT(list.size() >= 3);
783     RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists");
784     WidgetDAOReadOnlyPtr dao = list.front();
785     RUNNER_ASSERT_MSG(!dao->getPkgname().IsNull(), "dao object do not have tizen id");
786 }
787
788 /*
789 Name: widget_dao_test_get_widget_attributes
790 Description: Tests returning basic widget attributes by dao
791 Expected: Attributes should match values inserted into database
792 */
793 RUNNER_TEST(widget_dao_test_get_widget_attributes)
794 {
795     {
796         WidgetPkgName pkgname = L"tizenid201";
797         WidgetDAO dao(pkgname);
798
799         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000");
800         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0");
801         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000");
802         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(),
803                                            "a_email_2000");
804         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000");
805         RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/");
806         RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true);
807         RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
808     }
809 }
810
811 /*
812 Name: widget_dao_test_localization
813 Description: Tests inserting and returning localization info
814 Expected: Values inserted into database should match values received from database
815 */
816 RUNNER_TEST(widget_dao_test_localization)
817 {
818     WacSecurityMock sec;
819
820     // icon
821     WidgetRegisterInfo regInfo;
822     ConfigParserData::Icon icon(L"icon1");
823     icon.width = 10;
824     icon.height = 10;
825     LocaleSet locs;
826     locs.insert(DPL::FromUTF8String("en"));
827     locs.insert(DPL::FromUTF8String("pl"));
828     WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
829     regInfo.localizationData.icons.push_back(locIcon);
830
831     //start file
832     WidgetRegisterInfo::StartFileProperties prop_en;
833     prop_en.encoding = DPL::FromUTF8String("encoding_en");
834     prop_en.type = DPL::FromUTF8String("type_en");
835
836     WidgetRegisterInfo::StartFileProperties prop_pl;
837     prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
838     prop_pl.type = DPL::FromUTF8String("type_pl");
839
840     WidgetRegisterInfo::LocalizedStartFile file;
841     file.path = DPL::FromUTF8String("path");
842     file.propertiesForLocales.insert(
843             std::make_pair(DPL::FromUTF8String("en"), prop_en));
844     file.propertiesForLocales.insert(
845             std::make_pair(DPL::FromUTF8String("pl"), prop_pl));
846     regInfo.localizationData.startFiles.push_back(file);
847
848     // register widget
849     WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
850
851     WidgetDAO dao(pkgname);
852
853     // check localized icons
854     WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
855     RUNNER_ASSERT(locList.size() == locs.size());
856
857     // non-localized icon
858     WidgetDAO::WidgetIconList list = dao.getIconList();
859     int iconId = list.front().iconId;
860
861     // compare every icon with the origin
862     auto locsIt = locs.begin();
863     auto iconIt = locList.begin();
864     for(;locsIt!=locs.end() && iconIt!=locList.end();++locsIt,++iconIt) {
865         RUNNER_ASSERT(iconIt->appId == dao.getHandle());
866         RUNNER_ASSERT(iconIt->iconId == iconId);
867         RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
868     }
869
870     // localized start file list
871     WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
872     RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
873
874     int startFileId = dao.getStartFileList().front().startFileId;
875
876     FOREACH(it,fList)
877     {
878         RUNNER_ASSERT(it->appId == dao.getHandle());
879         auto propIt = file.propertiesForLocales.find(it->widgetLocale);
880         RUNNER_ASSERT(propIt != file.propertiesForLocales.end());
881         RUNNER_ASSERT(it->encoding == propIt->second.encoding);
882         RUNNER_ASSERT(it->type == propIt->second.type);
883         RUNNER_ASSERT(it->startFileId == startFileId);
884     }
885 }
886
887 /*
888 Name: widget_dao_test_wac_security
889 Description: Tests inserting and returning wac security information
890 Expected: Values inserted into database should match values received from database
891 */
892 RUNNER_TEST(widget_dao_test_wac_security)
893 {
894     WacSecurityMock sec;
895     WidgetRegisterInfo regInfo;
896     {
897         // register widget
898         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
899         WidgetDAO dao(pkgname);
900
901         RUNNER_ASSERT(!dao.isDistributorSigned());
902         RUNNER_ASSERT(!dao.isRecognized());
903         RUNNER_ASSERT(!dao.isWacSigned());
904     }
905     sec.setDistributorSigned(true);
906     sec.setRecognized(true);
907     sec.setWacSigned(true);
908     {
909         // register widget
910         WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
911         WidgetDAO dao(pkgname);
912
913         RUNNER_ASSERT(dao.isDistributorSigned());
914         RUNNER_ASSERT(dao.isRecognized());
915         RUNNER_ASSERT(dao.isWacSigned());
916     }
917 }
918
919 #undef RUNNER_ASSERT_WHAT_EQUALS