[M40 Merge] Add ewk_notification_icon_save_as_png API
authorKamil Klimek <k.klimek@partner.samsung.com>
Wed, 4 Mar 2015 11:18:17 +0000 (12:18 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
After notification API refactoring the only way to retrieve notification
icon was to create new Evas_Object with icon. Add extra API for
convinience

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=11368
Reviewed by: Antonio Gomes, Eun Namgung, Jaesik Chang, Piotr Tworek, commitbot

Change-Id: Ia383aef963e403e3879c7a098761dc39ebadbd51
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
tizen_src/ewk/efl_integration/private/ewk_notification_private.cc
tizen_src/ewk/efl_integration/private/ewk_notification_private.h
tizen_src/ewk/efl_integration/public/ewk_notification.cc
tizen_src/ewk/efl_integration/public/ewk_notification.h
tizen_src/ewk/unittest/ewk-tests.gypi
tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_save_as_png_func.cpp [new file with mode: 0755]

index d9ebc9c..c31ae12 100644 (file)
@@ -5,6 +5,7 @@
 #include "ewk_notification_private.h"
 
 #include "content/public/browser/browser_thread.h"
+#include "third_party/skia/include/core/SkImageEncoder.h"
 
 using content::BrowserThread;
 
@@ -70,6 +71,10 @@ const _Ewk_Security_Origin* Ewk_Notification::GetSecurityOrigin() const {
   return origin_.get();
 }
 
+bool Ewk_Notification::SaveAsPng(const char* path) const {
+  return SkImageEncoder::EncodeFile(path, icon_,
+      SkImageEncoder::kPNG_Type, 100); // use max quality
+}
 
 Ewk_Notification_Permission_Request::Ewk_Notification_Permission_Request(
     Evas_Object* webview,
index a195b93..cecdd22 100644 (file)
@@ -34,6 +34,7 @@ struct Ewk_Notification {
   Evas_Object* GetIcon(Evas* evas) const;
   int GetID() const;
   const _Ewk_Security_Origin* GetSecurityOrigin() const;
+  bool SaveAsPng(const char* path) const;
 
  private:
   std::string body_;
index f446801..3818c32 100644 (file)
@@ -74,6 +74,15 @@ const char* ewk_notification_body_get(const Ewk_Notification* ewk_notification)
   return ewk_notification->GetBody();
 }
 
+Eina_Bool ewk_notification_icon_save_as_png(
+    const Ewk_Notification* ewk_notification, const char* path)
+{
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
+
+  return ewk_notification->SaveAsPng(path);
+}
+
 Eina_Bool ewk_notification_clicked(uint64_t notification_id)
 {
   ContentBrowserClientEfl* cbce = GetContentBrowserClient();
index 34d2ce8..165652c 100644 (file)
@@ -62,6 +62,17 @@ EAPI Eina_Bool ewk_notification_callbacks_reset();
 EAPI Evas_Object* ewk_notification_icon_get(const Ewk_Notification* ewk_notification, Evas* evas);
 
 /**
+ * Save notification icon as PNG image
+ *
+ * @param ewk_notification notification data pointer
+ * @param path path where file will be saved
+ *
+ * @return EINA_TRUE on success
+ */
+EAPI Eina_Bool ewk_notification_icon_save_as_png(
+    const Ewk_Notification* ewk_notification, const char* path);
+
+/**
  * Requests for getting body of notification.
  *
  * @param ewk_notification pointer of notificaion data
index fa504e6..1c877af 100644 (file)
         'utc_blink_ewk_notification_clicked_func.cpp',
         'utc_blink_ewk_notification_closed_func.cpp',
         'utc_blink_ewk_notification_icon_get_func.cpp',
+        'utc_blink_ewk_notification_icon_save_as_png_func.cpp',
         'utc_blink_ewk_notification_id_get_func.cpp',
         'utc_blink_ewk_notification_permission_reply_func.cpp',
         'utc_blink_ewk_notification_permission_request_origin_get_func.cpp',
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_save_as_png_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_save_as_png_func.cpp
new file mode 100755 (executable)
index 0000000..a682b91
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2015 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_notification_test_base.h"
+
+class utc_blink_ewk_notification_icon_save_as_png : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_icon_save_as_png()
+    : saved_to_file(false)
+    , notification_icon_path("/tmp/notification_icon.png")
+  {}
+
+  void NotificationShow(Ewk_Notification* notification) override
+  {
+    saved_to_file = ewk_notification_icon_save_as_png(notification, notification_icon_path);
+    EventLoopStop(Success);
+  }
+
+ protected:
+  bool saved_to_file;
+  const char *notification_icon_path;
+};
+
+/**
+* @brief Positive test case for ewk_notification_icon_get()
+*/
+TEST_F(utc_blink_ewk_notification_icon_save_as_png, POS_TEST)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(saved_to_file);
+  Evas_Object* img = evas_object_image_add(GetEwkEvas());
+  ASSERT_TRUE(img);
+  evas_object_image_file_set(img, notification_icon_path, NULL);
+  // Skia and Efl may decode png in different way, we add fuzziness of 3 points
+  // difference between pixel values
+  ASSERT_TRUE(CompareEvasImageWithResource(img, "/common/logo.png", 3));
+  evas_object_del(img);
+}
+
+/**
+* @brief Checking whether function works properly in case of nullptr value pass
+*/
+TEST_F(utc_blink_ewk_notification_icon_save_as_png, NEG_TEST)
+{
+  ASSERT_FALSE(ewk_notification_icon_save_as_png(nullptr, nullptr));
+  ASSERT_FALSE(ewk_notification_icon_save_as_png(
+      reinterpret_cast<Ewk_Notification*>(1), nullptr));
+  ASSERT_FALSE(ewk_notification_icon_save_as_png(nullptr,
+      notification_icon_path));
+}