Refactor notification API
authorKamil Klimek <k.klimek@partner.samsung.com>
Fri, 2 Jan 2015 13:25:23 +0000 (14:25 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
HTML5 notification handling in chromium has changed and it made
impossible to implement some of existing EWK notification APIS. This
required us to refactor notification API. Notifications are now not
related with webview.

Deprecated:
 * notification,show smart callback
   - smart callbacks require webview Evas_Object
 * notification,cancel smart callback
   - smart callbacks require webview Evas_Object
 * ewk_notification_icon_url_get
   - icon is now stored internaly as SkBitmap
 * ewk_view_notification_closed
   - notifications are not related to webview

Introduced:
 * ewk_notification_callbacks_set
   - api to set callbacks for notification show/cancel
 * ewk_notification_callbacks_reset
   - resets notification callbacks to NULL
 * ewk_notification_icon_get
   - creates Evas_Object with notification icon
 * ewk_notification_closed
   - notify engine that notification was closed

Modified:
 * ewk_notification_clicked
   - return Eina_Bool to indicate if event was dispatched
   - removed Ewk_Context parameter as it is not required anymore
 * ewk_notification_showed
   - return Eina_Bool to indicate if event was dispatched
   - removed Ewk_Context parameter as it is not required anymore
 * ewk_notification_cached_permissions_set
   - return Eina_Bool to indicate if permissions were set
   - removed Ewk_Context parameter as it is not required anymore
 * ewk_notification_permission_reply
   - return Eina_Bool to indicate if operation was successful
 * ewk_notification_permission_request_set
   - return Eina_Bool to indicate if operation was successful
 * ewk_notification_permission_request_suspend
   - return Eina_Bool to indicate if operation was successful
 * ewk_notification_policies_removed
   - return Eina_Bool to indicate if operation was successful
   - removed Ewk_Context parameter as it is not required anymore

Additionaly all notification related unit tests were refactored to share
common base setup. Some unit tests were also improved to test not only
API calls but check also expected results like checking if proper JS
engine events were produced.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9540
Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9526
Reviewed by: Antonio Gomes, Jaesik Chang, Janusz Majnert, Piotr Tworek

Change-Id: I0d5788b2a4e00a1af2d5dc6479244cc6150627df
Signed-off-by: Kamil Klimek <k.klimek@partner.samsung.com>
45 files changed:
tizen_src/ewk/efl_integration/public/ewk_notification.cc
tizen_src/ewk/efl_integration/public/ewk_notification.h
tizen_src/ewk/efl_integration/public/ewk_view.cc
tizen_src/ewk/efl_integration/public/ewk_view.h
tizen_src/ewk/efl_webview_app/app.c
tizen_src/ewk/unittest/ewk-tests.gypi
tizen_src/ewk/unittest/resources/common/sample_notification_1.html [changed mode: 0755->0644]
tizen_src/ewk/unittest/resources/common/sample_notification_2.html [deleted file]
tizen_src/ewk/unittest/utc_blink_ewk_base.cpp
tizen_src/ewk/unittest/utc_blink_ewk_base.h
tizen_src/ewk/unittest/utc_blink_ewk_notification_body_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_reset_func.cpp [new file with mode: 0755]
tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_set_func.cpp [new file with mode: 0755]
tizen_src/ewk/unittest/utc_blink_ewk_notification_clicked_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_closed_func.cpp [new file with mode: 0755]
tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_get_func.cpp [new file with mode: 0755]
tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_url_get_func.cpp [deleted file]
tizen_src/ewk/unittest/utc_blink_ewk_notification_id_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_permission_reply_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_permission_request_origin_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_permission_request_set_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_permission_request_suspend_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_policies_removed_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_security_origin_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_showed_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_notification_test_base.h [new file with mode: 0644]
tizen_src/ewk/unittest/utc_blink_ewk_notification_title_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_security_origin_host_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_security_origin_port_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_security_origin_protocol_get_func.cpp
tizen_src/ewk/unittest/utc_blink_ewk_view_notification_closed_func.cpp [deleted file]
tizen_src/ewk/unittest/utc_blink_ewk_view_notification_permission_callback_set_func.cpp
tizen_src/impl/browser/notification/notification_controller_efl.cc
tizen_src/impl/browser/notification/notification_controller_efl.h
tizen_src/impl/browser_context_efl.cc
tizen_src/impl/browser_context_efl.h
tizen_src/impl/content_browser_client_efl.cc
tizen_src/impl/content_browser_client_efl.h
tizen_src/impl/content_main_delegate_efl.cc
tizen_src/impl/content_main_delegate_efl.h
tizen_src/impl/eweb_view_callbacks.h
tizen_src/impl/ewk_global_data.cc
tizen_src/impl/ewk_global_data.h
tizen_src/impl/tizen_webview/public/tw_notification.cc
tizen_src/impl/tizen_webview/public/tw_notification.h

index d0345c5..f4815c5 100644 (file)
@@ -9,43 +9,97 @@
 #include <../impl/eweb_view.h>
 #include <../impl/browser_context_efl.h>
 
+
+#include "../impl/browser/notification/notification_controller_efl.h"
+#include "../impl/content_browser_client_efl.h"
+#include "../impl/content_main_delegate_efl.h"
+#include "../impl/ewk_global_data.h"
+
 #include "private/ewk_context_private.h"
 #include "private/ewk_security_origin_private.h"
 #include "private/ewk_notification_private.h"
 #include "private/ewk_private.h"
 
-const char *ewk_notification_body_get(const Ewk_Notification *ewk_notification)
+using content::ContentBrowserClientEfl;
+using content::ContentMainDelegateEfl;
+
+namespace {
+ContentBrowserClientEfl* GetContentBrowserClient()
+{
+  if (!EwkGlobalData::IsInitialized()) {
+    return nullptr;
+  }
+
+  ContentMainDelegateEfl& cmde = EwkGlobalData::GetInstance()->GetContentMainDelegatEfl();
+  ContentBrowserClientEfl* cbce = static_cast<ContentBrowserClientEfl*>(cmde.GetContentBrowserClient());
+
+  return cbce;
+}
+}
+
+Eina_Bool ewk_notification_callbacks_set(Ewk_Notification_Show_Callback show_callback, Ewk_Notification_Cancel_Callback cancel_callback, void* user_data)
+{
+  EINA_SAFETY_ON_NULL_RETURN_VAL(show_callback, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cancel_callback, EINA_FALSE);
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+
+  ContentBrowserClientEfl::Notification_Show_Callback scb =
+      reinterpret_cast<ContentBrowserClientEfl::Notification_Show_Callback>(show_callback);
+
+  ContentBrowserClientEfl::Notification_Cancel_Callback ccb =
+      reinterpret_cast<ContentBrowserClientEfl::Notification_Cancel_Callback>(cancel_callback);
+
+  cbce->SetNotificationCallbacks(scb, ccb, user_data);
+
+  return EINA_TRUE;
+}
+
+Eina_Bool ewk_notification_callbacks_reset()
+{
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+
+  cbce->SetNotificationCallbacks(nullptr, nullptr, nullptr);
+  return EINA_TRUE;
+}
+
+EAPI Evas_Object* ewk_notification_icon_get(const Ewk_Notification* ewk_notification, Evas* evas)
+{
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, nullptr);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(evas, nullptr);
+  return ewk_notification->GetIcon(evas);
+}
+
+const char* ewk_notification_body_get(const Ewk_Notification* ewk_notification)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, 0);
   return ewk_notification->GetBody();
 }
 
-void ewk_notification_clicked(Ewk_Context *context, uint64_t notification_id)
+Eina_Bool ewk_notification_clicked(uint64_t notification_id)
 {
-#if !defined(EWK_BRINGUP)
-#warning "[M38] TODO: Fix and re-enable notifications (edit efl_integration/public/ewk_notifications.cc)"
-  EINA_SAFETY_ON_NULL_RETURN(context);
-  context->browser_context()->GetNotificationController()->NotifyNotificationClicked(notification_id);
-#endif
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  return cbce->GetNotificationController()->NotificationClicked(notification_id);
 }
 
-const char *ewk_notification_icon_url_get(const Ewk_Notification *ewk_notification)
+const char* ewk_notification_icon_url_get(const Ewk_Notification* ewk_notification)
 {
-  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, 0);
-  return ewk_notification->GetIconUrl();
+  return nullptr;
 }
 
-uint64_t ewk_notification_id_get(const Ewk_Notification *ewk_notification)
+uint64_t ewk_notification_id_get(const Ewk_Notificationewk_notification)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, 0);
   return ewk_notification->GetID();
 }
 
-void ewk_notification_cached_permissions_set(Ewk_Context *context, Eina_List *ewk_notification_permissions)
+Eina_Bool ewk_notification_cached_permissions_set(Eina_List* ewk_notification_permissions)
 {
-#if defined(ENABLE_NOTIFICATIONS)
-  EINA_SAFETY_ON_NULL_RETURN(context);
-  scoped_refptr<content::NotificationControllerEfl> notification_controller(context->browser_context()->GetNotificationController());
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  content::NotificationControllerEfl* notification_controller = cbce->GetNotificationController();
   notification_controller->ClearPermissions();
   Eina_List* list;
   void* data;
@@ -53,63 +107,67 @@ void ewk_notification_cached_permissions_set(Ewk_Context *context, Eina_List *ew
     Ewk_Notification_Permission* perm = static_cast<Ewk_Notification_Permission*>(data);
     notification_controller->AddPermission(GURL(perm->origin), (perm->allowed == EINA_TRUE));
   }
-#else
-  NOTIMPLEMENTED();
-#endif
+
+  return EINA_TRUE;
 }
 
-const Ewk_Security_Origin *ewk_notification_permission_request_origin_get(
-    const Ewk_Notification_Permission_Request *request)
+const Ewk_Security_Originewk_notification_permission_request_origin_get(
+    const Ewk_Notification_Permission_Requestrequest)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
   return static_cast<const Ewk_Security_Origin*>(request->GetSecurityOrigin());
 }
 
-void ewk_notification_permission_reply(Ewk_Notification_Permission_Request *request, Eina_Bool allow)
+Eina_Bool ewk_notification_permission_reply(Ewk_Notification_Permission_Request* request, Eina_Bool allow)
 {
-#if defined(ENABLE_NOTIFICATIONS)
-  EINA_SAFETY_ON_NULL_RETURN(request);
-  request->Reply(allow == EINA_TRUE);
-#endif
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(request, EINA_FALSE);
+  cbce->GetNotificationController()->SetPermissionForNotification(request, allow);
+  return request->Reply(allow == EINA_TRUE);
 }
 
-void ewk_notification_permission_request_set(Ewk_Notification_Permission_Request *request, Eina_Bool allowed)
+Eina_Bool ewk_notification_permission_request_set(Ewk_Notification_Permission_Request* request, Eina_Bool allow)
 {
-#if defined(ENABLE_NOTIFICATIONS)
-  EINA_SAFETY_ON_NULL_RETURN(request);
-  request->Reply(allowed == EINA_TRUE);
-#endif
+  return ewk_notification_permission_reply(request, allow);
 }
 
-void ewk_notification_permission_request_suspend(Ewk_Notification_Permission_Request *request)
+Eina_Bool ewk_notification_permission_request_suspend(Ewk_Notification_Permission_Request* request)
 {
-  EINA_SAFETY_ON_NULL_RETURN(request);
-  request->SetSuspend(true);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(request, EINA_FALSE);
+  return request->SetSuspend(true);
 }
 
-void ewk_notification_policies_removed(Ewk_Context* ewkContext, Eina_List* origins)
+Eina_Bool ewk_notification_policies_removed(Eina_List* origins)
 {
-#if defined(ENABLE_NOTIFICATIONS)
-  EINA_SAFETY_ON_NULL_RETURN(ewkContext);
-  EINA_SAFETY_ON_NULL_RETURN(origins);
-  ewkContext->browser_context()->GetNotificationController()->RemovePermissions(origins);
-#else
-  NOTIMPLEMENTED();
-#endif
+  EINA_SAFETY_ON_NULL_RETURN_VAL(origins, EINA_FALSE);
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  cbce->GetNotificationController()->RemovePermissions(origins);
+  return EINA_TRUE;
 }
 
-const Ewk_Security_Origin *ewk_notification_security_origin_get(const Ewk_Notification *ewk_notification)
+const Ewk_Security_Origin* ewk_notification_security_origin_get(const Ewk_Notification* ewk_notification)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, 0);
   return static_cast<const Ewk_Security_Origin*>(ewk_notification->GetSecurityOrigin());
 }
 
-void ewk_notification_showed(Ewk_Context *context, uint64_t notification_id)
+Eina_Bool ewk_notification_showed(uint64_t notification_id)
+{
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  return cbce->GetNotificationController()->NotificationDisplayed(notification_id);
+}
+
+Eina_Bool ewk_notification_closed(uint64_t notification_id, Eina_Bool by_user)
 {
-  // No Matching content API
+  ContentBrowserClientEfl* cbce = GetContentBrowserClient();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cbce, EINA_FALSE);
+  return cbce->GetNotificationController()->NotificationClosed(notification_id, by_user);
 }
 
-const char *ewk_notification_title_get(const Ewk_Notification *ewk_notification)
+const char* ewk_notification_title_get(const Ewk_Notification* ewk_notification)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_notification, 0);
   return ewk_notification->GetTitle();
index 3e49122..a02b278 100644 (file)
@@ -6,7 +6,7 @@
 #define ewk_notification_h
 
 #include <Eina.h>
-#include "ewk_context.h"
+#include <Evas.h>
 #include "ewk_export.h"
 #include "ewk_security_origin.h"
 
