Implementation of ewk_home_directory_set API.
authorWojciech Bielawski <w.bielawski@samsung.com>
Wed, 3 Dec 2014 13:11:56 +0000 (14:11 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
In this patch there are two APIs implemented - set(public) & get(private).
This is because 'get' API is necessary in tests for 'set' API.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=4994
This is a cherry-pick from: http://165.213.202.130:8080/#/c/69072/

This is a cherry-pick from: http://165.213.202.130:8080/#/c/69454/2

Change-Id: I14fdb472855e5ed733507afb55eb4a9c645e16a8
Signed-off-by: Wojciech Bielawski <w.bielawski@samsung.com>
tizen_src/ewk/chromium-ewk.gyp
tizen_src/ewk/efl_integration/private/ewk_main_private.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/private/ewk_main_private.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/public/ewk_main.cc
tizen_src/ewk/efl_integration/public/ewk_main.h
tizen_src/ewk/unittest/ewk-tests.gypi
tizen_src/ewk/unittest/utc_blink_ewk_home_directory_get_func.cpp [new file with mode: 0644]
tizen_src/ewk/unittest/utc_blink_ewk_home_directory_set_func.cpp [new file with mode: 0644]

index 618e3b1..191f624 100644 (file)
       'efl_integration/private/ewk_frame_private.h',
       'efl_integration/private/ewk_hit_test_private.h',
       'efl_integration/private/ewk_hit_test_private.cc',
+      'efl_integration/private/ewk_main_private.h',
+      'efl_integration/private/ewk_main_private.cc',
       'efl_integration/private/ewk_notification_private.h',
       'efl_integration/private/ewk_notification_private.cc',
       'efl_integration/private/ewk_policy_decision_private.cc',
diff --git a/tizen_src/ewk/efl_integration/private/ewk_main_private.cc b/tizen_src/ewk/efl_integration/private/ewk_main_private.cc
new file mode 100644 (file)
index 0000000..c706779
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "ewk_main_private.h"
+#include "webview_delegate_ewk.h"
+
+const char* m_homeDirectory = NULL;
+
+const char* ewk_home_directory_get()
+{
+  if (m_homeDirectory && m_homeDirectory[0])
+    return m_homeDirectory;
+
+  const char *home = getenv("HOME");
+  if (!home)
+    home = getenv("TMPDIR");
+  if (!home)
+    home = "/tmp";
+
+  return home;
+}
+
diff --git a/tizen_src/ewk/efl_integration/private/ewk_main_private.h b/tizen_src/ewk/efl_integration/private/ewk_main_private.h
new file mode 100644 (file)
index 0000000..a7f3ee2
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ewk_main_private_h
+#define ewk_main_private_h
+
+#include "ewk_export.h"
+
+extern const char* m_homeDirectory;
+
+/**
+ * Returns home directory.
+ *
+ * If home directory is not previously set by ewk_home_directory_set() then $HOME envvar is returned.
+ * If $HOME is not set then "/tmp" is returned.
+ *
+ * @return home directory
+ */
+EAPI const char* ewk_home_directory_get();
+
+#endif // ewk_main_private_h
+
index 4947da8..359972b 100644 (file)
@@ -36,6 +36,7 @@
 #include "public/ewk_log.h"
 #include "private/webview_delegate_ewk.h"
 #include "private/ewk_private.h"
+#include "private/ewk_main_private.h"
 
 // TODO: remove dependency
 #include <../impl/command_line_efl.h>
@@ -167,7 +168,7 @@ void ewk_set_arguments(int argc, char** argv)
 
 void ewk_home_directory_set(const char* path)
 {
-  LOG_EWK_API_MOCKUP();
+  m_homeDirectory = path;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////
index 24894e0..1461f9b 100644 (file)
@@ -59,9 +59,10 @@ EAPI int ewk_shutdown(void);
  */
 EAPI void ewk_set_arguments(int argc, char** argv);
 
-// #if ENABLE(TIZEN_WEBKIT2_SET_HOME_DIRECTORY)
+/**
+* Set home directory.
+*/
 EAPI void ewk_home_directory_set(const char* path);
-// #endif
 
 #ifdef __cplusplus
 }
index f173a0b..da81900 100644 (file)
         'utc_blink_ewk_hit_test_node_value_get_func.cpp',
         'utc_blink_ewk_hit_test_result_context_get_func.cpp',
         'utc_blink_ewk_hit_test_tag_name_get_func.cpp',
+        'utc_blink_ewk_home_directory_get_func.cpp',
+        'utc_blink_ewk_home_directory_set_func.cpp',
         'utc_blink_ewk_notification_body_get_func.cpp',
         'utc_blink_ewk_notification_clicked_func.cpp',
         'utc_blink_ewk_notification_icon_url_get_func.cpp',
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_home_directory_get_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_home_directory_get_func.cpp
new file mode 100644 (file)
index 0000000..60c7bb0
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Chromium EFL
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "utc_blink_ewk_base.h"
+#include "../private/ewk_main_private.h"
+
+class utc_blink_ewk_home_directory_get : public utc_blink_ewk_base
+{
+};
+
+/**
+ * @brief Test if home directory is correctly returned when m_homeDirectory is set.
+ */
+TEST_F(utc_blink_ewk_home_directory_get, m_homeDirectory_is_set)
+{
+  ewk_home_directory_set("/someNewDir");
+  const char* dir = ewk_home_directory_get();
+  utc_message("Home dir == %s", dir);
+  ASSERT_STREQ("/someNewDir", dir);
+  ewk_home_directory_set(NULL);
+}
+
+/**
+ * @brief Test if home directory is correctly returned when there is no m_homeDirectory and $HOME is set.
+ */
+TEST_F(utc_blink_ewk_home_directory_get, m_homeDirectory_not_set)
+{
+  ewk_home_directory_set(NULL);
+
+  // If there is no $HOME set it
+  const char* home = getenv("HOME");
+  bool home_set = false;
+  if (!home) {
+    setenv("HOME", "/newHomeDir", 1);
+    home = getenv("HOME");
+    home_set = true;
+  }
+
+  // Get home directory
+  const char* dir = ewk_home_directory_get();
+  utc_message("Home dir == %s", dir);
+  ASSERT_STREQ(home, dir);
+
+  // Unset $HOME if it was previously set
+  if (home_set) {
+    unsetenv("HOME");
+    ASSERT_EQ(NULL, getenv("HOME"));
+  }
+}
+
+/**
+ * @brief Test if home directory is correctly returned when $HOME is not set.
+ */
+TEST_F(utc_blink_ewk_home_directory_get, env_HOME_not_set)
+{
+  ewk_home_directory_set(NULL);
+  // Save original $HOME
+  const char* orig_home = getenv("HOME");
+  if (orig_home) {
+    unsetenv("HOME");
+    ASSERT_EQ(NULL, getenv("HOME"));
+  }
+
+  // If there is no $TMPDIR set it
+  const char* tmpdir = getenv("TMPDIR");
+  bool tmpdir_set = false;
+  if (!tmpdir) {
+    setenv("TMPDIR", "/newtmpdir", 1);
+    tmpdir = getenv("TMPDIR");
+    tmpdir_set = true;
+  }
+
+  // Get home directory
+  const char* dir = ewk_home_directory_get();
+  utc_message("Home dir == %s", dir);
+  ASSERT_STREQ(tmpdir, dir);
+
+  // Restore original $HOME
+  if (orig_home) {
+    setenv("HOME", orig_home, 1);
+    ASSERT_STREQ(orig_home, getenv("HOME"));
+  }
+
+  // Unset $TMPDIR if it was previously set
+  if (tmpdir_set) {
+    unsetenv("TMPDIR");
+    ASSERT_EQ(NULL, getenv("TMPDIR"));
+  }
+}
+
+/**
+ * @brief Test if home directory is correctly returned when $TMPDIR is not set.
+ */
+TEST_F(utc_blink_ewk_home_directory_get, env_TMPDIR_not_set)
+{
+  ewk_home_directory_set(NULL);
+  // Save $HOME
+  const char* home = getenv("HOME");
+  if (home) {
+    unsetenv("HOME");
+    ASSERT_EQ(NULL, getenv("HOME"));
+  }
+
+  // Save $TMPDIR
+  const char* tmpdir = getenv("TMPDIR");
+  if (tmpdir) {
+    unsetenv("TMPDIR");
+    ASSERT_EQ(NULL, getenv("TMPDIR"));
+  }
+
+  // Get home directory
+  const char* dir = ewk_home_directory_get();
+  utc_message("Home dir == %s", dir);
+  ASSERT_STREQ("/tmp", dir);
+
+  // Restore $HOME
+  if (home) {
+    setenv("HOME", home, 1);
+    ASSERT_STREQ(home, getenv("HOME"));
+  }
+
+  // Restore $TMPDIR
+  if (tmpdir) {
+    setenv("TMPDIR", tmpdir, 1);
+    ASSERT_STREQ(tmpdir, getenv("TMPDIR"));
+  }
+}
+
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_home_directory_set_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_home_directory_set_func.cpp
new file mode 100644 (file)
index 0000000..152b921
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Chromium EFL
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "utc_blink_ewk_base.h"
+#include "../private/ewk_main_private.h"
+
+class utc_blink_ewk_home_directory_set : public utc_blink_ewk_base
+{
+};
+
+/**
+ * @brief Test if home directory is correctly set.
+ */
+TEST_F(utc_blink_ewk_home_directory_set, POS_TEST1)
+{
+  const char* home_dir = ewk_home_directory_get();
+  ASSERT_TRUE(home_dir);
+  const char* new_dir = "/foobar";
+  ASSERT_STRNE(home_dir, new_dir);
+  ewk_home_directory_set(new_dir);
+  ASSERT_STREQ(new_dir, ewk_home_directory_get());
+}
+
+/**
+ * @brief Test if function works correctly with NULL argument.
+ */
+TEST_F(utc_blink_ewk_home_directory_set, NEG_TEST1)
+{
+  // Set any home dir
+  const char* new_dir = "/foobar";
+  ewk_home_directory_set(new_dir);
+  ASSERT_STREQ(new_dir, ewk_home_directory_get());
+
+  // Set it to NULL
+  ewk_home_directory_set(NULL);
+  const char* ewk_home_dir = ewk_home_directory_get();
+  utc_message("Home dir == %s", ewk_home_dir);
+  // Check if it was changed
+  ASSERT_STRNE(new_dir, ewk_home_dir);
+
+  // Check if it was returned as one of the the expected values
+  const char* home_dir = getenv("HOME");
+  const char* tmp_dir = getenv("TMPDIR");
+  if (home_dir && home_dir[0]) {
+    ASSERT_STREQ(home_dir, ewk_home_dir);
+  } else if (tmp_dir && tmp_dir[0]) {
+    ASSERT_STREQ(tmp_dir, ewk_home_dir);
+  } else {
+    ASSERT_STREQ("/tmp", ewk_home_dir);
+  }
+}
+