geary/test/client/components/components-web-view-test-case.vala

59 lines
1.8 KiB
Vala
Raw Normal View History

/*
* Copyright 2016 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 abstract class Components.WebViewTestCase<V> : TestCase {
protected V? test_view = null;
protected Application.Configuration? config = null;
protected WebViewTestCase(string name) {
base(name);
}
public override void set_up() {
this.config = new Application.Configuration(Application.Client.SCHEMA_ID);
this.config.enable_debug = true;
WebView.init_web_context(
this.config,
File.new_for_path(Config.BUILD_ROOT_DIR).get_child("src"),
File.new_for_path("/tmp"), // XXX use something better here
false // https://bugs.webkit.org/show_bug.cgi?id=213174
);
try {
WebView.load_resources(GLib.File.new_for_path("/tmp"));
} catch (GLib.Error err) {
GLib.assert_not_reached();
}
this.test_view = set_up_test_view();
}
protected override void tear_down() {
this.config = null;
this.test_view = null;
}
protected abstract V set_up_test_view();
Clean up how composer loads content into its web view. The main gist of this is to ensure that the composer's widgets are constructed seperately to loading its content, and that we only ever call ComposerWebView::load_html precisely once per composer instance. * src/client/composer/composer-widget.vala: Remove referred message, quote text and draft flag param from constructor signature, move any calls that loaded data from them to new load method. Don't load anything into the editor here. Make loading the signature file async, and call new ComposerWebView::updateSignature method on the editor to update it. (ComposerWidget::load): New async message for loading content into the composer. Move related code from the constructor and GearyController here, make methods that were previously public for that private again. Tidy up calls a bit now that we have a single place from which to do it all, and can understand the process a bit better. (ComposerWidget::on_editor_key_press_event): Don't reload the editor to remove the quoted text, call new ComposerWebView::delete_quoted_message method on it instead. * src/client/composer/composer-web-view.vala (ComposerWebView): Add ::delete_quoted_message ::update_signature methods, thunk to JS. (ComposerWebView::load_html): Add quote and is_draft parameters, construct HTML for the composer using apporporate spacing here, instead of relying on all the disparate parts from doing the right thing. * src/client/application/geary-controller.vala (GearyController::create_compose_widget_async): Load composer content after adding it to the widget hierarchy, set focus only after everything is set up. * src/engine/rfc822/rfc822-utils.vala (quote_email_for_reply, quote_email_for_forward): Don't add extra padding around quoted parts - let callers manage their own whitespace. * test/client/components/client-web-view-test-case.vala (TestCase:load_body_fixture): Make HTML param non-nullable, update subclasses. * ui/composer-web-view.js (ComposerPageState): Add ::updateSignature and ::deleteQuotedMessage method stubs.
2017-01-25 11:16:20 +11:00
protected virtual void load_body_fixture(string html = "") {
WebView client_view = (WebView) this.test_view;
client_view.load_html_headless(html);
while (!client_view.is_content_loaded) {
Gtk.main_iteration();
}
}
protected JSC.Value? run_javascript(string command) throws Error {
WebView view = (WebView) this.test_view;
view.evaluate_javascript.begin(command, -1, null, null, null, this.async_completion);
return view.evaluate_javascript.end(async_result());
}
}