@@ -22,6 +22,43 @@ struct _Ewk_Notification_Permission {
 typedef struct Ewk_Notification Ewk_Notification;
 typedef struct _Ewk_Notification_Permission Ewk_Notification_Permission;
 typedef struct Ewk_Notification_Permission_Request Ewk_Notification_Permission_Request;
+typedef void (*Ewk_Notification_Show_Callback)(Ewk_Notification*, void*);
+typedef void (*Ewk_Notification_Cancel_Callback)(uint64_t, void*);
+
+/**
+ * Sets callbacks for notifications handling.
+ *
+ * These callbacks will receive all notifications from all webview instances.
+ * @e show_callback is used to display notification UI. Embeder should call
+ * ewk_notification_showed after it displays notification UI. @e cancel_callback
+ * will be called after notification is closed by engine. It's used to notify
+ * embeder that related notification UI should be destroyed.
+ *
+ * @param show_callback notification show callback. Can't be NULL
+ * @param cancel_callback notification close callback. Can't be NULL
+ * @param user_data extra data for callback
+ *
+ * @return EINA_TRUE on success, EINA_FALSE on failure (i.e. when ewk_init was not called)
+ */
+EAPI Eina_Bool ewk_notification_callbacks_set(Ewk_Notification_Show_Callback show_callback, Ewk_Notification_Cancel_Callback cancel_callback, void* user_data);
+
+/**
+ * Resets notification callbacks to NULL
+ *
+ * @return EINA_TRUE on success, EINA_FALSE on failure (i.e. when ewk_init was not called)
+ */
+EAPI Eina_Bool ewk_notification_callbacks_reset();
+
+/**
+ * Get notification icon as Evas_Object
+ *
+ * @param ewk_notification pointer to notification data
+ * @param evas canvas where icon object will be added
+ *
+ * @return Evas_Object containing icon if successful, @c NULL otherwise.
+ *         Caller takes ownership of returned Evas_Object.
+ */
+EAPI Evas_Object* ewk_notification_icon_get(const Ewk_Notification* ewk_notification, Evas* evas);
 
 /**
  * Requests for getting body of notification.
@@ -31,25 +68,27 @@ typedef struct Ewk_Notification_Permission_Request Ewk_Notification_Permission_R
  * @return body of notification
  *         Lifetime only valid as long as @a ewk_notification is valid.
  */
-EAPI const char *ewk_notification_body_get(const Ewk_Notification *ewk_notification);
+EAPI const char* ewk_notification_body_get(const Ewk_Notification* ewk_notification);
 
 /**
  * Notify that notification is clicked.
  *
- * @param context context object
  * @param notification_id identifier of notification
+ *
+ * @return EINA_TRUE on success, EINA_FALSE if notification id is invalid
  */
-EAPI void ewk_notification_clicked(Ewk_Context *context, uint64_t notification_id);
+EAPI Eina_Bool ewk_notification_clicked(uint64_t notification_id);
 
 /**
  * Requests for getting icon url of notification.
  *
  * @param ewk_notification pointer of notification data
  *
- * @return icon url of notification
- *         Lifetime only valid as long as @a ewk_notification is valid.
+ * @return Always returns NULL - this API is deprecated.
+ *
+ * @deprecated
  */
-EAPI const char *ewk_notification_icon_url_get(const Ewk_Notification *ewk_notification);
+EINA_DEPRECATED EAPI const char* ewk_notification_icon_url_get(const Ewk_Notification* ewk_notification);
 
 /**
  * Requests for getting id of notification.
@@ -58,7 +97,7 @@ EAPI const char *ewk_notification_icon_url_get(const Ewk_Notification *ewk_notif
  *
  * @return id of notification
  */
-EAPI uint64_t ewk_notification_id_get(const Ewk_Notification *ewk_notification);
+EAPI uint64_t ewk_notification_id_get(const Ewk_Notificationewk_notification);
 
 /**
  * Requests for setting cached notification permissions.
@@ -67,8 +106,10 @@ EAPI uint64_t ewk_notification_id_get(const Ewk_Notification *ewk_notification);
  *
  * @param context context object
  * @param ewk_notification_permissions list of cached permissions(Ewk_Notification_Permission)
+ *
+ * @return EINA_TRUE if successful, EINA_FALSE if ewk_init was not called
  */
-EAPI void ewk_notification_cached_permissions_set(Ewk_Context *context, Eina_List *ewk_notification_permissions);
+EAPI Eina_Bool ewk_notification_cached_permissions_set(Eina_List *ewk_notification_permissions);
 
 /**
  * Requests for getting origin of notification permission request.
@@ -78,15 +119,19 @@ EAPI void ewk_notification_cached_permissions_set(Ewk_Context *context, Eina_Lis
  * @return security origin of notification permission request
  *         Lifetime only valid as long as @a ewk_notification is valid.
  */
-EAPI const Ewk_Security_Origin *ewk_notification_permission_request_origin_get(const Ewk_Notification_Permission_Request *request);
+EAPI const Ewk_Security_Origin* ewk_notification_permission_request_origin_get(const Ewk_Notification_Permission_Request* request);
 
 /**
  * Reply the result about notification permission.
  *
- * @param request Ewk_Notification_Permission_Request object to get the infomation about notification permission request.
+ * @param request Ewk_Notification_Permission_Request object to get the
+ *                infomation about notification permission request.
  * @param allow result about notification permission
+ *
+ * @return EINA_TRUE is successful. EINA_FALSE if reply was already called for
+ *         this request or if request is NULL
  */
-EAPI void ewk_notification_permission_reply(Ewk_Notification_Permission_Request *request, Eina_Bool allow);
+EAPI Eina_Bool ewk_notification_permission_reply(Ewk_Notification_Permission_Request *request, Eina_Bool allow);
 
 /**
  * Deprecated, use ewk_notification_permission_reply instead.
@@ -95,8 +140,14 @@ EAPI void ewk_notification_permission_reply(Ewk_Notification_Permission_Request
  * @param request Ewk_Notification_Permission_Request object to allow/deny notification permission
  *        request is freed in this function.
  * @param allowed @c EINA_TRUE if permission is allowed, @c EINA_FALSE if permission is denied
+ *
+ * @return EINA_TRUE is successful. EINA_FALSE if reply was already called for
+ *         this request or if request is NULL
+ *
+ * @deprecated
+ * @see ewk_notification_permission_reply
  */
-EINA_DEPRECATED EAPI void ewk_notification_permission_request_set(Ewk_Notification_Permission_Request *request, Eina_Bool allowed);
+EINA_DEPRECATED EAPI Eina_Bool ewk_notification_permission_request_set(Ewk_Notification_Permission_Request* request, Eina_Bool allowed);
 
 /**
  * Suspend the operation for permission request.
@@ -106,7 +157,7 @@ EINA_DEPRECATED EAPI void ewk_notification_permission_request_set(Ewk_Notificati
  *
  * @param request Ewk_Notification_Permission_Request object to suspend notification permission request
  */
-EAPI void ewk_notification_permission_request_suspend(Ewk_Notification_Permission_Request *request);
+EAPI Eina_Bool ewk_notification_permission_request_suspend(Ewk_Notification_Permission_Request* request);
 
 /**
  * Notify that notification policies are removed.
@@ -114,7 +165,7 @@ EAPI void ewk_notification_permission_request_suspend(Ewk_Notification_Permissio
  * @param context context object
  * @param origins list of security origins(made by UAs)
  */
-EAPI void ewk_notification_policies_removed(Ewk_Context *context, Eina_List *origins);
+EAPI Eina_Bool ewk_notification_policies_removed(Eina_List* origins);
 
 /**
  * Requests for getting security origin of notification.
@@ -124,15 +175,23 @@ EAPI void ewk_notification_policies_removed(Ewk_Context *context, Eina_List *ori
  * @return security origin of notification
  *         Lifetime only valid as long as @a ewk_notification is valid.
  */
-EAPI const Ewk_Security_Origin *ewk_notification_security_origin_get(const Ewk_Notification *ewk_notification);
+EAPI const Ewk_Security_Origin* ewk_notification_security_origin_get(const Ewk_Notification* ewk_notification);
 
 /**
  * Notify that notification is showed.
  *
- * @param context context object
  * @param notification_id identifier of notification
  */
-EAPI void ewk_notification_showed(Ewk_Context *context, uint64_t notification_id);
+EAPI Eina_Bool ewk_notification_showed(uint64_t notification_id);
+
+/**
+ * Notify that notification was closed.
+ *
+ * @param notification_id identifier of notification
+ * @param by_user         informs whether notification was closed by user
+ *                        action or by some other application logic
+ */
+EAPI Eina_Bool ewk_notification_closed(uint64_t notification_id, Eina_Bool by_user);
 
 /**
  * Requests for getting title of notification.
@@ -142,7 +201,7 @@ EAPI void ewk_notification_showed(Ewk_Context *context, uint64_t notification_id
  * @return title of notification
  *         Lifetime only valid as long as @a ewk_notification is valid.
  */
-EAPI const char *ewk_notification_title_get(const Ewk_Notification *ewk_notification);
+EAPI const char* ewk_notification_title_get(const Ewk_Notification* ewk_notification);
 
 #ifdef __cplusplus
 }
index 392c7f0..08b7e5e 100644 (file)
@@ -650,34 +650,7 @@ Ewk_History* ewk_view_history_get(Evas_Object* ewkView)
 
 Eina_Bool ewk_view_notification_closed(Evas_Object* ewkView, Eina_List* notification_list)
 {
-  EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
-
-#if !defined(EWK_BRINGUP)
-#warning "[M38] Fix and re-enable notifications (edit efl_integration/public/ewk_view.cc)"
-  // copied from deleted NotificationControllerEfl::RemoveClosedNotifications()
-  if (!eina_list_count(notification_list))
-    return false;
-
-  assert(impl->GetWebContext());
-  assert(impl->GetWebContext()->browser_context());
-  assert(impl->GetWebContext()->browser_context()->GetNotificationController());
-  scoped_refptr<content::NotificationControllerEfl> controller =
-      impl->GetWebContext()->browser_context()->GetNotificationController();
-
-  Eina_List* notification_iterator = NULL;
-  void* notification_data = NULL;
-  EINA_LIST_FOREACH(notification_list, notification_iterator, notification_data) {
-    Ewk_Notification* notification =
-      static_cast<Ewk_Notification*>(notification_data);
-
-    if (notification) {
-      controller->DeleteNotification(notification->GetID(), true);
-      delete notification;
-    }
-  }
-#endif
-  return true;
-
+  return EINA_FALSE;
 }
 
 Eina_Bool ewk_view_popup_menu_select(Evas_Object* ewkView, unsigned int selectedIndex)
