[M120 Migration][MM] Support W3C EME
[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) override {
16     ecore_timer_add(2, getTitle, this);
17   }
18
19   static Eina_Bool getTitle(void *data)
20   {
21
22     utc_blink_ewk_view_content_security_policy_set* owner = static_cast<utc_blink_ewk_view_content_security_policy_set*>(data);
23
24     owner->title = ewk_view_title_get(owner->GetEwkWebView());
25
26     owner->EventLoopStop(utc_blink_ewk_base::Success);
27
28     return EINA_FALSE;
29   }
30 };
31
32 /**
33  * @brief Tests if it isn't possible to eval inline script when content security policy is set
34  * and enforce policy header is set.
35  */
36 TEST_F(utc_blink_ewk_view_content_security_policy_set, POS_TEST)
37 {
38   ewk_view_content_security_policy_set(GetEwkWebView(), policy, EWK_ENFORCE_POLICY);
39
40   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
41   if (!result)
42     FAIL();
43
44   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
45   if (main_result != utc_blink_ewk_base::Success)
46     FAIL();
47
48   utc_check_str_eq((const char*)title.c_str(), "PASS");
49 }
50
51 /**
52  * @brief Tests if there is possibility to eval inline script when content security policy
53  * and report only policy header is set.
54  */
55 TEST_F(utc_blink_ewk_view_content_security_policy_set, POS_TEST2)
56 {
57   ewk_view_content_security_policy_set(GetEwkWebView(), policy, EWK_REPORT_ONLY);
58
59   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
60   if (!result)
61     FAIL();
62
63   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
64   if (main_result != utc_blink_ewk_base::Success)
65     FAIL();
66
67   utc_check_str_eq((const char*)title.c_str(), "FAIL");
68 }
69
70 /**
71  * @brief Tests if there is possibility to eval inline script when content security policy is disabled.
72  */
73 TEST_F(utc_blink_ewk_view_content_security_policy_set, NEG_TEST)
74 {
75   ewk_view_content_security_policy_set(NULL, NULL, EWK_ENFORCE_POLICY);
76
77   Eina_Bool result = ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_CONTENT_SECURITY_POLICY).c_str());
78   if (!result)
79     FAIL();
80
81   utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
82   if (main_result != utc_blink_ewk_base::Success)
83     FAIL();
84
85   utc_check_str_ne((const char*)title.c_str(), "PASS");
86 }