[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_policy_decision_frame_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 class utc_blink_ewk_policy_decision_frame_get: public utc_blink_ewk_base
8 {
9 protected:
10   void PostSetUp() override
11   {
12     Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
13     old_can_open_windows_setting_ = ewk_settings_scripts_can_open_windows_get(settings);
14     ewk_settings_scripts_can_open_windows_set(settings, true);
15   }
16
17   void PreTearDown() override {
18     Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
19     ewk_settings_scripts_can_open_windows_set(settings, old_can_open_windows_setting_);
20   }
21
22   static void frame_check(void* data, Evas_Object* webview, void* event_info)
23   {
24     utc_message("  [ %s ]", __PRETTY_FUNCTION__);
25
26     ASSERT_TRUE(data); // test will wait for timeout, nothing we can do here
27     utc_blink_ewk_policy_decision_frame_get* owner = NULL;
28     OwnerFromVoid(data, &owner);
29
30     if (!event_info) {
31       // stop event loop so we won't have to wait for timeout
32       owner->EventLoopStop(Failure);
33       ASSERT_TRUE(event_info);
34     }
35
36     Ewk_Policy_Decision* policy_decision = static_cast<Ewk_Policy_Decision*>(event_info);
37     EXPECT_TRUE(ewk_policy_decision_frame_get(policy_decision));
38     owner->EventLoopStop(Success);
39   }
40
41 private:
42   bool old_can_open_windows_setting_;
43 };
44
45 TEST_F(utc_blink_ewk_policy_decision_frame_get, NAVIGATION_DECIDE)
46 {
47   evas_object_smart_callback_auto scb(GetEwkWebView(), "policy,navigation,decide", frame_check, this);
48   std::string resurl = GetResourceUrl("ewk_policy_decision/iframe.html");
49   ASSERT_NE(0, resurl.length());
50   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resurl.c_str()));
51   // Wait for stop from main frame
52   ASSERT_EQ(Success, EventLoopStart());
53
54   // Wait for second stop from sub frame
55   ASSERT_EQ(Success, EventLoopStart());
56 }
57
58 TEST_F(utc_blink_ewk_policy_decision_frame_get, RESPONSE_DECIDE)
59 {
60   evas_object_smart_callback_auto scb(GetEwkWebView(), "policy,response,decide", frame_check, this);
61
62   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), "http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe"));
63   // Wait for stop from main frame
64   ASSERT_EQ(Success, EventLoopStart());
65
66   // Wait for second stop from sub frame
67   ASSERT_EQ(Success, EventLoopStart());
68 }
69
70 TEST_F(utc_blink_ewk_policy_decision_frame_get, NEWWINDOW_DECIDE)
71 {
72   evas_object_smart_callback_auto scb(GetEwkWebView(), "policy,newwindow,decide", frame_check, this);
73
74   std::string resurl = GetResourceUrl("ewk_policy_decision/mainframe_newwindow.html");
75   ASSERT_NE(0, resurl.length());
76   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resurl.c_str()));
77   // Wait for stop from main frame
78   ASSERT_EQ(Success, EventLoopStart());
79
80   // Wait for second stop from sub frame
81   ASSERT_EQ(Success, EventLoopStart());
82 }
83
84 TEST_F(utc_blink_ewk_policy_decision_frame_get, INVALID_ARGS)
85 {
86   EXPECT_FALSE(ewk_policy_decision_frame_get(NULL));
87 }