[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_view_quota_permission_request_reply_func.cpp
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "utc_blink_ewk_base.h"
6
7 #define SAMPLE_HTML_FILE        ("/ewk_view/quota_ask.html")
8
9
10 class utc_blink_ewk_view_quota_permission_request_reply : public utc_blink_ewk_base
11 {
12 protected:
13  void PreSetUp() override {
14    isTitleNull = true;
15    title = "";
16   }
17
18   void PostSetUp() override {
19     evas_object_smart_callback_add(GetEwkWebView(), "title,changed",
20                                    ToSmartCallback(title_changed), this);
21   }
22   void PreTearDown() override {
23     evas_object_smart_callback_del(GetEwkWebView(), "title,changed",
24                                    ToSmartCallback(title_changed));
25   }
26
27   static void quotaPermission(Evas_Object*, const Ewk_Quota_Permission_Request* request,
28                               utc_blink_ewk_view_quota_permission_request_reply* owner)
29   {
30     utc_message("[ %s ]", __PRETTY_FUNCTION__);
31     if (!request)
32     {
33       ASSERT_TRUE(owner);
34       owner->EventLoopStop(Failure);
35       return;
36     }
37     ewk_view_quota_permission_request_reply(request, EINA_FALSE);
38   }
39
40   static void title_changed(utc_blink_ewk_view_quota_permission_request_reply* owner,
41                             Evas_Object*, const char* title)
42   {
43     utc_message("[ %s ]", __PRETTY_FUNCTION__);
44     ASSERT_TRUE(owner);
45     if (!title)
46     {
47       owner->isTitleNull = true;
48       owner->title = "";
49       owner->EventLoopStop(Failure);
50       return;
51     }
52     owner->isTitleNull = false;
53     owner->title = title;
54     // Ignore initial title
55     if (owner->title != "No reply yet")
56       owner->EventLoopStop(Success);
57   }
58
59 protected:
60   bool isTitleNull;
61   std::string title;
62 };
63
64 /**
65  * @brief Positive  test case of ewk_view_quota_permission_request_reply()
66  * ewk_view_quota_permission_request_callback should be set if the page content triggers a request callback
67  */
68 TEST_F(utc_blink_ewk_view_quota_permission_request_reply, POS_TEST)
69 {
70   ewk_view_quota_permission_request_callback_set(
71                            GetEwkWebView(),
72                            reinterpret_cast<Ewk_Quota_Permission_Request_Callback>(quotaPermission),
73                            this);
74   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(),
75                                         GetResourceUrl(SAMPLE_HTML_FILE).c_str()));
76   ASSERT_EQ(Success, EventLoopStart());
77   ASSERT_STREQ("0", title.c_str());
78 }
79
80 /**
81   * Test case with ewk_view_quota_permission_request_reply(request, EINA_TRUE)
82   * is not possible because file protocol doesn't support quota for storage.
83   * However engine asks for quota permission in case of file protocol
84   * but in case of EINA_TRUE engine responds in HTML page with error callback.
85   * We cannot determine if error was due to file protocol or internal error.
86   */
87
88 /**
89 * @brief Checking whether function works properly in case of NULL of a webview and callback.
90 */
91 TEST_F(utc_blink_ewk_view_quota_permission_request_reply, NEG_TEST)
92 {
93   ewk_view_quota_permission_request_reply(NULL, EINA_TRUE);
94 }