[evolution/wip/mcrha/webkit-jsc-api] Let the internal tests use .js files from sources, not those installed
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Let the internal tests use .js files from sources, not those installed
- Date: Thu, 7 Nov 2019 13:52:34 +0000 (UTC)
commit 6da72c44337076781410f42b3910d5123ebe0df1
Author: Milan Crha <mcrha redhat com>
Date: Thu Nov 7 14:52:17 2019 +0100
Let the internal tests use .js files from sources, not those installed
src/e-util/test-html-editor-units.c | 1 +
src/e-util/test-html-editor.c | 2 ++
src/e-util/test-web-view-jsc.c | 2 ++
.../webkit-editor/web-extension/CMakeLists.txt | 1 +
.../web-extension/e-editor-web-extension.c | 26 ++++++++++++++++++++--
src/web-extensions/CMakeLists.txt | 1 +
src/web-extensions/e-web-extension.c | 26 ++++++++++++++++++++--
7 files changed, 55 insertions(+), 4 deletions(-)
---
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index 9d3035f9bd..ead54c464b 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -2767,6 +2767,7 @@ main (gint argc,
user settings when playing with them. */
g_setenv ("GIO_EXTRA_MODULES", EVOLUTION_TESTGIOMODULESDIR, TRUE);
g_setenv ("GSETTINGS_BACKEND", TEST_KEYFILE_SETTINGS_BACKEND_NAME, TRUE);
+ g_setenv ("E_HTML_EDITOR_TEST_SOURCES", "1", FALSE);
g_setenv (TEST_KEYFILE_SETTINGS_FILENAME_ENVVAR, test_keyfile_filename, TRUE);
g_test_init (&argc, &argv, NULL);
diff --git a/src/e-util/test-html-editor.c b/src/e-util/test-html-editor.c
index b21632f0d1..84010ff899 100644
--- a/src/e-util/test-html-editor.c
+++ b/src/e-util/test-html-editor.c
@@ -571,6 +571,8 @@ main (gint argc,
e_util_init_main_thread (NULL);
e_passwords_init ();
+ g_setenv ("E_HTML_EDITOR_TEST_SOURCES", "1", FALSE);
+
modules = e_module_load_all_in_directory (EVOLUTION_MODULEDIR);
g_list_free_full (modules, (GDestroyNotify) g_type_module_unuse);
diff --git a/src/e-util/test-web-view-jsc.c b/src/e-util/test-web-view-jsc.c
index 0856984df9..c4a6644773 100644
--- a/src/e-util/test-web-view-jsc.c
+++ b/src/e-util/test-web-view-jsc.c
@@ -1929,6 +1929,8 @@ main (gint argc,
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("https://gitlab.gnome.org/GNOME/evolution/issues/");
+ g_setenv ("E_WEB_VIEW_TEST_SOURCES", "1", FALSE);
+
gtk_init (&argc, &argv);
e_util_init_main_thread (NULL);
diff --git a/src/modules/webkit-editor/web-extension/CMakeLists.txt
b/src/modules/webkit-editor/web-extension/CMakeLists.txt
index 02123840a1..7852e44834 100644
--- a/src/modules/webkit-editor/web-extension/CMakeLists.txt
+++ b/src/modules/webkit-editor/web-extension/CMakeLists.txt
@@ -32,6 +32,7 @@ set(sources
)
set(extra_defines
-DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
+ -DEVOLUTION_SOURCE_WEBKITDATADIR=\"${CMAKE_SOURCE_DIR}/data/webkit\"
)
set(extra_cflags)
diff --git a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
index bfd1c6030b..dbcb9c9dc5 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -96,19 +96,41 @@ web_page_send_request_cb (WebKitWebPage *web_page,
return FALSE;
}
+static gboolean
+use_sources_js_file (void)
+{
+ static gint res = -1;
+
+ if (res == -1)
+ res = g_strcmp0 (g_getenv ("E_HTML_EDITOR_TEST_SOURCES"), "1") == 0 ? 1 : 0;
+
+ return res;
+}
+
static void
load_javascript_file (JSCContext *jsc_context,
const gchar *js_filename)
{
JSCValue *result;
JSCException *exception;
- gchar *content, *filename, *resource_uri;
+ gchar *content, *filename = NULL, *resource_uri;
gsize length = 0;
GError *error = NULL;
g_return_if_fail (jsc_context != NULL);
- filename = g_build_filename (EVOLUTION_WEBKITDATADIR, js_filename, NULL);
+ if (use_sources_js_file ()) {
+ filename = g_build_filename (EVOLUTION_SOURCE_WEBKITDATADIR, js_filename, NULL);
+
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ g_warning ("Cannot find '%s', using installed file '%s/%s' instead", filename,
EVOLUTION_WEBKITDATADIR, js_filename);
+
+ g_clear_pointer (&filename, g_free);
+ }
+ }
+
+ if (!filename)
+ filename = g_build_filename (EVOLUTION_WEBKITDATADIR, js_filename, NULL);
if (!g_file_get_contents (filename, &content, &length, &error)) {
g_warning ("Failed to load '%s': %s", filename, error ? error->message : "Unknown error");
diff --git a/src/web-extensions/CMakeLists.txt b/src/web-extensions/CMakeLists.txt
index 35151503fe..dd699b76c0 100644
--- a/src/web-extensions/CMakeLists.txt
+++ b/src/web-extensions/CMakeLists.txt
@@ -19,6 +19,7 @@ add_dependencies(ewebextension
target_compile_definitions(ewebextension PRIVATE
-DG_LOG_DOMAIN=\"ewebextension\"
-DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
+ -DEVOLUTION_SOURCE_WEBKITDATADIR=\"${CMAKE_SOURCE_DIR}/data/webkit\"
)
target_compile_options(ewebextension PUBLIC
diff --git a/src/web-extensions/e-web-extension.c b/src/web-extensions/e-web-extension.c
index 87c52fd91e..ce295905fe 100644
--- a/src/web-extensions/e-web-extension.c
+++ b/src/web-extensions/e-web-extension.c
@@ -136,19 +136,41 @@ web_page_created_cb (WebKitWebExtension *wk_extension,
extension, 0);
}
+static gboolean
+use_sources_js_file (void)
+{
+ static gint res = -1;
+
+ if (res == -1)
+ res = g_strcmp0 (g_getenv ("E_WEB_VIEW_TEST_SOURCES"), "1") == 0 ? 1 : 0;
+
+ return res;
+}
+
static void
load_javascript_file (JSCContext *jsc_context,
const gchar *js_filename)
{
JSCValue *result;
JSCException *exception;
- gchar *content, *filename, *resource_uri;
+ gchar *content, *filename = NULL, *resource_uri;
gsize length = 0;
GError *error = NULL;
g_return_if_fail (jsc_context != NULL);
- filename = g_build_filename (EVOLUTION_WEBKITDATADIR, js_filename, NULL);
+ if (use_sources_js_file ()) {
+ filename = g_build_filename (EVOLUTION_SOURCE_WEBKITDATADIR, js_filename, NULL);
+
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ g_warning ("Cannot find '%s', using installed file '%s/%s' instead", filename,
EVOLUTION_WEBKITDATADIR, js_filename);
+
+ g_clear_pointer (&filename, g_free);
+ }
+ }
+
+ if (!filename)
+ filename = g_build_filename (EVOLUTION_WEBKITDATADIR, js_filename, NULL);
if (!g_file_get_contents (filename, &content, &length, &error)) {
g_warning ("Failed to load '%s': %s", filename, error ? error->message : "Unknown error");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]