index 13b5afd..592afde 100644 (file)
@@ -1210,15 +1210,19 @@ EAPI Eina_Bool ewk_view_hit_test_request(Evas_Object* o, int x, int y, int hit_t
 EAPI Ewk_History* ewk_view_history_get(Evas_Object* o);
 #endif
 
-/*
+/**
+ * Deprecated.
  * Notify that notification is closed.
  *
  * @param notification_list list of Ewk_Notification pointer
  *        notification_list is freed in this function.
  *
- * @return @c EINA_TRUE on successful request or @c EINA_FALSE on failure
+ * @return this function will always return EINA_FALSE since it is deprecated
+ *
+ * @deprecated
+ * @see ewk_notification_closed
  */
-EAPI Eina_Bool ewk_view_notification_closed(Evas_Object* o, Eina_List* notification_list);
+EINA_DEPRECATED EAPI Eina_Bool ewk_view_notification_closed(Evas_Object* o, Eina_List* notification_list);
 
 /*
  * Sends the orientation of the device.
index a4f1f33..4d98bd8 100644 (file)
@@ -42,7 +42,7 @@ static Evas* e;
 static Evas_Object* view;
 static Evas_Object *popup;
 
-Ewk_Notification *current_notification;
+uint64_t current_notification_id;
 
 static Ewk_Auth_Challenge* auth_challenge_holder = NULL;
 static Evas_Object* credentials[2] = {0};//username and password
@@ -59,7 +59,7 @@ static int content_text_callback_data = 10;
 static int content_text_callback_data_1 = 20;
 static Eina_Bool test_cookie;
 static Eina_Bool clear_cookie_called;
-static Ewk_Cookie_Accept_Policy set_cookie_policy;  
+static Ewk_Cookie_Accept_Policy set_cookie_policy;
 static Eina_List* application_cache_origins = NULL;
 static Evas_Object* prompt_entry;
 static Eina_List* web_database_origins = NULL;
@@ -119,9 +119,9 @@ static void __scroll_right_cb(void* data, Evas_Object* obj, void* event_info);
 static void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info);
 
 static void on_evas_resize(Ecore_Evas*);
-static void __notification_show_cb(void *data, Evas_Object *obj, void *event_info);
-static Eina_Bool __notification_permission_cb(void *data, Evas_Object *obj, void *event_info);
-static void __notification_cancel_cb(void *data, Evas_Object *obj, void *event_info);
+static void __notification_show_cb(Ewk_Notification*, void* event_info);
+static Eina_Bool __notification_permission_cb(Evas_Object*, Ewk_Notification_Permission_Request*, void*);
+static void __notification_cancel_cb(uint64_t notification_id, void* event_info);
 static void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info);
 static void __download_callback(const char*download_url, void* user_data);
 static void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info);
@@ -283,16 +283,16 @@ static void on_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
     }
 }
 
-static void on_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info) 
+static void on_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info)
 {
-    Evas_Event_Mouse_Wheel* event = (Evas_Event_Mouse_Wheel*)event_info; 
+    Evas_Event_Mouse_Wheel* event = (Evas_Event_Mouse_Wheel*)event_info;
     static double scale_factor = 1.0;
-    if (evas_key_modifier_is_set(event->modifiers, "Control")) 
-    { 
+
+    if (evas_key_modifier_is_set(event->modifiers, "Control"))
+    {
         if (event->z == -1)
             scale_factor += 0.1;
-        else 
+        else
             scale_factor -= 0.1;
 
         printf("ewk_view_scale_set() : %lf (%d, %d)\n", scale_factor, event->output.x, event->output.y);
@@ -473,8 +473,6 @@ int main(int argc, char** argv)
   evas_object_smart_callback_add(view, "load,provisional,started", __did_start_provisional_load_for_frame_cb, 0);
   evas_object_smart_callback_add(view, "geolocation,permission,request", __geoLocation_popup_display_cb,0);
   evas_object_smart_callback_add(view, "authentication,challenge", __auth_challenge_cb, 0);
-  evas_object_smart_callback_add(view, "notification,show", __notification_show_cb,0);
-  evas_object_smart_callback_add(view, "notification,cancel", __notification_cancel_cb,0);
   evas_object_smart_callback_add(view, "policy,response,decide", __policy_response_decide_cb, 0);
   evas_object_smart_callback_add(view, "contextmenu,customize", __customize_context_menu_cb, 0);
   evas_object_smart_callback_add(view, "contextmenu,selected", __customize_context_menu_item_selected_cb, 0);
@@ -501,7 +499,8 @@ int main(int argc, char** argv)
   evas_object_smart_callback_add(view, "webprocess,crashed", __webprocess_crashed_cb, 0);
   evas_object_smart_callback_add(view, "undo,size", __undo_size_cb, 0);
   evas_object_smart_callback_add(view, "redo,size", __redo_size_cb, 0);
-  
+
+  ewk_notification_callbacks_set(__notification_show_cb, __notification_cancel_cb, 0);
   ewk_view_custom_header_add(view, "X-Test-header", "X-Value-1");
 
   ewk_view_notification_permission_callback_set(view, __notification_permission_cb, 0);
@@ -550,7 +549,7 @@ void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error
   int host_count = eina_list_count(hostnames);
   printf("APP.c total hosts received:%d\n",host_count);
   if (clear_cookie_called) {
-    if (host_count) 
+    if (host_count)
       printf("APP.C clear cookie call did not delete cookies\n");
     else
       printf("APP.c all cookies cleared\n");
@@ -612,7 +611,7 @@ void __ewk_cookie_manager_async_policy_get_cb(Ewk_Cookie_Accept_Policy policy,
 void __load_finished_cb(void *data, Evas_Object *obj, void *event_info)
 {
   printf ("APP.C callback called __load_finished_cb \n");
-  
+
   if(clear_cache)
     ewk_context_cache_clear((Ewk_Context*)data);
 
@@ -658,7 +657,7 @@ void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info)
 {
   printf ("APP.C callback called __load_progress_finsihed_cb \n");
   ewk_view_custom_header_remove(view, "X-Test-header");
-  
+
   int width, height;
   ewk_view_contents_size_get(view, &width, &height);
   printf("APP.c called ewk_view_contents_size_get. width = %d, height = %d\n", width, height);
@@ -948,21 +947,17 @@ void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info)
 
 void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info)
 {
-   Eina_List *list = NULL;
-   list =  eina_list_append(list, current_notification);
-   ewk_view_notification_closed(view, list);
+   ewk_notification_closed(current_notification_id, EINA_TRUE);
+   current_notification_id = 0;
    evas_object_hide(popup);
-   evas_object_del(obj);
    evas_object_del(popup);
 }
 
-void __notification_show_cb(void *data, Evas_Object *obj, void *event_info)
+void __notification_show_cb(Ewk_Notification* current_notification, void* event_info)
 {
-  current_notification = (Ewk_Notification*)event_info;
   if (current_notification) {
     printf("APP.C callback _notification_show_cb Details: \n");
     printf("APP.C callback Body = %s \n",ewk_notification_body_get(current_notification));
-    printf("APP.C callback Icon url = %s\n", ewk_notification_icon_url_get(current_notification));
     printf("APP.C callback Title = %s\n",ewk_notification_title_get(current_notification));
     const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)current_notification);
     printf("APP.C callback Origin Host = %s\n",ewk_security_origin_host_get(org));
@@ -970,23 +965,26 @@ void __notification_show_cb(void *data, Evas_Object *obj, void *event_info)
     printf("APP.C callback Origin Port = %d\n",ewk_security_origin_port_get(org));
     // Adding pop up code
     popup = elm_popup_add(view);
+    Evas_Object* icon = ewk_notification_icon_get(current_notification, evas_object_evas_get(popup));
+
     elm_popup_allow_events_set(popup, EINA_TRUE);
     elm_object_text_set(popup,ewk_notification_body_get(current_notification));
     elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
     elm_object_part_text_set(popup, "title,text", ewk_notification_title_get(current_notification));
+    elm_object_part_content_set(popup, "title,icon", icon);
     evas_object_show(popup);
 
     Evas_Object *btn1 = elm_button_add(popup);
     elm_object_text_set(btn1, "CLOSE");
     elm_object_part_content_set(popup, "button1", btn1);
+    current_notification_id = ewk_notification_id_get(current_notification);
     evas_object_smart_callback_add(btn1, "clicked", __notification_cancel_byuser_cb, 0);
   }
   printf ("APP.C callback called __notification_show_cb \n");
 }
 
-Eina_Bool __notification_permission_cb(void *data, Evas_Object *obj, void *event_info)
+Eina_Bool __notification_permission_cb(Evas_Object* o, Ewk_Notification_Permission_Request* request, void* user_data)
 {
-  Ewk_Notification_Permission_Request *request = (Ewk_Notification_Permission_Request*)event_info;
   if(request) {
     const Ewk_Security_Origin *sec_origin = ewk_notification_permission_request_origin_get((const Ewk_Notification_Permission_Request*)request);
     if (sec_origin) {
@@ -998,11 +996,10 @@ Eina_Bool __notification_permission_cb(void *data, Evas_Object *obj, void *event
   return EINA_FALSE;
 }
 
-void __notification_cancel_cb(void *data, Evas_Object *obj, void *event_info)
+void __notification_cancel_cb(uint64_t notification_id, void* event_info)
 {
-  uint64_t *notification_id = (uint64_t*)event_info;
   evas_object_del(popup);
-  printf("APP.C callback  __notification_cancel_cb with notification id = %d\n", (int)*notification_id);
+  printf("APP.C callback  __notification_cancel_cb with notification id = %Lu\n", (long long unsigned int)notification_id);
 }
 
 void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info)
index 4738d3d..37b8fff 100644 (file)
         '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_callbacks_reset_func.cpp',
+        'utc_blink_ewk_notification_callbacks_set_func.cpp',
         'utc_blink_ewk_notification_clicked_func.cpp',
-        'utc_blink_ewk_notification_icon_url_get_func.cpp',
+        'utc_blink_ewk_notification_closed_func.cpp',
+        'utc_blink_ewk_notification_icon_get_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',
         'utc_blink_ewk_view_load_progress_get_func.cpp',
         'utc_blink_ewk_view_main_frame_get_func.cpp',
         'utc_blink_ewk_view_mhtml_data_get_func.cpp',
-        'utc_blink_ewk_view_notification_closed_func.cpp',
         'utc_blink_ewk_view_notification_permission_callback_set_func.cpp',
         'utc_blink_ewk_view_orientation_lock_callback_set_func.cpp',
         'utc_blink_ewk_view_orientation_send_func.cpp',
old mode 100755 (executable)
new mode 100644 (file)
index 8ed3ed4..97db402
@@ -9,22 +9,18 @@
 <p id="notificationTest">This is a sample page to test EWK Notification APIs.</p>
 
 <script type="text/javascript">
-       
 function testNotifications()
 {
-    if (window.webkitNotifications.checkPermission() == 0)
-    {
-        var icon  = 'logo.png';
-        var title = 'Notification Title';
-        var body   = 'Notification body content';
-
-        var notification_test = window.webkitNotifications.createNotification(icon, title, body);
-        notification_test.show();
-    }
-    else
-    {
-        window.webkitNotifications.requestPermission(testNotifications);
-    }
+  Notification.requestPermission(function() {
+      var notification = new Notification('Notification Title', {
+            body: 'Notification body content',
+            icon: 'logo.png',
+            tag: 'replace_tag',
+            });
+      notification.onshow = function() { console.log('notification.show'); }
+      notification.onclick = function() { console.log('notification.click'); }
+      notification.onclose = function() { console.log('notification.close'); }
+  });
 }
 
 </script>
diff --git a/tizen_src/ewk/unittest/resources/common/sample_notification_2.html b/tizen_src/ewk/unittest/resources/common/sample_notification_2.html
deleted file mode 100644 (file)
index 4c7cb0e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-<html>
-<meta name="viewport" content="initial-scale=1.0">
-<head>
-<style>
-button {
-    width: 100%;
-    height: 100%;
-}
-</style>
-</head>
-<body onload="test()">
-<button type="button" id="startButton" onclick="test()">start test</button>
-<script type="text/javascript">
-
-function showNotification() {
-    var notification = new Notification("Notification Title", {
-        icon: "logo.png",
-        body: "Notification body content"
-    });
-
-    notification.onclick = function() {
-        document.title = "notification_clicked";
-    };
-
-    notification.onshow = function() {
-        document.title = "notification_shown";
-    };
-
-    notification.onclose = function() {
-        document.title = "notification_closed";
-    };
-}
-
-function test() {
-    console.log("Checking permissions");
-    if (!("Notification" in window)) {
-        console.log("Notifications not available!");
-        return;
-    }
-    if (Notification.permission === "granted") {
-        console.log("event_loop_stop:Permission granted");
-        showNotification();
-    } else {
-        console.log("Requesting permission...");
-        Notification.requestPermission(function (permission) {
-            console.log("received permission: " + permission);
-            if (permission === "granted") {
-               Notification.permission = permission;
-               console.log("event_loop_stop:Permission granted after request");
-               showNotification();
-            }
-        });
-    }
-}
-
-</script>
-</body>
-</html>
index b7db2bc..1c266c5 100644 (file)
@@ -56,6 +56,90 @@ std::string utc_blink_ewk_base::GetResourcePath(const char* resource_path) const
     return retval;
 }
 
+bool utc_blink_ewk_base::CompareEvasImageWithResource(Evas_Object* image, const char* resource, int pixel_fuzziness) const
+{
+  if (!image || !resource) {
+    utc_message("[CompareEvasImageWithResource] :: both image and resource can't be NULL");
+    return false;
+  }
+  std::string resource_absolute_path = GetResourcePath(resource);
+
+  Evas_Object* resource_image = evas_object_image_filled_add(GetEwkEvas());
+  evas_object_image_file_set(resource_image, resource_absolute_path.c_str(), nullptr);
+
+  int resource_w = 0, resource_h = 0;
+  evas_object_image_size_get(resource_image, &resource_w, &resource_h);
+
+  int image_w = 0, image_h = 0;
+  evas_object_image_size_get(image, &image_w, &image_h);
+
+  if (resource_w != image_w || resource_h != image_h) {
+    evas_object_del(resource_image);
+    utc_message("[CompareEvasImageWithResource] :: image size differs: %dx%d (image) vs %dx%d (resource)", image_w, image_h, resource_w, resource_h);
+    return false;
+  }
+
+  if (evas_object_image_colorspace_get(image) != evas_object_image_colorspace_get(resource_image)) {
+    evas_object_del(resource_image);
+    utc_message("[CompareEvasImageWithResource] :: image colorspace differs");
+    return false;
+  }
+
+  int bytes_per_pixel = 0;
+
+  switch (evas_object_image_colorspace_get(image)) {
+    case EVAS_COLORSPACE_ARGB8888:
+      bytes_per_pixel = 4;
+      break;
+
+    case EVAS_COLORSPACE_RGB565_A5P:
+      bytes_per_pixel = 2;
+      break;
+
+    case EVAS_COLORSPACE_GRY8:
+      bytes_per_pixel = 1;
+      break;
+
+    default:
+      evas_object_del(resource_image);
+      utc_message("[CompareEvasImageWithResource] :: unsupported colorspace");
+      return false;
+  }
+
+  unsigned char* image_data = static_cast<unsigned char*>(evas_object_image_data_get(image, EINA_FALSE));
+  unsigned char* resource_data = static_cast<unsigned char*>(evas_object_image_data_get(resource_image, EINA_FALSE));
+
+  bool retval = true;
+  int mismatch_bytes = 0;
+  for (int i = 0; i < image_w * image_h * bytes_per_pixel; i += bytes_per_pixel) {
+    // we allow little differences in pixels, Evas_Image and SkBitmap has different decoders and there
+    // may be little diference in individual bytes
+
+    int total_diff = 0;
+
+    for (int j = 0; j < bytes_per_pixel; ++j) {
+      total_diff += abs(resource_data[i + j] - image_data[i + j]);
+    }
+
+    if (total_diff > pixel_fuzziness) {
+      utc_message("[CompareEvasImageWithResource] :: maximum fuzziness (%d) exceeded at %d pixel: %d", pixel_fuzziness, i, total_diff);
+      retval = false;
+
+      for (int j = 0; j < bytes_per_pixel; ++j) {
+        utc_message("image: 0x%2X resource: 0x%2X", image_data[i + j], resource_data[i + j]);
+      }
+
+      break;
+    }
+  }
+
+  evas_object_image_data_set(image, image_data);
+  evas_object_image_data_set(resource_image, resource_data);
+  evas_object_del(resource_image);
+
+  return retval;
+}
+
 std::string utc_blink_ewk_base::GetResourceUrl(const char* resource_path) const
 {
     std::string retval("file://");
index 46b7925..0b14fb4 100644 (file)
@@ -124,6 +124,23 @@ protected:
     void SetLogJavascript(bool enabled) { log_javascript = enabled; }
 
     /**
+     * Checks if given Evas_Object contains image pointed by source
+     *
+     * @param [in] image_object Evas_Object containing image
+     * @param [in] resource relative path to the resource. This method will expand it to absolute path.
+     * @param [in] pixel_fuzziness maximum allowed pixel difference between resource and image_object.
+     *                             image_object may be created from different image decoder than resource
+     *                             will be. It may cause little differences in pixels. Difference is calculated
+     *                             by summing absolute values of differences between each pixel color. e.g.:
+     *                             ARGB(123,231,5,1) vs ARGB(125,231,5,1) gives difference of 2 points
+     *                             ARGB(123,231,5,1) vs ARGB(124,231,6,1) gives difference of 2 points
+     *                             ARGB(123,231,5,1) vs ARGB(124,231,5,1) gives difference of 1 point:q
+     *
+     * @return true if Evas_Image produced from path is equal to given Evas_Image (memory compare)
+     */
+    bool CompareEvasImageWithResource(Evas_Object* image_object, const char* resource, int pixel_fuzziness) const;
+
+    /**
      * Generates proper path for resource file
      *
      * @param [in] resource_path  resource file subpath
index 19802ee..e3f8bc4 100755 (executable)
@@ -2,70 +2,26 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_body_get : public utc_blink_ewk_base {
-protected:
-  utc_blink_ewk_notification_body_get() : body(NULL) {}
+class utc_blink_ewk_notification_body_get : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_body_get()
+    : body(NULL)
+  {}
 
-  /* Startup function */
-  virtual void PostSetUp()
+  void NotificationShow(Ewk_Notification* notification) override
   {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
-  {
-    utc_message("[notificationPermissionRequest] :: ");
-
-    utc_blink_ewk_notification_body_get *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
-  }
-
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: ");
-
-    if (!event_info) {
-      utc_fail();
-    }
-
-    if (!data) {
-      utc_fail();
-    }
-
-    utc_blink_ewk_notification_body_get* owner = static_cast<utc_blink_ewk_notification_body_get*>(data);
-
     //call ewk_notification API
-    owner->body = strdup(ewk_notification_body_get((Ewk_Notification*)event_info));
-    owner->EventLoopStop(Success);
+    body = eina_stringshare_add(ewk_notification_body_get(notification));
+    EventLoopStop(Success);
   }
 
-protected:
-  static const char* const resource_relative_path;
+ protected:
   static const char* const notification_body_ref;
-  char* body;
+  Eina_Stringshare* body;
 };
 
-const char* const utc_blink_ewk_notification_body_get::resource_relative_path = "/common/sample_notification_2.html";
 const char* const utc_blink_ewk_notification_body_get::notification_body_ref = "Notification body content";
 
 /**
@@ -73,19 +29,17 @@ const char* const utc_blink_ewk_notification_body_get::notification_body_ref = "
 */
 TEST_F(utc_blink_ewk_notification_body_get, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
   ASSERT_TRUE(body);
   ASSERT_STREQ(body, notification_body_ref);
-  free(body);
+  eina_stringshare_del(body);
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL of a webview.
+* @brief Checking whether function works properly in case of nullptr of a webview.
 */
 TEST_F(utc_blink_ewk_notification_body_get, NEG_TEST)
 {
-  const char *bodyText = ewk_notification_body_get(NULL);
-  utc_check_eq(NULL, bodyText);
+  ASSERT_EQ(nullptr, ewk_notification_body_get(nullptr));
 }
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_reset_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_reset_func.cpp
new file mode 100755 (executable)
index 0000000..a2f51e8
--- /dev/null
@@ -0,0 +1,38 @@
+// 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_callbacks_reset : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_callbacks_reset()
+    : notification_id(0)
+  {}
+
+  void NotificationShow(Ewk_Notification* notification) override
+  {
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);
+  }
+
+ protected:
+  uint64_t notification_id;
+};
+
+/**
+* @brief Check if all callbacks are called
+*/
+TEST_F(utc_blink_ewk_notification_callbacks_reset, POS_TEST)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+
+  notification_id = 0;
+  ASSERT_EQ(EINA_TRUE, ewk_notification_callbacks_reset());
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Timeout, EventLoopStart(10.0)); // 10 seconds should be enough
+  ASSERT_EQ(0, notification_id);
+}
+
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_set_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_callbacks_set_func.cpp
new file mode 100755 (executable)
index 0000000..970ebeb
--- /dev/null
@@ -0,0 +1,69 @@
+// 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_callbacks_set : public utc_blink_ewk_notification_test_base {
+ protected:
+  void NotificationShow(Ewk_Notification* notification) override
+  {
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);
+  }
+
+  void NotificationCancel(uint64_t notification_id) override
+  {
+    EventLoopStop(Failure);
+  }
+
+  void ConsoleMessage(Evas_Object* webview, const Ewk_Console_Message* message) override
+  {
+    if (message) {
+      const char* message_text = ewk_console_message_text_get(message);
+      if (message_text) {
+        console_message = message_text;
+      }
+    }
+
+    EventLoopStop(Success);
+  }
+
+  static void dummy_notification_show_callback(Ewk_Notification* notification, void* user_data)
+  {
+  }
+
+  static void dummy_notification_cancel_callback(uint64_t notificationId, void* user_data)
+  {
+  }
+
+ protected:
+  std::string console_message;
+  uint64_t notification_id = 0;
+};
+
+/**
+* @brief Check if all callbacks are called
+*/
+TEST_F(utc_blink_ewk_notification_callbacks_set, POS_TEST)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+  ASSERT_TRUE(ewk_notification_showed(notification_id));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.show", console_message.c_str());
+  ewk_view_script_execute(GetEwkWebView(), "new Notification('Title', {tag: 'replace_tag'});", nullptr, nullptr);
+  ASSERT_EQ(Failure, EventLoopStart());
+}
+
+/**
+* @brief Checking whether function works properly in case of nullptr parameters
+*/
+TEST_F(utc_blink_ewk_notification_callbacks_set, NEG_TEST)
+{
+  // both callbacks must be set
+  ASSERT_FALSE(ewk_notification_callbacks_set(nullptr, nullptr, nullptr));
+  ASSERT_FALSE(ewk_notification_callbacks_set(dummy_notification_show_callback, nullptr, nullptr));
+  ASSERT_FALSE(ewk_notification_callbacks_set(nullptr, dummy_notification_cancel_callback, nullptr));
+}
index 920791d..ff209b7 100644 (file)
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_clicked : public utc_blink_ewk_base
+class utc_blink_ewk_notification_clicked : public utc_blink_ewk_notification_test_base
 {
  protected:
-  utc_blink_ewk_notification_clicked() : clicked(false) {}
+  utc_blink_ewk_notification_clicked()
+    : notification_id(0)
+  {}
 
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  void NotificationShow(Ewk_Notification* notification) override
   {
-    utc_message("[notificationPermissionRequest] :: \n");
-    utc_blink_ewk_notification_clicked *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);;
   }
 
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
+  void ConsoleMessage(Evas_Object* webview, const Ewk_Console_Message* message) override
   {
-    utc_message("[notificationShow] :: \n");
-
-    Ewk_Context* context = ewk_view_context_get(webview);
-    if (!event_info || !context) {
-      utc_message("event_info: %p\ncontext: %p", event_info, context);
-      FAIL();
-    }
-
-    if (!data) {
-      FAIL();
+    if (message) {
+      const char* message_text = ewk_console_message_text_get(message);
+      if (message_text) {
+        console_message = message_text;
+      }
     }
 
-    uint64_t notification_id = ewk_notification_id_get(static_cast<Ewk_Notification*>(event_info));
-    ewk_notification_clicked(context, notification_id);
-  }
-
-  static void titleChanged(void* data, Evas_Object* webview, void* event_info)
-  {
-    const char* title = static_cast<const char*>(event_info);
-    utc_message("[titleChanged] :: title = %s", title);
-    utc_blink_ewk_notification_clicked* owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (title && strcmp(title, "notification_clicked") == 0) {
-      owner->clicked = true;
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  /* Startup function */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "title,changed", titleChanged, this);
+    EventLoopStop(Success);
   }
 
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-    evas_object_smart_callback_del(GetEwkWebView(), "title,changed", titleChanged);
-  }
-
-  // helper function
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
-  }
-
-protected:
-  static const char* const resource_relative_path;
-  bool clicked;
+ protected:
+  uint64_t notification_id;
+  std::string console_message;
 };
 
