[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_auth_challenge_credential_cancel_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 #define URL "https://review.tizen.org/gerrit/#/"
7
8 static Eina_Bool is_failed;
9 static Eina_Bool is_Authenticated;
10
11 class utc_blink_ewk_auth_challenge_credential_cancel : public utc_blink_ewk_base {
12 protected:
13     void PostSetUp() override
14     {
15         ewk_view_authentication_callback_set(GetEwkWebView(), AuthenticationChallenge, this);
16     }
17
18     void PreTearDown() override
19     {
20         ewk_view_authentication_callback_set(GetEwkWebView(), nullptr, nullptr);
21     }
22
23     void LoadFinished(Evas_Object* webview) override {
24       EventLoopStop(utc_blink_ewk_base::Failure);  // will noop if EventLoopStop
25                                                    // was alraedy called
26     }
27
28     static void AuthenticationChallenge(Evas_Object* o, Ewk_Auth_Challenge* auth_challenge, void* data)
29     {
30         utc_blink_ewk_auth_challenge_credential_cancel *owner = static_cast<utc_blink_ewk_auth_challenge_credential_cancel*>(data);
31         utc_message("[authentication_challenge] :: ");
32
33         if (!auth_challenge) {
34             owner->EventLoopStop(utc_blink_ewk_base::Failure);
35             return;
36         }
37
38         const char* realm = ewk_auth_challenge_realm_get(auth_challenge);
39         const char* url = ewk_auth_challenge_url_get(auth_challenge);
40
41         if (!realm || !url) {
42             owner->EventLoopStop(utc_blink_ewk_base::Failure);
43             return;
44         }
45
46         // TODO: invalid test
47         // this test does not check if cancel was successful. It checks if authentication,challange was called
48         ewk_auth_challenge_credential_cancel(auth_challenge);
49         owner->EventLoopStop(utc_blink_ewk_base::Success);
50     }
51 };
52
53 /**
54   * @brief Checking whether sending cancellation notification for authentication challenge works properly.
55   */
56 TEST_F(utc_blink_ewk_auth_challenge_credential_cancel, POS_TEST)
57 {
58     is_failed = EINA_FALSE;
59     is_Authenticated = EINA_FALSE;
60
61     Eina_Bool result = ewk_view_url_set(GetEwkWebView(), URL);
62     if (!result)
63         FAIL();
64
65     utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
66
67     if (main_result != utc_blink_ewk_base::Success)
68         FAIL();
69
70     evas_object_show(GetEwkWebView());
71     evas_object_show(GetEwkWindow());
72 }
73
74 // TODO: this case does nothing. It didn't even start event loop, so callback wouldn't be ever called.
75 /**
76 * @brief Checking whether function works properly in case of NULL of a webview.
77 */
78 /*
79 TEST_F(utc_blink_ewk_auth_challenge_credential_cancel, NEG_TEST)
80 {
81     Eina_Bool result = ewk_view_url_set(NULL, URL);
82     if (result)
83         FAIL();
84
85     utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart(15.0);
86     evas_object_show(GetEwkWebView());
87     evas_object_show(GetEwkWindow());
88
89
90
91     EXPECT_NE(main_result, utc_blink_ewk_base::Success);
92 }
93 */
94