[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_policy_decision_http_method_get_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 baseURL "http://google.com"
8
9 class utc_blink_ewk_policy_decision_http_method_get : public utc_blink_ewk_base
10 {
11  protected:
12   void PostSetUp() override {
13     evas_object_smart_callback_add(GetEwkWebView(), "policy,navigation,decide", ToSmartCallback(policy_navigation_decide), this);
14   }
15
16   void PreTearDown() override {
17     evas_object_smart_callback_del(GetEwkWebView(), "policy,navigation,decide", ToSmartCallback(policy_navigation_decide));
18   }
19
20   static void policy_navigation_decide(utc_blink_ewk_policy_decision_http_method_get* owner,
21           Evas_Object* webview, Ewk_Policy_Decision* policy_decision)
22   {
23     ASSERT_TRUE(owner);
24     const char* method = ewk_policy_decision_http_method_get(policy_decision);
25     owner->receivedMethod = method ? method : "";
26     owner->EventLoopStop(Success);
27   }
28
29   std::string getDocumentForMethod(const std::string& method)
30   {
31     return std::string(
32           "<html>"
33           "<body>"
34             "<form id='theForm' method='" + method + "' action='" + baseURL + "'>"
35               "<input name='x' value='y'/>"
36             "</form>"
37           "</body>"
38           "<script>"
39             "document.getElementById('theForm').submit();"
40           "</script>"
41           "</html>");
42   }
43
44  protected:
45    std::string receivedMethod;
46    std::string currentMethod;
47 };
48
49 /**
50  * @brief Tests if the method for policy decision is returned properly.
51  */
52 TEST_F(utc_blink_ewk_policy_decision_http_method_get, TEST_DEFALUT_METHOD)
53 {
54   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), baseURL));
55   ASSERT_EQ(Success, EventLoopStart());
56   ASSERT_EQ("GET", receivedMethod);
57 }
58
59 TEST_F(utc_blink_ewk_policy_decision_http_method_get, TEST_METHOD_GET)
60 {
61   currentMethod="GET";
62   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), getDocumentForMethod(currentMethod).c_str(), baseURL, 0));
63   ASSERT_EQ(Success, EventLoopStart());
64   ASSERT_EQ(currentMethod, receivedMethod);
65 }
66
67 TEST_F(utc_blink_ewk_policy_decision_http_method_get, TEST_METHOD_POST)
68 {
69   currentMethod="POST";
70   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), getDocumentForMethod(currentMethod).c_str(), baseURL, 0));
71   ASSERT_EQ(Success, EventLoopStart());
72   ASSERT_EQ(currentMethod, receivedMethod);
73 }
74
75 TEST_F(utc_blink_ewk_policy_decision_http_method_get, TEST_INVALID_PARAM)
76 {
77   ASSERT_EQ(NULL, ewk_policy_decision_http_method_get(NULL));
78 }