-const char* const utc_blink_ewk_notification_clicked::resource_relative_path = "/common/sample_notification_2.html";
-
 /**
 * @brief Positive test case for ewk_notification_clicked()
 */
 TEST_F(utc_blink_ewk_notification_clicked, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+  ASSERT_TRUE(ewk_notification_showed(notification_id));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.show", console_message.c_str());
+  ASSERT_TRUE(ewk_notification_clicked(notification_id));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(clicked);
+  ASSERT_STREQ("notification.click", console_message.c_str());
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL value pass
+* @brief Checking whether function works properly in case of invalid notification id value pass
 */
 TEST_F(utc_blink_ewk_notification_clicked, NEG_TEST)
 {
-  ewk_notification_clicked(NULL, 0);
-  /* If NULL argument passing won't give segmentation fault negative test case will pass */
-  SUCCEED();
+  ASSERT_FALSE(ewk_notification_clicked(0));
 }
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_closed_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_closed_func.cpp
new file mode 100755 (executable)
index 0000000..d8a3985
--- /dev/null
@@ -0,0 +1,75 @@
+// 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_closed : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_closed()
+    : notification_id(0)
+  {}
+
+  void NotificationShow(Ewk_Notification* notification) override
+  {
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);
+  }
+
+  void ConsoleMessage(Evas_Object* webview, const Ewk_Console_Message* message) override
+  {
+    if (message) {
+      const char* message_text = ewk_console_message_text_get(message);
+      if (message_text) {
+        console_message = message_text;
+      }
+    }
+
+    EventLoopStop(Success);
+  }
+
+ protected:
+  std::string console_message;
+  uint64_t notification_id;
+};
+
+/**
+* @brief Positive test case for ewk_notification_closed()
+*/
+TEST_F(utc_blink_ewk_notification_closed, by_user_true)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+  ASSERT_TRUE(ewk_notification_showed(notification_id));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.show", console_message.c_str());
+  ASSERT_TRUE(ewk_notification_closed(notification_id, EINA_TRUE));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.close", console_message.c_str());
+}
+
+/**
+* @brief Positive test case for ewk_notification_closed()
+*/
+TEST_F(utc_blink_ewk_notification_closed, by_user_false)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+  ASSERT_TRUE(ewk_notification_showed(notification_id));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.show", console_message.c_str());
+  ASSERT_TRUE(ewk_notification_closed(notification_id, EINA_FALSE));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.close", console_message.c_str());
+}
+
+/**
+* @brief Checking whether function works properly in case of invalid notification id value pass
+*/
+TEST_F(utc_blink_ewk_notification_closed, NEG_TEST)
+{
+  ASSERT_FALSE(ewk_notification_closed(0, EINA_TRUE));
+  ASSERT_FALSE(ewk_notification_closed(0, EINA_FALSE));
+}
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_get_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_get_func.cpp
new file mode 100755 (executable)
index 0000000..4cbf08d
--- /dev/null
@@ -0,0 +1,44 @@
+// 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_get : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_icon_get()
+    : notification_icon(NULL)
+  {}
+
+  void NotificationShow(Ewk_Notification* notification) override
+  {
+    notification_icon = ewk_notification_icon_get(notification, GetEwkEvas());
+    EventLoopStop(Success);
+  }
+
+ protected:
+  Evas_Object* notification_icon;
+};
+
+/**
+* @brief Positive test case for ewk_notification_icon_get()
+*/
+TEST_F(utc_blink_ewk_notification_icon_get, POS_TEST)
+{
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_icon);
+  // Skia and Efl may decode png in different way, we add fuzziness of 3 points
+  // difference between pixel values
+  ASSERT_TRUE(CompareEvasImageWithResource(notification_icon, "/common/logo.png", 3));
+  evas_object_del(notification_icon);
+}
+
+/**
+* @brief Checking whether function works properly in case of nullptr value pass
+*/
+TEST_F(utc_blink_ewk_notification_icon_get, NEG_TEST)
+{
+  ASSERT_FALSE(ewk_notification_icon_get(nullptr, nullptr));
+  ASSERT_FALSE(ewk_notification_icon_get(nullptr, GetEwkEvas()));
+}
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_url_get_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_notification_icon_url_get_func.cpp
deleted file mode 100755 (executable)
index e5e6cb4..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-// 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_notification_icon_url_get : public utc_blink_ewk_base {
-protected:
-  utc_blink_ewk_notification_icon_url_get() : icon_url(NULL) {}
-
-  /* Startup function */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
-  {
-    utc_message("[notificationPermissionRequest] :: ");
-
-    utc_blink_ewk_notification_icon_url_get *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
-  }
-
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: ");
-
-    if (!event_info) {
-      FAIL();
-    }
-
-    if (!data) {
-      FAIL();
-    }
-
-    utc_blink_ewk_notification_icon_url_get* owner = static_cast<utc_blink_ewk_notification_icon_url_get*>(data);
-    //call ewk_notification API
-    owner->icon_url = ewk_notification_icon_url_get((Ewk_Notification*)event_info);
-    utc_message("[notificationShow] :: icon_url = %s", owner->icon_url);
-    if (owner->icon_url) {
-      char* getIconName = strrchr((char*)owner->icon_url, '/');
-      owner->icon_url = ++getIconName;
-    }
-
-    owner->EventLoopStop(Success);
-  }
-
-  // helper function
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
-  }
-
-protected:
-  static const char* const resource_relative_path;
-  static const char* const notification_icon_ref;
-  const char* icon_url;
-};
-
-const char* const utc_blink_ewk_notification_icon_url_get::resource_relative_path = "/common/sample_notification_2.html";
-const char* const utc_blink_ewk_notification_icon_url_get::notification_icon_ref = "logo.png";
-
-/**
-* @brief Positive test case for ewk_notification_body_get(). Text returned by api is compared against expected text and result is set in notificationShow()
-*/
-TEST_F(utc_blink_ewk_notification_icon_url_get, POS_TEST)
-{
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
-  ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(icon_url);
-  ASSERT_STREQ(icon_url, notification_icon_ref);
-}
-
-/**
-* @brief Checking whether function works properly in case of NULL of a webview.
-*/
-TEST_F(utc_blink_ewk_notification_icon_url_get, NEG_TEST)
-{
-  const char* iconURL = ewk_notification_icon_url_get(NULL);
-  EXPECT_EQ(NULL, iconURL);
-}
index 8da70e2..e1c33f3 100755 (executable)
@@ -4,84 +4,40 @@
 
 /* Define those macros _before_ you include the utc_blink_ewk.h header file. */
 
-#include "utc_blink_ewk_base.h"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_id_get : public utc_blink_ewk_base {
+class utc_blink_ewk_notification_id_get : public utc_blink_ewk_notification_test_base {
  protected:
-  utc_blink_ewk_notification_id_get() : id(0) {}
+  utc_blink_ewk_notification_id_get()
+    : notification_id(0)
+  {}
 
-  /* Startup function */
-  virtual void PostSetUp()
+  void NotificationShow(Ewk_Notification* notification) override
   {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
-  {
-    utc_message("[notificationPermissionRequest] :: ");
-    utc_blink_ewk_notification_id_get *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
-  }
-
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: ");
-    if (!event_info) {
-      FAIL();
-    }
-
-    if (!data) {
-      FAIL();
-    }
-
-    utc_blink_ewk_notification_id_get* owner = static_cast<utc_blink_ewk_notification_id_get*>(data);
-
     //call ewk_notification API
-    owner->id = ewk_notification_id_get((Ewk_Notification*)event_info);
-    owner->EventLoopStop(Success);
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);
   }
 
-protected:
-  static const char* const resource_relative_path;
-  int id;
+ protected:
+  uint64_t notification_id;
 };
 
-const char* const utc_blink_ewk_notification_id_get::resource_relative_path = "/common/sample_notification_2.html";
-
 /**
-* @brief Positive test case for ewk_notification_body_get(). Text returned by api is compared against expected text and result is set in notificationShow()
+* @brief Positive test case for ewk_notification_id_get(). Text returned by
+* api is compared against expected text and result is set in notificationShow()
 */
 TEST_F(utc_blink_ewk_notification_id_get, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(id);
+  ASSERT_TRUE(notification_id);
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL of a webview.
+* @brief Checking whether function works properly in case of nullptr.
 */
 TEST_F(utc_blink_ewk_notification_id_get, NEG_TEST)
 {
-  int id = ewk_notification_id_get(NULL);
-  utc_check_eq(id, 0);
+  ASSERT_EQ(0, ewk_notification_id_get(nullptr));
 }
index 2bb86e4..11cdc07 100644 (file)
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_permission_reply : public utc_blink_ewk_base {
-protected:
+class utc_blink_ewk_notification_permission_reply : public utc_blink_ewk_notification_test_base {
+ protected:
   utc_blink_ewk_notification_permission_reply()
-  : utc_blink_ewk_base()
-  , notificationPermissionFirsttime(EINA_FALSE)
-  , notificationPermissionSecondtime(EINA_FALSE)
-  {
-  }
+    : notification_permission_request_cnt(0)
+  {}
 
-  virtual ~utc_blink_ewk_notification_permission_reply() {
-  }
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request) override
   {
-    utc_blink_ewk_notification_permission_reply* owner = static_cast<utc_blink_ewk_notification_permission_reply*>(data);
-
-    Ewk_Context *context = ewk_view_context_get(webview);
-    if (!request || !context) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-
-    if (!owner->notificationPermissionFirsttime) {
-      owner->notificationPermissionFirsttime = EINA_TRUE;
-    } else {
-      owner->notificationPermissionSecondtime = EINA_TRUE;
-      owner->EventLoopStop(Failure);
-    }
+    EXPECT_EQ(EINA_TRUE, ewk_notification_permission_reply(request, EINA_TRUE));
+    ++notification_permission_request_cnt;
     return EINA_TRUE;
   }
 
-  static void cb_console_message(utc_blink_ewk_notification_permission_reply *owner, Evas_Object *obj, void *event_info)
-  {
-    Ewk_Console_Message* console = static_cast<Ewk_Console_Message*>(event_info);
-    const char *cmsg = ewk_console_message_text_get(console);
-    if (!cmsg) {
-      return;
-    }
-    std::string msg(cmsg);
-    std::string::size_type pos = msg.find(':');
-    if (pos == std::string::npos) {
-      return;
-    }
-    if (msg.substr(0, pos) == "event_loop_stop") {
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  // helper function
-  bool click()
+  virtual void NotificationShow(Ewk_Notification* notification)
   {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
+    EventLoopStop(Success);
   }
 
-  /* Startup and cleanup functions */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message), this);
-  }
-
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message));
-  }
-
-protected:
-  Eina_Bool notificationPermissionFirsttime;
-  Eina_Bool notificationPermissionSecondtime;
-  static const char* const resource_relative_path;
+ protected:
+  int notification_permission_request_cnt;
 };
 
-const char* const utc_blink_ewk_notification_permission_reply::resource_relative_path = "/common/sample_notification_2.html";
-
 /**
  * @brief Positive test case for ewk_notification_permission_reply function
  */
 TEST_F(utc_blink_ewk_notification_permission_reply, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_EQ(1, notification_permission_request_cnt);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "new Notification('Notification title');", NULL, NULL));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_EQ(EINA_TRUE, notificationPermissionFirsttime);
-  ASSERT_EQ(EINA_FALSE, notificationPermissionSecondtime);
+  // once granted it should not request permission anymore
+  ASSERT_EQ(1, notification_permission_request_cnt);
 
-  ASSERT_TRUE(click());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_EQ(EINA_TRUE, notificationPermissionFirsttime);
-  ASSERT_EQ(EINA_FALSE, notificationPermissionSecondtime);
+  // once granted it should not request permission anymore
+  ASSERT_EQ(1, notification_permission_request_cnt);
 }
 
 /**
- * @brief Tests whether function works properly in case of NULL value pass.
+ * @brief Tests whether function works properly in case of nullptr value pass.
  */
 TEST_F(utc_blink_ewk_notification_permission_reply, NEG_TEST)
 {
   /* TODO: this code should use ewk_notification_cached_permissions_set and check its behaviour.
   Results should be reported using one of utc_ macros */
-  ewk_notification_permission_reply(NULL,0);
+  ewk_notification_permission_reply(nullptr, EINA_TRUE);
 
-  // If  NULL argument passing wont give segmentation fault negative test case will pass
+  // If  nullptr argument passing wont give segmentation fault negative test case will pass
   SUCCEED();
 }
index 870f3c1..64ac553 100755 (executable)
@@ -2,74 +2,73 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_permission_request_origin_get : public utc_blink_ewk_base {
-protected:
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request *request, void* data)
+class utc_blink_ewk_notification_permission_request_origin_get : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_permission_request_origin_get()
+    : expected_origin_protocol("")
+    , expected_origin_host("")
+    , expected_origin_port(65535)
+    , received_origin_protocol(NULL)
+    , received_origin_host(NULL)
+    , received_origin_port(0)
+  {}
+
+  ~utc_blink_ewk_notification_permission_request_origin_get()
   {
-    utc_message("[notificationPermissionRequest] :: ");
-    utc_blink_ewk_notification_permission_request_origin_get *owner = static_cast<utc_blink_ewk_notification_permission_request_origin_get *>(data);
-    if (!owner) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
+    eina_stringshare_del(received_origin_protocol);
+    eina_stringshare_del(received_origin_host);
+  }
 
-    MainLoopResult res = Failure;
+  /* Callback for "notification,permission,request" */
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request)
+  {
     const Ewk_Security_Origin* origin = ewk_notification_permission_request_origin_get(request);
 
-    if (origin) {
-      const char* host = ewk_security_origin_host_get(origin);
-      const char* protocol = ewk_security_origin_protocol_get(origin);
-      uint16_t port = ewk_security_origin_port_get(origin);
-      utc_message("__actual__\nhost: %s\tprotocol: %s\tport: %d", host, protocol, port);
-      utc_message("__expected__\nhost: %s\tprotocol: %s\tport: %d", expected_origin_host, expected_origin_protocol, expected_origin_port);
+    EXPECT_FALSE(received_origin_protocol);
+    EXPECT_FALSE(received_origin_host);
+    EXPECT_FALSE(received_origin_port);
+    if (received_origin_protocol || received_origin_host || received_origin_port) {
+      EventLoopStop(Failure);
+      return EINA_FALSE;
+    }
 
-      if (!strcmp(protocol, expected_origin_protocol) && !strcmp(host, expected_origin_host) && port == expected_origin_port) {
-        res = Success;
-      }
+    if (origin) {
+      received_origin_host = eina_stringshare_add(ewk_security_origin_host_get(origin));
+      received_origin_protocol = eina_stringshare_add(ewk_security_origin_protocol_get(origin));
+      received_origin_port = ewk_security_origin_port_get(origin);
     }
 
     //allow the notification
     ewk_notification_permission_reply(request, EINA_TRUE);
-    owner->EventLoopStop(res);
+    EventLoopStop(Success);
     return EINA_TRUE;
   }
 
-  /* Startup and cleanup functions */
-  virtual void PostSetUp()
-  {
-    ewk_view_mouse_events_enabled_set(GetEwkWebView(), EINA_TRUE);
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-  }
-
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-  }
+ protected:
+  const char* const expected_origin_protocol = "";
+  const char* const expected_origin_host = "";
+  const uint16_t expected_origin_port = 65535;
 
-protected:
-  static const char* const resource_file;
-  static const char* const expected_origin_protocol;
-  static const char* const expected_origin_host;
-  static const uint16_t expected_origin_port;
+  Eina_Stringshare* received_origin_protocol = NULL;
+  Eina_Stringshare* received_origin_host = NULL;
+  uint16_t received_origin_port = 0;
 };
 
-const char* const utc_blink_ewk_notification_permission_request_origin_get::resource_file = "common/sample_notification_2.html";
-const char* const utc_blink_ewk_notification_permission_request_origin_get::expected_origin_protocol = "";
-const char* const utc_blink_ewk_notification_permission_request_origin_get::expected_origin_host = "";
-const uint16_t utc_blink_ewk_notification_permission_request_origin_get::expected_origin_port = 65535;
-
 /**
  * @brief Positive test case for ewk_notification_permission_reply function
  */
 TEST_F(utc_blink_ewk_notification_permission_request_origin_get, POS_TEST)
 {
-  /* TODO: this code should use ewk_notification_permission_reply and check its behaviour.
-  Results should be reported using one of utc_ macros */
-  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), GetResourceUrl(resource_file).c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
+
+  EXPECT_TRUE(received_origin_protocol);
+  EXPECT_TRUE(received_origin_host);
+  EXPECT_EQ(expected_origin_port, received_origin_port);
+  EXPECT_STREQ(expected_origin_host, received_origin_host);
+  EXPECT_STREQ(expected_origin_protocol, received_origin_protocol);
 }
 
 /**
@@ -77,10 +76,5 @@ TEST_F(utc_blink_ewk_notification_permission_request_origin_get, POS_TEST)
  */
 TEST_F(utc_blink_ewk_notification_permission_request_origin_get, NEG_TEST)
 {
-  /* TODO: this code should use ewk_notification_cached_permissions_set and check its behaviour.
-  Results should be reported using one of utc_ macros */
-  ewk_notification_permission_reply(NULL,0);
-
-  // If  NULL argument passing wont give segmentation fault negative test case will pass
-  utc_pass();
+  ASSERT_FALSE(ewk_notification_permission_request_origin_get(NULL));
 }
