X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxwalk%2Fapplication%2Fcommon%2Fmanifest_handlers%2Funittest_util.cc;h=6401d10c0e3d1af06c4e68cfc5b499e0cc211478;hb=a3137fbf780cf581b1011fd9024eff767a6c1d4b;hp=64c617124b47534ca6fa76934205876d2955a21c;hpb=949d079b90dcfa5fa918e1f366a6efb689615d20;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/xwalk/application/common/manifest_handlers/unittest_util.cc b/src/xwalk/application/common/manifest_handlers/unittest_util.cc index 64c6171..6401d10 100644 --- a/src/xwalk/application/common/manifest_handlers/unittest_util.cc +++ b/src/xwalk/application/common/manifest_handlers/unittest_util.cc @@ -4,7 +4,7 @@ #include "xwalk/application/common/manifest_handlers/unittest_util.h" -#include +#include "base/strings/string_util.h" #include "xwalk/application/common/application_manifest_constants.h" namespace xwalk { @@ -16,28 +16,49 @@ namespace application { namespace { -const char kDefaultVersion[] = "0"; -const char kDefaultName[] = "no name"; +// Makes a path to widget.element. +std::string MakeWidgetPath(const std::string& element) { + return MakeElementPath(widget_keys::kWidgetKey, element); +} #if defined(OS_TIZEN) -const char kDefaultPackageId[] = "abcdefghij"; -const char kDefaultApplicationName[] = "noname"; -const char kDefaultRequiredVersion[] = "0"; - -#endif // defined(OS_TIZEN) +// Makes a path to widget.application.element. +std::string MakeApplicationPath(const std::string& element) { + return MakeElementPath(widget_keys::kTizenApplicationKey, element); +} -std::string DotConnect(const std::string& first, const std::string& second) { - return first + '.' + second; +// Creates an app-widget element id basing on values of default package id +// and default application name. +std::string GetDefaultApplicationId() { + std::vector parts; + parts.push_back(kDefaultWidgetPackageId); + parts.push_back(kDefaultWidgetApplicationName); + return JoinString(parts, '.'); } +#endif // defined(OS_TIZEN) + } // namespace +const char kDefaultManifestName[] = "no name"; +const char kDefaultManifestVersion[] = "0"; +const char kDefaultWidgetName[] = "no name"; +const char kDefaultWidgetVersion[] = "0"; + +#if defined(OS_TIZEN) + +const char kDefaultWidgetPackageId[] = "abcdefghij"; +const char kDefaultWidgetApplicationName[] = "noname"; +const char kDefaultWidgetRequiredVersion[] = "0"; + +#endif // defined(OS_TIZEN) + scoped_ptr CreateDefaultManifestConfig() { scoped_ptr manifest(new base::DictionaryValue()); - manifest->SetString(manifest_keys::kXWalkVersionKey, kDefaultVersion); - manifest->SetString(manifest_keys::kNameKey, kDefaultName); + manifest->SetString(manifest_keys::kXWalkVersionKey, kDefaultManifestVersion); + manifest->SetString(manifest_keys::kNameKey, kDefaultManifestName); return manifest.Pass(); } @@ -47,32 +68,27 @@ scoped_ptr CreateDefaultWidgetConfig() { // widget attributes - manifest->SetString( - DotConnect(widget_keys::kWidgetKey, widget_keys::kNamespaceKey), - widget_keys::kWidgetNamespacePrefix); - manifest->SetString(widget_keys::kVersionKey, kDefaultVersion); - manifest->SetString(widget_keys::kNameKey, kDefaultName); + manifest->SetString(MakeWidgetPath(widget_keys::kNamespaceKey), + widget_keys::kWidgetNamespacePrefix); + manifest->SetString(widget_keys::kVersionKey, kDefaultWidgetVersion); + manifest->SetString(widget_keys::kNameKey, kDefaultWidgetName); #if defined(OS_TIZEN) // widget.application attributes manifest->SetString( - DotConnect(widget_keys::kTizenApplicationKey, - widget_keys::kNamespaceKey), + MakeApplicationPath(widget_keys::kNamespaceKey), widget_keys::kTizenNamespacePrefix); manifest->SetString( - DotConnect(widget_keys::kTizenApplicationKey, - widget_keys::kTizenApplicationIdKey), - DotConnect(kDefaultPackageId, kDefaultApplicationName)); + MakeApplicationPath(widget_keys::kTizenApplicationIdKey), + GetDefaultApplicationId()); manifest->SetString( - DotConnect(widget_keys::kTizenApplicationKey, - widget_keys::kTizenApplicationPackageKey), - kDefaultPackageId); + MakeApplicationPath(widget_keys::kTizenApplicationPackageKey), + kDefaultWidgetPackageId); manifest->SetString( - DotConnect(widget_keys::kTizenApplicationKey, - widget_keys::kTizenApplicationRequiredVersionKey), - kDefaultRequiredVersion); + MakeApplicationPath(widget_keys::kTizenApplicationRequiredVersionKey), + kDefaultWidgetRequiredVersion); #endif @@ -89,5 +105,41 @@ scoped_refptr CreateApplication(Manifest::Type type, return application; } +std::string MakeElementPath(const std::string& parent, + const std::string& element) { + std::vector parts; + parts.push_back(parent); + parts.push_back(element); + return JoinString(parts, '.'); +} + +bool AddDictionary(const std::string& key, + scoped_ptr child, base::DictionaryValue* parent) { + if (key.empty() || !child || !parent) + return false; + + scoped_ptr existing_child; + base::DictionaryValue* unused; + if (parent->GetDictionary(key, &unused)) { + if (!parent->Remove(key, &existing_child)) + return false; + } + + if (existing_child) { + scoped_ptr list(new base::ListValue); + list->Set(list->GetSize(), existing_child.release()); + list->Set(list->GetSize(), child.release()); + parent->Set(key, list.release()); + } else { + base::ListValue* list; + if (parent->GetList(key, &list)) + list->Set(list->GetSize(), child.release()); + else + parent->Set(key, child.release()); + } + + return true; +} + } // namespace application } // namespace xwalk