[geary/wip/jsc-migration: 3/5] Move Geary.JS package into client as Util.JS
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/jsc-migration: 3/5] Move Geary.JS package into client as Util.JS
- Date: Sun, 21 Jul 2019 00:06:49 +0000 (UTC)
commit da6ac828bda3479a43edf6026b798208bbd9e1a6
Author: Michael Gratton <mike vee net>
Date: Sun Jul 21 10:00:32 2019 +1000
Move Geary.JS package into client as Util.JS
The only reason it was in the engine was so it could be used by both
the client and the web extension, without worrying about the
webkit2gtk and webkit2gtk_web_extension packages conflicting. However
it didn't really belong there, and added a dependency for the engine
on javascriptcoregtk which doesn't belong. So this fixes all that.
po/POTFILES.in | 2 +-
src/client/components/client-web-view.vala | 16 +++----
src/client/composer/composer-web-view.vala | 43 +++++++++++--------
.../conversation-viewer/conversation-web-view.vala | 38 ++++++++--------
src/client/meson.build | 3 ++
src/{engine => client}/util/util-js.vala | 50 +++++++++++-----------
src/client/util/util-webkit.vala | 28 ++++++------
src/client/web-process/web-process-extension.vala | 6 +--
src/engine/meson.build | 2 -
src/meson.build | 12 ++++--
test/client/util/util-js-test.vala | 24 +++++++++++
test/engine/util-js-test.vala | 24 -----------
test/js/composer-page-state-test.vala | 44 +++++++++----------
test/js/conversation-page-state-test.vala | 4 +-
test/meson.build | 2 +-
test/test-client.vala | 1 +
test/test-engine.vala | 1 -
17 files changed, 158 insertions(+), 142 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a967d0af..5e396773 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -96,6 +96,7 @@ src/client/util/util-files.vala
src/client/util/util-gio.vala
src/client/util/util-gtk.vala
src/client/util/util-international.vala
+src/client/util/util-js.vala
src/client/util/util-migrate.vala
src/client/util/util-webkit.vala
src/client/web-process/web-process-extension.vala
@@ -388,7 +389,6 @@ src/engine/util/util-idle-manager.vala
src/engine/util/util-imap-utf7.vala
src/engine/util/util-inet.vala
src/engine/util/util-iterable.vala
-src/engine/util/util-js.vala
src/engine/util/util-loggable.vala
src/engine/util/util-numeric.vala
src/engine/util/util-object.vala
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index b6931596..aa938292 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -393,7 +393,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
*/
public async string? get_html() throws Error {
return Util.WebKit.to_string(
- yield call(Geary.JS.callable("geary.getHtml"), null)
+ yield call(Util.JS.callable("geary.getHtml"), null)
);
}
@@ -438,7 +438,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
* Load any remote images previously that were blocked.
*/
public void load_remote_images() {
- this.call.begin(Geary.JS.callable("geary.loadRemoteImages"), null);
+ this.call.begin(Util.JS.callable("geary.loadRemoteImages"), null);
}
/**
@@ -484,14 +484,14 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
Cancellable? cancellable)
throws Error {
yield call(
- Geary.JS.callable("geary.setEditable").bool(enabled), cancellable
+ Util.JS.callable("geary.setEditable").bool(enabled), cancellable
);
}
/**
- * Invokes a {@link Geary.JS.Callable} on this web view.
+ * Invokes a {@link Util.JS.Callable} on this web view.
*/
- protected async WebKit.JavascriptResult call(Geary.JS.Callable target,
+ protected async WebKit.JavascriptResult call(Util.JS.Callable target,
Cancellable? cancellable)
throws Error {
return yield run_javascript(target.to_string(), cancellable);
@@ -618,7 +618,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
double height = this.webkit_reported_height;
try {
height = Util.WebKit.to_double(result);
- } catch (Geary.JS.Error err) {
+ } catch (Util.JS.Error err) {
debug("Could not get preferred height: %s", err.message);
}
@@ -632,7 +632,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
try {
string[] values = Util.WebKit.to_string(result).split(",");
command_stack_changed(values[0] == "true", values[1] == "true");
- } catch (Geary.JS.Error err) {
+ } catch (Util.JS.Error err) {
debug("Could not get command stack state: %s", err.message);
}
}
@@ -659,7 +659,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
this.has_selection = has_selection;
}
selection_changed(has_selection);
- } catch (Geary.JS.Error err) {
+ } catch (Util.JS.Error err) {
debug("Could not get selection content: %s", err.message);
}
}
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index 37840874..e57902d8 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -191,7 +191,9 @@ public class ComposerWebView : ClientWebView {
public void set_rich_text(bool enabled) {
this.is_rich_text = enabled;
if (this.is_content_loaded) {
- this.call.begin(Geary.JS.callable("geary.setRichText").bool(enabled), null);
+ this.call.begin(
+ Util.JS.callable("geary.setRichText").bool(enabled), null
+ );
}
}
@@ -199,14 +201,14 @@ public class ComposerWebView : ClientWebView {
* Undoes the last edit operation.
*/
public void undo() {
- this.call.begin(Geary.JS.callable("geary.undo"), null);
+ this.call.begin(Util.JS.callable("geary.undo"), null);
}
/**
* Redoes the last undone edit operation.
*/
public void redo() {
- this.call.begin(Geary.JS.callable("geary.redo"), null);
+ this.call.begin(Util.JS.callable("geary.redo"), null);
}
/**
@@ -217,7 +219,7 @@ public class ComposerWebView : ClientWebView {
*/
public async string save_selection() throws Error {
return Util.WebKit.to_string(
- yield call(Geary.JS.callable("geary.saveSelection"), null)
+ yield call(Util.JS.callable("geary.saveSelection"), null)
);
}
@@ -225,7 +227,9 @@ public class ComposerWebView : ClientWebView {
* Removes a saved selection.
*/
public void free_selection(string id) {
- this.call.begin(Geary.JS.callable("geary.freeSelection").string(id), null);
+ this.call.begin(
+ Util.JS.callable("geary.freeSelection").string(id), null
+ );
}
/**
@@ -332,7 +336,9 @@ public class ComposerWebView : ClientWebView {
*/
public void insert_link(string href, string selection_id) {
this.call.begin(
- Geary.JS.callable("geary.insertLink").string(href).string(selection_id),
+ Util.JS.callable(
+ "geary.insertLink"
+ ).string(href).string(selection_id),
null
);
}
@@ -341,7 +347,7 @@ public class ComposerWebView : ClientWebView {
* Removes any A element at the current text cursor location.
*/
public void delete_link() {
- this.call.begin(Geary.JS.callable("geary.deleteLink"), null);
+ this.call.begin(Util.JS.callable("geary.deleteLink"), null);
}
/**
@@ -361,39 +367,42 @@ public class ComposerWebView : ClientWebView {
* Indents the line at the current text cursor location.
*/
public void indent_line() {
- this.call.begin(Geary.JS.callable("geary.indentLine"), null);
+ this.call.begin(Util.JS.callable("geary.indentLine"), null);
}
public void insert_olist() {
- this.call.begin(Geary.JS.callable("geary.insertOrderedList"), null);
+ this.call.begin(Util.JS.callable("geary.insertOrderedList"), null);
}
public void insert_ulist() {
- this.call.begin(Geary.JS.callable("geary.insertUnorderedList"), null);
+ this.call.begin(Util.JS.callable("geary.insertUnorderedList"), null);
}
/**
* Updates the signature block if it has not been deleted.
*/
public new void update_signature(string signature) {
- this.call.begin(Geary.JS.callable("geary.updateSignature").string(signature), null);
+ this.call.begin(
+ Util.JS.callable("geary.updateSignature").string(signature), null
+ );
}
/**
* Removes the quoted message (if any) from the composer.
*/
public void delete_quoted_message() {
- this.call.begin(Geary.JS.callable("geary.deleteQuotedMessage"), null);
+ this.call.begin(Util.JS.callable("geary.deleteQuotedMessage"), null);
}
/**
* Determines if the editor content contains an attachment keyword.
*/
- public async bool contains_attachment_keywords(string keyword_spec, string subject) {
+ public async bool contains_attachment_keywords(string keyword_spec,
+ string subject) {
try {
return Util.WebKit.to_bool(
yield call(
- Geary.JS.callable("geary.containsAttachmentKeyword")
+ Util.JS.callable("geary.containsAttachmentKeyword")
.string(keyword_spec)
.string(subject),
null)
@@ -411,7 +420,7 @@ public class ComposerWebView : ClientWebView {
* this.
*/
public async void clean_content() throws Error {
- this.call.begin(Geary.JS.callable("geary.cleanContent"), null);
+ this.call.begin(Util.JS.callable("geary.cleanContent"), null);
}
/**
@@ -422,7 +431,7 @@ public class ComposerWebView : ClientWebView {
const int MAX_UNBREAKABLE_LEN = 998; // SMTP line limit
string body_text = Util.WebKit.to_string(
- yield call(Geary.JS.callable("geary.getText"), null)
+ yield call(Util.JS.callable("geary.getText"), null)
);
string[] lines = body_text.split("\n");
GLib.StringBuilder flowed = new GLib.StringBuilder.sized(body_text.length);
@@ -498,7 +507,7 @@ public class ComposerWebView : ClientWebView {
private void on_cursor_context_changed(WebKit.JavascriptResult result) {
try {
cursor_context_changed(new EditContext(Util.WebKit.to_string(result)));
- } catch (Geary.JS.Error err) {
+ } catch (Util.JS.Error err) {
debug("Could not get text cursor style: %s", err.message);
}
}
diff --git a/src/client/conversation-viewer/conversation-web-view.vala
b/src/client/conversation-viewer/conversation-web-view.vala
index d0ad7549..4a972634 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -73,7 +73,7 @@ public class ConversationWebView : ClientWebView {
*/
public async string? get_selection_for_find() throws Error{
WebKit.JavascriptResult result = yield call(
- Geary.JS.callable("geary.getSelectionForFind"), null
+ Util.JS.callable("geary.getSelectionForFind"), null
);
return Util.WebKit.to_string(result);
}
@@ -83,7 +83,7 @@ public class ConversationWebView : ClientWebView {
*/
public async string? get_selection_for_quoting() throws Error {
WebKit.JavascriptResult result = yield call(
- Geary.JS.callable("geary.getSelectionForQuoting"), null
+ Util.JS.callable("geary.getSelectionForQuoting"), null
);
return Util.WebKit.to_string(result);
}
@@ -94,7 +94,7 @@ public class ConversationWebView : ClientWebView {
public async int? get_anchor_target_y(string anchor_body)
throws GLib.Error {
WebKit.JavascriptResult result = yield call(
- Geary.JS.callable("geary.getAnchorTargetY")
+ Util.JS.callable("geary.getAnchorTargetY")
.string(anchor_body), null
);
return (int) Util.WebKit.to_int32(result);
@@ -199,36 +199,36 @@ public class ConversationWebView : ClientWebView {
private void on_deceptive_link_clicked(WebKit.JavascriptResult result) {
try {
JSC.Value object = result.get_js_value();
- uint reason = (uint) Geary.JS.to_int32(
- Geary.JS.get_property(object, "reason")
+ uint reason = (uint) Util.JS.to_int32(
+ Util.JS.get_property(object, "reason")
);
- string href = Geary.JS.to_string(
- Geary.JS.get_property(object, "href")
+ string href = Util.JS.to_string(
+ Util.JS.get_property(object, "href")
);
- string text = Geary.JS.to_string(
- Geary.JS.get_property(object, "text")
+ string text = Util.JS.to_string(
+ Util.JS.get_property(object, "text")
);
- JSC.Value js_location = Geary.JS.get_property(object, "location");
+ JSC.Value js_location = Util.JS.get_property(object, "location");
Gdk.Rectangle location = Gdk.Rectangle();
- location.x = Geary.JS.to_int32(
- Geary.JS.get_property(js_location, "x")
+ location.x = Util.JS.to_int32(
+ Util.JS.get_property(js_location, "x")
);
- location.y = Geary.JS.to_int32(
- Geary.JS.get_property(js_location, "y")
+ location.y = Util.JS.to_int32(
+ Util.JS.get_property(js_location, "y")
);
- location.width = Geary.JS.to_int32(
- Geary.JS.get_property(js_location, "width")
+ location.width = Util.JS.to_int32(
+ Util.JS.get_property(js_location, "width")
);
- location.height = Geary.JS.to_int32(
- Geary.JS.get_property(js_location, "height")
+ location.height = Util.JS.to_int32(
+ Util.JS.get_property(js_location, "height")
);
deceptive_link_clicked((DeceptiveText) reason, text, href, location);
- } catch (Geary.JS.Error err) {
+ } catch (Util.JS.Error err) {
debug("Could not get deceptive link param: %s", err.message);
}
}
diff --git a/src/client/meson.build b/src/client/meson.build
index 7f1a1df7..2d17542a 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -104,6 +104,7 @@ geary_client_vala_sources = files(
'util/util-gio.vala',
'util/util-gtk.vala',
'util/util-international.vala',
+ 'util/util-js.vala',
'util/util-migrate.vala',
'util/util-webkit.vala',
)
@@ -125,6 +126,7 @@ geary_client_dependencies = [
gspell,
gtk,
json_glib,
+ javascriptcoregtk,
libcanberra,
libhandy,
libsecret,
@@ -147,6 +149,7 @@ if libunity.found()
geary_client_vala_options += ['-D', 'HAVE_LIBUNITY']
endif
+# Main client application library
geary_client_lib = static_library('geary-client',
geary_client_sources,
dependencies: geary_client_dependencies,
diff --git a/src/engine/util/util-js.vala b/src/client/util/util-js.vala
similarity index 79%
rename from src/engine/util/util-js.vala
rename to src/client/util/util-js.vala
index 7011431b..6d12072c 100644
--- a/src/engine/util/util-js.vala
+++ b/src/client/util/util-js.vala
@@ -1,17 +1,17 @@
/*
- * Copyright 2017 Michael James Gratton <mike vee net>
+ * Copyright 2017,2019 Michael James Gratton <mike vee net>
*
* This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later). See the COPYING file in this distribution.
+ * (version 2.1 or later). See the COPYING file in this distribution.
*/
/**
* Utility functions for WebKit JavaScriptCore (JSC) objects.
*/
-namespace Geary.JS {
+namespace Util.JS {
/**
- * Errors produced by functions in {@link Geary.JS}.
+ * Errors produced by functions in {@link Util.JS}.
*/
public errordomain Error {
/**
@@ -28,85 +28,85 @@ namespace Geary.JS {
/**
* Returns a JSC Value as a bool.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* value is not a JavaScript `Boolean`.
*/
public bool to_bool(JSC.Value value)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
if (!value.is_boolean()) {
- throw new Geary.JS.Error.TYPE("Value is not a JS Boolean object");
+ throw new Util.JS.Error.TYPE("Value is not a JS Boolean object");
}
bool boolean = value.to_boolean();
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return boolean;
}
/**
* Returns a JSC Value as a double.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* value is not a JavaScript `Number`.
*/
public double to_double(JSC.Value value)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
if (!value.is_number()) {
- throw new Geary.JS.Error.TYPE("Value is not a JS Number object");
+ throw new Util.JS.Error.TYPE("Value is not a JS Number object");
}
double number = value.to_double();
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return number;
}
/**
* Returns a JSC Value as an int32.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* value is not a JavaScript `Number`.
*/
public int32 to_int32(JSC.Value value)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
if (!value.is_number()) {
- throw new Geary.JS.Error.TYPE("Value is not a JS Number object");
+ throw new Util.JS.Error.TYPE("Value is not a JS Number object");
}
int32 number = value.to_int32();
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return number;
}
/**
* Returns a JSC Value as a string.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* value is not a JavaScript `String`.
*/
public string to_string(JSC.Value value)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
if (!value.is_string()) {
- throw new Geary.JS.Error.TYPE("Value is not a JS String object");
+ throw new Util.JS.Error.TYPE("Value is not a JS String object");
}
string str = value.to_string();
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return str;
}
/**
* Returns the value of an object property.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* value is not an object or does not contain the named property.
*/
public inline JSC.Value get_property(JSC.Value value,
string name)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
if (!value.is_object()) {
- throw new Geary.JS.Error.TYPE("Value is not a JS Object");
+ throw new Util.JS.Error.TYPE("Value is not a JS Object");
}
JSC.Value property = value.object_get_property(name);
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return property;
}
@@ -114,7 +114,7 @@ namespace Geary.JS {
* Checks an JS exception returned from a JSC call.
*
* If the given context has a current exception, it will cleared
- * and a {@link Geary.JS.Error} will be thrown.
+ * and a {@link Util.JS.Error} will be thrown.
*/
public inline void check_exception(JSC.Context context)
throws Error {
diff --git a/src/client/util/util-webkit.vala b/src/client/util/util-webkit.vala
index 89074a61..2e7d9a85 100644
--- a/src/client/util/util-webkit.vala
+++ b/src/client/util/util-webkit.vala
@@ -13,45 +13,45 @@ namespace Util.WebKit {
/**
* Returns a WebKit JavascriptResult as a `bool`.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Boolean`.
*/
public bool to_bool(global::WebKit.JavascriptResult result)
- throws Geary.JS.Error {
- return Geary.JS.to_bool(result.get_js_value());
+ throws Util.JS.Error {
+ return Util.JS.to_bool(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a `double`.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Number`.
*/
public inline double to_int32(global::WebKit.JavascriptResult result)
- throws Geary.JS.Error {
- return Geary.JS.to_double(result.get_js_value());
+ throws Util.JS.Error {
+ return Util.JS.to_double(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a `int32`.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Number`.
*/
public inline int32 to_double(global::WebKit.JavascriptResult result)
- throws Geary.JS.Error {
- return Geary.JS.to_int32(result.get_js_value());
+ throws Util.JS.Error {
+ return Util.JS.to_int32(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a GLib string.
*
- * This will raise a {@link Geary.JS.Error.TYPE} error if the
+ * This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `String`.
*/
public inline string to_string(global::WebKit.JavascriptResult result)
- throws Geary.JS.Error {
- return Geary.JS.to_string(result.get_js_value());
+ throws Util.JS.Error {
+ return Util.JS.to_string(result.get_js_value());
}
/**
@@ -62,10 +62,10 @@ namespace Util.WebKit {
* `toString()` method on it, and returning that value.
*/
public string as_string(global::WebKit.JavascriptResult result)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
JSC.Value value = result.get_js_value();
string str = value.to_string();
- Geary.JS.check_exception(value.context);
+ Util.JS.check_exception(value.context);
return str;
}
diff --git a/src/client/web-process/web-process-extension.vala
b/src/client/web-process/web-process-extension.vala
index 024967be..1644aca2 100644
--- a/src/client/web-process/web-process-extension.vala
+++ b/src/client/web-process/web-process-extension.vala
@@ -95,7 +95,7 @@ public class GearyWebExtension : Object {
GLib.Log.METHOD,
GLib.Log.LINE
);
- should_load = Geary.JS.to_bool(ret);
+ should_load = Util.JS.to_bool(ret);
} catch (GLib.Error err) {
debug(
"Error checking PageState::allowRemoteImages: %s",
@@ -145,11 +145,11 @@ public class GearyWebExtension : Object {
string file_name,
string method_name,
int line_number)
- throws Geary.JS.Error {
+ throws Util.JS.Error {
JSC.Value ret = context.evaluate_with_source_uri(
script, -1, "geary:%s/%s".printf(file_name, method_name), line_number
);
- Geary.JS.check_exception(context);
+ Util.JS.check_exception(context);
return ret;
}
diff --git a/src/engine/meson.build b/src/engine/meson.build
index 71815983..c59e19bd 100644
--- a/src/engine/meson.build
+++ b/src/engine/meson.build
@@ -306,7 +306,6 @@ geary_engine_vala_sources = files(
'util/util-imap-utf7.vala',
'util/util-inet.vala',
'util/util-iterable.vala',
- 'util/util-js.vala',
'util/util-loggable.vala',
'util/util-numeric.vala',
'util/util-object.vala',
@@ -330,7 +329,6 @@ geary_engine_dependencies = [
gio,
glib,
gmime,
- javascriptcoregtk,
libxml,
libytnef,
posix,
diff --git a/src/meson.build b/src/meson.build
index 31894cb3..8cc47817 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -48,15 +48,20 @@ subdir('client')
subdir('console')
subdir('mailer')
+geary_web_process_sources = files(
+ 'client/web-process/web-process-extension.vala',
+ 'client/util/util-js.vala',
+)
+
# Web process extension library
geary_web_process = library('geary-web-process',
- join_paths('client', 'web-process', 'web-process-extension.vala'),
+ geary_web_process_sources,
c_args: geary_c_options,
dependencies: [
+ geary_engine_dep,
gee,
gmime,
- webkit2gtk_web_extension ,
- geary_engine_dep,
+ webkit2gtk_web_extension,
],
install: true,
install_dir: web_extensions_dir
@@ -80,6 +85,7 @@ geary_bin_dependencies = [
gmime,
goa,
gtk,
+ javascriptcoregtk,
libhandy,
libmath,
libsoup,
diff --git a/test/client/util/util-js-test.vala b/test/client/util/util-js-test.vala
new file mode 100644
index 00000000..203f9e55
--- /dev/null
+++ b/test/client/util/util-js-test.vala
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public class Util.JS.Test : TestCase {
+
+ public Test() {
+ base("Util.JS.Test");
+ add_test("escape_string", escape_string);
+ }
+
+ public void escape_string() throws Error {
+ assert(Util.JS.escape_string("\n") == """\n""");
+ assert(Util.JS.escape_string("\r") == """\r""");
+ assert(Util.JS.escape_string("\t") == """\t""");
+ assert(Util.JS.escape_string("\'") == """\'""");
+ assert(Util.JS.escape_string("\"") == """\"""");
+
+ assert(Util.JS.escape_string("something…\n") == """something…\n""");
+ }
+}
diff --git a/test/js/composer-page-state-test.vala b/test/js/composer-page-state-test.vala
index bdcbcb1b..adbfccae 100644
--- a/test/js/composer-page-state-test.vala
+++ b/test/js/composer-page-state-test.vala
@@ -40,8 +40,8 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
try {
assert(Util.WebKit.to_string(run_javascript(@"new
EditContext(document.getElementById('test')).encode()"))
.has_prefix("1,url,"));
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -56,8 +56,8 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
try {
assert(Util.WebKit.to_string(run_javascript(@"new
EditContext(document.getElementById('test')).encode()")) ==
"0,,Comic Sans,144");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -73,8 +73,8 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
assert(Util.WebKit.to_int32(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")) ==
1);
assert(Util.WebKit.to_string(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText"))
==
"some text");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -106,8 +106,8 @@ some text
assert(!Util.WebKit.to_bool(run_javascript(
@"geary.containsAttachmentKeyword(\"outerquote\", \"subject text\");"
)));
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -145,8 +145,8 @@ unknown://example6.com
run_javascript("geary.cleanContent();");
assert(Util.WebKit.to_string(run_javascript("geary.bodyPart.innerHTML;")) ==
CLEAN_BODY_TEMPLATE.printf(expected));
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -160,8 +160,8 @@ unknown://example6.com
try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getHtml();")) ==
COMPLETE_BODY_TEMPLATE.printf(html));
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -174,8 +174,8 @@ unknown://example6.com
try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
"para\n\n\n\n");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -189,8 +189,8 @@ unknown://example6.com
try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
@"pre\n\n$(q_marker)quote\n$(q_marker)\npost\n\n\n\n");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s", err.message);
@@ -204,8 +204,8 @@ unknown://example6.com
try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
@"pre\n\n$(q_marker)quote1\n$(q_marker)\n$(q_marker)$(q_marker)quote2\n$(q_marker)$(q_marker)\npost\n\n\n\n");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -257,8 +257,8 @@ unknown://example6.com
assert(Util.WebKit.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('something.something.sf2', $complete_keys,
$suffix_keys);"
)));
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
@@ -275,8 +275,8 @@ unknown://example6.com
"a b");
assert(Util.WebKit.to_string(run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(multiple_nbsp)');"))
==
"a b c");
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
diff --git a/test/js/conversation-page-state-test.vala b/test/js/conversation-page-state-test.vala
index b56dc8fe..4f189faa 100644
--- a/test/js/conversation-page-state-test.vala
+++ b/test/js/conversation-page-state-test.vala
@@ -162,8 +162,8 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
return (uint) Util.WebKit.to_int32(
run_javascript(@"ConversationPageState.isDeceptiveText(\"$text\", \"$href\")")
);
- } catch (Geary.JS.Error err) {
- print("Geary.JS.Error: %s\n", err.message);
+ } catch (Util.JS.Error err) {
+ print("Util.JS.Error: %s\n", err.message);
assert_not_reached();
} catch (Error err) {
print("WKError: %s\n", err.message);
diff --git a/test/meson.build b/test/meson.build
index 9bf86e1b..4fde2875 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -60,7 +60,6 @@ geary_test_engine_sources = [
'engine/util-html-test.vala',
'engine/util-idle-manager-test.vala',
'engine/util-inet-test.vala',
- 'engine/util-js-test.vala',
'engine/util-string-test.vala',
'engine/util-timeout-manager-test.vala',
@@ -87,6 +86,7 @@ geary_test_client_sources = [
'client/util/util-avatar-test.vala',
'client/util/util-cache-test.vala',
'client/util/util-email-test.vala',
+ 'client/util/util-js-test.vala',
'js/client-page-state-test.vala',
'js/composer-page-state-test.vala',
diff --git a/test/test-client.vala b/test/test-client.vala
index dccb36b9..6665582b 100644
--- a/test/test-client.vala
+++ b/test/test-client.vala
@@ -53,6 +53,7 @@ int main(string[] args) {
client.add_suite(new Util.Avatar.Test().get_suite());
client.add_suite(new Util.Cache.Test().get_suite());
client.add_suite(new Util.Email.Test().get_suite());
+ client.add_suite(new Util.JS.Test().get_suite());
TestSuite js = new TestSuite("js");
diff --git a/test/test-engine.vala b/test/test-engine.vala
index 0b5d2179..0f28510a 100644
--- a/test/test-engine.vala
+++ b/test/test-engine.vala
@@ -71,7 +71,6 @@ int main(string[] args) {
engine.add_suite(new Geary.ContactStoreImplTest().get_suite());
engine.add_suite(new Geary.Inet.Test().get_suite());
- engine.add_suite(new Geary.JS.Test().get_suite());
engine.add_suite(new Geary.Mime.ContentTypeTest().get_suite());
engine.add_suite(new Geary.Outbox.EmailIdentifierTest().get_suite());
engine.add_suite(new Geary.RFC822.MailboxAddressTest().get_suite());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]