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.
5 #include "utc_blink_ewk_base.h"
7 class utc_blink_ewk_settings_scripts_window_open_set : public utc_blink_ewk_base {
9 utc_blink_ewk_settings_scripts_window_open_set()
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));
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);
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));
29 static void popup_blocked_cb(utc_blink_ewk_settings_scripts_window_open_set* owner, Evas_Object*, Eina_Stringshare* uri)
32 owner->EventLoopStop(Success);
35 static void create_window_cb(utc_blink_ewk_settings_scripts_window_open_set* owner, Evas_Object*, void*)
38 owner->EventLoopStop(Failure);
42 Ewk_Settings* settings;
46 * @brief Positive test case of ewk_settings_scripts_window_open_set()
48 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, SetFalse)
50 // first check if new windows are created
51 char htmlBuffer[] = "<html>"
53 "<body onload=\"window.open('http://www.google.com/')\"></body>"
56 ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
57 ASSERT_EQ(Failure, EventLoopStart());
60 ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_FALSE));
62 // check if option was toggled
63 ASSERT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_get(settings));
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());
70 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, ToggleBeforeLoad)
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
76 ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_FALSE));
78 // check if option was toggled
79 ASSERT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_get(settings));
81 char htmlBuffer[] = "<html>"
83 "<body onload=\"window.open('http://www.google.com/')\"></body>"
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());
90 // toggle option again
91 ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_set(settings, EINA_TRUE));
93 // check if option was toggled
94 ASSERT_EQ(EINA_TRUE, ewk_settings_scripts_window_open_get(settings));
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());
102 * @brief Test case of ewk_settings_scripts_window_open_set() when view is NULL
104 TEST_F(utc_blink_ewk_settings_scripts_window_open_set, InvalidArg)
106 EXPECT_EQ(EINA_FALSE, ewk_settings_scripts_window_open_set(NULL, EINA_TRUE));