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(""), false);
219 ConfigParserData::Param par(DPL::FromUTF8String(("")));
220 par.value = DPL::FromUTF8String("");
221 feat.paramsList.insert(par);
222 regInfo.configInfo.featuresList.insert(feat);
225 regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
228 ConfigParserData::AccessInfo access(DPL::FromUTF8String(""), true);
229 regInfo.configInfo.accessInfoSet.insert(access);
232 WidgetCertificateData cert;
233 cert.owner = WidgetCertificateData::AUTHOR;
234 cert.type = WidgetCertificateData::ROOT;
236 cert.strMD5Fingerprint = "";
237 cert.strSHA1Fingerprint = "";
238 cert.strCommonName = DPL::FromUTF8String("");
240 WacSecurityMock security;
241 security.getCertificateListRef().push_back(cert);
243 REGISTER_WIDGET(regInfo, security);
247 * Name: widget_dao_test_register_widget_empty_strings
248 * Description: Tests possiblity of registering twice same content (different
250 * Expected: it should be possible
252 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
256 WidgetRegisterInfo regInfo;
257 REGISTER_WIDGET(regInfo, sec);
260 WidgetRegisterInfo regInfo;
261 REGISTER_WIDGET(regInfo, sec);
266 * Name: widget_dao_test_register_widget_minimum_info
267 * Description: Tests simplest registeration of new widget
268 * Expected: widget should be registered in database
270 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
273 const std::size_t NUMBER_OF_WIDGETS = 5;
275 TizenAppId lastTizenAppId;
277 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
278 WidgetRegisterInfo regInfo;
279 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
281 lastTizenAppId = tizenAppId;
283 WidgetDAO dao(tizenAppId);
289 * Name: widget_dao_test_register_widget_info
290 * Description: Tests registeration of many widgets
291 * Expected: all widgets should be registered in database
293 RUNNER_TEST(widget_dao_test_register_widget_info)
296 const std::size_t NUMBER_OF_WIDGETS = 5;
298 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
299 std::ostringstream str;
300 str << "register_info_test_" << number;
302 WidgetRegisterInfo regInfo;
303 regInfo.configInfo.widget_id = DPL::FromUTF8String(str.str());
304 regInfo.configInfo.version = DPL::FromUTF8String(str.str());
305 regInfo.configInfo.width = 10;
306 regInfo.configInfo.height = 10;
307 regInfo.configInfo.authorName = DPL::FromUTF8String(str.str());
308 regInfo.configInfo.authorEmail = DPL::FromUTF8String(str.str());
309 regInfo.configInfo.authorHref = DPL::FromUTF8String(str.str());
310 regInfo.baseFolder = str.str(); //base folder at the end has /
311 regInfo.configInfo.flashNeeded = false;
312 //TODO authenticated, etc...
313 //in wrt-installer: TaskWidgetConfig::fillWidgetConfig:
314 //regInfo.minVersion = regInfo.configInfo.minVersionRequired
315 regInfo.minVersion = DPL::FromUTF8String("1.0");
316 regInfo.configInfo.backSupported = true;
318 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
320 WidgetDAO dao(tizenAppId);
321 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), str.str());
322 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), str.str());
323 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), str.str());
324 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), str.str());
325 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), str.str());
326 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), str.str() + "/");
327 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == false);
329 // dao.GetWidgetSecurityDomain() == WacSecurity::Trusted);
330 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
335 * Name: widget_dao_test_register_widget_extended_info
336 * Description: Tests registeration of widget_extended_info
337 * Expected: registeration of extended inforamtion is checked
338 * via existence of backgroudn page value
340 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
343 const std::size_t NUMBER_OF_WIDGETS = 5;
345 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
346 std::ostringstream str;
347 str << "register_ext_info_test_" << number;
349 WidgetRegisterInfo regInfo;
351 // regInfo.shareHref = str.str();
352 regInfo.configInfo.backgroundPage = L"background.html";
354 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
356 WidgetDAO dao(tizenAppId);
357 // RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
359 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
365 * Name: widget_dao_test_register_widget_localized_info
366 * Description: Tests registeration of localized widgets information
367 * Expected: values received by dao should match those which were registered
369 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
372 const std::size_t NUMBER_OF_WIDGETS = 5;
374 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) {
375 WidgetRegisterInfo regInfo;
376 std::ostringstream str_en;
377 std::ostringstream str_pl;
378 str_en << "register_loc_info_test_en_" << number;
379 str_pl << "register_loc_info_test_pl_" << number;
381 ConfigParserData::LocalizedData locDataEn;
382 locDataEn.name = DPL::FromUTF8String(str_en.str());
383 locDataEn.shortName = DPL::FromUTF8String(str_en.str());
384 locDataEn.description = DPL::FromUTF8String(str_en.str());
385 locDataEn.license = DPL::FromUTF8String(str_en.str());
386 locDataEn.licenseFile = DPL::FromUTF8String(str_en.str());
387 locDataEn.licenseHref = DPL::FromUTF8String(str_en.str());
388 regInfo.configInfo.localizedDataSet.insert(
389 std::make_pair(DPL::FromUTF8String("en"), locDataEn));
393 ConfigParserData::LocalizedData locDataPl;
394 locDataPl.name = DPL::FromUTF8String(str_pl.str());
395 locDataPl.shortName = DPL::FromUTF8String(str_pl.str());
396 locDataPl.description = DPL::FromUTF8String(str_pl.str());
397 locDataPl.license = DPL::FromUTF8String(str_pl.str());
398 locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str());
399 locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str());
400 regInfo.configInfo.localizedDataSet.insert(
401 std::make_pair(DPL::FromUTF8String("pl"), locDataPl));
404 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
406 WidgetDAO dao(tizenAppId);
407 RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
408 "language tags list invalid");
411 WidgetLocalizedInfo locInfo =
412 dao.getLocalizedInfo(DPL::FromUTF8String("en"));
414 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
416 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
418 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
420 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
422 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
427 WidgetLocalizedInfo locInfo =
428 dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
430 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
432 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
434 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
436 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
438 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
445 * Name: widget_dao_test_register_widget_icons
446 * Description: Tests registeration of localized icons information
447 * Expected: values received by dao should match those which were registered
450 RUNNER_TEST(widget_dao_test_register_widget_icons)
453 WidgetRegisterInfo regInfo;
455 ConfigParserData::Icon icon(L"icon1");
459 locs.insert(DPL::FromUTF8String("en"));
460 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
461 regInfo.localizationData.icons.push_back(locIcon);
463 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
465 WidgetDAO dao(tizenAppId);
466 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
468 RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size());
469 WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin();
470 WidgetRegisterInfo::LocalizedIconList::const_iterator it2 =
471 regInfo.localizationData.icons.begin();
472 for (; it1 != list.end() && it2 != regInfo.localizationData.icons.end();
475 RUNNER_ASSERT(it2->height == it1->iconHeight);
476 RUNNER_ASSERT(it2->width == it1->iconWidth);
477 RUNNER_ASSERT(it2->src == it1->iconSrc);
478 RUNNER_ASSERT(it2->availableLocales == locs);
483 * Name: widget_dao_test_register_widget_start_files
484 * Description: Tests registeration of localized start files
485 * Expected: no expectations as it should be removed
487 RUNNER_TEST(widget_dao_test_register_widget_start_files)
491 WidgetRegisterInfo::LocalizedStartFileList files;
492 WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
493 WidgetRegisterInfo::StartFileProperties prop1;
494 prop1.encoding = DPL::FromUTF8String("enc1");
495 prop1.type = DPL::FromUTF8String("type1");
497 map1.insert(std::make_pair(DPL::FromUTF8String("en"), prop1));
498 map1.insert(std::make_pair(DPL::FromUTF8String("pl"), prop1));
500 WidgetRegisterInfo::LocalizedStartFile file1;
501 WidgetRegisterInfo::LocalizedStartFile file2;
502 file1.path = DPL::FromUTF8String("path1");
503 file1.propertiesForLocales = map1;
504 file2.path = DPL::FromUTF8String("path2");
505 file2.propertiesForLocales = map1;
507 files.push_back(file1);
508 files.push_back(file1);
510 WidgetRegisterInfo regInfo;
511 regInfo.localizationData.startFiles = files;
513 REGISTER_WIDGET(regInfo, sec);
515 //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
516 // but it will be removed
520 * Name: widget_dao_test_register_widget_features
521 * Description: Tests registeration of features of widget
522 * Expected: number of features should match (for given widget reginfo)
524 RUNNER_TEST(widget_dao_test_register_widget_features)
527 ConfigParserData::FeaturesList features;
528 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1"), true));
529 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2")));
530 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3"),
533 WidgetRegisterInfo regInfo;
534 FOREACH(it, features)
535 regInfo.configInfo.featuresList.insert(*it);
537 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
539 WidgetDAO dao(tizenAppId);
540 WidgetFeatureSet out = dao.getFeaturesList();
541 RUNNER_ASSERT_MSG(out.size() == features.size(),
542 "wrong number of features");
544 // RUNNER_ASSERT(features.find(*it) != features.end());
548 * Name: widget_dao_test_register_widget_security_settings
549 * Description: Tests registeration of dafault values of security settings
550 * Expected: widget should be registered in database.
551 * Returned values should match dafault.
553 RUNNER_TEST(widget_dao_test_register_widget_security_settings)
556 WidgetRegisterInfo regInfo;
557 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
559 WidgetDAO dao(tizenAppId);
561 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_ON,
562 "SecurityPopupUsage is not deafult on");
564 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
565 "GeolocationUsage is not deafult on");
567 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
568 "WebNotificationUsage is not deafult on");
570 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
571 "WebDatabaseUsage is not deafult on");
573 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
574 "FileSystemUsage is not deafult on");
576 dao.setSecurityPopupUsage(WrtDB::SETTINGS_TYPE_OFF);
578 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
579 "SecurityPopupUsage - wrong value");
581 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON,
582 "GeolocationUsage - wrong value");
584 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
585 "WebNotificationUsage - wrong value");
587 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
588 "WebDatabaseUsage - wrong value");
590 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
591 "FileSystemUsage - wrong value");
593 dao.setGeolocationUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
595 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
596 "SecurityPopupUsage - wrong value");
598 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
599 "GeolocationUsage - wrong value");
601 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON,
602 "WebNotificationUsage - wrong value");
604 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
605 "WebDatabaseUsage - wrong value");
607 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
608 "FileSystemUsage - wrong value");
610 dao.setWebNotificationUsage(WrtDB::SETTINGS_TYPE_OFF);
612 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
613 "SecurityPopupUsage - wrong value");
615 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
616 "GeolocationUsage - wrong value");
618 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
619 "WebNotificationUsage - wrong value");
621 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON,
622 "WebDatabaseUsage - wrong value");
624 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
625 "FileSystemUsage - wrong value");
627 dao.setWebDatabaseUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
629 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
630 "SecurityPopupUsage - wrong value");
632 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
633 "GeolocationUsage - wrong value");
635 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
636 "WebNotificationUsage - wrong value");
638 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
639 "WebDatabaseUsage - wrong value");
641 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
642 "FileSystemUsage - wrong value");
644 dao.setFileSystemUsage(WrtDB::SETTINGS_TYPE_OFF);
646 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
647 "SecurityPopupUsage - wrong value");
649 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
650 "GeolocationUsage - wrong value");
652 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
653 "WebNotificationUsage - wrong value");
655 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
656 "WebDatabaseUsage - wrong value");
658 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_OFF,
659 "FileSystemUsage - wrong value");
661 dao.setFileSystemUsage(WrtDB::SETTINGS_TYPE_ON);
663 dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF,
664 "SecurityPopupUsage - wrong value");
666 dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
667 "GeolocationUsage - wrong value");
669 dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF,
670 "WebNotificationUsage - wrong value");
672 dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK,
673 "WebDatabaseUsage - wrong value");
675 dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON,
676 "FileSystemUsage - wrong value");
680 * Name: widget_dao_test_register_widget_win_modes
681 * Description: Tests registeration of window modes
682 * Expected: all modes should be returned from dao
684 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
687 std::set<DPL::String> modes;
688 modes.insert(DPL::FromUTF8String("full"));
689 modes.insert(DPL::FromUTF8String("window"));
691 WidgetRegisterInfo regInfo;
694 regInfo.configInfo.windowModes.insert(*it);
696 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
698 WidgetDAO dao(tizenAppId);
699 std::list<DPL::String> wins = dao.getWindowModes();
700 RUNNER_ASSERT_MSG(modes.size() == wins.size(),
701 "wrong number of window modes");
703 RUNNER_ASSERT(modes.find(*it) != modes.end());
707 * Name: widget_dao_test_register_widget_warp_info
708 * Description: Tests registeration of access info iris
709 * Expected: all access info iris should be returned from dao
711 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
714 ConfigParserData::AccessInfoSet orig;
715 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
717 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
719 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
722 WidgetRegisterInfo regInfo;
724 regInfo.configInfo.accessInfoSet.insert(*it);
726 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
728 WidgetDAO dao(tizenAppId);
730 WidgetAccessInfoList out;
731 dao.getWidgetAccessInfo(out);
732 RUNNER_ASSERT_MSG(out.size() == orig.size(),
733 "wrong number of access info elem");
735 ConfigParserData::AccessInfo tmp(it->strIRI, it->bSubDomains);
736 RUNNER_ASSERT(orig.find(tmp) != orig.end());
741 * Name: widget_dao_test_register_widget_certificates
742 * Description: Tests registeration of widget certificates
743 * Expected: all certificates should be returned from dao
744 * and should contain inserted data
746 RUNNER_TEST(widget_dao_test_register_widget_certificates)
749 WidgetRegisterInfo regInfo;
751 WidgetCertificateData cert;
752 cert.owner = WidgetCertificateData::AUTHOR;
753 cert.type = WidgetCertificateData::ROOT;
755 cert.strMD5Fingerprint = "md5";
756 cert.strSHA1Fingerprint = "sha1";
757 cert.strCommonName = DPL::FromUTF8String("common name");
759 WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
760 certListRef.push_back(cert);
763 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
765 WidgetDAO dao(tizenAppId);
768 WidgetCertificateDataList recList = dao.getCertificateDataList();
769 RUNNER_ASSERT(recList.size() == certListRef.size());
771 auto recListIt = recList.begin();
772 auto certListIt = certListRef.begin();
773 for (; recListIt != recList.end() && certListIt != certListRef.end();
774 ++recListIt, ++certListIt)
776 RUNNER_ASSERT(recListIt->chainId == certListIt->chainId);
777 RUNNER_ASSERT(recListIt->owner == certListIt->owner);
778 RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName);
779 RUNNER_ASSERT(recListIt->strMD5Fingerprint ==
780 certListIt->strMD5Fingerprint);
781 RUNNER_ASSERT(recListIt->strSHA1Fingerprint ==
782 certListIt->strSHA1Fingerprint);
783 RUNNER_ASSERT(recListIt->type == certListIt->type);
787 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
788 WidgetCertificateData::ENDENTITY).
790 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
791 WidgetCertificateData::ENDENTITY).
793 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
794 WidgetCertificateData::ROOT).empty());
796 FingerPrintList fingerprints = dao.getKeyFingerprints(
797 WidgetCertificateData::AUTHOR,
798 WidgetCertificateData::ROOT);
800 RUNNER_ASSERT(fingerprints.size() == certListRef.size() * 2);
801 FOREACH(it, certListRef)
803 auto md5 = std::find(fingerprints.begin(),
805 it->strMD5Fingerprint);
806 RUNNER_ASSERT(md5 != fingerprints.end());
808 auto sha = std::find(fingerprints.begin(),
810 it->strSHA1Fingerprint);
811 RUNNER_ASSERT(sha != fingerprints.end());
815 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
816 WidgetCertificateData::ENDENTITY).
818 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
819 WidgetCertificateData::ENDENTITY).
821 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
822 WidgetCertificateData::ROOT).empty());
824 FingerPrintList commonNames = dao.getKeyCommonNameList(
825 WidgetCertificateData::AUTHOR,
826 WidgetCertificateData::ROOT);
828 RUNNER_ASSERT(commonNames.size() == certListRef.size());
829 FOREACH(it, certListRef)
831 auto cn = std::find(commonNames.begin(),
833 DPL::ToUTF8String(it->strCommonName));
834 RUNNER_ASSERT(cn != commonNames.end());
839 * Name: widget_dao_test_is_widget_installed
840 * Description: Tests checking if widgets are installed
841 * Expected: installed widgets should be stated as installed
843 RUNNER_TEST(widget_dao_test_is_widget_installed)
845 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
848 WidgetRegisterInfo regInfo;
850 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
852 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(tizenAppId));
856 * Name: widget_dao_test_unregister_widget
857 * Description: Tests unregistering widgets
858 * Expected: widget register informations should be successfully removed
860 RUNNER_TEST(widget_dao_test_unregister_widget)
863 WidgetHandleList handles = WidgetDAO::getHandleList();
865 WidgetRegisterInfo regInfo;
867 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
869 WidgetDAO::unregisterWidget(tizenAppId);
871 RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
872 "Widget unregister failed");
876 * Name: widget_dao_test_register_or_update_widget
877 * Description: Tests reregistering widgets
878 * Expected: widget should be successfully replaced
880 RUNNER_TEST(widget_dao_test_register_or_update_widget)
884 WidgetRegisterInfo regInfo;
885 regInfo.configInfo.version = L"1.0";
886 regInfo.configInfo.authorName = L"AAA";
888 WidgetRegisterInfo regInfo2;
889 regInfo2.configInfo.version = L"1.1";
890 regInfo2.configInfo.authorName = L"BBB";
892 WrtDB::TizenAppId tizenAppId(L"abcdefghij");
895 WidgetDAO::registerWidget(tizenAppId, regInfo, sec);
896 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
897 tizenAppId), "Widget is not registered");
899 //success full update
900 WidgetDAO::registerOrUpdateWidget(tizenAppId, regInfo2, sec);
901 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(
902 tizenAppId), "Widget is not reregistered");
903 WidgetDAO dao(tizenAppId);
905 *dao.getVersion() == L"1.1", "Data widget was not updated");
907 *dao.getAuthorName() == L"BBB", "Data widget was not updated");
909 WidgetDAO::unregisterWidget(tizenAppId);
913 * Name: widget_dao_test_get_widget_tizenAppId_list
914 * Description: Tests getTizenAppidList API for backendlib
915 * Expected: For all position in database should be returned one item in list
917 RUNNER_TEST(widget_dao_test_get_widget_tizenAppId_list)
919 TizenAppIdList tizenAppIds = WidgetDAO::getTizenAppidList();
920 RUNNER_ASSERT(tizenAppIds.size() >= 3);
924 * Name: widget_dao_test_get_widget_list
925 * Description: Tests getTizenAppidList API for backendlib
926 * Expected: For all position in database should be returned one item in list
927 * Those item should contain valid tizenAppId
929 RUNNER_TEST(widget_dao_test_get_widget_list)
931 WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList();
932 RUNNER_ASSERT(list.size() >= 3);
933 RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists");
934 WidgetDAOReadOnlyPtr dao = list.front();
938 * Name: widget_dao_test_get_widget_attributes
939 * Description: Tests returning basic widget attributes by dao
940 * Expected: Attributes should match values inserted into database
942 RUNNER_TEST(widget_dao_test_get_widget_attributes)
945 TizenAppId tizenAppId = L"tizenid201";
946 WidgetDAO dao(tizenAppId);
948 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000");
949 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0");
950 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000");
951 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(),
953 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000");
954 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/");
955 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true);
956 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
961 * Name: widget_dao_test_localization
962 * Description: Tests inserting and returning localization info
963 * Expected: Values inserted into database should match values received from
966 RUNNER_TEST(widget_dao_test_localization)
971 WidgetRegisterInfo regInfo;
972 ConfigParserData::Icon icon(L"icon1");
976 locs.insert(DPL::FromUTF8String("en"));
977 locs.insert(DPL::FromUTF8String("pl"));
978 WidgetRegisterInfo::LocalizedIcon locIcon(icon, locs);
979 regInfo.localizationData.icons.push_back(locIcon);
982 WidgetRegisterInfo::StartFileProperties prop_en;
983 prop_en.encoding = DPL::FromUTF8String("encoding_en");
984 prop_en.type = DPL::FromUTF8String("type_en");
986 WidgetRegisterInfo::StartFileProperties prop_pl;
987 prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
988 prop_pl.type = DPL::FromUTF8String("type_pl");
990 WidgetRegisterInfo::LocalizedStartFile file;
991 file.path = DPL::FromUTF8String("path");
992 file.propertiesForLocales.insert(
993 std::make_pair(DPL::FromUTF8String("en"), prop_en));
994 file.propertiesForLocales.insert(
995 std::make_pair(DPL::FromUTF8String("pl"), prop_pl));
996 regInfo.localizationData.startFiles.push_back(file);
999 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1001 WidgetDAO dao(tizenAppId);
1003 // check localized icons
1004 WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
1005 RUNNER_ASSERT(locList.size() == locs.size());
1007 // non-localized icon
1008 WidgetDAO::WidgetIconList list = dao.getIconList();
1009 int iconId = list.front().iconId;
1011 // compare every icon with the origin
1012 auto locsIt = locs.begin();
1013 auto iconIt = locList.begin();
1014 for (; locsIt != locs.end() && iconIt != locList.end(); ++locsIt,
1017 RUNNER_ASSERT(iconIt->appId == dao.getHandle());
1018 RUNNER_ASSERT(iconIt->iconId == iconId);
1019 RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
1022 // localized start file list
1023 WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
1024 RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
1026 int startFileId = dao.getStartFileList().front().startFileId;
1030 RUNNER_ASSERT(it->appId == dao.getHandle());
1031 auto propIt = file.propertiesForLocales.find(it->widgetLocale);
1032 RUNNER_ASSERT(propIt != file.propertiesForLocales.end());
1033 RUNNER_ASSERT(it->encoding == propIt->second.encoding);
1034 RUNNER_ASSERT(it->type == propIt->second.type);
1035 RUNNER_ASSERT(it->startFileId == startFileId);
1040 * Name: widget_dao_test_wac_security
1041 * Description: Tests inserting and returning wac security information
1042 * Expected: Values inserted into database should match values received from
1045 RUNNER_TEST(widget_dao_test_wac_security)
1047 WacSecurityMock sec;
1048 WidgetRegisterInfo regInfo;
1051 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1052 WidgetDAO dao(tizenAppId);
1054 RUNNER_ASSERT(!dao.isDistributorSigned());
1055 RUNNER_ASSERT(!dao.isRecognized());
1056 RUNNER_ASSERT(!dao.isWacSigned());
1058 sec.setDistributorSigned(true);
1059 sec.setRecognized(true);
1060 sec.setWacSigned(true);
1063 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1064 WidgetDAO dao(tizenAppId);
1066 RUNNER_ASSERT(dao.isDistributorSigned());
1067 RUNNER_ASSERT(dao.isRecognized());
1068 RUNNER_ASSERT(dao.isWacSigned());
1073 * Name: widget_dao_test_register_scp
1074 * Description: Tests inserting and returning scp policy information
1075 * Expected: Value inserted into database should match values received from
1078 RUNNER_TEST(widget_dao_test_register_scp)
1080 WacSecurityMock sec;
1081 WidgetRegisterInfo regInfo;
1082 DPL::OptionalString policy = DPL::FromUTF8String("Some awesome csp policy");
1083 regInfo.configInfo.cspPolicy = policy;
1086 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1087 WidgetDAO dao(tizenAppId);
1089 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
1090 dao.getCspPolicy(), DPL::ToUTF8String(*policy));
1095 * Name: widget_dao_test_register_csp_empty
1096 * Description: Tests inserting and returning empty csp policy
1097 * Expected: Value inserted into database should match values received from
1100 RUNNER_TEST(widget_dao_test_register_csp_empty)
1102 WacSecurityMock sec;
1103 WidgetRegisterInfo regInfo;
1106 TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
1107 WidgetDAO dao(tizenAppId);
1109 RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
1112 #undef RUNNER_ASSERT_WHAT_EQUALS