[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_intercept_request_ignore_func.cpp
1 // Copyright 2016 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 #include <string>
8
9 #include "utc_blink_api_result_locked.h"
10
11 static const char* const kTitleChangedCb = "title,changed";
12
13 class utc_blink_ewk_intercept_request_ignore : public utc_blink_ewk_base {
14  protected:
15   static const char* kInterceptURL;
16
17   void LoadFinished(Evas_Object* webview) override {
18     // URL loads normally if intercept request is ignored in callback
19     const char* url = ewk_view_url_get(webview);
20     if (url)
21       url_ = url;
22     if (!title_.empty())
23       EventLoopStop(Success);
24   }
25
26   void PostSetUp() override {
27     evas_object_smart_callback_add(GetEwkWebView(), kTitleChangedCb,
28                                    TitleChanged, this);
29   }
30
31   void PreTearDown() override {
32     evas_object_smart_callback_del(GetEwkWebView(), kTitleChangedCb,
33                                    TitleChanged);
34   }
35
36   static void TitleChanged(void* data, Evas_Object*, void* event_info) {
37     if (!data) {
38       utc_message("TitleChanged :: data is null");
39       return;
40     }
41     auto owner = static_cast<utc_blink_ewk_intercept_request_ignore*>(data);
42     if (!event_info) {
43       utc_message("TitleChanged :: event_info is null");
44       return;
45     }
46     auto title = static_cast<char*>(event_info);
47     owner->title_ = title;
48     if (!owner->url_.empty())
49       owner->EventLoopStop(Success);
50   }
51
52   static void intercept_request_callback_ignore(
53       Ewk_Context* /*ctx*/,
54       Ewk_Intercept_Request* intercept_request,
55       void* user_data) {
56     auto* owner =
57         static_cast<utc_blink_ewk_intercept_request_ignore*>(user_data);
58     owner->api_result_ = ewk_intercept_request_ignore(intercept_request);
59   }
60
61   static void intercept_request_callback_ignore_null(
62       Ewk_Context* /*ctx*/,
63       Ewk_Intercept_Request* /*intercept_request*/,
64       void* user_data) {
65     auto* owner =
66         static_cast<utc_blink_ewk_intercept_request_ignore*>(user_data);
67     owner->api_result_ = ewk_intercept_request_ignore(nullptr);
68   }
69
70   std::string url_;
71   std::string title_;
72   ApiResultLocked<Eina_Bool> api_result_;
73 };
74
75 const char* utc_blink_ewk_intercept_request_ignore::kInterceptURL =
76     "http://www.google.com/";
77
78 /**
79  * @brief Tests if url loads if intercept request is ignored.
80  */
81 TEST_F(utc_blink_ewk_intercept_request_ignore, POS_TEST_IGNORE) {
82   ewk_context_intercept_request_callback_set(
83       ewk_view_context_get(GetEwkWebView()), intercept_request_callback_ignore,
84       this);
85
86   ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), kInterceptURL));
87   ASSERT_EQ(Success, EventLoopStart());
88   ASSERT_TRUE(api_result_.IsSet());
89   EXPECT_TRUE(api_result_.Get());
90   EXPECT_NE(std::string::npos, url_.find("google"))
91       << "Substring \"google\" not in "
92       << "\"" << url_ << "\"." << std::endl;
93   EXPECT_NE(std::string::npos, title_.find("Google"))
94       << "Substring \"Google\" not in "
95       << "\"" << title_ << "\"." << std::endl;
96 }
97
98 /**
99  * @brief Tests if EINA_FALSE is returned for null intercept request.
100  */
101 TEST_F(utc_blink_ewk_intercept_request_ignore, NEG_TEST_IGNORE_NULL) {
102   ewk_context_intercept_request_callback_set(
103       ewk_view_context_get(GetEwkWebView()),
104       intercept_request_callback_ignore_null, this);
105
106   ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), kInterceptURL));
107   ASSERT_EQ(Timeout, EventLoopStart(3.0));
108   ASSERT_TRUE(api_result_.IsSet());
109   ASSERT_FALSE(api_result_.Get());
110 }