index f75898b..213aa81 100755 (executable)
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_permission_request_set : public utc_blink_ewk_base {
-protected:
+class utc_blink_ewk_notification_permission_request_set : public utc_blink_ewk_notification_test_base {
+ protected:
   utc_blink_ewk_notification_permission_request_set()
-  : utc_blink_ewk_base()
-  , notificationPermissionFirsttime(EINA_FALSE)
-  , notificationPermissionSecondtime(EINA_FALSE)
-  {
-  }
+    : notification_permission_request_cnt(0)
+  {}
 
-  virtual ~utc_blink_ewk_notification_permission_request_set() {
-  }
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request) override
   {
-    utc_blink_ewk_notification_permission_request_set* owner = static_cast<utc_blink_ewk_notification_permission_request_set*>(data);
-
-    Ewk_Context *context = ewk_view_context_get(webview);
-    if (!request || !context) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
     ewk_notification_permission_request_set(request, EINA_TRUE);
-
-    if (!owner->notificationPermissionFirsttime) {
-      owner->notificationPermissionFirsttime = EINA_TRUE;
-    } else {
-      owner->notificationPermissionSecondtime = EINA_TRUE;
-      owner->EventLoopStop(Failure);
-    }
+    ++notification_permission_request_cnt;
     return EINA_TRUE;
   }
 
-  static void cb_console_message(utc_blink_ewk_notification_permission_request_set *owner, Evas_Object *obj, void *event_info)
-  {
-    Ewk_Console_Message* console = static_cast<Ewk_Console_Message*>(event_info);
-    const char *cmsg = ewk_console_message_text_get(console);
-    if (!cmsg) {
-      return;
-    }
-    std::string msg(cmsg);
-    std::string::size_type pos = msg.find(':');
-    if (pos == std::string::npos) {
-      return;
-    }
-    if (msg.substr(0, pos) == "event_loop_stop") {
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  // helper function
-  bool click()
+  virtual void NotificationShow(Ewk_Notification* notification)
   {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
+    EventLoopStop(Success);
   }
 
-  /* Startup and cleanup functions */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message), this);
-  }
-
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message));
-  }
-
-protected:
-  Eina_Bool notificationPermissionFirsttime;
-  Eina_Bool notificationPermissionSecondtime;
-  static const char* const resource_relative_path;
+ protected:
+  int notification_permission_request_cnt;
 };
 
-const char* const utc_blink_ewk_notification_permission_request_set::resource_relative_path = "/common/sample_notification_2.html";
-
 /**
  * @brief Positive test case for ewk_notification_permission_request_set function
  */
 TEST_F(utc_blink_ewk_notification_permission_request_set, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_EQ(1, notification_permission_request_cnt);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "new Notification('Notification title');", NULL, NULL));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_EQ(EINA_TRUE, notificationPermissionFirsttime);
-  ASSERT_EQ(EINA_FALSE, notificationPermissionSecondtime);
+  // once granted it should not request permission anymore
+  ASSERT_EQ(1, notification_permission_request_cnt);
 
-  ASSERT_TRUE(click());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_EQ(EINA_TRUE, notificationPermissionFirsttime);
-  ASSERT_EQ(EINA_FALSE, notificationPermissionSecondtime);
+  // once granted it should not request permission anymore
+  ASSERT_EQ(1, notification_permission_request_cnt);
 }
 
 /**
- * @brief Tests whether function works properly in case of NULL value pass.
+ * @brief Tests whether function works properly in case of nullptr value pass.
  */
 TEST_F(utc_blink_ewk_notification_permission_request_set, NEG_TEST)
 {
   /* TODO: this code should use ewk_notification_cached_permissions_set and check its behaviour.
   Results should be reported using one of utc_ macros */
-  ewk_notification_permission_request_set(NULL,0);
+  ewk_notification_permission_request_set(nullptr, EINA_TRUE);
 
-  // If  NULL argument passing wont give segmentation fault negative test case will pass
+  // If  nullptr argument passing wont give segmentation fault negative test case will pass
   SUCCEED();
 }
index d40abf7..612fc78 100755 (executable)
@@ -2,96 +2,49 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
+
+class utc_blink_ewk_notification_permission_request_suspend : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_permission_request_suspend()
+    : permission_request(NULL)
+  {}
 
-class utc_blink_ewk_notification_permission_request_suspend : public utc_blink_ewk_base {
-protected:
-  utc_blink_ewk_notification_permission_request_suspend() {}
   /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request) override
   {
-    Ewk_Context *context = ewk_view_context_get(webview);
-    utc_blink_ewk_notification_permission_request_suspend *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if(!request || !context) {
-      utc_message("event_info: %p\ncontext: %p", request, context);
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_request_suspend(request);
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    owner->EventLoopStop(Success);
+    EXPECT_EQ(EINA_TRUE, ewk_notification_permission_request_suspend(request));
+    permission_request = request;
+    EventLoopStop(Success);
     return EINA_TRUE;
   }
 
-  static void cb_console_message(utc_blink_ewk_notification_permission_request_suspend *owner, Evas_Object *obj, void *event_info)
-  {
-    Ewk_Console_Message* console = static_cast<Ewk_Console_Message*>(event_info);
-    const char *cmsg = ewk_console_message_text_get(console);
-    if (!cmsg) {
-      return;
-    }
-    std::string msg(cmsg);
-    std::string::size_type pos = msg.find(':');
-    if (pos == std::string::npos) {
-      return;
-    }
-    if (msg.substr(0, pos) == "event_loop_stop") {
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  /* Startup function */
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
-  }
-
-  /* Startup and cleanup functions */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message), this);
-  }
-
-  virtual void PreTearDown()
+  virtual void NotificationShow(Ewk_Notification* notification)
   {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message));
+    EventLoopStop(Success);
   }
 
-protected:
-  static const char* const resource_relative_path;
-  static const char* const notification_title_ref;
+ protected:
+  Ewk_Notification_Permission_Request* permission_request;
 };
 
-const char* const utc_blink_ewk_notification_permission_request_suspend::resource_relative_path = "/common/sample_notification_2.html";
-const char* const utc_blink_ewk_notification_permission_request_suspend::notification_title_ref = "Notification Title";
-
 /**
 * @brief Positive test case for ewk_notification_permission_request_suspened()
 */
 TEST_F(utc_blink_ewk_notification_permission_request_suspend, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
-  ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(click());
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  EXPECT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(permission_request);
+  ASSERT_EQ(EINA_TRUE, ewk_notification_permission_reply(permission_request, EINA_TRUE));
+  permission_request = NULL;
   ASSERT_EQ(Success, EventLoopStart());
-
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL value pass
+* @brief Checking whether function works properly in case of nullptr value pass
 */
 TEST_F(utc_blink_ewk_notification_permission_request_suspend, NEG_TEST)
 {
-  ewk_notification_permission_request_suspend(NULL);
-  // If  NULL argument passing wont give segmentation fault negative test case will pass
-  SUCCEED();
+  ASSERT_EQ(EINA_FALSE, ewk_notification_permission_request_suspend(nullptr));
 }
index 24a7902..4518311 100644 (file)
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_policies_removed : public utc_blink_ewk_base {
-protected:
+class utc_blink_ewk_notification_policies_removed : public utc_blink_ewk_notification_test_base {
+ protected:
   utc_blink_ewk_notification_policies_removed()
-    : permission_requested_(false), proto_(NULL), host_(NULL)
-  {
-  }
+    : permission_request_call_cnt(0)
+    , proto_(NULL)
+    , host_(NULL)
+    , expected_proto_("")
+    , expected_host_("")
+  {}
 
   ~utc_blink_ewk_notification_policies_removed()
   {
-    if (proto_) free(proto_);
-    if (host_) free(host_);
-  }
-
-  void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), cb_permission_request, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message), this);
-    // clear permissions
-    ewk_notification_cached_permissions_set(ewk_view_context_get(GetEwkWebView()), NULL);
-  }
-
-  void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "console,message",
-                                   ToSmartCallback(cb_console_message));
+    eina_stringshare_del(proto_);
+    eina_stringshare_del(host_);
   }
 
   /* Callback for notification permission request */
-  static Eina_Bool cb_permission_request(Evas_Object *obj, Ewk_Notification_Permission_Request *request, void *data)
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* obj, Ewk_Notification_Permission_Request* request) override
   {
-    utc_message("[cb_permission_request()]");
-    utc_blink_ewk_notification_policies_removed *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
     const Ewk_Security_Origin* origin = ewk_notification_permission_request_origin_get(request);
+
     if (!origin) {
-      owner->EventLoopStop(Failure);
+      EventLoopStop(Failure);
+      EXPECT_TRUE(origin);
       return EINA_FALSE;
     }
-    owner->proto_ = strdup(ewk_security_origin_protocol_get(origin));
-    utc_message("[cb_permission_request] :: proto_ : %s", owner->proto_);
-    owner->host_ = strdup(ewk_security_origin_host_get(origin));
-    utc_message("[cb_permission_request] :: host_ : %s", owner->host_);
-    owner->permission_requested_ = true;
+
+    ++permission_request_call_cnt;
+    proto_ = eina_stringshare_add(ewk_security_origin_protocol_get(origin));
+    host_ = eina_stringshare_add(ewk_security_origin_host_get(origin));
     ewk_notification_permission_reply(request, EINA_TRUE);
     return EINA_TRUE;
   }
 
-  static void cb_console_message(utc_blink_ewk_notification_policies_removed *owner, Evas_Object *obj, void *event_info)
+  virtual void NotificationShow(Ewk_Notification*) override
   {
-    Ewk_Console_Message* console = static_cast<Ewk_Console_Message*>(event_info);
-    const char *cmsg = ewk_console_message_text_get(console);
-    if (!cmsg) {
-      return;
-    }
-    std::string msg(cmsg);
-    std::string::size_type pos = msg.find(':');
-    if (pos == std::string::npos) {
-      return;
-    }
-    if (msg.substr(0, pos) == "event_loop_stop") {
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  // helper function
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
+    EventLoopStop(Success);
   }
 
-protected:
-  bool permission_requested_;
-  char *proto_;
-  char *host_;
-  static const char * const expected_proto_;
-  static const char * const expected_host_;
-  static const char * const resource_file_;
+ protected:
+  int permission_request_call_cnt;
+  Eina_Stringshare* proto_;
+  Eina_Stringshare* host_;
+  const char* const expected_proto_;
+  const char* const expected_host_;
 };
 
-const char * const utc_blink_ewk_notification_policies_removed::expected_proto_ = "";
-const char * const utc_blink_ewk_notification_policies_removed::expected_host_ = "";
-const char * const utc_blink_ewk_notification_policies_removed::resource_file_ = "common/sample_notification_2.html";
-
 TEST_F(utc_blink_ewk_notification_policies_removed, POS_TEST)
 {
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(resource_file_).c_str()));
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
 
-  ASSERT_TRUE(permission_requested_);
+  ASSERT_EQ(1, permission_request_call_cnt);
   ASSERT_STREQ(expected_proto_, proto_);
   ASSERT_STREQ(expected_host_, host_);
 
-  permission_requested_ = false;
-  ASSERT_TRUE(click());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_EQ(1, permission_request_call_cnt);
 
-  ASSERT_FALSE(permission_requested_);
 
   Eina_List *list = NULL;
   Ewk_Security_Origin *origin = ewk_security_origin_new_from_string((std::string(proto_) + "://" + std::string(host_)).c_str());
   list = eina_list_append(list, origin);
-  ewk_notification_policies_removed(ewk_view_context_get(GetEwkWebView()), list);
-  ewk_security_origin_free(origin);
-  ASSERT_TRUE(click());
-  ASSERT_EQ(Success, EventLoopStart());
 
-  ASSERT_TRUE(permission_requested_);
+  ASSERT_EQ(EINA_TRUE, ewk_notification_policies_removed(list));
+
+  void* data = NULL;
+  EINA_LIST_FREE(list, data) {
+    origin = static_cast<Ewk_Security_Origin*>(data);
+    ewk_security_origin_free(origin);
+  }
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_EQ(2, permission_request_call_cnt);
 }
 
 TEST_F(utc_blink_ewk_notification_policies_removed, NEG_TEST)
 {
-  ewk_notification_policies_removed(ewk_view_context_get(GetEwkWebView()), NULL);
+  ewk_notification_policies_removed(NULL);
   SUCCEED();
 }
index 296fc29..feeab38 100755 (executable)
@@ -2,93 +2,57 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_security_origin_get_func : public utc_blink_ewk_base
+class utc_blink_ewk_notification_security_origin_get : public utc_blink_ewk_notification_test_base
 {
-protected:
-  utc_blink_ewk_notification_security_origin_get_func() {}
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+ protected:
+  utc_blink_ewk_notification_security_origin_get()
+    : origin_protocol(NULL)
+    , origin_host(NULL)
+    , origin_port(1)
+  {}
+
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    utc_message("[notificationPermissionRequest] ::");
-    utc_blink_ewk_notification_security_origin_get_func *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
-  }
-
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] ::");
-    ASSERT_TRUE(event_info != NULL);
-    ASSERT_TRUE(data != NULL);
-
     //call ewk_notification API
-    const Ewk_Security_Origin* origin = ewk_notification_security_origin_get(static_cast<Ewk_Notification*>(event_info));
-    ASSERT_TRUE(origin != NULL);
-    utc_blink_ewk_notification_security_origin_get_func *owner = NULL;
-    OwnerFromVoid(data, &owner);
+    const Ewk_Security_Origin* origin = ewk_notification_security_origin_get(notification);
 
-    owner->protocol = ewk_security_origin_protocol_get(origin);
-    owner->host = ewk_security_origin_host_get(origin);
-    owner->port = ewk_security_origin_port_get(origin);
-
-    owner->EventLoopStop(Success);
-  }
-
-  void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
+    if (origin) {
+      origin_protocol = eina_stringshare_add(ewk_security_origin_protocol_get(origin));
+      origin_host = eina_stringshare_add(ewk_security_origin_host_get(origin));
+      origin_port = ewk_security_origin_port_get(origin);
+    }
 
-  // helper function
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
+    EventLoopStop(Success);
   }
 
-protected:
-  const char* protocol;
-  const char* host;
-  uint16_t port;
+ protected:
+  Eina_Stringshare* origin_protocol;
+  Eina_Stringshare* origin_host;
+  uint16_t origin_port;
 };
 
 /**
 * @brief Positive test case for ewk_notification_security_origin_get().
 */
