Implement EWK web context inspector APIs
authorPiotr Sieduszewski <p.sieduszews@samsung.com>
Wed, 7 Jan 2015 08:00:00 +0000 (09:00 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Implementation of:
- ewk_context_inspector_server_start
- ewk_context_inspector_server_stop

Classes WebContext and EWebContest implement methods for starting and
stopping debug tools supported by a class DevToolsDelegateEfl

TC for ewk_context_inspector_server_start try start inspector server on:
- specified port and open url
- unspecified port and open url with returned port
- used port

TC for ewk_context_inspector_server_stop try:
- stop WebInspector without start (expexted fail).
- start WebInspector on port 11111 TCP and stop it.
To see if it's stopped:
- try open page on this port, and
- run WebInspector on the same port again.

This patch contains following patches:
http://165.213.202.130:8080/68795
http://165.213.202.130:8080/69030
http://165.213.202.130:8080/69486
http://165.213.202.130:8080/69059

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9549
Reviewed by: Janusz Majnert, Kamil Klimek, Min-Soo Koo, Piotr Tworek

Change-Id: Ib769a0d27fb45b4f90a8f8afa1722955f5c77eb4
Signed-off-by: Piotr Sieduszewski <p.sieduszews@samsung.com>
tizen_src/ewk/efl_integration/public/ewk_context.cc
tizen_src/ewk/unittest/ewk-tests.gypi
tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_start_func.cpp [new file with mode: 0644]
tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_stop_func.cpp [new file with mode: 0644]
tizen_src/impl/eweb_context.cc
tizen_src/impl/eweb_context.h
tizen_src/impl/tizen_webview/public/tw_web_context.cc
tizen_src/impl/tizen_webview/public/tw_web_context.h

index fca1007..ab81ede 100644 (file)
@@ -473,7 +473,7 @@ void ewk_context_vibration_client_callbacks_set(Ewk_Context* context,
 Eina_Bool ewk_context_tizen_extensible_api_string_set(Ewk_Context* ewkContext,  const char* extensibleAPI, Eina_Bool enable)
 {
   LOG_EWK_API_MOCKUP();
-  return NULL;
+  return EINA_FALSE;
 }
 
 Eina_Bool ewk_context_tizen_extensible_api_set(Ewk_Context * /*context*/, Ewk_Extensible_API /*extensibleAPI*/, Eina_Bool /*enable*/)
@@ -511,14 +511,14 @@ int ewk_context_pixmap_get(Ewk_Context *context)
 
 unsigned int ewk_context_inspector_server_start(Ewk_Context* ewkContext, unsigned int port)
 {
-  LOG_EWK_API_MOCKUP();
-  return NULL;
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
+  return ewkContext->InspectorServerStart(port);
 }
 
 Eina_Bool ewk_context_inspector_server_stop(Ewk_Context* ewkContext)
 {
-  LOG_EWK_API_MOCKUP();
-  return NULL;
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, EINA_FALSE);
+  return ewkContext->InspectorServerStop();
 }
 
 void ewk_send_widget_info(Ewk_Context *context,
index da81900..2fd3b65 100644 (file)
@@ -96,6 +96,8 @@
         'utc_blink_ewk_context_form_password_data_delete_all_func.cpp',
         'utc_blink_ewk_context_icon_database_icon_object_add_func.cpp',
         'utc_blink_ewk_context_icon_database_path_set_func.cpp',
+        'utc_blink_ewk_context_inspector_server_start_func.cpp',
+        'utc_blink_ewk_context_inspector_server_stop_func.cpp',
         'utc_blink_ewk_context_local_file_system_all_delete_func.cpp',
         'utc_blink_ewk_context_local_file_system_delete_func.cpp',
         'utc_blink_ewk_context_memory_sampler_start_func.cpp',
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_start_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_start_func.cpp
new file mode 100644 (file)
index 0000000..7d48289
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2014 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "utc_blink_ewk_base.h"
+
+class utc_blink_ewk_context_inspector_server_start : public utc_blink_ewk_base
+{
+  void LoadFinished(Evas_Object* webview)
+  {
+    EventLoopStop(Success);
+  }
+};
+
+/* @brief Negative test case of ewk_context_inspector_server_start */
+TEST_F(utc_blink_ewk_context_inspector_server_start, NullArg)
+{
+  ASSERT_NE(EINA_TRUE, ewk_context_inspector_server_start(NULL,0));
+}
+
+/* @brief Try start inspector of context on specified TCP port*/
+TEST_F(utc_blink_ewk_context_inspector_server_start, Start)
+{
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), "http://localhost:11111"));
+  ASSERT_NE(Success, EventLoopStart()) << "http://localhost:11111";
+
+  ASSERT_EQ(11111, ewk_context_inspector_server_start(ewk_context_default_get(), 11111));
+  EventLoopWait(1);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), "http://localhost:11111"));
+  ASSERT_EQ(Success, EventLoopStart()) << "http://localhost:11111";
+}
+
+/* @brief Try start inspector of context on unspecified TCP port*/
+TEST_F(utc_blink_ewk_context_inspector_server_start, DefaultPort)
+{
+  int port=ewk_context_inspector_server_start(ewk_context_default_get(), 0);
+  ASSERT_NE(0, port) << "ewk_context_inspector_server_start(0)";
+  EventLoopWait(1);
+
+  char url[32]; sprintf(url, "http://localhost:%u", port);
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), url));
+  ASSERT_EQ(Success, EventLoopStart()) << url;
+
+}
+
+/* @brief Negative test case of ewk_context_inspector_server_start on used port*/
+TEST_F(utc_blink_ewk_context_inspector_server_start, UsedPort)
+{
+  ASSERT_EQ(11111, ewk_view_inspector_server_start(GetEwkWebView(),11111));
+  EventLoopWait(1);
+  ASSERT_NE(11111, ewk_context_inspector_server_start(ewk_context_default_get(),11111));
+}
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_stop_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_context_inspector_server_stop_func.cpp
new file mode 100644 (file)
index 0000000..15d7384
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright 2014 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "utc_blink_ewk_base.h"
+
+class utc_blink_ewk_context_inspector_server_stop : public utc_blink_ewk_base
+{
+protected:
+  void LoadFinished(Evas_Object* webview)
+  {
+    EventLoopStop(Success);
+  }
+};
+
+/* @brief Try stop inspector with NULL as context */
+TEST_F(utc_blink_ewk_context_inspector_server_stop, NullArg)
+{
+  ASSERT_NE(EINA_TRUE, ewk_context_inspector_server_stop(NULL));
+}
+
+/* @brief Try stop inspector without start */
+TEST_F(utc_blink_ewk_context_inspector_server_stop, WithOutStart)
+{
+  ASSERT_NE(EINA_TRUE, ewk_context_inspector_server_stop(ewk_context_default_get()));
+}
+
+/* @brief Try start inspector after stop */
+TEST_F(utc_blink_ewk_context_inspector_server_stop, StartStop)
+{
+  ASSERT_EQ(11111, ewk_context_inspector_server_start(ewk_context_default_get(), 11111));
+  EventLoopWait(3);
+
+  ASSERT_EQ(EINA_TRUE, ewk_context_inspector_server_stop(ewk_context_default_get()));
+  EventLoopWait(3);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), "http://localhost:11111"));
+  EXPECT_NE(Success, EventLoopStart());
+
+  ASSERT_EQ(11111, ewk_context_inspector_server_start(ewk_context_default_get(), 11111));
+  EventLoopWait(3);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), "http://localhost:11111"));
+  EXPECT_EQ(Success, EventLoopStart());
+}
index bef0f79..92e1fe5 100644 (file)
@@ -230,6 +230,7 @@ bool EWebContext::ShouldOverrideMimeForURL(
 
 EWebContext::EWebContext(bool incognito)
     : m_pixmap(0),
+      inspector_server_(NULL),
       incognito_(incognito) {
   CHECK(EwkGlobalData::GetInstance());
 
@@ -500,3 +501,17 @@ void EWebContext::ClearPasswordData() {
 #endif
 }
 
+unsigned int EWebContext::InspectorServerStart(unsigned int port) {
+  InspectorServerStop();
+  inspector_server_ = new content::DevToolsDelegateEfl(port);
+  return inspector_server_ ? inspector_server_->port() : 0;
+}
+
+bool EWebContext::InspectorServerStop() {
+  if (!inspector_server_)
+    return false;
+  // The call below destroys inspector_server_.
+  inspector_server_->Stop();
+  inspector_server_ = NULL;
+  return true;
+}
index d672f44..a8ff3f7 100644 (file)
@@ -10,6 +10,7 @@
 #include "browser/renderer_host/web_cache_manager_efl.h"
 #include "tizen_webview/public/tw_cache_model.h"
 #include "tizen_webview/public/tw_callbacks.h"
+#include "devtools_delegate_efl.h"
 
 namespace tizen_webview {
 class URL;
@@ -99,6 +100,9 @@ class EWebContext {
   FaviconDatabase* GetFaviconDatabase();
 #endif
 
+  unsigned int InspectorServerStart(unsigned int port);
+  bool InspectorServerStop();
+
  private:
   EWebContext(bool incognito);
   ~EWebContext();
@@ -112,6 +116,7 @@ class EWebContext {
   std::string proxy_uri_;
   scoped_ptr<EwkDidStartDownloadCallback> start_download_callback_;
   int m_pixmap;
+  content::DevToolsDelegateEfl* inspector_server_;
   bool incognito_;
 };
 
index 1cdde08..56e22c6 100644 (file)
@@ -248,4 +248,12 @@ void WebContext::StopMemorySampler() const {
   impl->StopMemorySampler();
 }
 
+unsigned int WebContext::InspectorServerStart(unsigned int port) const {
+  return impl->InspectorServerStart(port);
+}
+
+bool WebContext::InspectorServerStop() const {
+  return impl->InspectorServerStop();
+}
+
 } // namespace tizen_webview
index 32ff492..d8f0e90 100644 (file)
@@ -129,6 +129,9 @@ struct WebContext : public tizen_webview::RefCounted<WebContext> {
   FaviconDatabase* GetFaviconDatabase();
 #endif
 
+  unsigned int InspectorServerStart(unsigned int port) const;
+  bool InspectorServerStop() const;
+
  private:
   EWebContext* impl;