[evolution/wip/mcrha/webkit-jsc-api] Add e_web_view_jsc_set_element_disabled() and e_web_view_jsc_set_element_checked()



commit 4b7b2761f54257030df9d6d6b858bc8e25438887
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 7 12:10:35 2019 +0200

    Add e_web_view_jsc_set_element_disabled() and e_web_view_jsc_set_element_checked()

 src/e-util/e-web-view-jsc-utils.c |  34 ++++++++++
 src/e-util/e-web-view-jsc-utils.h |  12 ++++
 src/e-util/test-web-view-jsc.c    | 131 ++++++++++++++++++++++++++++++++++++++
 src/web-extensions/ext-utils.js   |  16 +++++
 4 files changed, 193 insertions(+)
---
diff --git a/src/e-util/e-web-view-jsc-utils.c b/src/e-util/e-web-view-jsc-utils.c
index 6bb72f82e9..8e6f33e335 100644
--- a/src/e-util/e-web-view-jsc-utils.c
+++ b/src/e-util/e-web-view-jsc-utils.c
@@ -294,6 +294,40 @@ e_web_view_jsc_set_element_hidden (WebKitWebView *web_view,
                value ? 1 : 0);
 }
 
+void
+e_web_view_jsc_set_element_disabled (WebKitWebView *web_view,
+                                    const gchar *iframe_id,
+                                    const gchar *element_id,
+                                    gboolean value,
+                                    GCancellable *cancellable)
+{
+       g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+       g_return_if_fail (element_id != NULL);
+
+       e_web_view_jsc_run_script (web_view, cancellable,
+               "Evo.SetElementDisabled(%s,%s,%d)",
+               iframe_id,
+               element_id,
+               value ? 1 : 0);
+}
+
+void
+e_web_view_jsc_set_element_checked (WebKitWebView *web_view,
+                                   const gchar *iframe_id,
+                                   const gchar *element_id,
+                                   gboolean value,
+                                   GCancellable *cancellable)
+{
+       g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+       g_return_if_fail (element_id != NULL);
+
+       e_web_view_jsc_run_script (web_view, cancellable,
+               "Evo.SetElementChecked(%s,%s,%d)",
+               iframe_id,
+               element_id,
+               value ? 1 : 0);
+}
+
 void
 e_web_view_jsc_set_element_style_property (WebKitWebView *web_view,
                                           const gchar *iframe_id,
diff --git a/src/e-util/e-web-view-jsc-utils.h b/src/e-util/e-web-view-jsc-utils.h
index c9d8eda02e..8abb21bf46 100644
--- a/src/e-util/e-web-view-jsc-utils.h
+++ b/src/e-util/e-web-view-jsc-utils.h
@@ -58,6 +58,18 @@ void         e_web_view_jsc_set_element_hidden
                                                 const gchar *element_id,
                                                 gboolean value,
                                                 GCancellable *cancellable);
+void           e_web_view_jsc_set_element_disabled
+                                               (WebKitWebView *web_view,
+                                                const gchar *iframe_id,
+                                                const gchar *element_id,
+                                                gboolean value,
+                                                GCancellable *cancellable);
+void           e_web_view_jsc_set_element_checked
+                                               (WebKitWebView *web_view,
+                                                const gchar *iframe_id,
+                                                const gchar *element_id,
+                                                gboolean value,
+                                                GCancellable *cancellable);
 void           e_web_view_jsc_set_element_style_property
                                                (WebKitWebView *web_view,
                                                 const gchar *iframe_id,
diff --git a/src/e-util/test-web-view-jsc.c b/src/e-util/test-web-view-jsc.c
index ed58fabc96..2179b05577 100644
--- a/src/e-util/test-web-view-jsc.c
+++ b/src/e-util/test-web-view-jsc.c
@@ -483,6 +483,7 @@ test_utils_load_body (TestFixture *fixture,
                        "<html><body>"
                        "Top<br>"
                        "<input id=\"btn1\" class=\"cbtn1\" type=\"button\" value=\"Button1\"><br>"
+                       "<input id=\"chk1\" class=\"cchk1\" type=\"checkbox\" value=\"Check1\">"
                        "<iframe id=\"frm1\" src=\"empty:///frm1\"></iframe><br>"
                        "<iframe id=\"frm2\" src=\"empty:///frm2\"></iframe><br>"
                        "<input id=\"btn3\" class=\"cbtn3\" type=\"button\" value=\"Button3\">"
@@ -504,6 +505,7 @@ test_utils_load_body (TestFixture *fixture,
                        "<html><body>"
                        "frm1_1<br>"
                        "<input id=\"btn1\" class=\"cbtn1\" type=\"button\" value=\"Button1\">"
+                       "<input id=\"chk1\" class=\"cchk1\" type=\"checkbox\" value=\"Check1\">"
                        "<a name=\"dots\" id=\"dots2\" class=\"cdots\">...</a>"
                        "<input id=\"btn2\" class=\"cbtn2\" type=\"button\" value=\"Button2\">"
                        "</body></html>");
@@ -515,6 +517,7 @@ test_utils_load_body (TestFixture *fixture,
                        "frm2<br>"
                        "<input id=\"btn1\" class=\"cbtn1\" type=\"button\" value=\"Button1\">"
                        "<input id=\"btn2\" class=\"cbtn2\" type=\"button\" value=\"Button2\">"
+                       "<input id=\"chk2\" class=\"cchk2\" type=\"checkbox\" value=\"Check2\">"
                        "</body></html>");
        }
 }
