[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_auth_challenge_credential_use_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 URL "https://review.tizen.org/gerrit/#/"
8
9 class utc_blink_ewk_auth_challenge_credential_use : public utc_blink_ewk_base
10 {
11 protected:
12   void PostSetUp() override
13   {
14     ewk_view_authentication_callback_set(GetEwkWebView(), AuthenticationChallenge, this);
15   }
16
17   void PreTearDown() override
18   {
19     evas_object_smart_callback_del( GetEwkWebView(), "authentication,challenge", authentication_challenge);
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 was alraedy called
25   }
26
27   static void AuthenticationChallenge(Evas_Object* o, Ewk_Auth_Challenge* auth_challenge, void* data)
28   {
29     utc_message("[authentication_challenge] :: ");
30     utc_blink_ewk_auth_challenge_credential_use *owner = static_cast<utc_blink_ewk_auth_challenge_credential_use*>(data);
31
32     if (!auth_challenge) {
33       owner->EventLoopStop( utc_blink_ewk_base::Failure ); // will noop if EventLoopStop was alraedy called
34       utc_fail();
35     }
36
37     const char* realm = ewk_auth_challenge_realm_get(auth_challenge);
38     const char* url = ewk_auth_challenge_url_get(auth_challenge);
39     if (!realm || !url) {
40       owner->EventLoopStop( utc_blink_ewk_base::Failure ); // will noop if EventLoopStop was alraedy called
41       utc_fail();
42     }
43
44     const char* user = "access";
45     const char* password = "early";
46     ewk_auth_challenge_credential_use(auth_challenge, user, password);
47     owner->EventLoopStop( utc_blink_ewk_base::Success );
48     // TODO
49     // Here is a logical error because success is called a question about authorization,
50     // not about the result of the authorization.
51     // In the casete of re-call up the callback should be return failuare
52   }
53 };
54
55   /**
56   * @brief Checking whether sending cancellation notification for authentication challenge works properly.
57   */
58 TEST_F(utc_blink_ewk_auth_challenge_credential_use, POS_TEST)
59 {
60   utc_check_true( ewk_view_url_set( GetEwkWebView(), URL));
61
62   utc_check_eq( EventLoopStart(), utc_blink_ewk_base::Success);
63
64   evas_object_show( GetEwkWebView());
65   evas_object_show( GetEwkWindow());
66 }
67
68   /**
69   * @brief Checking whether function works properly in case of NULL of a webview.
70   */
71 TEST_F(utc_blink_ewk_auth_challenge_credential_use, NEG_TEST)
72 {
73   Eina_Bool result = ewk_view_url_set( NULL, URL);
74
75   if (result) {
76     utc_fail();
77   }
78
79   evas_object_show( GetEwkWebView());
80   evas_object_show( GetEwkWindow());
81 }
82