-TEST_F(utc_blink_ewk_notification_security_origin_get_func, POS_TEST)
+TEST_F(utc_blink_ewk_notification_security_origin_get, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl("common/sample_notification_2.html");
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(protocol);
-  ASSERT_TRUE(host);
-  ASSERT_STREQ("", protocol);
-  ASSERT_STREQ("", host);
-  ASSERT_EQ(0, port);
+  EXPECT_TRUE(origin_protocol);
+  EXPECT_TRUE(origin_host);
+  EXPECT_STREQ("", origin_protocol);
+  EXPECT_STREQ("", origin_host);
+  EXPECT_EQ(0, origin_port);
+  eina_stringshare_del(origin_protocol);
+  eina_stringshare_del(origin_host);
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL of a webview.
+* @brief Checking whether function works properly in case of nullptr of a webview.
 */
-TEST_F(utc_blink_ewk_notification_security_origin_get_func, InvalidArg)
+TEST_F(utc_blink_ewk_notification_security_origin_get, InvalidArg)
 {
-  EXPECT_EQ(NULL, ewk_notification_security_origin_get(NULL));
+  EXPECT_EQ(nullptr, ewk_notification_security_origin_get(nullptr));
 }
index 1ccba81..6353705 100755 (executable)
@@ -2,85 +2,50 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_showed : public utc_blink_ewk_base {
+class utc_blink_ewk_notification_showed : public utc_blink_ewk_notification_test_base {
  protected:
-  utc_blink_ewk_notification_showed() {}
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    utc_message("[notificationPermissionRequest] :: \n");
-    utc_blink_ewk_notification_showed *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-        owner->EventLoopStop(Failure);
-        return EINA_FALSE;
-    }
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
+    notification_id = ewk_notification_id_get(notification);
+    EventLoopStop(Success);;
   }
 
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
+  virtual void ConsoleMessage(Evas_Object* webview, const Ewk_Console_Message* message) override
   {
-    utc_message("[notificationShow] :: \n");
-
-    Ewk_Context* context = ewk_view_context_get(webview);
-    if (!event_info || !context) {
-      utc_message("event_info: %p\ncontext: %p", event_info, context);
-      FAIL();
-    }
-
-    if (!data) {
-      FAIL();
+    if (message) {
+      const char* message_text = ewk_console_message_text_get(message);
+      if (message_text) {
+        console_message = message_text;
+      }
     }
 
-    utc_blink_ewk_notification_showed* owner = static_cast<utc_blink_ewk_notification_showed*>(data);
-
-    uint64_t notification_id = ewk_notification_id_get((Ewk_Notification*)event_info);
-    ewk_notification_showed(context, notification_id);
-    owner->EventLoopStop(Success);
+    EventLoopStop(Success);
   }
 
-  /* Startup function */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-protected:
-  static const char* const resource_relative_path;
+ protected:
+  std::string console_message;
+  uint64_t notification_id = 0;
 };
 
-const char* const utc_blink_ewk_notification_showed::resource_relative_path = "/common/sample_notification_2.html";
-
 /**
 * @brief Positive test case for ewk_notification_showed()
 */
 TEST_F(utc_blink_ewk_notification_showed, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_TRUE(notification_id);
+  ASSERT_TRUE(ewk_notification_showed(notification_id));
   ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("notification.show", console_message.c_str());
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL value pass
+* @brief Checking whether function works properly in case of invalid id
 */
 TEST_F(utc_blink_ewk_notification_showed, NEG_TEST)
 {
-  ewk_notification_showed(NULL, 0);
-  /* If NULL argument passing won't give segmentation fault negative test case will pass */
-  SUCCEED();
+  ASSERT_FALSE(ewk_notification_showed(0));
 }
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_notification_test_base.h b/tizen_src/ewk/unittest/utc_blink_ewk_notification_test_base.h
new file mode 100644 (file)
index 0000000..cdda6ee
--- /dev/null
@@ -0,0 +1,122 @@
+// 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_base.h"
+
+class utc_blink_ewk_notification_test_base : public utc_blink_ewk_base
+{
+ protected:
+  utc_blink_ewk_notification_test_base()
+    : security_origins(NULL)
+    , notification_sample_1(GetResourceUrl("/common/sample_notification_1.html"))
+  {}
+
+  /* Common setup */
+  void PostSetUp() override
+  {
+    ewk_view_notification_permission_callback_set(GetEwkWebView(),
+        reinterpret_cast<Ewk_View_Notification_Permission_Callback>(
+            notification_permission_request_callback),
+        this);
+    ewk_notification_callbacks_set(
+        reinterpret_cast<Ewk_Notification_Show_Callback>(notification_show_callback),
+        reinterpret_cast<Ewk_Notification_Cancel_Callback>(notification_cancel_callback),
+        this);
+  }
+
+  void PreTearDown() override
+  {
+    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
+    ewk_notification_callbacks_reset();
+
+    if (security_origins) {
+      // if it fails, than other TCs can produce false negatives/positives
+      EXPECT_EQ(EINA_TRUE, ewk_notification_policies_removed(security_origins));
+
+      void* data = NULL;
+
+      EINA_LIST_FREE(security_origins, data) {
+        Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(data);
+        ewk_security_origin_free(origin);
+      }
+    }
+  }
+
+  virtual void NotificationShow(Ewk_Notification* notification)
+  {
+  }
+
+  virtual void NotificationCancel(uint64_t notificationId)
+  {
+  }
+
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request)
+  {
+    //allow the notification by default
+    EXPECT_EQ(EINA_TRUE, ewk_notification_permission_reply(request, EINA_TRUE));
+    return EINA_TRUE;
+  }
+
+  static Eina_Bool notification_permission_request_callback(Evas_Object* webview, Ewk_Notification_Permission_Request* request, utc_blink_ewk_notification_test_base* owner)
+  {
+    utc_message("[notification_permission_request_callback] :: ");
+    if (!owner) {
+      EINA_FALSE;
+    }
+
+    if (!request) {
+      owner->EventLoopStop(Failure);
+      return EINA_FALSE;
+    }
+
+    const Ewk_Security_Origin *perm_origin = ewk_notification_permission_request_origin_get(request);
+
+    if (perm_origin) {
+      std::string proto, host;
+
+      if (ewk_security_origin_protocol_get(perm_origin)) {
+        proto = ewk_security_origin_protocol_get(perm_origin);
+      }
+
+      if (ewk_security_origin_host_get(perm_origin)) {
+        host = ewk_security_origin_host_get(perm_origin);
+      }
+
+      Ewk_Security_Origin *origin = ewk_security_origin_new_from_string((proto + "://" + host).c_str());
+      owner->security_origins = eina_list_append(owner->security_origins, origin);
+    }
+
+    return owner->NotificationPermissionRequest(webview, request);
+  }
+
+  static void notification_show_callback(Ewk_Notification* notification, utc_blink_ewk_notification_test_base* owner)
+  {
+    utc_message("[notification_show_callback] :: ");
+    ASSERT_TRUE(owner);
+
+    if (!notification) {
+      owner->EventLoopStop(Failure);
+      ASSERT_TRUE(notification);
+    }
+
+    owner->NotificationShow(notification);
+  }
+
+  static void notification_cancel_callback(uint64_t notificationId, utc_blink_ewk_notification_test_base* owner)
+  {
+    utc_message("[notification_cancel_callback] :: ");
+    ASSERT_TRUE(owner);
+
+    if (!notificationId) {
+      owner->EventLoopStop(Failure);
+      ASSERT_TRUE(notificationId);
+    }
+
+    owner->NotificationCancel(notificationId);
+  }
+
+ protected:
+  Eina_List* security_origins;
+  const std::string notification_sample_1;
+};
index 12249cf..1e9bde1 100755 (executable)
@@ -3,89 +3,45 @@
 // found in the LICENSE file.
 
 /* Define those macros _before_ you include the utc_blink_ewk.h header file. */
-#include "utc_blink_ewk_base.h"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_notification_title_get : public utc_blink_ewk_base {
-protected:
-  utc_blink_ewk_notification_title_get() : title(NULL) {}
+class utc_blink_ewk_notification_title_get : public utc_blink_ewk_notification_test_base {
+ protected:
+  utc_blink_ewk_notification_title_get()
+    : title(NULL)
+    , notification_title_ref("Notification Title")
+  {}
 
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
+  ~utc_blink_ewk_notification_title_get()
   {
-    utc_message("[notificationPermissionRequest] :: ");
-    utc_blink_ewk_notification_title_get *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-    return EINA_TRUE;
+    eina_stringshare_del(title);
   }
 
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    utc_message("[notificationShow] :: ");
-
-    if (!event_info) {
-      FAIL();
-    }
-
-    if (!data) {
-      FAIL();
-    }
-
-    utc_blink_ewk_notification_title_get* owner = static_cast<utc_blink_ewk_notification_title_get*>(data);
-
-    //call ewk_notification API
-    owner->title = ewk_notification_title_get((Ewk_Notification*)event_info);
-    owner->EventLoopStop(Success);
+    title = eina_stringshare_add(ewk_notification_title_get(notification));
+    EventLoopStop(Success);
   }
 
-  /* Startup function */
-  virtual void PostSetUp()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  /* Cleanup function */
-  virtual void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-protected:
-  static const char* const resource_relative_path;
-  static const char* const notification_title_ref;
-  const char* title;
+ protected:
+  Eina_Stringshare* title;
+  const char* const notification_title_ref;
 };
 
-const char* const utc_blink_ewk_notification_title_get::resource_relative_path = "/common/sample_notification_2.html";
-const char* const utc_blink_ewk_notification_title_get::notification_title_ref = "Notification Title";
-
 /**
 * @brief Positive test case for ewk_notification_title_get(). Text returned by api is compared against expected text and result is set in notificationShow()
 */
 TEST_F(utc_blink_ewk_notification_title_get, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(resource_relative_path);
-
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(title);
   ASSERT_STREQ(notification_title_ref, title);
 }
 
 /**
-* @brief Checking whether function works properly in case of NULL of a webview.
+* @brief Checking whether function works properly in case of nullptr of a webview.
 */
 TEST_F(utc_blink_ewk_notification_title_get, NEG_TEST)
 {
-  const char* getTitle = ewk_notification_title_get(NULL);
-  utc_check_eq(NULL, getTitle);
+  ASSERT_FALSE(ewk_notification_title_get(nullptr));
 }
index d858905..bb9370b 100755 (executable)
@@ -2,56 +2,21 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_security_origin_host_get : public utc_blink_ewk_base
+class utc_blink_ewk_security_origin_host_get : public utc_blink_ewk_notification_test_base
 {
-protected:
-  /* Startup and cleanup functions */
-  void PostSetUp()
+ protected:
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  void PreTearDown()
-  {
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-  /* Callback for "notification,permission,request" */
-  static void notificationPermissionRequest(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationPermissionRequest] :: \n");
-
-    if (!event_info)
-      utc_fail();
-
-    //allow the notification
-    ewk_notification_permission_reply((Ewk_Notification_Permission_Request*)event_info, EINA_TRUE);
-  }
-
-   /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: [Check Origin Host Get]\n");
-
-    if (!event_info || !data)
-      utc_fail();
-
-    utc_blink_ewk_security_origin_host_get* owner = static_cast<utc_blink_ewk_security_origin_host_get*>( data );
-    MainLoopResult result=Failure;
-    Ewk_Notification* notification = static_cast<Ewk_Notification*>( event_info );
-    if (notification) {
-      const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)notification);
-      if (org) {
-        const char* host = ewk_security_origin_host_get(org);
-        if (host && !strcmp(host, ""))
-          result = Success;
-      }
+    const Ewk_Security_Origin* org = ewk_notification_security_origin_get(notification);
+    MainLoopResult result = Failure;
+    if (org) {
+      const char* host = ewk_security_origin_host_get(org);
+      if (host && !strcmp(host, ""))
+        result = Success;
     }
-    owner->EventLoopStop(result);
+    EventLoopStop(result);
   }
 };
 
@@ -60,17 +25,14 @@ protected:
  */
 TEST_F(utc_blink_ewk_security_origin_host_get, POS_TEST)
 {
-  if(!ewk_view_url_set(GetEwkWebView(),GetResourceUrl("common/sample_notification_1.html").c_str()))
-    utc_fail();
-
-  utc_check_eq(EventLoopStart(), Success);
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
 }
 
 /**
- * @brief Checking whether function works properly in case of NULL as origin.
+ * @brief Checking whether function works properly in case of nullptr as origin.
  */
 TEST_F(utc_blink_ewk_security_origin_host_get, NEG_TEST)
 {
-  const char* const host = ewk_security_origin_host_get(NULL);
-  utc_check_false(host);
+  ASSERT_FALSE(ewk_security_origin_host_get(nullptr));
 }
index b34a036..1e5df84 100755 (executable)
@@ -2,56 +2,23 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_security_origin_port_get : public utc_blink_ewk_base
+class utc_blink_ewk_security_origin_port_get : public utc_blink_ewk_notification_test_base
 {
-protected:
-  /* Startup and cleanup functions */
-  void PostSetUp()
+ protected:
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  void PreTearDown()
-  {
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
+    MainLoopResult result = Failure;
 
-  /* Callback for "notification,permission,request" */
-  static void notificationPermissionRequest(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationPermissionRequest] :: \n");
-
-    if (event_info)
-      utc_fail();
-
-    //allow the notification
-    ewk_notification_permission_reply((Ewk_Notification_Permission_Request*)event_info, EINA_TRUE);
-  }
-
-   /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: [Check Origin Port Get]\n");
-
-    if (!event_info || !data)
-      utc_fail();
-
-    utc_blink_ewk_security_origin_port_get* owner = static_cast<utc_blink_ewk_security_origin_port_get*>( data );
-    MainLoopResult result=Failure;
-    Ewk_Notification* notification = static_cast<Ewk_Notification*>( event_info );
-    if (notification) {
-      const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)notification);
-      if (org) {
-        uint16_t port = ewk_security_origin_port_get(org);
-        if (port == 0)
-          result = Success;
-      }
+    const Ewk_Security_Origin* org = ewk_notification_security_origin_get((const Ewk_Notification*)notification);
+    if (org) {
+      uint16_t port = ewk_security_origin_port_get(org);
+      if (port == 0)
+        result = Success;
     }
-    owner->EventLoopStop(result);
+
+    EventLoopStop(result);
   }
 };
 
@@ -60,17 +27,15 @@ protected:
  */
 TEST_F(utc_blink_ewk_security_origin_port_get, POS_TEST)
 {
-  if(!ewk_view_url_set(GetEwkWebView(),GetResourceUrl("common/sample_notification_1.html").c_str()))
-    utc_fail();
-
-  utc_check_eq(EventLoopStart(), Success);
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),notification_sample_1.c_str()));
+  EXPECT_EQ(Success, EventLoopStart());
 }
 
 /**
- * @brief Checking whether function works properly in case of NULL as origin.
+ * @brief Checking whether function works properly in case of nullptr as origin.
  */
 TEST_F(utc_blink_ewk_security_origin_port_get, NEG_TEST)
 {
-  uint16_t port = ewk_security_origin_port_get(NULL);
-  utc_check_false(port);
+  EXPECT_EQ(0, ewk_security_origin_port_get(nullptr));
+
 }
index 74c376e..b773f30 100755 (executable)
@@ -2,56 +2,23 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_security_origin_protocol_get : public utc_blink_ewk_base
+class utc_blink_ewk_security_origin_protocol_get : public utc_blink_ewk_notification_test_base
 {
-protected:
-  /* Startup and cleanup functions */
-  void PostSetUp()
+ protected:
+  virtual void NotificationShow(Ewk_Notification* notification) override
   {
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-  }
-
-  void PreTearDown()
-  {
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,permission,request", notificationPermissionRequest);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-  }
-
-  /* Callback for "notification,permission,request" */
-  static void notificationPermissionRequest(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationPermissionRequest] :: \n");
-
-    if (!event_info)
-      utc_fail();
+    MainLoopResult result = Failure;
 
-    //allow the notification
-    ewk_notification_permission_reply((Ewk_Notification_Permission_Request*)event_info, EINA_TRUE);
-  }
-
-   /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: [Check Origin Protocal Get]\n");
-
-    if (!event_info || !data)
-      utc_fail();
-
-    utc_blink_ewk_security_origin_protocol_get* owner = static_cast<utc_blink_ewk_security_origin_protocol_get*>( data );
-    MainLoopResult result=Failure;
-    Ewk_Notification* notification = static_cast<Ewk_Notification*>( event_info );
-    if (notification) {
-      const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)notification);
-      if (org) {
-        const char* protocol = ewk_security_origin_protocol_get(org);
-        if (protocol && !strcmp(protocol, ""))
-          result = Success;
-      }
+    const Ewk_Security_Origin* org = ewk_notification_security_origin_get((const Ewk_Notification*)notification);
+    if (org) {
+      const char* protocol = ewk_security_origin_protocol_get(org);
+      if (protocol && !strcmp(protocol, ""))
+        result = Success;
     }
-    owner->EventLoopStop(result);
+
+    EventLoopStop(result);
   }
 };
 