@@ -652,6 +655,132 @@ test_set_element_hidden (TestFixture *fixture)
        g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").hidden"));
 }
 
+static void
+test_set_element_disabled (TestFixture *fixture)
+{
+       test_utils_load_body (fixture, LOAD_ALL);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "", "btn1", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "frm1_1", "btn1", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "frm2", "btn2", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "", "btn1", FALSE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "frm2", "btn1", FALSE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+
+       e_web_view_jsc_set_element_disabled (fixture->web_view, "frm1_1", "btn1", FALSE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"btn3\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"btn1\").disabled"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn1\").disabled"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"btn2\").disabled"));
+}
+
+static void
+test_set_element_checked (TestFixture *fixture)
+{
+       test_utils_load_body (fixture, LOAD_ALL);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "", "chk1", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "frm1_1", "chk1", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "", "chk1", FALSE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "frm2", "chk2", FALSE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "", "chk1", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+
+       e_web_view_jsc_set_element_checked (fixture->web_view, "frm1_1", "chk1", FALSE, NULL);
+       e_web_view_jsc_set_element_checked (fixture->web_view, "frm2", "chk2", TRUE, NULL);
+       test_utils_wait_noop (fixture);
+
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"\", \"chk1\").checked"));
+       g_assert (!test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm1_1\", \"chk1\").checked"));
+       g_assert (test_utils_jsc_call_bool_sync (fixture, "Evo.findElement(\"frm2\", \"chk2\").checked"));
+}
+
 static void
 test_set_element_style_property (TestFixture *fixture)
 {
@@ -1741,6 +1870,8 @@ main (gint argc,
 
        test_utils_add_test ("/EWebView/JSCObjectProperties", test_jsc_object_properties);
        test_utils_add_test ("/EWebView/SetElementHidden", test_set_element_hidden);
+       test_utils_add_test ("/EWebView/SetElementDisabled", test_set_element_disabled);
+       test_utils_add_test ("/EWebView/SetElementChecked", test_set_element_checked);
        test_utils_add_test ("/EWebView/SetElementStyleProperty", test_set_element_style_property);
        test_utils_add_test ("/EWebView/SetElementAttribute", test_set_element_attribute);
        test_utils_add_test ("/EWebView/StyleSheets", test_style_sheets);
diff --git a/src/web-extensions/ext-utils.js b/src/web-extensions/ext-utils.js
index 1e6db68da6..b2a102bfbd 100644
--- a/src/web-extensions/ext-utils.js
+++ b/src/web-extensions/ext-utils.js
@@ -132,6 +132,22 @@ Evo.SetElementHidden = function(iframe_id, element_id, value)
                elem.hidden = value;
 }
 
+Evo.SetElementDisabled = function(iframe_id, element_id, value)
+{
+       var elem = Evo.findElement(iframe_id, element_id);
+
+       if (elem)
+               elem.disabled = value;
+}
+
+Evo.SetElementChecked = function(iframe_id, element_id, value)
+{
+       var elem = Evo.findElement(iframe_id, element_id);
+
+       if (elem)
+               elem.checked = value;
+}
+
 Evo.SetElementStyleProperty = function(iframe_id, element_id, property_name, value)
 {
        var elem = Evo.findElement(iframe_id, element_id);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]