2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file TestCases_WidgetDAO.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains tests for widget dao class.
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>
36 using namespace WrtDB;
39 class WacSecurityMock : public WrtDB::IWacSecurity
44 mDistributorSigned(false),
48 virtual const WidgetCertificateDataList& getCertificateList() const
53 virtual bool isRecognized() const
57 virtual bool isDistributorSigned() const
59 return mDistributorSigned;
61 virtual bool isWacSigned() const
65 virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {}
66 virtual void getCertificateChainList(CertificateChainList& /*lst*/,
67 CertificateSource /*source*/) const {}
69 WrtDB::WidgetCertificateDataList& getCertificateListRef()
74 void setRecognized(bool recognized)
76 mRecognized = recognized;
78 void setDistributorSigned(bool distributorSigned)
80 mDistributorSigned = distributorSigned;
82 void setWacSigned(bool wacSigned)
84 mWacSigned = wacSigned;
88 WrtDB::WidgetCertificateDataList mList;
89 // author signature verified
92 bool mDistributorSigned;
97 TizenAppId _registerWidget(const WidgetRegisterInfo& regInfo,
98 const IWacSecurity& sec,
101 TizenAppId tizenAppId;
103 auto previous = WidgetDAO::getTizenAppidList();
106 tizenAppId = WidgetDAO::registerWidgetGeneratePkgId(regInfo, sec);
108 RUNNER_ASSERT_MSG(!tizenAppId.empty(),
109 "(called from line " << line << ")");
111 auto current = WidgetDAO::getTizenAppidList();
112 RUNNER_ASSERT_MSG(previous.size() + 1 == current.size(),
113 "(called from line " << line << ")");
115 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
117 "(called from line " << line << " tizenAppId: " <<
120 Catch(WidgetDAO::Exception::AlreadyRegistered) {
123 "Unexpected exception (called from line " << line << ")");
128 #define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo), \
133 // Widgets used <2300,2500), 2000, 2001, 2002, 2003
135 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
136 { std::string tmp(in); \
137 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
139 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
141 if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
142 else { RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in), test); } \
145 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test) \
147 if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
148 else { RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); } \
151 RUNNER_TEST_GROUP_INIT(DAO)
155 * Name: widget_dao_test_register_widget_empty_strings
156 * Description: Tests registeration of new widget with empty values
157 * Expected: widget should be registered in database
159 RUNNER_TEST(widget_dao_test_register_widget_empty_strings)
161 WidgetRegisterInfo regInfo;
164 regInfo.shareHref = "";
167 regInfo.configInfo.widget_id = DPL::FromUTF8String("");
168 regInfo.configInfo.version = DPL::FromUTF8String("");
169 regInfo.configInfo.width = 10;
170 regInfo.configInfo.height = 10;
171 regInfo.configInfo.authorName = DPL::FromUTF8String("");
172 regInfo.configInfo.authorEmail = DPL::FromUTF8String("");
173 regInfo.configInfo.authorHref = DPL::FromUTF8String("");
174 regInfo.baseFolder = "";
175 //TODO authenticated, etc...
176 regInfo.configInfo.flashNeeded = false;
177 regInfo.configInfo.minVersionRequired = DPL::FromUTF8String("1.0");
178 regInfo.configInfo.backSupported = true;
181 ConfigParserData::LocalizedData locData;
182 locData.name = DPL::FromUTF8String("");
183 locData.shortName = DPL::FromUTF8String("");
184 locData.description = DPL::FromUTF8String("");
185 locData.license = DPL::FromUTF8String("");
186 locData.licenseFile = DPL::FromUTF8String("");
187 locData.licenseHref = DPL::FromUTF8String("");
188 regInfo.configInfo.localizedDataSet.insert(
189 std::make_pair(DPL::FromUTF8String("en"), locData));
194 ConfigParserData::Icon icon(DPL::FromUTF8String(""));
198 locs.insert(DPL::FromUTF8String("en"));
199 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
200 regInfo.localizationData.icons.push_back(locIcon);
203 WidgetRegisterInfo::StartFileProperties prop;
204 prop.encoding = DPL::FromUTF8String("");
205 prop.type = DPL::FromUTF8String("");
206 WidgetRegisterInfo::LocalizedStartFile file;
207 file.path = DPL::FromUTF8String("");
208 file.propertiesForLocales.insert(
209 std::make_pair(DPL::FromUTF8String("en"), prop));
210 regInfo.localizationData.startFiles.push_back(file);
213 ConfigParserData::Preference pref(DPL::FromUTF8String(""), false);
214 pref.value = DPL::FromUTF8String("");
215 regInfo.configInfo.preferencesList.insert(pref);
218 ConfigParserData::Feature feat(DPL::FromUTF8String(""));
219 regInfo.configInfo.featuresList.insert(feat);
222 regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
225 ConfigParserData::AccessInfo access(DPL::FromUTF8String(""), true);
226 regInfo.configInfo.accessInfoSet.insert(access);
229 WidgetCertificateData cert;
230 cert.owner = WidgetCertificateData::AUTHOR;
231 cert.type = WidgetCertificateData::ROOT;
233 cert.strMD5Fingerprint = "";
234 cert.strSHA1Fingerprint = "";
235 cert.strCommonName = DPL::FromUTF8String("");
237 WacSecurityMock security;
238 security.getCertificateListRef().push_back(cert);
240 REGISTER_WIDGET(regInfo, security);
244 * Name: widget_dao_test_register_widget_empty_strings
245 * Description: Tests possiblity of registering twice same content (different
247 * Expected: it should be possible
249 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
253 WidgetRegisterInfo regInfo;
254 REGISTER_WIDGET(regInfo, sec);
257 WidgetRegisterInfo regInfo;
258 REGISTER_WIDGET(regInfo, sec);
263 * Name: widget_dao_test_register_widget_minimum_info
264 * Description: Tests simplest registeration of new widget
265 * Expected: widget should be registered in database
267 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
270 const std::size_t NUMBER_OF_WIDGETS = 5;
272 TizenAppId lastTizenAppId;
274 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
275 WidgetRegisterInfo regInfo;
276 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
278 lastTizenAppId = tizenAppId;
280 WidgetDAO dao(tizenAppId);
286 * Name: widget_dao_test_register_widget_info
287 * Description: Tests registeration of many widgets
288 * Expected: all widgets should be registered in database
290 RUNNER_TEST(widget_dao_test_register_widget_info)
293 const std::size_t NUMBER_OF_WIDGETS = 5;
295 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
296 std::ostringstream str;
297 str << "register_info_test_" << number;
299 WidgetRegisterInfo regInfo;
300 regInfo.configInfo.widget_id = DPL::FromUTF8String(str.str());
301 regInfo.configInfo.version = DPL::FromUTF8String(str.str());
302 regInfo.configInfo.width = 10;
303 regInfo.configInfo.height = 10;
304 regInfo.configInfo.authorName = DPL::FromUTF8String(str.str());
305 regInfo.configInfo.authorEmail = DPL::FromUTF8String(str.str());
306 regInfo.configInfo.authorHref = DPL::FromUTF8String(str.str());
307 regInfo.baseFolder = str.str(); //base folder at the end has /
308 regInfo.configInfo.flashNeeded = false;
309 //TODO authenticated, etc...
310 //in wrt-installer: TaskWidgetConfig::fillWidgetConfig:
311 //regInfo.minVersion = regInfo.configInfo.minVersionRequired
312 regInfo.minVersion = DPL::FromUTF8String("1.0");
313 regInfo.configInfo.backSupported = true;
315 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
317 WidgetDAO dao(tizenAppId);
318 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), str.str());
319 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), str.str());
320 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), str.str());
321 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), str.str());
322 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), str.str());
323 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), str.str() + "/");
324 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == false);
326 // dao.GetWidgetSecurityDomain() == WacSecurity::Trusted);
327 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
332 * Name: widget_dao_test_register_widget_extended_info
333 * Description: Tests registeration of widget_extended_info
334 * Expected: registeration of extended inforamtion is checked
335 * via existence of backgroudn page value
337 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
340 const std::size_t NUMBER_OF_WIDGETS = 5;
342 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
343 std::ostringstream str;
344 str << "register_ext_info_test_" << number;
346 WidgetRegisterInfo regInfo;
348 // regInfo.shareHref = str.str();
349 regInfo.configInfo.backgroundPage = L"background.html";
351 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
353 WidgetDAO dao(tizenAppId);
354 // RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
356 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
362 * Name: widget_dao_test_register_widget_localized_info
363 * Description: Tests registeration of localized widgets information
364 * Expected: values received by dao should match those which were registered
366 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
369 const std::size_t NUMBER_OF_WIDGETS = 5;
371 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
372 WidgetRegisterInfo regInfo;
373 std::ostringstream str_en;
374 std::ostringstream str_pl;
375 str_en << "register_loc_info_test_en_" << number;
376 str_pl << "register_loc_info_test_pl_" << number;
378 ConfigParserData::LocalizedData locDataEn;
379 locDataEn.name = DPL::FromUTF8String(str_en.str());
380 locDataEn.shortName = DPL::FromUTF8String(str_en.str());
381 locDataEn.description = DPL::FromUTF8String(str_en.str());
382 locDataEn.license = DPL::FromUTF8String(str_en.str());
383 locDataEn.licenseFile = DPL::FromUTF8String(str_en.str());
384 locDataEn.licenseHref = DPL::FromUTF8String(str_en.str());
385 regInfo.configInfo.localizedDataSet.insert(
386 std::make_pair(DPL::FromUTF8String("en"), locDataEn));
390 ConfigParserData::LocalizedData locDataPl;
391 locDataPl.name = DPL::FromUTF8String(str_pl.str());
392 locDataPl.shortName = DPL::FromUTF8String(str_pl.str());
393 locDataPl.description = DPL::FromUTF8String(str_pl.str());
394 locDataPl.license = DPL::FromUTF8String(str_pl.str());
395 locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str());
396 locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str());
397 regInfo.configInfo.localizedDataSet.insert(
398 std::make_pair(DPL::FromUTF8String("pl"), locDataPl));
401 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
403 WidgetDAO dao(tizenAppId);
404 RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
405 "language tags list invalid");
408 WidgetLocalizedInfo locInfo =
409 dao.getLocalizedInfo(DPL::FromUTF8String("en"));
411 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
413 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
415 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
417 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
419 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
424 WidgetLocalizedInfo locInfo =
425 dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
427 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
429 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
431 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
433 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
435 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
442 * Name: widget_dao_test_register_widget_icons
443 * Description: Tests registeration of localized icons information
444 * Expected: values received by dao should match those which were registered
447 RUNNER_TEST(widget_dao_test_register_widget_icons)
450 WidgetRegisterInfo regInfo;
452 ConfigParserData::Icon icon(L"icon1");
456 locs.insert(DPL::FromUTF8String("en"));
457 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
458 regInfo.localizationData.icons.push_back(locIcon);
460 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
462 WidgetDAO dao(tizenAppId);
463 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
465 RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size());
466 WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin();
467 WidgetRegisterInfo::LocalizedIconList::const_iterator it2 =
468 regInfo.localizationData.icons.begin();
469 for (; it1 != list.end() && it2 != regInfo.localizationData.icons.end();
472 RUNNER_ASSERT(it2->height == it1->iconHeight);
473 RUNNER_ASSERT(it2->width == it1->iconWidth);
474 RUNNER_ASSERT(it2->src == it1->iconSrc);
475 RUNNER_ASSERT(it2->availableLocales == locs);
480 * Name: widget_dao_test_register_widget_start_files
481 * Description: Tests registeration of localized start files
482 * Expected: no expectations as it should be removed
484 RUNNER_TEST(widget_dao_test_register_widget_start_files)
488 WidgetRegisterInfo::LocalizedStartFileList files;
489 WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
490 WidgetRegisterInfo::StartFileProperties prop1;
491 prop1.encoding = DPL::FromUTF8String("enc1");
492 prop1.type = DPL::FromUTF8String("type1");
494 map1.insert(std::make_pair(DPL::FromUTF8String("en"), prop1));
495 map1.insert(std::make_pair(DPL::FromUTF8String("pl"), prop1));
497 WidgetRegisterInfo::LocalizedStartFile file1;
498 WidgetRegisterInfo::LocalizedStartFile file2;
499 file1.path = DPL::FromUTF8String("path1");
500 file1.propertiesForLocales = map1;
501 file2.path = DPL::FromUTF8String("path2");
502 file2.propertiesForLocales = map1;
504 files.push_back(file1);
505 files.push_back(file1);
507 WidgetRegisterInfo regInfo;
508 regInfo.localizationData.startFiles = files;
510 REGISTER_WIDGET(regInfo, sec);
512 //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
513 // but it will be removed
517 * Name: widget_dao_test_register_widget_features
518 * Description: Tests registeration of features of widget
519 * Expected: number of features should match (for given widget reginfo)
521 RUNNER_TEST(widget_dao_test_register_widget_features)
524 ConfigParserData::FeaturesList features;
525 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1")));
526 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2")));
527 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3")));
529 WidgetRegisterInfo regInfo;
530 FOREACH(it, features)
531 regInfo.configInfo.featuresList.insert(*it);
533 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
535 WidgetDAO dao(tizenAppId);
536 WidgetFeatureSet out = dao.getFeaturesList();
537 RUNNER_ASSERT_MSG(out.size() == features.size(),
538 "wrong number of features");
540 // RUNNER_ASSERT(features.find(*it) != features.end());
544 * Name: widget_dao_test_register_widget_security_settings
545 * Description: Tests registeration of dafault values of security settings
546 * Expected: widget should be registered in database.
547 * Returned values should match dafault.
549 RUNNER_TEST(widget_dao_test_register_widget_security_settings)
552 WidgetRegisterInfo regInfo;
553 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
555 WidgetDAO dao(tizenAppId);
557 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_ON,
558 "SecurityPopupUsage is not deafult on");
560 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
561 "GeolocationUsage is not deafult on");
563 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
564 "WebNotificationUsage is not deafult on");
566 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
567 "WebDatabaseUsage is not deafult on");
569 dao.setSecurityPopupUsage(WrtDB::SETTINGS_TYPE_OFF);
571 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
572 "SecurityPopupUsage - wrong value");
574 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
575 "GeolocationUsage - wrong value");
577 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
578 "WebNotificationUsage - wrong value");
580 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
581 "WebDatabaseUsage - wrong value");
583 dao.setGeolocationUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
585 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
586 "SecurityPopupUsage - wrong value");
588 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
589 "GeolocationUsage - wrong value");
591 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
592 "WebNotificationUsage - wrong value");
594 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
595 "WebDatabaseUsage - wrong value");
597 dao.setWebNotificationUsage(WrtDB::SETTINGS_TYPE_OFF);
599 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
600 "SecurityPopupUsage - wrong value");
602 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
603 "GeolocationUsage - wrong value");
605 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
606 "WebNotificationUsage - wrong value");
608 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
609 "WebDatabaseUsage - wrong value");
611 dao.setWebDatabaseUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
613 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
614 "SecurityPopupUsage - wrong value");
616 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
617 "GeolocationUsage - wrong value");
619 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
620 "WebNotificationUsage - wrong value");
622 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
623 "WebDatabaseUsage - wrong value");
627 * Name: widget_dao_test_register_widget_win_modes
628 * Description: Tests registeration of window modes
629 * Expected: all modes should be returned from dao
631 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
634 std::set<DPL::String> modes;
635 modes.insert(DPL::FromUTF8String("full"));
636 modes.insert(DPL::FromUTF8String("window"));
638 WidgetRegisterInfo regInfo;
641 regInfo.configInfo.windowModes.insert(*it);
643 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
645 WidgetDAO dao(tizenAppId);
646 std::list<DPL::String> wins = dao.getWindowModes();
647 RUNNER_ASSERT_MSG(modes.size() == wins.size(),
648 "wrong number of window modes");
650 RUNNER_ASSERT(modes.find(*it) != modes.end());
654 * Name: widget_dao_test_register_widget_warp_info
655 * Description: Tests registeration of access info iris
656 * Expected: all access info iris should be returned from dao
658 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
661 ConfigParserData::AccessInfoSet orig;
662 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
664 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
666 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
669 WidgetRegisterInfo regInfo;
671 regInfo.configInfo.accessInfoSet.insert(*it);
673 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
675 WidgetDAO dao(tizenAppId);
677 WidgetAccessInfoList out;
678 dao.getWidgetAccessInfo(out);
679 RUNNER_ASSERT_MSG(out.size() == orig.size(),
680 "wrong number of access info elem");
682 ConfigParserData::AccessInfo tmp(it->strIRI, it->bSubDomains);
683 RUNNER_ASSERT(orig.find(tmp) != orig.end());
688 * Name: widget_dao_test_register_widget_certificates
689 * Description: Tests registeration of widget certificates
690 * Expected: all certificates should be returned from dao
691 * and should contain inserted data
693 RUNNER_TEST(widget_dao_test_register_widget_certificates)
696 WidgetRegisterInfo regInfo;
698 WidgetCertificateData cert;
699 cert.owner = WidgetCertificateData::AUTHOR;
700 cert.type = WidgetCertificateData::ROOT;
702 cert.strMD5Fingerprint = "md5";
703 cert.strSHA1Fingerprint = "sha1";
704 cert.strCommonName = DPL::FromUTF8String("common name");
706 WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
707 certListRef.push_back(cert);
710 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
712 WidgetDAO dao(tizenAppId);
715 WidgetCertificateDataList recList = dao.getCertificateDataList();
716 RUNNER_ASSERT(recList.size() == certListRef.size());
718 auto recListIt = recList.begin();
719 auto certListIt = certListRef.begin();
720 for (; recListIt != recList.end() && certListIt != certListRef.end();
721 ++recListIt, ++certListIt)
723 RUNNER_ASSERT(recListIt->chainId == certListIt->chainId);
724 RUNNER_ASSERT(recListIt->owner == certListIt->owner);
725 RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName);
726 RUNNER_ASSERT(recListIt->strMD5Fingerprint ==
727 certListIt->strMD5Fingerprint);
728 RUNNER_ASSERT(recListIt->strSHA1Fingerprint ==
729 certListIt->strSHA1Fingerprint);
730 RUNNER_ASSERT(recListIt->type == certListIt->type);
734 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
735 WidgetCertificateData::ENDENTITY).
737 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
738 WidgetCertificateData::ENDENTITY).
740 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
741 WidgetCertificateData::ROOT).empty());
743 FingerPrintList fingerprints = dao.getKeyFingerprints(
744 WidgetCertificateData::AUTHOR,
745 WidgetCertificateData::ROOT);
747 RUNNER_ASSERT(fingerprints.size() == certListRef.size() * 2);
748 FOREACH(it, certListRef)
750 auto md5 = std::find(fingerprints.begin(),
752 it->strMD5Fingerprint);
753 RUNNER_ASSERT(md5 != fingerprints.end());
755 auto sha = std::find(fingerprints.begin(),
757 it->strSHA1Fingerprint);
758 RUNNER_ASSERT(sha != fingerprints.end());
762 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
763 WidgetCertificateData::ENDENTITY).
765 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
766 WidgetCertificateData::ENDENTITY).
768 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
769 WidgetCertificateData::ROOT).empty());
771 FingerPrintList commonNames = dao.getKeyCommonNameList(
772 WidgetCertificateData::AUTHOR,
773 WidgetCertificateData::ROOT);
775 RUNNER_ASSERT(commonNames.size() == certListRef.size());
776 FOREACH(it, certListRef)
778 auto cn = std::find(commonNames.begin(),
780 DPL::ToUTF8String(it->strCommonName));
781 RUNNER_ASSERT(cn != commonNames.end());
786 * Name: widget_dao_test_register_widget_privileges
787 * Description: Tests registration of widget privileges
789 RUNNER_TEST(widget_dao_test_register_widget_privileges)
793 WidgetRegisterInfo regInfo;
795 ConfigParserData::PrivilegeList& privilegeList =
796 regInfo.configInfo.privilegeList;
797 privilegeList.insert(DPL::FromUTF8String("name"));
798 privilegeList.insert(DPL::FromUTF8String("name2"));
800 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
801 WidgetDAO dao(tizenAppId);
803 WrtDB::PrivilegeList privListFromDB;
804 privListFromDB = dao.getWidgetPrivilege();
806 RUNNER_ASSERT(privilegeList.size() == privListFromDB.size());
808 auto privListIt = privilegeList.begin();
809 auto privDBIt = privListFromDB.begin();
810 for(; privListIt != privilegeList.end() && privDBIt != privListFromDB.end();
811 ++privListIt, ++privDBIt)
813 RUNNER_ASSERT(*privDBIt == privListIt->name);
818 * Name: widget_dao_test_register_app_control
819 * Description: Tests app control
821 RUNNER_TEST(widget_dao_test_register_app_control)
824 WidgetRegisterInfo regInfo;
826 ConfigParserData::AppControlInfo appControl(DPL::FromUTF8String("operation"));
827 appControl.m_disposition
828 = ConfigParserData::AppControlInfo::Disposition::WINDOW;
829 appControl.m_mimeList.insert(DPL::FromUTF8String("mime"));
830 appControl.m_src = DPL::FromUTF8String("src");
831 appControl.m_uriList.insert(DPL::FromUTF8String("uri"));
833 ConfigParserData::AppControlInfoList& appControlListRef
834 = regInfo.configInfo.appControlList;
835 appControlListRef.push_back(appControl);
837 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
839 WidgetDAO dao(tizenAppId);
841 WrtDB::WidgetAppControlList appControlInfoListDB;
842 dao.getAppControlList(appControlInfoListDB);
843 RUNNER_ASSERT(appControlInfoListDB.size() == appControlListRef.size());
844 auto appDBIt = appControlInfoListDB.begin();
845 auto appRefIt = appControlListRef.begin();
847 for (;appDBIt != appControlInfoListDB.end()
848 && appRefIt != appControlListRef.end();
849 ++appDBIt, ++appRefIt)
851 RUNNER_ASSERT((WidgetAppControl::Disposition)
852 appRefIt->m_disposition == appDBIt->disposition);
853 RUNNER_ASSERT(appRefIt->m_index == appDBIt->index);
854 RUNNER_ASSERT(appRefIt->m_operation == appDBIt->operation);
855 RUNNER_ASSERT(appRefIt->m_src == appDBIt->src);
856 for(auto it = appRefIt->m_mimeList.begin();
857 it != appRefIt->m_mimeList.end();
860 RUNNER_ASSERT((*it) == appDBIt->mime);
862 for(auto it = appRefIt->m_uriList.begin();
863 it != appRefIt->m_uriList.end();
866 RUNNER_ASSERT((*it) == appDBIt->uri);
872 * Name: widget_dao_test_is_widget_installed
873 * Description: Tests checking if widgets are installed
874 * Expected: installed widgets should be stated as installed
876 RUNNER_TEST(widget_dao_test_is_widget_installed)
878 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
881 WidgetRegisterInfo regInfo;
883 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
885 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(tizenAppId));
889 * Name: widget_dao_test_unregister_widget
890 * Description: Tests unregistering widgets
891 * Expected: widget register informations should be successfully removed
893 RUNNER_TEST(widget_dao_test_unregister_widget)
896 WidgetHandleList handles = WidgetDAO::getHandleList();
898 WidgetRegisterInfo regInfo;
900 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
902 WidgetDAO::unregisterWidget(tizenAppId);
904 RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
905 "Widget unregister failed");
909 * Name: widget_dao_test_register_or_update_widget
910 * Description: Tests reregistering widgets
911 * Expected: widget should be successfully replaced
913 RUNNER_TEST(widget_dao_test_register_or_update_widget)
917 WidgetRegisterInfo regInfo;
918 regInfo.configInfo.version = L"1.0";
919 regInfo.configInfo.authorName = L"AAA";
921 WidgetRegisterInfo regInfo2;
922 regInfo2.configInfo.version = L"1.1";
923 regInfo2.configInfo.authorName = L"BBB";
925 WrtDB::TizenAppId tizenAppId(L"abcdefghij");
928 WidgetDAO::registerWidget(tizenAppId, regInfo, sec);
929 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
930 tizenAppId), "Widget is not registered");
932 //success full update
933 WidgetDAO::registerOrUpdateWidget(tizenAppId, regInfo2, sec);
934 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
935 tizenAppId), "Widget is not reregistered");
936 WidgetDAO dao(tizenAppId);
938 *dao.getVersion() == L"1.1", "Data widget was not updated");
940 *dao.getAuthorName() == L"BBB", "Data widget was not updated");
942 WidgetDAO::unregisterWidget(tizenAppId);
946 * Name: widget_dao_test_get_widget_tizenAppId_list
947 * Description: Tests getTizenAppidList API for backendlib
948 * Expected: For all position in database should be returned one item in list
950 RUNNER_TEST(widget_dao_test_get_widget_tizenAppId_list)
952 TizenAppIdList tizenAppIds = WidgetDAO::getTizenAppidList();
953 RUNNER_ASSERT(tizenAppIds.size() >= 3);
957 * Name: widget_dao_test_get_widget_list
958 * Description: Tests getTizenAppidList API for backendlib
959 * Expected: For all position in database should be returned one item in list
960 * Those item should contain valid tizenAppId
962 RUNNER_TEST(widget_dao_test_get_widget_list)
964 WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList();
965 RUNNER_ASSERT(list.size() >= 3);
966 RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists");
967 WidgetDAOReadOnlyPtr dao = list.front();
971 * Name: widget_dao_test_get_widget_attributes
972 * Description: Tests returning basic widget attributes by dao
973 * Expected: Attributes should match values inserted into database
975 RUNNER_TEST(widget_dao_test_get_widget_attributes)
978 TizenAppId tizenAppId = L"tizenid201";
979 WidgetDAO dao(tizenAppId);
981 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000");
982 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0");
983 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000");
984 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(),
986 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000");
987 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/");
988 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true);
989 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
994 * Name: widget_dao_test_localization
995 * Description: Tests inserting and returning localization info
996 * Expected: Values inserted into database should match values received from
999 RUNNER_TEST(widget_dao_test_localization)
1001 WacSecurityMock sec;
1004 WidgetRegisterInfo regInfo;
1005 ConfigParserData::Icon icon(L"icon1");
1009 locs.insert(DPL::FromUTF8String("en"));
1010 locs.insert(DPL::FromUTF8String("pl"));
1011 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
1012 regInfo.localizationData.icons.push_back(locIcon);
1015 WidgetRegisterInfo::StartFileProperties prop_en;
1016 prop_en.encoding = DPL::FromUTF8String("encoding_en");
1017 prop_en.type = DPL::FromUTF8String("type_en");
1019 WidgetRegisterInfo::StartFileProperties prop_pl;
1020 prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
1021 prop_pl.type = DPL::FromUTF8String("type_pl");
1023 WidgetRegisterInfo::LocalizedStartFile file;
1024 file.path = DPL::FromUTF8String("path");
1025 file.propertiesForLocales.insert(
1026 std::make_pair(DPL::FromUTF8String("en"), prop_en));
1027 file.propertiesForLocales.insert(
1028 std::make_pair(DPL::FromUTF8String("pl"), prop_pl));
1029 regInfo.localizationData.startFiles.push_back(file);
1032 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1034 WidgetDAO dao(tizenAppId);
1036 // check localized icons
1037 WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
1038 RUNNER_ASSERT(locList.size() == locs.size());
1040 // non-localized icon
1041 WidgetDAO::WidgetIconList list = dao.getIconList();
1042 int iconId = list.front().iconId;
1044 // compare every icon with the origin
1045 auto locsIt = locs.begin();
1046 auto iconIt = locList.begin();
1047 for (; locsIt != locs.end() && iconIt != locList.end(); ++locsIt,
1050 RUNNER_ASSERT(iconIt->appId == dao.getHandle());
1051 RUNNER_ASSERT(iconIt->iconId == iconId);
1052 RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
1055 // localized start file list
1056 WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
1057 RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
1059 int startFileId = dao.getStartFileList().front().startFileId;
1063 RUNNER_ASSERT(it->appId == dao.getHandle());
1064 auto propIt = file.propertiesForLocales.find(it->widgetLocale);
1065 RUNNER_ASSERT(propIt != file.propertiesForLocales.end());
1066 RUNNER_ASSERT(it->encoding == propIt->second.encoding);
1067 RUNNER_ASSERT(it->type == propIt->second.type);
1068 RUNNER_ASSERT(it->startFileId == startFileId);
1073 * Name: widget_dao_test_wac_security
1074 * Description: Tests inserting and returning wac security information
1075 * Expected: Values inserted into database should match values received from
1078 RUNNER_TEST(widget_dao_test_wac_security)
1080 WacSecurityMock sec;
1081 WidgetRegisterInfo regInfo;
1084 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1085 WidgetDAO dao(tizenAppId);
1087 RUNNER_ASSERT(!dao.isDistributorSigned());
1088 RUNNER_ASSERT(!dao.isRecognized());
1089 RUNNER_ASSERT(!dao.isWacSigned());
1091 sec.setDistributorSigned(true);
1092 sec.setRecognized(true);
1093 sec.setWacSigned(true);
1096 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1097 WidgetDAO dao(tizenAppId);
1099 RUNNER_ASSERT(dao.isDistributorSigned());
1100 RUNNER_ASSERT(dao.isRecognized());
1101 RUNNER_ASSERT(dao.isWacSigned());
1106 * Name: widget_dao_test_register_scp
1107 * Description: Tests inserting and returning scp policy information
1108 * Expected: Value inserted into database should match values received from
1111 RUNNER_TEST(widget_dao_test_register_scp)
1113 WacSecurityMock sec;
1114 WidgetRegisterInfo regInfo;
1115 DPL::OptionalString policy = DPL::FromUTF8String("Some awesome csp policy");
1116 regInfo.configInfo.cspPolicy = policy;
1119 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1120 WidgetDAO dao(tizenAppId);
1122 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
1123 dao.getCspPolicy(), DPL::ToUTF8String(*policy));
1128 * Name: widget_dao_test_register_csp_empty
1129 * Description: Tests inserting and returning empty csp policy
1130 * Expected: Value inserted into database should match values received from
1133 RUNNER_TEST(widget_dao_test_register_csp_empty)
1135 WacSecurityMock sec;
1136 WidgetRegisterInfo regInfo;
1139 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1140 WidgetDAO dao(tizenAppId);
1142 RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
1145 #undef RUNNER_ASSERT_WHAT_EQUALS