Upstream version 11.39.264.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / unittest_util.cc
index 64c6171..6401d10 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "xwalk/application/common/manifest_handlers/unittest_util.h"
 
-#include <string>
+#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<std::string> 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<base::DictionaryValue> CreateDefaultManifestConfig() {
   scoped_ptr<base::DictionaryValue> 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<base::DictionaryValue> 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<ApplicationData> CreateApplication(Manifest::Type type,
   return application;
 }
 
+std::string MakeElementPath(const std::string& parent,
+    const std::string& element) {
+  std::vector<std::string> parts;
+  parts.push_back(parent);
+  parts.push_back(element);
+  return JoinString(parts, '.');
+}
+
+bool AddDictionary(const std::string& key,
+    scoped_ptr<base::DictionaryValue> child, base::DictionaryValue* parent) {
+  if (key.empty() || !child || !parent)
+    return false;
+
+  scoped_ptr<base::Value> existing_child;
+  base::DictionaryValue* unused;
+  if (parent->GetDictionary(key, &unused)) {
+    if (!parent->Remove(key, &existing_child))
+      return false;
+  }
+
+  if (existing_child) {
+    scoped_ptr<base::ListValue> 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