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::IWidgetSecurity
44 mDistributorSigned(false)
47 virtual const WidgetCertificateDataList& getCertificateList() const
52 virtual bool isRecognized() const
56 virtual bool isDistributorSigned() const
58 return mDistributorSigned;
60 virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {}
61 virtual void getCertificateChainList(CertificateChainList& /*lst*/,
62 CertificateSource /*source*/) const {}
64 WrtDB::WidgetCertificateDataList& getCertificateListRef()
69 void setRecognized(bool recognized)
71 mRecognized = recognized;
73 void setDistributorSigned(bool distributorSigned)
75 mDistributorSigned = distributorSigned;
79 WrtDB::WidgetCertificateDataList mList;
80 // author signature verified
83 bool mDistributorSigned;
87 TizenAppId _registerWidget(const WidgetRegisterInfo& regInfo,
88 const IWidgetSecurity& sec,
91 TizenAppId tizenAppId;
93 auto previous = WidgetDAO::getTizenAppidList();
96 tizenAppId = WidgetDAO::registerWidgetGeneratePkgId(regInfo, sec);
98 RUNNER_ASSERT_MSG(!tizenAppId.empty(),
99 "(called from line " << line << ")");
101 auto current = WidgetDAO::getTizenAppidList();
102 RUNNER_ASSERT_MSG(previous.size() + 1 == current.size(),
103 "(called from line " << line << ")");
105 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
107 "(called from line " << line << " tizenAppId: " <<
110 Catch(WidgetDAO::Exception::AlreadyRegistered) {
113 "Unexpected exception (called from line " << line << ")");
118 #define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo), \
123 // Widgets used <2300,2500), 2000, 2001, 2002, 2003
125 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
126 { std::string tmp(in); \
127 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
129 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
131 if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
132 else { RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in), test); } \
135 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test) \
137 if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
138 else { RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); } \
141 RUNNER_TEST_GROUP_INIT(DAO)
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
149 RUNNER_TEST(widget_dao_test_register_widget_empty_strings)
151 WidgetRegisterInfo regInfo;
154 regInfo.shareHref = "";
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;
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));
184 ConfigParserData::Icon icon(DPL::FromUTF8String(""));
188 locs.insert(DPL::FromUTF8String("en"));
189 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
190 regInfo.localizationData.icons.push_back(locIcon);
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);
203 ConfigParserData::Preference pref(DPL::FromUTF8String(""), false);
204 pref.value = DPL::FromUTF8String("");
205 regInfo.configInfo.preferencesList.insert(pref);
208 ConfigParserData::Feature feat(DPL::FromUTF8String(""));
209 regInfo.configInfo.featuresList.insert(feat);
212 regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
215 ConfigParserData::AccessInfo access(DPL::FromUTF8String(""), true);
216 regInfo.configInfo.accessInfoSet.insert(access);
219 WidgetCertificateData cert;
220 cert.owner = WidgetCertificateData::AUTHOR;
221 cert.type = WidgetCertificateData::ROOT;
223 cert.strMD5Fingerprint = "";
224 cert.strSHA1Fingerprint = "";
225 cert.strCommonName = DPL::FromUTF8String("");
227 WacSecurityMock security;
228 security.getCertificateListRef().push_back(cert);
230 REGISTER_WIDGET(regInfo, security);
234 * Name: widget_dao_test_register_widget_empty_strings
235 * Description: Tests possiblity of registering twice same content (different
237 * Expected: it should be possible
239 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
243 WidgetRegisterInfo regInfo;
244 REGISTER_WIDGET(regInfo, sec);
247 WidgetRegisterInfo regInfo;
248 REGISTER_WIDGET(regInfo, sec);
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
257 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
260 const std::size_t NUMBER_OF_WIDGETS = 5;
262 TizenAppId lastTizenAppId;
264 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
265 WidgetRegisterInfo regInfo;
266 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
268 lastTizenAppId = tizenAppId;
270 WidgetDAO dao(tizenAppId);
276 * Name: widget_dao_test_register_widget_info
277 * Description: Tests registeration of many widgets
278 * Expected: all widgets should be registered in database
280 RUNNER_TEST(widget_dao_test_register_widget_info)
283 const std::size_t NUMBER_OF_WIDGETS = 5;
285 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
286 std::ostringstream str;
287 str << "register_info_test_" << number;
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;
305 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
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);
316 // dao.GetWidgetSecurityDomain() == WacSecurity::Trusted);
317 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
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
327 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
330 const std::size_t NUMBER_OF_WIDGETS = 5;
332 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
333 std::ostringstream str;
334 str << "register_ext_info_test_" << number;
336 WidgetRegisterInfo regInfo;
338 // regInfo.shareHref = str.str();
339 regInfo.configInfo.backgroundPage = L"background.html";
341 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
343 WidgetDAO dao(tizenAppId);
344 // RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
346 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
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
356 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
359 const std::size_t NUMBER_OF_WIDGETS = 5;
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;
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));
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));
391 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
393 WidgetDAO dao(tizenAppId);
394 RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
395 "language tags list invalid");
398 WidgetLocalizedInfo locInfo =
399 dao.getLocalizedInfo(DPL::FromUTF8String("en"));
401 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
403 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
405 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
407 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
409 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
414 WidgetLocalizedInfo locInfo =
415 dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
417 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
419 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
421 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
423 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
425 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
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
437 RUNNER_TEST(widget_dao_test_register_widget_icons)
440 WidgetRegisterInfo regInfo;
442 ConfigParserData::Icon icon(L"icon1");
446 locs.insert(DPL::FromUTF8String("en"));
447 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
448 regInfo.localizationData.icons.push_back(locIcon);
450 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
452 WidgetDAO dao(tizenAppId);
453 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
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();
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);
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
474 RUNNER_TEST(widget_dao_test_register_widget_start_files)
478 WidgetRegisterInfo::LocalizedStartFileList files;
479 WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
480 WidgetRegisterInfo::StartFileProperties prop1;
481 prop1.encoding = DPL::FromUTF8String("enc1");
482 prop1.type = DPL::FromUTF8String("type1");
484 map1.insert(std::make_pair(DPL::FromUTF8String("en"), prop1));
485 map1.insert(std::make_pair(DPL::FromUTF8String("pl"), prop1));
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;
494 files.push_back(file1);
495 files.push_back(file1);
497 WidgetRegisterInfo regInfo;
498 regInfo.localizationData.startFiles = files;
500 REGISTER_WIDGET(regInfo, sec);
502 //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
503 // but it will be removed
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)
511 RUNNER_TEST(widget_dao_test_register_widget_features)
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")));
519 WidgetRegisterInfo regInfo;
520 FOREACH(it, features)
521 regInfo.configInfo.featuresList.insert(*it);
523 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
525 WidgetDAO dao(tizenAppId);
526 WidgetFeatureSet out = dao.getFeaturesList();
527 RUNNER_ASSERT_MSG(out.size() == features.size(),
528 "wrong number of features");
530 // RUNNER_ASSERT(features.find(*it) != features.end());
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.
539 RUNNER_TEST(widget_dao_test_register_widget_security_settings)
542 WidgetRegisterInfo regInfo;
543 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
545 WidgetDAO dao(tizenAppId);
547 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_ON,
548 "SecurityPopupUsage is not deafult on");
550 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
551 "GeolocationUsage is not deafult on");
553 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
554 "WebNotificationUsage is not deafult on");
556 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
557 "WebDatabaseUsage is not deafult on");
559 dao.setSecurityPopupUsage(WrtDB::SETTINGS_TYPE_OFF);
561 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
562 "SecurityPopupUsage - wrong value");
564 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
565 "GeolocationUsage - wrong value");
567 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
568 "WebNotificationUsage - wrong value");
570 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
571 "WebDatabaseUsage - wrong value");
573 dao.setGeolocationUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
575 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
576 "SecurityPopupUsage - wrong value");
578 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
579 "GeolocationUsage - wrong value");
581 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
582 "WebNotificationUsage - wrong value");
584 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
585 "WebDatabaseUsage - wrong value");
587 dao.setWebNotificationUsage(WrtDB::SETTINGS_TYPE_OFF);
589 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
590 "SecurityPopupUsage - wrong value");
592 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
593 "GeolocationUsage - wrong value");
595 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
596 "WebNotificationUsage - wrong value");
598 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
599 "WebDatabaseUsage - wrong value");
601 dao.setWebDatabaseUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
603 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
604 "SecurityPopupUsage - wrong value");
606 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
607 "GeolocationUsage - wrong value");
609 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
610 "WebNotificationUsage - wrong value");
612 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
613 "WebDatabaseUsage - wrong value");
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
621 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
624 std::set<DPL::String> modes;
625 modes.insert(DPL::FromUTF8String("full"));
626 modes.insert(DPL::FromUTF8String("window"));
628 WidgetRegisterInfo regInfo;
631 regInfo.configInfo.windowModes.insert(*it);
633 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
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");
640 RUNNER_ASSERT(modes.find(*it) != modes.end());
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
648 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
651 ConfigParserData::AccessInfoSet orig;
652 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
654 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
656 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
659 WidgetRegisterInfo regInfo;
661 regInfo.configInfo.accessInfoSet.insert(*it);
663 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
665 WidgetDAO dao(tizenAppId);
667 WidgetAccessInfoList out;
668 dao.getWidgetAccessInfo(out);
669 RUNNER_ASSERT_MSG(out.size() == orig.size(),
670 "wrong number of access info elem");
672 ConfigParserData::AccessInfo tmp(it->strIRI, it->bSubDomains);
673 RUNNER_ASSERT(orig.find(tmp) != orig.end());
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
683 RUNNER_TEST(widget_dao_test_register_widget_certificates)
686 WidgetRegisterInfo regInfo;
688 WidgetCertificateData cert;
689 cert.owner = WidgetCertificateData::AUTHOR;
690 cert.type = WidgetCertificateData::ROOT;
692 cert.strMD5Fingerprint = "md5";
693 cert.strSHA1Fingerprint = "sha1";
694 cert.strCommonName = DPL::FromUTF8String("common name");
696 WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
697 certListRef.push_back(cert);
700 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
702 WidgetDAO dao(tizenAppId);
705 WidgetCertificateDataList recList = dao.getCertificateDataList();
706 RUNNER_ASSERT(recList.size() == certListRef.size());
708 auto recListIt = recList.begin();
709 auto certListIt = certListRef.begin();
710 for (; recListIt != recList.end() && certListIt != certListRef.end();
711 ++recListIt, ++certListIt)
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);
724 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
725 WidgetCertificateData::ENDENTITY).
727 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
728 WidgetCertificateData::ENDENTITY).
730 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
731 WidgetCertificateData::ROOT).empty());
733 FingerPrintList fingerprints = dao.getKeyFingerprints(
734 WidgetCertificateData::AUTHOR,
735 WidgetCertificateData::ROOT);
737 RUNNER_ASSERT(fingerprints.size() == certListRef.size() * 2);
738 FOREACH(it, certListRef)
740 auto md5 = std::find(fingerprints.begin(),
742 it->strMD5Fingerprint);
743 RUNNER_ASSERT(md5 != fingerprints.end());
745 auto sha = std::find(fingerprints.begin(),
747 it->strSHA1Fingerprint);
748 RUNNER_ASSERT(sha != fingerprints.end());
752 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
753 WidgetCertificateData::ENDENTITY).
755 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
756 WidgetCertificateData::ENDENTITY).
758 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
759 WidgetCertificateData::ROOT).empty());
761 FingerPrintList commonNames = dao.getKeyCommonNameList(
762 WidgetCertificateData::AUTHOR,
763 WidgetCertificateData::ROOT);
765 RUNNER_ASSERT(commonNames.size() == certListRef.size());
766 FOREACH(it, certListRef)
768 auto cn = std::find(commonNames.begin(),
770 DPL::ToUTF8String(it->strCommonName));
771 RUNNER_ASSERT(cn != commonNames.end());
776 * Name: widget_dao_test_register_widget_privileges
777 * Description: Tests registration of widget privileges
779 RUNNER_TEST(widget_dao_test_register_widget_privileges)
783 WidgetRegisterInfo regInfo;
785 ConfigParserData::PrivilegeList& privilegeList =
786 regInfo.configInfo.privilegeList;
787 privilegeList.insert(DPL::FromUTF8String("name"));
788 privilegeList.insert(DPL::FromUTF8String("name2"));
790 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
791 WidgetDAO dao(tizenAppId);
793 WrtDB::PrivilegeList privListFromDB;
794 privListFromDB = dao.getWidgetPrivilege();
796 RUNNER_ASSERT(privilegeList.size() == privListFromDB.size());
798 auto privListIt = privilegeList.begin();
799 auto privDBIt = privListFromDB.begin();
800 for(; privListIt != privilegeList.end() && privDBIt != privListFromDB.end();
801 ++privListIt, ++privDBIt)
803 RUNNER_ASSERT(*privDBIt == privListIt->name);
808 * Name: widget_dao_test_register_app_control
809 * Description: Tests app control
811 RUNNER_TEST(widget_dao_test_register_app_control)
814 WidgetRegisterInfo regInfo;
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"));
823 ConfigParserData::AppControlInfoList& appControlListRef
824 = regInfo.configInfo.appControlList;
825 appControlListRef.push_back(appControl);
827 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
829 WidgetDAO dao(tizenAppId);
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();
837 for (;appDBIt != appControlInfoListDB.end()
838 && appRefIt != appControlListRef.end();
839 ++appDBIt, ++appRefIt)
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();
850 RUNNER_ASSERT((*it) == appDBIt->mime);
852 for(auto it = appRefIt->m_uriList.begin();
853 it != appRefIt->m_uriList.end();
856 RUNNER_ASSERT((*it) == appDBIt->uri);
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
866 RUNNER_TEST(widget_dao_test_is_widget_installed)
868 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
871 WidgetRegisterInfo regInfo;
873 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
875 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(tizenAppId));
879 * Name: widget_dao_test_unregister_widget
880 * Description: Tests unregistering widgets
881 * Expected: widget register informations should be successfully removed
883 RUNNER_TEST(widget_dao_test_unregister_widget)
886 WidgetHandleList handles = WidgetDAO::getHandleList();
888 WidgetRegisterInfo regInfo;
890 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
892 WidgetDAO::unregisterWidget(tizenAppId);
894 RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
895 "Widget unregister failed");
899 * Name: widget_dao_test_register_or_update_widget
900 * Description: Tests reregistering widgets
901 * Expected: widget should be successfully replaced
903 RUNNER_TEST(widget_dao_test_register_or_update_widget)
907 WidgetRegisterInfo regInfo;
908 regInfo.configInfo.version = L"1.0";
909 regInfo.configInfo.authorName = L"AAA";
911 WidgetRegisterInfo regInfo2;
912 regInfo2.configInfo.version = L"1.1";
913 regInfo2.configInfo.authorName = L"BBB";
915 WrtDB::TizenAppId tizenAppId(L"abcdefghij");
918 WidgetDAO::registerWidget(tizenAppId, regInfo, sec);
919 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
920 tizenAppId), "Widget is not registered");
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);
930 *dao.getVersion() == L"1.1", "Data widget was not updated");
932 *dao.getAuthorName() == L"BBB", "Data widget was not updated");
935 WidgetDAO::unregisterWidget(tizenAppId);
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
943 RUNNER_TEST(widget_dao_test_get_widget_tizenAppId_list)
945 TizenAppIdList tizenAppIds = WidgetDAO::getTizenAppidList();
946 RUNNER_ASSERT(tizenAppIds.size() >= 3);
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
955 RUNNER_TEST(widget_dao_test_get_widget_list)
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();
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
968 RUNNER_TEST(widget_dao_test_get_widget_attributes)
971 TizenAppId tizenAppId = L"tizenid201";
972 WidgetDAO dao(tizenAppId);
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(),
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");
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
992 RUNNER_TEST(widget_dao_test_localization)
997 WidgetRegisterInfo regInfo;
998 ConfigParserData::Icon icon(L"icon1");
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);
1008 WidgetRegisterInfo::StartFileProperties prop_en;
1009 prop_en.encoding = DPL::FromUTF8String("encoding_en");
1010 prop_en.type = DPL::FromUTF8String("type_en");
1012 WidgetRegisterInfo::StartFileProperties prop_pl;
1013 prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
1014 prop_pl.type = DPL::FromUTF8String("type_pl");
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);
1025 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1027 WidgetDAO dao(tizenAppId);
1029 // check localized icons
1030 WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
1031 RUNNER_ASSERT(locList.size() == locs.size());
1033 // non-localized icon
1034 WidgetDAO::WidgetIconList list = dao.getIconList();
1035 int iconId = list.front().iconId;
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,
1043 RUNNER_ASSERT(iconIt->appId == dao.getHandle());
1044 RUNNER_ASSERT(iconIt->iconId == iconId);
1045 RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
1048 // localized start file list
1049 WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
1050 RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
1052 int startFileId = dao.getStartFileList().front().startFileId;
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);
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
1071 RUNNER_TEST(widget_dao_test_wac_security)
1073 WacSecurityMock sec;
1074 WidgetRegisterInfo regInfo;
1077 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1078 WidgetDAO dao(tizenAppId);
1080 RUNNER_ASSERT(!dao.isDistributorSigned());
1081 RUNNER_ASSERT(!dao.isRecognized());
1083 sec.setDistributorSigned(true);
1084 sec.setRecognized(true);
1087 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1088 WidgetDAO dao(tizenAppId);
1090 RUNNER_ASSERT(dao.isDistributorSigned());
1091 RUNNER_ASSERT(dao.isRecognized());
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
1101 RUNNER_TEST(widget_dao_test_register_scp)
1103 WacSecurityMock sec;
1104 WidgetRegisterInfo regInfo;
1105 DPL::OptionalString policy = DPL::FromUTF8String("Some awesome csp policy");
1106 regInfo.configInfo.cspPolicy = policy;
1109 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1110 WidgetDAO dao(tizenAppId);
1112 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
1113 dao.getCspPolicy(), DPL::ToUTF8String(*policy));
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
1123 RUNNER_TEST(widget_dao_test_register_csp_empty)
1125 WacSecurityMock sec;
1126 WidgetRegisterInfo regInfo;
1129 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1130 WidgetDAO dao(tizenAppId);
1132 RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
1135 #undef RUNNER_ASSERT_WHAT_EQUALS