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;
40 class WacSecurityMock : public WrtDB::IWacSecurity
45 mDistributorSigned(false),
50 virtual const WidgetCertificateDataList& getCertificateList() const
55 virtual bool isRecognized() const { return mRecognized; }
56 virtual bool isDistributorSigned() const { return mDistributorSigned; }
57 virtual bool isWacSigned() const { return mWacSigned; }
58 virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {}
59 virtual void getCertificateChainList(CertificateChainList& /*lst*/,
60 CertificateSource source) const {}
62 WrtDB::WidgetCertificateDataList& getCertificateListRef()
67 void setRecognized(bool recognized) { mRecognized = recognized; }
68 void setDistributorSigned(bool distributorSigned)
70 mDistributorSigned = distributorSigned;
72 void setWacSigned(bool wacSigned) { mWacSigned = wacSigned; }
75 WrtDB::WidgetCertificateDataList mList;
76 // author signature verified
79 bool mDistributorSigned;
85 WidgetPkgName _registerWidget(const WidgetRegisterInfo& regInfo,
86 const IWacSecurity& sec,
89 WidgetPkgName pkgname;
91 auto previous = WidgetDAO::getPkgnameList();
94 pkgname = WidgetDAO::registerWidgetGenerateTizenId(regInfo, sec);
96 RUNNER_ASSERT_MSG(!pkgname.empty(),
97 "(called from line " << line << ")");
99 auto current = WidgetDAO::getPkgnameList();
100 RUNNER_ASSERT_MSG(previous.size()+1 == current.size(),
101 "(called from line " << line << ")");
103 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname),
104 "(called from line " << line << " pkgname: " << pkgname << ")");
106 Catch (WidgetDAO::Exception::AlreadyRegistered) {
109 "Unexpected exception (called from line " << line << ")");
114 #define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo),(sec), __LINE__)
118 // Widgets used <2300,2500), 2000, 2001, 2002, 2003
120 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
121 {std::string tmp(in); \
122 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");}
124 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
126 if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \
127 else RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in),test);\
130 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test) \
132 if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \
133 else RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); \
136 RUNNER_TEST_GROUP_INIT(DAO)
140 Name: widget_dao_test_register_widget_empty_strings
141 Description: Tests registeration of new widget with empty values
142 Expected: widget should be registered in database
144 RUNNER_TEST(widget_dao_test_register_widget_empty_strings)
146 WidgetRegisterInfo regInfo;
149 regInfo.shareHref = "";
152 regInfo.configInfo.widget_id = DPL::FromUTF8String("");
153 regInfo.configInfo.version = DPL::FromUTF8String("");
154 regInfo.configInfo.width = 10;
155 regInfo.configInfo.height = 10;
156 regInfo.configInfo.authorName = DPL::FromUTF8String("");
157 regInfo.configInfo.authorEmail = DPL::FromUTF8String("");
158 regInfo.configInfo.authorHref = DPL::FromUTF8String("");
159 regInfo.baseFolder = "";
160 //TODO authenticated, etc...
161 regInfo.configInfo.flashNeeded = false;
162 regInfo.configInfo.minVersionRequired = DPL::FromUTF8String("1.0");
163 regInfo.configInfo.backSupported = true;
166 ConfigParserData::LocalizedData locData;
167 locData.name = DPL::FromUTF8String("");
168 locData.shortName = DPL::FromUTF8String("");
169 locData.description = DPL::FromUTF8String("");
170 locData.license = DPL::FromUTF8String("");
171 locData.licenseFile = DPL::FromUTF8String("");
172 locData.licenseHref = DPL::FromUTF8String("");
173 regInfo.configInfo.localizedDataSet.insert(
174 std::make_pair(DPL::FromUTF8String("en"),locData));
179 ConfigParserData::Icon icon(DPL::FromUTF8String(""));
183 locs.insert(DPL::FromUTF8String("en"));
184 WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
185 regInfo.localizationData.icons.push_back(locIcon);
188 WidgetRegisterInfo::StartFileProperties prop;
189 prop.encoding = DPL::FromUTF8String("");
190 prop.type = DPL::FromUTF8String("");
191 WidgetRegisterInfo::LocalizedStartFile file;
192 file.path = DPL::FromUTF8String("");
193 file.propertiesForLocales.insert(
194 std::make_pair(DPL::FromUTF8String("en"), prop));
195 regInfo.localizationData.startFiles.push_back(file);
198 ConfigParserData::Preference pref(DPL::FromUTF8String(""),false);
199 pref.value = DPL::FromUTF8String("");
200 regInfo.configInfo.preferencesList.insert(pref);
203 ConfigParserData::Feature feat(DPL::FromUTF8String(""),false);
204 ConfigParserData::Param par(DPL::FromUTF8String(("")));
205 par.value = DPL::FromUTF8String("");
206 feat.paramsList.insert(par);
207 regInfo.configInfo.featuresList.insert(feat);
210 regInfo.configInfo.windowModes.insert(DPL::FromUTF8String(""));
213 ConfigParserData::AccessInfo access(DPL::FromUTF8String(""),true);
214 regInfo.configInfo.accessInfoSet.insert(access);
217 WidgetCertificateData cert;
218 cert.owner = WidgetCertificateData::AUTHOR;
219 cert.type = WidgetCertificateData::ROOT;
221 cert.strMD5Fingerprint = "";
222 cert.strSHA1Fingerprint = "";
223 cert.strCommonName = DPL::FromUTF8String("");
225 WacSecurityMock security;
226 security.getCertificateListRef().push_back(cert);
228 REGISTER_WIDGET(regInfo,security);
232 Name: widget_dao_test_register_widget_empty_strings
233 Description: Tests possiblity of registering twice same content (different tizenId)
234 Expected: it should be possible
236 RUNNER_TEST(widget_dao_test_twice_install_same_widget)
240 WidgetRegisterInfo regInfo;
241 REGISTER_WIDGET(regInfo, sec);
244 WidgetRegisterInfo regInfo;
245 REGISTER_WIDGET(regInfo, sec);
251 Name: widget_dao_test_register_widget_minimum_info
252 Description: Tests simplest registeration of new widget
253 Expected: widget should be registered in database
255 RUNNER_TEST(widget_dao_test_register_widget_minimum_info)
258 const std::size_t NUMBER_OF_WIDGETS = 5;
260 WidgetPkgName lastPkgname;
262 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
264 WidgetRegisterInfo regInfo;
265 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
267 lastPkgname = pkgname;
269 WidgetDAO dao(pkgname);
275 Name: widget_dao_test_register_widget_info
276 Description: Tests registeration of many widgets
277 Expected: all widgets should be registered in database
279 RUNNER_TEST(widget_dao_test_register_widget_info)
282 const std::size_t NUMBER_OF_WIDGETS = 5;
284 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 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
307 WidgetDAO dao(pkgname);
308 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), str.str());
309 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), str.str());
310 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), str.str());
311 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), str.str());
312 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), str.str());
313 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), str.str() + "/");
314 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == false);
316 // dao.GetWidgetSecurityDomain() == WacSecurity::Trusted);
317 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
323 Name: widget_dao_test_register_widget_extended_info
324 Description: Tests registeration of widget_extended_info
325 Expected: registeration of extended inforamtion is checked
326 via existence of backgroudn page value
328 RUNNER_TEST(widget_dao_test_register_widget_extended_info)
331 const std::size_t NUMBER_OF_WIDGETS = 5;
333 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
335 std::ostringstream str;
336 str << "register_ext_info_test_" << number;
338 WidgetRegisterInfo regInfo;
340 // regInfo.shareHref = str.str();
341 regInfo.configInfo.backgroundPage = L"background.html";
343 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
345 WidgetDAO dao(pkgname);
346 // RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str());
348 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(),
354 Name: widget_dao_test_register_widget_localized_info
355 Description: Tests registeration of localized widgets information
356 Expected: values received by dao should match those which were registered
358 RUNNER_TEST(widget_dao_test_register_widget_localized_info)
361 const std::size_t NUMBER_OF_WIDGETS = 5;
363 for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number)
365 WidgetRegisterInfo regInfo;
366 std::ostringstream str_en;
367 std::ostringstream str_pl;
368 str_en << "register_loc_info_test_en_" << number;
369 str_pl<< "register_loc_info_test_pl_" << number;
371 ConfigParserData::LocalizedData locDataEn;
372 locDataEn.name = DPL::FromUTF8String(str_en.str());
373 locDataEn.shortName = DPL::FromUTF8String(str_en.str());
374 locDataEn.description = DPL::FromUTF8String(str_en.str());
375 locDataEn.license = DPL::FromUTF8String(str_en.str());
376 locDataEn.licenseFile = DPL::FromUTF8String(str_en.str());
377 locDataEn.licenseHref = DPL::FromUTF8String(str_en.str());
378 regInfo.configInfo.localizedDataSet.insert(
379 std::make_pair(DPL::FromUTF8String("en"),locDataEn));
383 ConfigParserData::LocalizedData locDataPl;
384 locDataPl.name = DPL::FromUTF8String(str_pl.str());
385 locDataPl.shortName = DPL::FromUTF8String(str_pl.str());
386 locDataPl.description = DPL::FromUTF8String(str_pl.str());
387 locDataPl.license = DPL::FromUTF8String(str_pl.str());
388 locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str());
389 locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str());
390 regInfo.configInfo.localizedDataSet.insert(
391 std::make_pair(DPL::FromUTF8String("pl"),locDataPl));
394 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
396 WidgetDAO dao(pkgname);
397 RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2,
398 "language tags list invalid");
401 WidgetLocalizedInfo locInfo =
402 dao.getLocalizedInfo(DPL::FromUTF8String("en"));
404 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
406 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
408 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
410 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
412 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
417 WidgetLocalizedInfo locInfo =
418 dao.getLocalizedInfo(DPL::FromUTF8String("pl"));
420 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name,
422 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName,
424 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description,
426 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license,
428 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref,
435 Name: widget_dao_test_register_widget_icons
436 Description: Tests registeration of localized icons information
437 Expected: values received by dao should match those which were registered
440 RUNNER_TEST(widget_dao_test_register_widget_icons)
443 WidgetRegisterInfo regInfo;
445 ConfigParserData::Icon icon(L"icon1");
449 locs.insert(DPL::FromUTF8String("en"));
450 WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
451 regInfo.localizationData.icons.push_back(locIcon);
453 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
455 WidgetDAO dao(pkgname);
456 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
458 RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size());
459 WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin();
460 WidgetRegisterInfo::LocalizedIconList::const_iterator it2 =
461 regInfo.localizationData.icons.begin();
462 for(;it1!=list.end() && it2!=regInfo.localizationData.icons.end();
465 RUNNER_ASSERT(it2->height == it1->iconHeight);
466 RUNNER_ASSERT(it2->width == it1->iconWidth);
467 RUNNER_ASSERT(it2->src == it1->iconSrc);
468 RUNNER_ASSERT(it2->availableLocales == locs);
473 Name: widget_dao_test_register_widget_start_files
474 Description: Tests registeration of localized start files
475 Expected: no expectations as it should be removed
477 RUNNER_TEST(widget_dao_test_register_widget_start_files)
481 WidgetRegisterInfo::LocalizedStartFileList files;
482 WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1;
483 WidgetRegisterInfo::StartFileProperties prop1;
484 prop1.encoding = DPL::FromUTF8String("enc1");
485 prop1.type = DPL::FromUTF8String("type1");
487 map1.insert(std::make_pair(DPL::FromUTF8String("en"),prop1));
488 map1.insert(std::make_pair(DPL::FromUTF8String("pl"),prop1));
490 WidgetRegisterInfo::LocalizedStartFile file1;
491 WidgetRegisterInfo::LocalizedStartFile file2;
492 file1.path = DPL::FromUTF8String("path1");
493 file1.propertiesForLocales = map1;
494 file2.path = DPL::FromUTF8String("path2");
495 file2.propertiesForLocales = map1;
497 files.push_back(file1);
498 files.push_back(file1);
500 WidgetRegisterInfo regInfo;
501 regInfo.localizationData.startFiles = files;
503 REGISTER_WIDGET(regInfo, sec);
505 //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO,
506 // but it will be removed
510 Name: widget_dao_test_register_widget_features
511 Description: Tests registeration of features of widget
512 Expected: number of features should match (for given widget reginfo)
514 RUNNER_TEST(widget_dao_test_register_widget_features)
517 ConfigParserData::FeaturesList features;
518 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1"),true));
519 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2")));
520 features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3"),
523 WidgetRegisterInfo regInfo;
524 FOREACH(it, features)
525 regInfo.configInfo.featuresList.insert(*it);
527 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
529 WidgetDAO dao(pkgname);
530 WidgetFeatureSet out = dao.getFeaturesList();
531 RUNNER_ASSERT_MSG(out.size() == features.size(),
532 "wrong number of features");
534 // RUNNER_ASSERT(features.find(*it) != features.end());
538 Name: widget_dao_test_register_widget_security_settings
539 Description: Tests registeration of dafault values of security settings
540 Expected: widget should be registered in database.
541 Returned values should match dafault.
543 RUNNER_TEST(widget_dao_test_register_widget_security_settings)
546 WidgetRegisterInfo regInfo;
547 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
549 WidgetDAO dao(pkgname);
550 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_ON, "SecurityPopupUsage is not deafult on");
551 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON, "GeolocationUsage is not deafult on");
552 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON, "WebNotificationUsage is not deafult on");
553 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON, "WebDatabaseUsage is not deafult on");
554 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage is not deafult on");
556 dao.setSecurityPopupUsage(WrtDB::SETTINGS_TYPE_OFF);
557 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
558 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ON, "GeolocationUsage - wrong value");
559 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON, "WebNotificationUsage - wrong value");
560 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON, "WebDatabaseUsage - wrong value");
561 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage - wrong value");
563 dao.setGeolocationUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
564 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
565 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "GeolocationUsage - wrong value");
566 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_ON, "WebNotificationUsage - wrong value");
567 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON, "WebDatabaseUsage - wrong value");
568 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage - wrong value");
570 dao.setWebNotificationUsage(WrtDB::SETTINGS_TYPE_OFF);
571 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
572 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "GeolocationUsage - wrong value");
573 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF, "WebNotificationUsage - wrong value");
574 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ON, "WebDatabaseUsage - wrong value");
575 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage - wrong value");
577 dao.setWebDatabaseUsage(WrtDB::SETTINGS_TYPE_ALWAYS_ASK);
578 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
579 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "GeolocationUsage - wrong value");
580 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF, "WebNotificationUsage - wrong value");
581 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "WebDatabaseUsage - wrong value");
582 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage - wrong value");
584 dao.setFileSystemUsage(WrtDB::SETTINGS_TYPE_OFF);
585 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
586 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "GeolocationUsage - wrong value");
587 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF, "WebNotificationUsage - wrong value");
588 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "WebDatabaseUsage - wrong value");
589 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_OFF, "FileSystemUsage - wrong value");
591 dao.setFileSystemUsage(WrtDB::SETTINGS_TYPE_ON);
592 RUNNER_ASSERT_MSG(dao.getSecurityPopupUsage() == WrtDB::SETTINGS_TYPE_OFF, "SecurityPopupUsage - wrong value");
593 RUNNER_ASSERT_MSG(dao.getGeolocationUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "GeolocationUsage - wrong value");
594 RUNNER_ASSERT_MSG(dao.getWebNotificationUsage() == WrtDB::SETTINGS_TYPE_OFF, "WebNotificationUsage - wrong value");
595 RUNNER_ASSERT_MSG(dao.getWebDatabaseUsage() == WrtDB::SETTINGS_TYPE_ALWAYS_ASK, "WebDatabaseUsage - wrong value");
596 RUNNER_ASSERT_MSG(dao.getFileSystemUsage() == WrtDB::SETTINGS_TYPE_ON, "FileSystemUsage - wrong value");
600 Name: widget_dao_test_register_widget_win_modes
601 Description: Tests registeration of window modes
602 Expected: all modes should be returned from dao
604 RUNNER_TEST(widget_dao_test_register_widget_win_modes)
607 std::set<DPL::String> modes;
608 modes.insert(DPL::FromUTF8String("full"));
609 modes.insert(DPL::FromUTF8String("window"));
611 WidgetRegisterInfo regInfo;
614 regInfo.configInfo.windowModes.insert(*it);
616 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
618 WidgetDAO dao(pkgname);
619 std::list<DPL::String> wins = dao.getWindowModes();
620 RUNNER_ASSERT_MSG(modes.size() == wins.size(),
621 "wrong number of window modes");
623 RUNNER_ASSERT(modes.find(*it) != modes.end());
627 Name: widget_dao_test_register_widget_warp_info
628 Description: Tests registeration of access info iris
629 Expected: all access info iris should be returned from dao
631 RUNNER_TEST(widget_dao_test_register_widget_warp_info)
634 ConfigParserData::AccessInfoSet orig;
635 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"),
637 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"),
639 orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"),
642 WidgetRegisterInfo regInfo;
644 regInfo.configInfo.accessInfoSet.insert(*it);
646 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
648 WidgetDAO dao(pkgname);
650 WidgetAccessInfoList out;
651 dao.getWidgetAccessInfo(out);
652 RUNNER_ASSERT_MSG(out.size() == orig.size(),
653 "wrong number of access info elem");
655 ConfigParserData::AccessInfo tmp(it->strIRI,it->bSubDomains);
656 RUNNER_ASSERT(orig.find(tmp) != orig.end());
661 Name: widget_dao_test_register_widget_certificates
662 Description: Tests registeration of widget certificates
663 Expected: all certificates should be returned from dao
664 and should contain inserted data
666 RUNNER_TEST(widget_dao_test_register_widget_certificates)
669 WidgetRegisterInfo regInfo;
671 WidgetCertificateData cert;
672 cert.owner = WidgetCertificateData::AUTHOR;
673 cert.type = WidgetCertificateData::ROOT;
675 cert.strMD5Fingerprint = "md5";
676 cert.strSHA1Fingerprint = "sha1";
677 cert.strCommonName = DPL::FromUTF8String("common name");
679 WidgetCertificateDataList& certListRef = sec.getCertificateListRef();
680 certListRef.push_back(cert);
683 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
685 WidgetDAO dao(pkgname);
688 WidgetCertificateDataList recList = dao.getCertificateDataList();
689 RUNNER_ASSERT(recList.size() == certListRef.size());
691 auto recListIt = recList.begin();
692 auto certListIt = certListRef.begin();
693 for(;recListIt != recList.end() && certListIt != certListRef.end();
694 ++recListIt,++certListIt)
696 RUNNER_ASSERT(recListIt->chainId == certListIt->chainId);
697 RUNNER_ASSERT(recListIt->owner == certListIt->owner);
698 RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName);
699 RUNNER_ASSERT(recListIt->strMD5Fingerprint ==
700 certListIt->strMD5Fingerprint);
701 RUNNER_ASSERT(recListIt->strSHA1Fingerprint ==
702 certListIt->strSHA1Fingerprint);
703 RUNNER_ASSERT(recListIt->type == certListIt->type);
707 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
708 WidgetCertificateData::ENDENTITY).empty());
709 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
710 WidgetCertificateData::ENDENTITY).empty());
711 RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
712 WidgetCertificateData::ROOT).empty());
714 FingerPrintList fingerprints = dao.getKeyFingerprints(
715 WidgetCertificateData::AUTHOR,
716 WidgetCertificateData::ROOT);
718 RUNNER_ASSERT(fingerprints.size() == certListRef.size()*2);
719 FOREACH(it, certListRef)
721 auto md5 = std::find(fingerprints.begin(),
723 it->strMD5Fingerprint);
724 RUNNER_ASSERT(md5 != fingerprints.end());
726 auto sha = std::find(fingerprints.begin(),
728 it->strSHA1Fingerprint);
729 RUNNER_ASSERT(sha != fingerprints.end());
733 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
734 WidgetCertificateData::ENDENTITY).empty());
735 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
736 WidgetCertificateData::ENDENTITY).empty());
737 RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
738 WidgetCertificateData::ROOT).empty());
740 FingerPrintList commonNames = dao.getKeyCommonNameList(
741 WidgetCertificateData::AUTHOR,
742 WidgetCertificateData::ROOT);
744 RUNNER_ASSERT(commonNames.size() == certListRef.size());
745 FOREACH(it, certListRef)
747 auto cn = std::find(commonNames.begin(),
749 DPL::ToUTF8String(it->strCommonName));
750 RUNNER_ASSERT(cn != commonNames.end());
755 Name: widget_dao_test_is_widget_installed
756 Description: Tests checking if widgets are installed
757 Expected: installed widgets should be stated as installed
759 RUNNER_TEST(widget_dao_test_is_widget_installed)
761 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201"));
764 WidgetRegisterInfo regInfo;
766 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
768 RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(pkgname));
772 Name: widget_dao_test_unregister_widget
773 Description: Tests unregistering widgets
774 Expected: widget register informations should be successfully removed
776 RUNNER_TEST(widget_dao_test_unregister_widget)
779 WidgetHandleList handles = WidgetDAO::getHandleList();
781 WidgetRegisterInfo regInfo;
783 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
785 WidgetDAO::unregisterWidget(pkgname);
787 RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(),
788 "Widget unregister failed");
792 Name: widget_dao_test_register_or_update_widget
793 Description: Tests reregistering widgets
794 Expected: widget should be successfully replaced
796 RUNNER_TEST(widget_dao_test_register_or_update_widget)
800 WidgetRegisterInfo regInfo;
801 regInfo.configInfo.version = L"1.0";
802 regInfo.configInfo.authorName = L"AAA";
804 WidgetRegisterInfo regInfo2;
805 regInfo2.configInfo.version = L"1.1";
806 regInfo2.configInfo.authorName = L"BBB";
808 WrtDB::WidgetPkgName pkgname(L"abcdefghij");
811 WidgetDAO::registerWidget(pkgname, regInfo, sec);
812 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not registered");
814 //success full update
815 WidgetDAO::registerOrUpdateWidget(pkgname, regInfo2, sec);
816 RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not reregistered");
817 WidgetDAO dao(pkgname);
818 RUNNER_ASSERT_MSG(*dao.getVersion() == L"1.1", "Data widget was not updated");
819 RUNNER_ASSERT_MSG(*dao.getAuthorName() == L"BBB", "Data widget was not updated");
821 WidgetDAO::unregisterWidget(pkgname);
825 Name: widget_dao_test_get_widget_pkgname_list
826 Description: Tests getPkgnameList API for backendlib
827 Expected: For all position in database should be returned one item in list
829 RUNNER_TEST(widget_dao_test_get_widget_pkgname_list)
831 WidgetPkgNameList pkgnames = WidgetDAO::getPkgnameList();
832 RUNNER_ASSERT(pkgnames.size() >= 3);
836 Name: widget_dao_test_get_widget_list
837 Description: Tests getPkgnameList API for backendlib
838 Expected: For all position in database should be returned one item in list
839 Those item should contain valid pkgname
841 RUNNER_TEST(widget_dao_test_get_widget_list)
843 WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList();
844 RUNNER_ASSERT(list.size() >= 3);
845 RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists");
846 WidgetDAOReadOnlyPtr dao = list.front();
850 Name: widget_dao_test_get_widget_attributes
851 Description: Tests returning basic widget attributes by dao
852 Expected: Attributes should match values inserted into database
854 RUNNER_TEST(widget_dao_test_get_widget_attributes)
857 WidgetPkgName pkgname = L"tizenid201";
858 WidgetDAO dao(pkgname);
860 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000");
861 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0");
862 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000");
863 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(),
865 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000");
866 RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/");
867 RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true);
868 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0");
873 Name: widget_dao_test_localization
874 Description: Tests inserting and returning localization info
875 Expected: Values inserted into database should match values received from database
877 RUNNER_TEST(widget_dao_test_localization)
882 WidgetRegisterInfo regInfo;
883 ConfigParserData::Icon icon(L"icon1");
887 locs.insert(DPL::FromUTF8String("en"));
888 locs.insert(DPL::FromUTF8String("pl"));
889 WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs);
890 regInfo.localizationData.icons.push_back(locIcon);
893 WidgetRegisterInfo::StartFileProperties prop_en;
894 prop_en.encoding = DPL::FromUTF8String("encoding_en");
895 prop_en.type = DPL::FromUTF8String("type_en");
897 WidgetRegisterInfo::StartFileProperties prop_pl;
898 prop_pl.encoding = DPL::FromUTF8String("encoding_pl");
899 prop_pl.type = DPL::FromUTF8String("type_pl");
901 WidgetRegisterInfo::LocalizedStartFile file;
902 file.path = DPL::FromUTF8String("path");
903 file.propertiesForLocales.insert(
904 std::make_pair(DPL::FromUTF8String("en"), prop_en));
905 file.propertiesForLocales.insert(
906 std::make_pair(DPL::FromUTF8String("pl"), prop_pl));
907 regInfo.localizationData.startFiles.push_back(file);
910 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
912 WidgetDAO dao(pkgname);
914 // check localized icons
915 WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
916 RUNNER_ASSERT(locList.size() == locs.size());
918 // non-localized icon
919 WidgetDAO::WidgetIconList list = dao.getIconList();
920 int iconId = list.front().iconId;
922 // compare every icon with the origin
923 auto locsIt = locs.begin();
924 auto iconIt = locList.begin();
925 for(;locsIt!=locs.end() && iconIt!=locList.end();++locsIt,++iconIt) {
926 RUNNER_ASSERT(iconIt->appId == dao.getHandle());
927 RUNNER_ASSERT(iconIt->iconId == iconId);
928 RUNNER_ASSERT(iconIt->widgetLocale == *locsIt);
931 // localized start file list
932 WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList();
933 RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size());
935 int startFileId = dao.getStartFileList().front().startFileId;
939 RUNNER_ASSERT(it->appId == dao.getHandle());
940 auto propIt = file.propertiesForLocales.find(it->widgetLocale);
941 RUNNER_ASSERT(propIt != file.propertiesForLocales.end());
942 RUNNER_ASSERT(it->encoding == propIt->second.encoding);
943 RUNNER_ASSERT(it->type == propIt->second.type);
944 RUNNER_ASSERT(it->startFileId == startFileId);
949 Name: widget_dao_test_wac_security
950 Description: Tests inserting and returning wac security information
951 Expected: Values inserted into database should match values received from database
953 RUNNER_TEST(widget_dao_test_wac_security)
956 WidgetRegisterInfo regInfo;
959 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
960 WidgetDAO dao(pkgname);
962 RUNNER_ASSERT(!dao.isDistributorSigned());
963 RUNNER_ASSERT(!dao.isRecognized());
964 RUNNER_ASSERT(!dao.isWacSigned());
966 sec.setDistributorSigned(true);
967 sec.setRecognized(true);
968 sec.setWacSigned(true);
971 WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec);
972 WidgetDAO dao(pkgname);
974 RUNNER_ASSERT(dao.isDistributorSigned());
975 RUNNER_ASSERT(dao.isRecognized());
976 RUNNER_ASSERT(dao.isWacSigned());
980 #undef RUNNER_ASSERT_WHAT_EQUALS