Fix non-breaking spaces breaking formatting in sent messages.
This ensures that non-breaking space chars (not HTML entities) are removed from text obtainined from the composer, and moves the F=F text formatting from JS back to Vala, to minimimse the JS footprint and return to using the old (working) version again. * src/client/composer/composer-web-view.vala (ClientWebView::get_text): Restore the old F=F formatting code previously in webkit-util, apply it to plain text obtained from the composer. * test/client/components/client-web-view-test-case.vala: New base class for tests involving ClientWebView. * test/client/composer/composer-web-view-test.vala: New tests for ComposerWebView::get_html and ::get_text. * test/js/composer-page-state-test.vala: Reworked to use ClientWebViewTestCase, updated tests now that JS is returning QUOTE_MARKER-delinated text, not F=F text. * test/testcase.vala (TestCase): Move ::async_complete and ::async_result from ComposerPageStateTest so all test cases can test async code. * test/CMakeLists.txt: Add new source files. * test/main.vala (main): Add new test. * ui/composer-web-view.js: Update doc comments, remove F=F code, break out non-breaking space replacement so it can be tested.
This commit is contained in:
parent
57f10446a9
commit
17fda41b85
8 changed files with 341 additions and 99 deletions
166
test/client/composer/composer-web-view-test.vala
Normal file
166
test/client/composer/composer-web-view-test.vala
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* 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("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 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();
|
||||
}
|
||||
Configuration config = new Configuration(GearyApplication.APP_ID);
|
||||
return new ComposerWebView(config);
|
||||
}
|
||||
|
||||
protected override void load_body_fixture(string? html = null) {
|
||||
this.test_view.load_html(html, null, false);
|
||||
while (this.test_view.is_loading) {
|
||||
Gtk.main_iteration();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue