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.
5 #include "utc_blink_ewk_base.h"
9 #include "utc_blink_api_result_locked.h"
11 static const char* const kTitleChangedCb = "title,changed";
13 class utc_blink_ewk_intercept_request_ignore : public utc_blink_ewk_base {
15 static const char* kInterceptURL;
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);
23 EventLoopStop(Success);
26 void PostSetUp() override {
27 evas_object_smart_callback_add(GetEwkWebView(), kTitleChangedCb,
31 void PreTearDown() override {
32 evas_object_smart_callback_del(GetEwkWebView(), kTitleChangedCb,
36 static void TitleChanged(void* data, Evas_Object*, void* event_info) {
38 utc_message("TitleChanged :: data is null");
41 auto owner = static_cast<utc_blink_ewk_intercept_request_ignore*>(data);
43 utc_message("TitleChanged :: event_info is null");
46 auto title = static_cast<char*>(event_info);
47 owner->title_ = title;
48 if (!owner->url_.empty())
49 owner->EventLoopStop(Success);
52 static void intercept_request_callback_ignore(
54 Ewk_Intercept_Request* intercept_request,
57 static_cast<utc_blink_ewk_intercept_request_ignore*>(user_data);
58 owner->api_result_ = ewk_intercept_request_ignore(intercept_request);
61 static void intercept_request_callback_ignore_null(
63 Ewk_Intercept_Request* /*intercept_request*/,
66 static_cast<utc_blink_ewk_intercept_request_ignore*>(user_data);
67 owner->api_result_ = ewk_intercept_request_ignore(nullptr);
72 ApiResultLocked<Eina_Bool> api_result_;
75 const char* utc_blink_ewk_intercept_request_ignore::kInterceptURL =
76 "http://www.google.com/";
79 * @brief Tests if url loads if intercept request is ignored.
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,
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;
99 * @brief Tests if EINA_FALSE is returned for null intercept request.
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);
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());