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.
178 lines
7.3 KiB
Vala
178 lines
7.3 KiB
Vala
/*
|
|
* 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 class ComposerWebViewTest : ClientWebViewTestCase<ComposerWebView> {
|
|
|
|
public ComposerWebViewTest() {
|
|
base("ComposerWebViewTest");
|
|
add_test("edit_context", edit_context);
|
|
add_test("get_html", get_html);
|
|
add_test("get_text", get_text);
|
|
add_test("get_text_with_quote", get_text_with_quote);
|
|
add_test("get_text_with_nested_quote", get_text_with_nested_quote);
|
|
add_test("get_text_with_long_line", get_text_with_long_line);
|
|
add_test("get_text_with_long_quote", get_text_with_long_quote);
|
|
add_test("get_text_with_nbsp", get_text_with_nbsp);
|
|
}
|
|
|
|
public void edit_context() {
|
|
assert(!(new ComposerWebView.EditContext("0,,,").is_link));
|
|
assert(new ComposerWebView.EditContext("1,,,").is_link);
|
|
assert(new ComposerWebView.EditContext("1,url,,").link_url == "url");
|
|
|
|
assert(new ComposerWebView.EditContext("0,,Helvetica,").font_family == "sans");
|
|
assert(new ComposerWebView.EditContext("0,,Times New Roman,").font_family == "serif");
|
|
assert(new ComposerWebView.EditContext("0,,Courier,").font_family == "monospace");
|
|
|
|
assert(new ComposerWebView.EditContext("0,,,12").font_size == 12);
|
|
}
|
|
|
|
public void get_html() {
|
|
string html = "<p>para</p>";
|
|
load_body_fixture(html);
|
|
this.test_view.get_html.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_html.end(async_result()) == html + "<br><br>");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text() {
|
|
load_body_fixture("<p>para</p>");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) == "para\n\n\n\n\n");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text_with_quote() {
|
|
load_body_fixture("<p>pre</p> <blockquote><p>quote</p></blockquote> <p>post</p>");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
"pre\n\n> quote\n> \npost\n\n\n\n\n");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text_with_nested_quote() {
|
|
load_body_fixture("<p>pre</p> <blockquote><p>quote1</p> <blockquote><p>quote2</p></blockquote></blockquote> <p>post</p>");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
"pre\n\n> quote1\n> \n>> quote2\n>> \npost\n\n\n\n\n");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text_with_long_line() {
|
|
load_body_fixture("""
|
|
<p>A long, long, long, long, long, long para. Well, longer than MAX_BREAKABLE_LEN
|
|
at least. Really long, long, long, long, long long, long long, long long, long.</p>
|
|
""");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
"""A long, long, long, long, long, long para. Well, longer than
|
|
MAX_BREAKABLE_LEN at least. Really long, long, long, long, long long,
|
|
long long, long long, long.
|
|
|
|
|
|
|
|
|
|
""");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text_with_long_quote() {
|
|
load_body_fixture("""
|
|
<blockquote><p>A long, long, long, long, long, long line. Well, longer than MAX_BREAKABLE_LEN at least.</p></blockquote>
|
|
|
|
<p>A long, long, long, long, long, long para. Well, longer than MAX_BREAKABLE_LEN
|
|
at least. Really long, long, long, long, long long, long long, long long, long.</p>""");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
"""> A long, long, long, long, long, long line. Well, longer than
|
|
> MAX_BREAKABLE_LEN at least.
|
|
>
|
|
A long, long, long, long, long, long para. Well, longer than
|
|
MAX_BREAKABLE_LEN at least. Really long, long, long, long, long long,
|
|
long long, long long, long.
|
|
|
|
|
|
|
|
|
|
""");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
public void get_text_with_nbsp() {
|
|
load_body_fixture("""On Sun, Jan 1, 2017 at 9:55 PM, Michael Gratton <mike@vee.net> wrote:<br>
|
|
<blockquote type="cite">long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long,
|
|
</blockquote><br>long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, <div style="white-space: pre;">
|
|
</div>
|
|
|
|
""");
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
try {
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
"""On Sun, Jan 1, 2017 at 9:55 PM, Michael Gratton <mike@vee.net> wrote:
|
|
> long, long, long, long, long, long, long, long, long, long, long,
|
|
> long, long, long, long, long, long, long, long, long, long, long,
|
|
> long, long, long, long, long, long, long, long, long, long, long,
|
|
> long, long, long, long, long, long, long, long, long, long, long,
|
|
> long, long, long, long, long,
|
|
|
|
long, long, long, long, long, long, long, long, long, long, long, long,
|
|
long, long, long, long, long, long, long, long, long, long, long, long,
|
|
long, long, long, long, long, long, long, long, long, long, long, long,
|
|
long, long, long, long, long, long, long, long, long, long, long, long,
|
|
long, long, long, long, long, long, long, long, long, long,
|
|
|
|
|
|
|
|
|
|
""");
|
|
} catch (Error err) {
|
|
print("Error: %s\n", err.message);
|
|
assert_not_reached();
|
|
}
|
|
}
|
|
|
|
protected override ComposerWebView set_up_test_view() {
|
|
try {
|
|
ComposerWebView.load_resources();
|
|
} catch (Error err) {
|
|
assert_not_reached();
|
|
}
|
|
return new ComposerWebView(this.config);
|
|
}
|
|
|
|
protected override void load_body_fixture(string html = "") {
|
|
this.test_view.load_html(html, "", "", false, false);
|
|
while (this.test_view.is_loading) {
|
|
Gtk.main_iteration();
|
|
}
|
|
}
|
|
|
|
}
|