Fix utc_blink_cb_popup_blocked
authorAntonio Gomes <a1.gomes@samsung.com>
Thu, 26 Nov 2015 19:18:59 +0000 (15:18 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
Patch executes Javascript strings with non-null user callbacks
with FRH::ExecuteJavaScriptWithUserGestureForTests rather than
FRH::ExecuteJavaScriptForTests.

Former allows window opening.

Patch also fixes the test utc_blink_cb_popup_blocked itself. First part
of the test relies on the popup opening setting being disabled, so
patch ensures it by explicitly set it to FALSE. Second part of the test,
it assumes that popup opening is enabled, so we set it explicitly to
TRUE. Last, after executing the tests, patch sets the setting value to
its original status (see changes in PostSetUp and PreTearDown).

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=13056

Reviewed by: a.renevier, djmix.kim

Change-Id: I2c2218406901735007435251e0549570b9d031bf
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/unittest/utc_blink_cb_popup_blocked.cpp

index 3f129458a1e2b4254786396e16365e478644646d..77c82896e72f01411a97b94a3128bcba1fd7bad3 100644 (file)
@@ -788,7 +788,8 @@ bool EWebView::ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Cal
     // In M47, it isn't possible anymore to execute javascript in the generic
     // case. We need to call ExecuteJavaScriptForTests to keep the behaviour
     // unchanged @see https://codereview.chromium.org/1123783002
-    render_frame_host->ExecuteJavaScriptForTests(js_script, base::Bind(&JavaScriptComplete, base::Owned(script_callback_data)));
+    render_frame_host->ExecuteJavaScriptWithUserGestureForTests(
+        js_script, base::Bind(&JavaScriptComplete, base::Owned(script_callback_data)));
   } else {
     // We use ExecuteJavaScriptWithUserGestureForTests instead of ExecuteJavaScript because
     // ExecuteJavaScriptWithUserGestureForTests sets user_gesture to true. This was the
index 9f542b5188b5c0f601c97c712448688906c647cc..a08bf657e1624214a8bd9f486204c4351c75135b 100644 (file)
@@ -11,17 +11,24 @@ class utc_blink_cb_popup_blocked : public utc_blink_ewk_base
 protected:
   utc_blink_cb_popup_blocked()
     : target_uri(NULL)
+    , old_can_open_windows_setting_(false)
   {
   }
 
   void PostSetUp()
   {
+    Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+    old_can_open_windows_setting_ = ewk_settings_scripts_can_open_windows_get(settings);
+
     evas_object_smart_callback_add(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb), this);
   }
 
   void PreTearDown()
   {
     evas_object_smart_callback_del(GetEwkWebView(), "popup,blocked", ToSmartCallback(popup_blocked_cb));
+
+    Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+    ewk_settings_scripts_can_open_windows_set(settings, old_can_open_windows_setting_);
   }
 
   static void popup_blocked_cb(utc_blink_cb_popup_blocked* owner, Evas_Object*, Eina_Stringshare* uri)
@@ -39,6 +46,7 @@ protected:
 
 protected:
   Eina_Stringshare* target_uri;
+  bool old_can_open_windows_setting_;
 };
 
 /**
@@ -53,10 +61,15 @@ TEST_F(utc_blink_cb_popup_blocked, callback)
                         "<body onload=\"window.open('http://www.google.com/')\"></body>"
                       "</html>";
 
+  Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+  ewk_settings_scripts_can_open_windows_set(settings, false);
+
   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
   ASSERT_EQ(Success, EventLoopStart());
   ASSERT_STREQ("http://www.google.com/", target_uri);
 
+  ewk_settings_scripts_can_open_windows_set(settings, true);
+
   // ewk_view_script_execute works like "user gesture" so window.open should not be blocked
   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));
   ASSERT_EQ(Failure, EventLoopStart());