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 #define URL ("http://google.com")
9 class utc_blink_cb_popup_blocked : public utc_blink_ewk_base
12 utc_blink_cb_popup_blocked()
14 , old_can_open_windows_setting_(false)
18 void PostSetUp() override {
19 Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
20 old_can_open_windows_setting_ = ewk_settings_scripts_can_open_windows_get(settings);
22 evas_object_smart_callback_add(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb), this);
25 void PreTearDown() override {
26 evas_object_smart_callback_del(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb));
28 Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
29 ewk_settings_scripts_can_open_windows_set(settings, old_can_open_windows_setting_);
32 static void popup_blocked_cb(utc_blink_cb_popup_blocked* owner, Evas_Object*, Eina_Stringshare* uri)
35 owner->target_uri = eina_stringshare_add(uri);
36 owner->EventLoopStop(Success);
39 static void window_open_script_executed(Evas_Object* o, const char* result_value, utc_blink_cb_popup_blocked* owner)
42 owner->EventLoopStop(Failure);
46 Eina_Stringshare* target_uri;
47 bool old_can_open_windows_setting_;
51 * @brief Tests "popup,blocked" callback
53 * By default chromium-efl will block all window.open JS requests that were not produced by "user gesture"
55 TEST_F(utc_blink_cb_popup_blocked, callback)
57 char htmlBuffer[] = "<html>"
59 "<body onload=\"window.open('http://www.google.com/')\"></body>"
62 Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
63 ewk_settings_scripts_can_open_windows_set(settings, false);
65 ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
66 ASSERT_EQ(Success, EventLoopStart());
67 ASSERT_STREQ("http://www.google.com/", target_uri);
69 ewk_settings_scripts_can_open_windows_set(settings, true);
71 // ewk_view_script_execute works like "user gesture" so window.open should not be blocked
72 ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "window.open('http://www.google.com/');", reinterpret_cast<Ewk_View_Script_Execute_Cb>(window_open_script_executed), this));
73 ASSERT_EQ(Failure, EventLoopStart());