@@ -60,17 +27,14 @@ protected:
  */
 TEST_F(utc_blink_ewk_security_origin_protocol_get, POS_TEST)
 {
-  if(!ewk_view_url_set(GetEwkWebView(),GetResourceUrl("common/sample_notification_1.html").c_str()))
-    utc_fail();
-
-  utc_check_eq(EventLoopStart(), Success);
+  ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),notification_sample_1.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
 }
 
 /**
- * @brief Checking whether function works properly in case of NULL as origin.
+ * @brief Checking whether function works properly in case of nullptr as origin.
  */
 TEST_F(utc_blink_ewk_security_origin_protocol_get, NEG_TEST)
 {
-  const char* const protocol = ewk_security_origin_protocol_get(NULL);
-  utc_check_false(protocol);
+  ASSERT_FALSE(ewk_security_origin_protocol_get(nullptr));
 }
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_view_notification_closed_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_view_notification_closed_func.cpp
deleted file mode 100755 (executable)
index 8254726..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-// 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_view_notification_closed : public utc_blink_ewk_base
-{
- protected:
-  utc_blink_ewk_view_notification_closed()
-    : closed(false)
-    , old_notification(NULL)
-  {}
-
-  /* Callback for notification permission request */
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
-  {
-    utc_message("[notificationPermissionRequest] :: \n");
-    assert(data != NULL);
-    utc_blink_ewk_view_notification_closed* owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (!request) {
-      owner->EventLoopStop(Failure);
-      return EINA_FALSE;
-    }
-
-    //allow the notification
-    ewk_notification_permission_reply(request, EINA_TRUE);
-  }
-
-  /* Callback for "notification,show" */
-  static void notificationShow(void* data, Evas_Object* webview, void* event_info)
-  {
-    utc_message("[notificationShow] :: \n");
-    if(!data)
-      utc_fail();
-    utc_blink_ewk_view_notification_closed* owner=static_cast<utc_blink_ewk_view_notification_closed*>(data);
-
-    Ewk_Context* context = ewk_view_context_get(webview);
-    if (!event_info || !context)
-      utc_fail();
-
-    owner->old_notification = static_cast<Ewk_Notification*>(event_info);
-    uint64_t notification_id = ewk_notification_id_get(owner->old_notification);
-    ewk_notification_showed(context, notification_id);
-    owner->EventLoopStop(Success);
-  }
-
-  static void titleChanged(void* data, Evas_Object* webview, void* event_info)
-  {
-    const char* title = static_cast<const char*>(event_info);
-    utc_message("[titleChanged] :: title = %s", title);
-    utc_blink_ewk_view_notification_closed* owner = NULL;
-    OwnerFromVoid(data, &owner);
-    if (title && strcmp(title, "notification_closed") == 0) {
-      owner->closed = true;
-      owner->EventLoopStop(Success);
-    }
-  }
-
-  /* Startup function */
-  void PostSetUp()
-  {
-    old_notification=0;
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "notification,show", notificationShow, this);
-    evas_object_smart_callback_add(GetEwkWebView(), "title,changed", titleChanged, this);
-  }
-
-  /* Cleanup function */
-  void PreTearDown()
-  {
-    ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
-    evas_object_smart_callback_del(GetEwkWebView(), "notification,show", notificationShow);
-    evas_object_smart_callback_del(GetEwkWebView(), "title,changed", titleChanged);
-  }
-
-protected:
-  static const char* const sample;
-  bool closed;
-  Ewk_Notification* old_notification;
-};
-
-const char*const utc_blink_ewk_view_notification_closed::sample="common/sample_notification_2.html";
-
-/**
-* @brief Positive test case for ewk_notification_showed()
-*/
-TEST_F(utc_blink_ewk_view_notification_closed, POS_TEST)
-{
-  std::string resource_url = GetResourceUrl(sample);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
-  ASSERT_EQ(Success, EventLoopStart());
-
-  Eina_List *list = NULL;
-  list =  eina_list_append(list, old_notification);
-  ASSERT_EQ(EINA_TRUE, ewk_view_notification_closed(GetEwkWebView(), list));
-  ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_TRUE(closed);
-}
-
-/**
-* @brief Checking whether function works properly in case of NULL value pass
-*/
-TEST_F(utc_blink_ewk_view_notification_closed, NEG_TEST)
-{
-  ewk_view_notification_closed(NULL, 0);
-  /* If NULL argument passing won't give segmentation fault negative test case will pass */
-  utc_pass();
-}
index aaad4b2..0fd271e 100644 (file)
@@ -2,66 +2,26 @@
 // 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"
+#include "utc_blink_ewk_notification_test_base.h"
 
-class utc_blink_ewk_view_notification_permission_callback_set : public utc_blink_ewk_base
+class utc_blink_ewk_view_notification_permission_callback_set : public utc_blink_ewk_notification_test_base
 {
  protected:
-  utc_blink_ewk_view_notification_permission_callback_set() : called(false) {}
-
-  void LoadFinished(Evas_Object *o)
+  virtual Eina_Bool NotificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request) override
   {
     EventLoopStop(Success);
-  }
-
-  static Eina_Bool notificationPermissionRequest(Evas_Object* webview, Ewk_Notification_Permission_Request* request, void* data)
-  {
-    utc_blink_ewk_view_notification_permission_callback_set *owner = NULL;
-    OwnerFromVoid(data, &owner);
-    owner->called = true;
-    owner->EventLoopStop(Success);
     return EINA_TRUE;
   }
-
-  // helper function
-  bool click()
-  {
-    utc_message("[click] :: ");
-    return ewk_view_script_execute(GetEwkWebView(), "document.getElementById(\"startButton\").click();", NULL, NULL) == EINA_TRUE;
-  }
-
- protected:
-  bool called;
-  static const char* const sample;
 };
 
-const char* const utc_blink_ewk_view_notification_permission_callback_set::sample = "common/sample_notification_2.html";
-
 TEST_F(utc_blink_ewk_view_notification_permission_callback_set, POS_TEST)
 {
-  std::string resource_url = GetResourceUrl(sample);
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resource_url.c_str()));
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
 
-  ASSERT_TRUE(click());
+  ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, NULL);
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), notification_sample_1.c_str()));
   ASSERT_EQ(Timeout, EventLoopStart(5.0));
-
-  ASSERT_FALSE(called);
-
-  ewk_view_notification_permission_callback_set(GetEwkWebView(), notificationPermissionRequest, this);
-
-  ASSERT_TRUE(click());
-  ASSERT_EQ(Success, EventLoopStart());
-
-  ASSERT_TRUE(called);
-  called = false;
-
-  ewk_view_notification_permission_callback_set(GetEwkWebView(), NULL, this);
-
-  ASSERT_TRUE(click());
-  ASSERT_EQ(Timeout, EventLoopStart(5.0));
-
-  ASSERT_FALSE(called);
 }
 
 TEST_F(utc_blink_ewk_view_notification_permission_callback_set, NEG_TEST)
index 432ef41..bdc8a38 100644 (file)
@@ -27,38 +27,49 @@ NotificationControllerEfl::~NotificationControllerEfl() {
   notification_map.Clear();
 }
 
