[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_settings_scripts_window_open_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 #include "utc_blink_ewk_base.h"
6
7 class utc_blink_ewk_settings_scripts_window_open_set : public utc_blink_ewk_base {
8 protected:
9   utc_blink_ewk_settings_scripts_window_open_set()
10     : settings(NULL)
11   {
12   }
13
14   void PostSetUp() override {
15     settings = ewk_view_settings_get(GetEwkWebView());
16     ASSERT_TRUE(settings);
17     // make sure default value is proper
18     ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_get(settings));
19
20     evas_object_smart_callback_add(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb), this);
21     evas_object_smart_callback_add(GetEwkWebView(), "create,window", ToSmartCallback(create_window_cb), this);
22   }
23
24   void PreTearDown() override {
25     evas_object_smart_callback_del(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb));
26     evas_object_smart_callback_del(GetEwkWebView(), "create,window", ToSmartCallback(create_window_cb));
27   }
28
29   static void popup_blocked_cb(utc_blink_ewk_settings_scripts_window_open_set* owner, Evas_Object*, Eina_Stringshare* uri)
30   {
31     ASSERT_TRUE(owner);
32     owner->EventLoopStop(Success);
33   }
34
35   static void create_window_cb(utc_blink_ewk_settings_scripts_window_open_set* owner, Evas_Object*, void*)
36   {
37     ASSERT_TRUE(owner);
38     owner->EventLoopStop(Failure);
39   }
40
41 protected:
42   Ewk_Settings* settings;
43 };
44
45 /**
46  * @brief Positive test case of ewk_settings_scripts_window_open_set()
47  */
48 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, SetFalse)
49 {
50   // first check if new windows are created
51   char htmlBuffer[] = "<html>"
52                         "<head></head>"
53                         "<body onload=\"window.open('http://www.google.com/')\"></body>"
54                       "</html>";
55
56   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
57   ASSERT_EQ(Failure, EventLoopStart());
58
59   // now toggle option
60   ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_FALSE));
61
62   // check if option was toggled
63   ASSERT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_get(settings));
64
65   // reload page and expect popup,blocked smart callback
66   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
67   ASSERT_EQ(Success, EventLoopStart());
68 }
69
70 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, ToggleBeforeLoad)
71 {
72   // Got feedback, that whem property is modified before loading anything to the view
73   // it may not work. This TC checks such case and tests provided solution
74
75   // toggle option
76   ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_FALSE));
77
78   // check if option was toggled
79   ASSERT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_get(settings));
80
81   char htmlBuffer[] = "<html>"
82                         "<head></head>"
83                         "<body onload=\"window.open('http://www.google.com/')\"></body>"
84                       "</html>";
85
86   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
87   // Expect that popup,blocked is called - option did work
88   ASSERT_EQ(Success, EventLoopStart());
89
90   // toggle option again
91   ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_TRUE));
92
93   // check if option was toggled
94   ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_get(settings));
95
96   // reload page and expect create,window smart callback
97   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
98   ASSERT_EQ(Failure, EventLoopStart());
99 }
100
101 /**
102  * @brief Test case of ewk_settings_scripts_window_open_set() when view is NULL
103  */
104 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, InvalidArg)
105 {
106   EXPECT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_set(NULL, EINA_TRUE));
107 }