Implement test for ewk_view_html_string_load
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_view_content_security_policy_set_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 #define SAMPLE_CONTENT_SECURITY_POLICY "ewk_view/sample_content_security_policy.html"
6
7 #include "utc_blink_ewk_base.h"
8
9 const char* policy = "default-src 'self';";
10
11 class utc_blink_ewk_view_content_security_policy_set : public utc_blink_ewk_base {
12 protected:
13   std::string title;
14
15   void LoadFinished(Evas_Object* webview) {
16
17      ecore_timer_add(2, getTitle, this);
18   }
19
20   static Eina_Bool getTitle(void *data)
21   {
22
23     utc_blink_ewk_view_content_security_policy_set* owner = static_cast<utc_blink_ewk_view_content_security_policy_set*>(data);
24
25     owner->title = ewk_view_title_get(owner->GetEwkWebView());
26
27     owner->EventLoopStop(utc_blink_ewk_base::Success);
28
29     return EINA_FALSE;
30   }
31 };
32
33 /**
34  * @brief Tests if it isn't possible to eval inline script when content security policy is set
35  * and enforce policy header is set.
36  */
37 TEST_F(utc_blink_ewk_view_content_security_policy_set, POS_TEST)
38 {
39   ewk_view_content_security_policy_set(GetEwkWebView(), policy, EWK_ENFORCE_POLICY);
40
41   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
42   if (!result)
43     FAIL();
44
45   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
46   if (main_result != utc_blink_ewk_base::Success)
47     FAIL();
48
49   utc_check_str_eq((const char*)title.c_str(), "PASS");
50 }
51
52 /**
53  * @brief Tests if there is possibility to eval inline script when content security policy
54  * and report only policy header is set.
55  */
56 TEST_F(utc_blink_ewk_view_content_security_policy_set, POS_TEST2)
57 {
58   ewk_view_content_security_policy_set(GetEwkWebView(), policy, EWK_REPORT_ONLY);
59
60   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
61   if (!result)
62     FAIL();
63
64   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
65   if (main_result != utc_blink_ewk_base::Success)
66     FAIL();
67
68   utc_check_str_eq((const char*)title.c_str(), "FAIL");
69 }
70
71 /**
72  * @brief Tests if there is possibility to eval inline script when content security policy is disabled.
73  */
74 TEST_F(utc_blink_ewk_view_content_security_policy_set, NEG_TEST)
75 {
76   ewk_view_content_security_policy_set(NULL, NULL, EWK_ENFORCE_POLICY);
77
78   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
79   if (!result)
80     FAIL();
81
82   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
83   if (main_result != utc_blink_ewk_base::Success)
84     FAIL();
85
86   utc_check_str_ne((const char*)title.c_str(), "PASS");
87 }