-void NotificationControllerEfl::AddNotification(uint64_t notification_id, int render_process_id, int render_view_id, const base::string16& replace_id) {
-  NotificationData* new_notification(new NotificationData(render_process_id, render_view_id, replace_id));
+void NotificationControllerEfl::NotificationAdd(uint64_t notification_id,
+    int render_process_id, const base::string16& replace_id,
+    scoped_ptr<DesktopNotificationDelegate> delegate) {
+
+  NotificationData* new_notification(new NotificationData(
+      render_process_id, replace_id, delegate.Pass()));
   notification_map.AddWithID(new_notification, notification_id);
 }
 
-void NotificationControllerEfl::DeleteNotification(uint64_t notification_id, int by_user) {
+bool NotificationControllerEfl::NotificationClosed(uint64_t notification_id,
+    bool by_user) {
+
   NotificationData* saved_data = notification_map.Lookup(notification_id);
   if (!saved_data)
-    return;
-
-  RenderViewHost* render_view_host = RenderViewHost::FromID(saved_data->render_process_id, saved_data->render_view_id);
-#warning "[M38] need proper impl. for desktop notification"
-  //if (render_view_host)
-  //  render_view_host->DesktopNotificationPostClose(notification_id, by_user);
+    return false;
 
+  saved_data->notification_delegate->NotificationClosed(by_user);
   notification_map.Remove(notification_id);
+  return true;
 }
 
-void NotificationControllerEfl::NotifyNotificationClicked(uint64_t notification_id) {
+bool NotificationControllerEfl::NotificationClicked(uint64_t notification_id) {
   NotificationData* saved_data = notification_map.Lookup(notification_id);
   if (!saved_data)
-    return;
+    return false;
 
-  RenderViewHost* render_view_host = RenderViewHost::FromID(saved_data->render_process_id, saved_data->render_view_id);
+  saved_data->notification_delegate->NotificationClick();
+  notification_map.Remove(notification_id);
+  return true;
+}
 
-#warning "[M38] need proper impl. for desktop notification"
-  //if (render_view_host)
-  //  render_view_host->DesktopNotificationPostClick(notification_id);
+bool NotificationControllerEfl::NotificationDisplayed(uint64_t notification_id) {
+  NotificationData* saved_data = notification_map.Lookup(notification_id);
+  if (!saved_data)
+    return false;
+
+  saved_data->notification_delegate->NotificationDisplayed();
+  return true;
 }
 
 void NotificationControllerEfl::SetPermissionForNotification(
     NotificationPermissionRequest* notification, bool isAllowed) {
+
   EWebView* wv = EWebView::FromEvasObject(notification->GetWebviewEvasObject());
   DCHECK(wv);
   RenderViewHost* render_view_host =
@@ -119,15 +130,18 @@ void NotificationControllerEfl::RemovePermissions(Eina_List* origins) {
   }
 }
 
-bool NotificationControllerEfl::IsNotificationPresent(const base::string16& replaceid, uint64_t& notification_id) {
-  std::string in_replaceid(base::UTF16ToUTF8(replaceid).c_str());
+bool NotificationControllerEfl::IsNotificationPresent(int render_process_id,
+    const base::string16& replaceid, uint64_t& notification_id) {
+
   IDMap<NotificationData, IDMapOwnPointer>::const_iterator it(&notification_map);
   for (; !it.IsAtEnd(); it.Advance()) {
-    if (!strcmp(in_replaceid.c_str(), it.GetCurrentValue()->replace_id)) {
+    if (replaceid == it.GetCurrentValue()->replace_id &&
+        render_process_id == it.GetCurrentValue()->render_process_id) {
       notification_id = it.GetCurrentKey();
       return true;
     }
   }
+
   return false;
 }
 
index 5aba8de..1e6b68b 100644 (file)
@@ -12,7 +12,8 @@
 
 #include "base/callback.h"
 #include "base/id_map.h"
-#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/utf_string_conversions.h"
 #include "base/strings/utf_string_conversions.h"
 #include "third_party/WebKit/public/platform/WebNotificationPermission.h"
 #include "tizen_webview/public/tw_url.h"
@@ -24,39 +25,40 @@ class NotificationPermissionRequest;
 }
 
 namespace content {
+class DesktopNotificationDelegate;
 
 class WebContents;
 
 struct NotificationData {
   int render_process_id;
-  int render_view_id;
-  Eina_Stringshare* replace_id;
+  const base::string16 replace_id;
+  scoped_ptr<DesktopNotificationDelegate> notification_delegate;
 
-  NotificationData(int render_process_id, int render_view_id, const base::string16& replaceid)
+  NotificationData(int render_process_id, const base::string16& replaceid,
+      scoped_ptr<DesktopNotificationDelegate> delegate)
       : render_process_id(render_process_id)
-      , render_view_id(render_view_id)
-      , replace_id(eina_stringshare_add((base::UTF16ToUTF8(replaceid)).c_str())) {
-  }
-
-  ~NotificationData() {
-    eina_stringshare_del(replace_id);
+      , replace_id(replaceid)
+      , notification_delegate(delegate.Pass()) {
   }
 };
 
-class NotificationControllerEfl :
-    public base::RefCountedThreadSafe<NotificationControllerEfl> {
+class NotificationControllerEfl {
  public:
   NotificationControllerEfl();
   ~NotificationControllerEfl();
 
   // Adds a new notification received from engine to a list
-  void AddNotification(uint64_t notification_id, int render_process_id, int render_view_id, const base::string16& replace_id);
+  void NotificationAdd(uint64_t notification_id, int render_process_id,
+      const base::string16& replace_id,
+      scoped_ptr<DesktopNotificationDelegate> delegate);
 
-  // Removes a notification when user or engine deletes it
-  void DeleteNotification(uint64_t notification_id, int by_user);
+  bool NotificationClosed(uint64_t notification_id, bool by_user);
 
   // Notify engine when user clicked on the notification
-  void NotifyNotificationClicked(uint64_t notification_id);
+  bool NotificationClicked(uint64_t notification_id);
+
+  // Notification engine that notification was displayed
+  bool NotificationDisplayed(uint64_t notification_id);
 
   // sets the permission for a particular pending notification
   void SetPermissionForNotification(
@@ -81,7 +83,8 @@ class NotificationControllerEfl :
 
   // Checks if the notification is already present.
   // If present returns the notification id of the notification else false
-  bool IsNotificationPresent(const base::string16& replaceid, uint64_t& notification_id);
+  bool IsNotificationPresent(int render_process_id,
+      const base::string16& replaceid, uint64_t& notification_id);
 
 
   void RequestPermission(WebContents* web_contents,
index e0c8488..2bd192f 100644 (file)
@@ -111,24 +111,9 @@ BrowserContextEfl::ResourceContextEfl::GetCookieManager() const {
   return getter_->cookieManager();
 }
 
-#if defined(ENABLE_NOTIFICATIONS)
-scoped_refptr<NotificationControllerEfl>
-    BrowserContextEfl::ResourceContextEfl::GetNotificationController() const {
-  return notification_controller_efl_;
-}
-
-void BrowserContextEfl::ResourceContextEfl::set_notification_controller_efl(
-    const scoped_refptr<NotificationControllerEfl>& controller) {
-  notification_controller_efl_ = controller;
-}
-#endif
-
 BrowserContextEfl::BrowserContextEfl(EWebContext* web_context, bool incognito)
   : resource_context_(NULL),
     web_context_(web_context),
-#if defined(ENABLE_NOTIFICATIONS)
-    notification_controller_efl_(new NotificationControllerEfl()),
-#endif
     temp_dir_creation_attempted_(false),
     incognito_(incognito) {
   InitVisitedLinkMaster();
@@ -158,10 +143,6 @@ net::URLRequestContextGetter* BrowserContextEfl::GetRequestContext() {
 ResourceContext* BrowserContextEfl::GetResourceContext() {
   if (!resource_context_) {
     resource_context_ = new ResourceContextEfl();
-#if defined(ENABLE_NOTIFICATIONS)
-    resource_context_->set_notification_controller_efl(
-        notification_controller_efl_);
-#endif
   }
 
   return resource_context_;
@@ -189,13 +170,6 @@ base::FilePath BrowserContextEfl::GetPath() const {
   return path;
 }
 
-#if defined(ENABLE_NOTIFICATIONS)
-scoped_refptr<content::NotificationControllerEfl>
-    BrowserContextEfl::GetNotificationController() const {
-  return notification_controller_efl_;
-}
-#endif
-
 net::URLRequestContextGetter* BrowserContextEfl::CreateRequestContext(
     content::ProtocolHandlerMap* protocol_handlers,
     URLRequestInterceptorScopedVector request_interceptors) {
index fa16d67..36b6d43 100644 (file)
@@ -13,7 +13,6 @@
 #include "base/synchronization/lock.h"
 #include "browser/download_manager_delegate_efl.h"
 #include "browser/geolocation/geolocation_permission_context_efl.h"
-#include "browser/notification/notification_controller_efl.h"
 #include "components/visitedlink/browser/visitedlink_delegate.h"
 #include "components/visitedlink/browser/visitedlink_master.h"
 #include "content/public/browser/content_browser_client.h"
@@ -61,19 +60,10 @@ class BrowserContextEfl
 
     scoped_refptr<CookieManager> GetCookieManager() const;
 
-#if defined(ENABLE_NOTIFICATIONS)
-    scoped_refptr<NotificationControllerEfl> GetNotificationController() const;
-    void set_notification_controller_efl(
-        const scoped_refptr<NotificationControllerEfl> &controller);
-#endif
-
    private:
     scoped_refptr<URLRequestContextGetterEfl> getter_;
     HTTPCustomHeadersEflMap http_custom_headers_;
     mutable base::Lock http_custom_headers_lock_;
-#if defined(ENABLE_NOTIFICATIONS)
-    scoped_refptr<NotificationControllerEfl> notification_controller_efl_;
-#endif
 
     DISALLOW_COPY_AND_ASSIGN(ResourceContextEfl);
   };
@@ -130,11 +120,6 @@ class BrowserContextEfl
   EWebContext* WebContext() const
   { return web_context_; }
 
-#if defined(ENABLE_NOTIFICATIONS)
-  scoped_refptr<content::NotificationControllerEfl>
-      GetNotificationController() const;
-#endif
-
  private:
   static void ReadCertificateAndAdd(base::FilePath* file_path);
   virtual SSLHostStateDelegate* GetSSLHostStateDelegate() override;
@@ -145,9 +130,6 @@ class BrowserContextEfl
   ResourceContextEfl* resource_context_;
   scoped_refptr<URLRequestContextGetterEfl> request_context_getter_;
   EWebContext* web_context_;
-#if defined(ENABLE_NOTIFICATIONS)
-  scoped_refptr<NotificationControllerEfl> notification_controller_efl_;
-#endif
   DownloadManagerDelegateEfl download_manager_delegate_;
   base::ScopedTempDir temp_dir_;
   bool temp_dir_creation_attempted_;
index 1a7ed1a..dc13752 100755 (executable)
@@ -17,6 +17,7 @@
 #include "browser/resource_dispatcher_host_delegate_efl.h"
 #include "browser/vibration/vibration_message_filter.h"
 #include "browser/web_view_browser_message_filter.h"
+#include "content/public/browser/browser_thread.h"
 #include "content/public/browser/render_widget_host.h"
 #include "content/public/browser/render_widget_host_iterator.h"
 #include "content/public/browser/resource_dispatcher_host.h"
@@ -33,6 +34,8 @@
 #include "browser/speech/tts_message_filter_efl.h"
 #endif
 
+#include "browser/notification/notification_controller_efl.h"
+
 #include "tizen_webview/public/tw_notification.h"
 #include "tizen_webview/public/tw_security_origin.h"
 #include "tizen_webview/public/tw_url.h"
@@ -44,11 +47,17 @@ using tizen_webview::URL;
 using web_contents_utils::WebContentsFromFrameID;
 using web_contents_utils::WebContentsFromViewID;
 using web_contents_utils::WebViewFromWebContents;
+using content::BrowserThread;
 
 namespace content {
 
 ContentBrowserClientEfl::ContentBrowserClientEfl()
-  : browser_main_parts_efl_(NULL) {
+  : browser_main_parts_efl_(nullptr)
+  , notification_controller_(new NotificationControllerEfl)
+  , notification_show_callback_(nullptr)
+  , notification_cancel_callback_(nullptr)
+  , notification_callback_user_data_(nullptr)
+{
 }
 
 BrowserMainParts* ContentBrowserClientEfl::CreateBrowserMainParts(
@@ -175,14 +184,8 @@ blink::WebNotificationPermission
         const GURL& source_url,
         ResourceContext* context,
         int) {
-  BrowserContextEfl::ResourceContextEfl* context_efl =
-      static_cast<BrowserContextEfl::ResourceContextEfl*>(context);
-#if defined(ENABLE_NOTIFICATIONS)
-  return context_efl->GetNotificationController()->CheckPermissionForOrigin(
+  return notification_controller_->CheckPermissionForOrigin(
       source_url.GetOrigin());
-#else
-  return blink::WebNotificationPermissionDefault;
-#endif
 }
 
 void ContentBrowserClientEfl::ShowDesktopNotification(
@@ -191,46 +194,39 @@ void ContentBrowserClientEfl::ShowDesktopNotification(
       int render_process_id,
       scoped_ptr<DesktopNotificationDelegate> delegate,
       base::Closure* cancel_callback) {
-#if defined(ENABLE_NOTIFICATIONS) && !defined(EWK_BRINGUP)
-  WebContents* web_contents = WebContentsFromViewID(render_process_id, render_view_id);
-  if (!web_contents)
+  if (!notification_show_callback_) {
+    delegate->NotificationClosed(false);
     return;
+  }
 
-  WebContentsDelegateEfl* delegate =
-      static_cast<WebContentsDelegateEfl*>(web_contents->GetDelegate());
-  if (!delegate)
-    return;
+  uint64_t replaceUniqueId = 0;
+  if (!params.replace_id.empty() &&
+      notification_controller_->IsNotificationPresent(render_process_id,
+          params.replace_id, replaceUniqueId)) {
 
-  BrowserContextEfl* browser_context =
-      static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
-  uint64_t old_notification_id = 0;
+    notification_controller_->NotificationClosed(replaceUniqueId, false);
+    // notify embeder that notification should be closed
+    if (notification_cancel_callback_) {
+      notification_cancel_callback_(replaceUniqueId, notification_callback_user_data_);
+    }
+  }
 
-  if (!params.replace_id.empty() && browser_context->GetNotificationController()->
-      IsNotificationPresent(params.replace_id, old_notification_id))
-    CancelDesktopNotification(render_process_id, render_view_id, old_notification_id);
+  uint64_t notificationUniqueId = reinterpret_cast<uint64_t>(delegate.get());
+  notification_controller_->NotificationAdd(notificationUniqueId,
+      render_process_id, params.replace_id, delegate.Pass());
 
-  browser_context->GetNotificationController()->
-      AddNotification(params.notification_id, render_process_id,
-                      render_view_id, params.replace_id);
   tizen_webview::Notification* notification =
       new tizen_webview::Notification(base::UTF16ToUTF8(params.body),
-                                      params.icon_url.spec(),
                                       base::UTF16ToUTF8(params.replace_id),
                                       base::UTF16ToUTF8(params.title),
-                                      params.notification_id,
+                                      params.icon,
+                                      notificationUniqueId,
                                       URL(params.origin.host(),
                                           params.origin.scheme(),
                                           atoi(params.origin.port().c_str())));
 
-  delegate->web_view()->
-      SmartCallback<EWebViewCallbacks::NotificationShow>().call(notification);
-  // A smart callback cannot have ownership for data because the callback may
-  // not ever exist. Therefore new resource should be deleted in the call site.
-  // [sns.park] TODO: uncomment below if no side effect.
-  //delete notification;
-#else
-  NOTIMPLEMENTED();
-#endif
+  notification_show_callback_(notification, notification_callback_user_data_);
+  delete notification;
 }
 
 bool ContentBrowserClientEfl::AllowGetCookie(const GURL& url,
@@ -357,17 +353,12 @@ void ContentBrowserClientEfl::RequestPermission(
       break;
     }
     case content::PERMISSION_NOTIFICATIONS:
-#if defined(ENABLE_NOTIFICATIONS)
     {
-      scoped_refptr<content::NotificationControllerEfl> notification_controller
-          = browser_context->GetNotificationController();
-      DCHECK(notification_controller.get());
-      notification_controller->RequestPermission(web_contents,
+      notification_controller_->RequestPermission(web_contents,
                                                  requesting_frame,
                                                  result_callback);
       break;
     }
-#endif
     case content::PERMISSION_PROTECTED_MEDIA:
     case content::PERMISSION_MIDI_SYSEX:
     case content::PERMISSION_PUSH_MESSAGING: {
@@ -435,4 +426,11 @@ std::string ContentBrowserClientEfl::GetApplicationLocale() {
   return locale;
 }
 
+void ContentBrowserClientEfl::SetNotificationCallbacks(Notification_Show_Callback show_callback, Notification_Cancel_Callback cancel_callback, void* user_data) {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+  notification_show_callback_ = show_callback;
+  notification_cancel_callback_ = cancel_callback;
+  notification_callback_user_data_ = user_data;
+}
+
 }
index 37bc4b4..c47cad4 100644 (file)
@@ -11,11 +11,16 @@ namespace base {
 class CommandLine;
 }
 
+namespace tizen_webview {
+class Notification;
+}
+
 class EWebContext;
 
 namespace content {
-class ResourceDispatcherHostDelegateEfl;
 class BrowserMainPartsEfl;
+class NotificationControllerEfl;
+class ResourceDispatcherHostDelegateEfl;
 class RenderViewHostDelegateView;
 class WebContents;
 class WebContentsView;
@@ -23,6 +28,9 @@ struct ShowDesktopNotificationHostMsgParams;
 
 class ContentBrowserClientEfl: public ContentBrowserClient {
  public:
+  typedef void (*Notification_Show_Callback)(tizen_webview::Notification*, void*);
+  typedef void (*Notification_Cancel_Callback)(uint64_t, void*);
+
   ContentBrowserClientEfl();
 
   virtual BrowserMainParts* CreateBrowserMainParts(
@@ -124,6 +132,13 @@ class ContentBrowserClientEfl: public ContentBrowserClient {
 
   std::string GetApplicationLocale() override;
 
+  void SetNotificationCallbacks(Notification_Show_Callback show_callback,
+      Notification_Cancel_Callback close_callback, void* user_data);
+
+  NotificationControllerEfl* GetNotificationController() const {
+    return notification_controller_.get();
+  }
+
  private:
   static void SetCertificatePemOnUIThread(int render_process_id,
       int render_view_id, std::string certificate);
@@ -132,6 +147,10 @@ class ContentBrowserClientEfl: public ContentBrowserClient {
 
   scoped_ptr<ResourceDispatcherHostDelegateEfl> resource_disp_host_del_efl_;
   BrowserMainPartsEfl* browser_main_parts_efl_;
+  scoped_ptr<NotificationControllerEfl> notification_controller_;
+  Notification_Show_Callback notification_show_callback_;
+  Notification_Cancel_Callback notification_cancel_callback_;
+  void* notification_callback_user_data_;
 
   DISALLOW_COPY_AND_ASSIGN(ContentBrowserClientEfl);
 };
index 9c1b8c3..1e7c2c8 100644 (file)
@@ -113,4 +113,8 @@ bool ContentMainDelegateEfl::BasicStartupComplete(int* /*exit_code*/) {
   return false;
 }
 
+ContentBrowserClient* ContentMainDelegateEfl::GetContentBrowserClient() const {
+  return client_.get();
+}
+
 } // namespace content
index f948aec..0e98878 100644 (file)
@@ -28,6 +28,8 @@ class ContentMainDelegateEfl
   virtual void PreSandboxStartup() override;
   virtual ContentBrowserClient* CreateContentBrowserClient() override;
 
+  ContentBrowserClient* GetContentBrowserClient() const;
+
  private:
   scoped_ptr<ContentBrowserClient> client_;
   ContentClientEfl content_client_;
index 0a6876b..5a244b3 100644 (file)
@@ -102,8 +102,6 @@ enum CallbackType {
   RequestCertificateConfirm,
   AuthChallenge,
   SetCertificatePem,
-  NotificationShow,
-  NotificationCancel,
   PolicyResponseDecide,
   ContextMenuCustomize,
   ContextMenuItemSelected,
@@ -243,8 +241,6 @@ DECLARE_EWK_VIEW_CALLBACK(GeoLocationValid, "geolocation,valid", Eina_Bool*);
 DECLARE_EWK_VIEW_CALLBACK(RequestCertificateConfirm, "request,certificate,confirm", _Ewk_Certificate_Policy_Decision*);
 DECLARE_EWK_VIEW_CALLBACK(AuthChallenge, "authentication,challenge", _Ewk_Auth_Challenge*);
 DECLARE_EWK_VIEW_CALLBACK(SetCertificatePem, "certificate,pem,set", const char*);
-DECLARE_EWK_VIEW_CALLBACK(NotificationShow, "notification,show", tizen_webview::Notification*);
-DECLARE_EWK_VIEW_CALLBACK(NotificationCancel, "notification,cancel", uint64_t*);
 DECLARE_EWK_VIEW_CALLBACK(PolicyResponseDecide, "policy,response,decide", tizen_webview::PolicyDecision*);
 DECLARE_EWK_VIEW_CALLBACK(ContextMenuCustomize, "contextmenu,customize", _Ewk_Context_Menu*);
 DECLARE_EWK_VIEW_CALLBACK(ContextMenuItemSelected, "contextmenu,selected", _Ewk_Context_Menu_Item*);
index e2ed5c2..a8e776c 100644 (file)
@@ -91,7 +91,8 @@ EwkGlobalData* EwkGlobalData::GetInstance() {
 
   ui::InstallScreenInstance();
 
-  content::ContentMainParams params(new ContentMainDelegateEfl());
+  instance_->content_main_delegate_efl_ = new ContentMainDelegateEfl();
+  content::ContentMainParams params(instance_->content_main_delegate_efl_);
   params.argc = CommandLineEfl::GetArgc();
   params.argv = CommandLineEfl::GetArgv();
 
@@ -141,3 +142,8 @@ void EwkGlobalData::Delete()
   delete instance_;
   instance_ = NULL;
 }
+
+// static
+bool EwkGlobalData::IsInitialized() {
+  return instance_ != NULL;
+}
index 9ee5318..eb0267a 100644 (file)
@@ -10,6 +10,7 @@
 namespace content {
   class BrowserMainRunner;
   class ContentMainRunner;
+  class ContentMainDelegateEfl;
 }
 
 class EwkGlobalData
@@ -17,6 +18,11 @@ class EwkGlobalData
  public:
   static EwkGlobalData* GetInstance();
   static void Delete();
+  static bool IsInitialized();
+
+  content::ContentMainDelegateEfl& GetContentMainDelegatEfl() const {
+    return *content_main_delegate_efl_;
+  }
 
  private:
   EwkGlobalData();
@@ -26,6 +32,9 @@ class EwkGlobalData
 
   content::ContentMainRunner* content_main_runner_;
   content::BrowserMainRunner* browser_main_runner_;
+  content::ContentMainDelegateEfl* content_main_delegate_efl_;
+
+
 
   DISALLOW_COPY_AND_ASSIGN(EwkGlobalData);
 };
index f7f391a..62adb3e 100644 (file)
@@ -6,9 +6,6 @@
 #include "tw_notification.h"
 
 #include "content/public/browser/browser_thread.h"
-#include "content/public/browser/web_contents.h"
-#include "eweb_view.h"
-#include "tw_web_context.h"
 
 using content::BrowserThread;
 
@@ -17,13 +14,13 @@ namespace tizen_webview {
 // tizen_webview::Notification ------------------------------------------------
 Notification::Notification(
     const std::string& body,
-    const std::string& iconURL,
     const std::string& replaceID,
     const std::string& title,
+    const SkBitmap& icon,
     uint64_t notificationID,
     const tizen_webview::URL& origin)
     : body_(body)
-    , iconURL_(iconURL)
+    , icon_(icon)
     , replaceID_(replaceID)
     , title_(title)
     , notificationID_(notificationID)
@@ -37,10 +34,6 @@ const char* Notification::GetBody() const {
   return body_.c_str();
 }
 
-const char* Notification::GetIconUrl() const {
-  return iconURL_.c_str();
-}
-
 const char* Notification::GetReplaceId() const {
   return replaceID_.c_str();
 }
@@ -49,6 +42,24 @@ const char* Notification::GetTitle() const {
   return title_.c_str();
 }
 
+Evas_Object* Notification::GetIcon(Evas* evas) const {
+  if (icon_.isNull()) {
+    return nullptr;
+  }
+
+  Evas_Object* icon = evas_object_image_filled_add(evas);
+  evas_object_image_size_set(icon, icon_.width(), icon_.height());
+  evas_object_image_colorspace_set(icon, EVAS_COLORSPACE_ARGB8888);
+  evas_object_image_alpha_set(icon, EINA_TRUE);
+  void* pixels = evas_object_image_data_get(icon, EINA_TRUE);
+  if (pixels) {
+    icon_.copyPixelsTo(pixels, icon_.getSize());
+    evas_object_image_data_set(icon, pixels);
+  }
+
+  return icon;
+}
+
 int Notification::GetID() const {
   return notificationID_;
 }
@@ -90,20 +101,20 @@ bool NotificationPermissionRequest::IsSuspended() const {
   return suspended_;
 }
 
-void NotificationPermissionRequest::SetSuspend(bool suspend) const {
-  suspended_ = suspend;
+bool NotificationPermissionRequest::SetSuspend(bool suspend) const {
+  if (suspend != suspended_) {
+    suspended_ = suspend;
+    return true;
+  }
+
+  return false;
 }
 
-void NotificationPermissionRequest::Reply(bool allow) {
-#if defined(ENABLE_NOTIFICATIONS)
+bool NotificationPermissionRequest::Reply(bool allow) {
   if (decided_)
-    return;
+    return false;
+
   decided_ = true;
-  EWebView* view = EWebView::FromEvasObject(webview_);
-  if (view) {
-    view->context()->browser_context()->GetNotificationController()->
-        SetPermissionForNotification(this, allow);
-  }
   callback_.Run(allow);
 
   if (suspended_) {
@@ -113,7 +124,8 @@ void NotificationPermissionRequest::Reply(bool allow) {
     // it will be deleted right after permission callbacks are executed.
     BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
   }
-#endif
+
+  return true;
 }
 
 } // namespace tizen_webview
index c48e17e..98e2690 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "base/callback.h"
 #include "base/memory/scoped_ptr.h"
+#include "third_party/skia/include/core/SkBitmap.h"
 
 #include "tizen_webview/public/tw_macro.h"
 #include "tizen_webview/public/tw_security_origin.h"
@@ -30,23 +31,23 @@ class URL;
 class Notification {
  public:
   Notification(const std::string& body,
-               const std::string& iconURL,
                const std::string& replaceID,
                const std::string& title,
+               const SkBitmap& icon,
                uint64_t notificationID,
                const tizen_webview::URL& securityOrigin);
   ~Notification();
 
   const char* GetBody() const;
-  const char* GetIconUrl() const;
   const char* GetReplaceId() const;
   const char* GetTitle() const;
+  Evas_Object* GetIcon(Evas* evas) const;
   int GetID() const;
   const Security_Origin* GetSecurityOrigin() const;
 
  private:
   std::string body_;
-  std::string iconURL_;
+  SkBitmap icon_;
   std::string replaceID_;
   std::string title_;
   uint64_t notificationID_;
@@ -66,8 +67,8 @@ class NotificationPermissionRequest {
   const Security_Origin* GetSecurityOrigin() const;
   bool IsDecided() const;
   bool IsSuspended() const;
-  void SetSuspend(bool suspend) const;
-  void Reply(bool allow);
+  bool SetSuspend(bool suspend) const;
+  bool Reply(bool allow);
 
  private:
   Evas_Object* webview_;