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 class utc_blink_ewk_context_intercept_request_callback_set
10 : public utc_blink_ewk_base {
12 utc_blink_ewk_context_intercept_request_callback_set()
13 : callback_called_(false) {}
15 static const char* kInterceptURL;
17 void LoadFinished(Evas_Object* webview) override {
18 // Should not load without decision about interception.
19 EventLoopStop(Failure);
22 static void intercept_request_callback(
24 Ewk_Intercept_Request* intercept_request,
27 static_cast<utc_blink_ewk_context_intercept_request_callback_set*>(
29 owner->callback_called_.store(true);
32 std::atomic<bool> callback_called_;
36 utc_blink_ewk_context_intercept_request_callback_set::kInterceptURL =
37 "http://www.google.com/";
40 * @brief Tests if intercept request callback is called.
42 TEST_F(utc_blink_ewk_context_intercept_request_callback_set,
43 POS_TEST_CALLBACK_SET) {
44 ewk_context_intercept_request_callback_set(
45 ewk_view_context_get(GetEwkWebView()), intercept_request_callback, this);
47 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), kInterceptURL));
48 ASSERT_EQ(Timeout, EventLoopStart(3.0));
49 ASSERT_TRUE(callback_called_.load());
53 * @brief Tests if function resets callback in case of NULL of a callback.
55 TEST_F(utc_blink_ewk_context_intercept_request_callback_set,
56 POS_TEST_CALLBACK_RESET) {
57 ewk_context_intercept_request_callback_set(
58 ewk_view_context_get(GetEwkWebView()), intercept_request_callback, this);
59 ewk_context_intercept_request_callback_set(
60 ewk_view_context_get(GetEwkWebView()), nullptr, nullptr);
62 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), kInterceptURL));
64 // Expected value Failure, because LoadFinished sets this status
65 // if url loads normally.
66 ASSERT_EQ(Failure, EventLoopStart());
67 ASSERT_FALSE(callback_called_.load());
71 * @brief Tests if function works properly in case of NULL of a context.
73 TEST_F(utc_blink_ewk_context_intercept_request_callback_set,
74 NEG_TEST_NULL_CONTEXT) {
75 ewk_context_intercept_request_callback_set(
76 nullptr, intercept_request_callback, nullptr);