2017-01-02 10:23:35 +11:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-11-25 21:58:48 +11:00
|
|
|
public class Composer.WebViewTest : Components.WebViewTestCase<Composer.WebView> {
|
2017-01-02 10:23:35 +11:00
|
|
|
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
2019-11-10 09:35:58 +11:00
|
|
|
public WebViewTest() {
|
|
|
|
|
base("Composer.WebViewTest");
|
2017-01-30 23:09:02 +11:00
|
|
|
add_test("load_resources", load_resources);
|
2017-01-19 01:48:03 +11:00
|
|
|
add_test("edit_context", edit_context);
|
2017-01-02 10:23:35 +11:00
|
|
|
add_test("get_html", get_html);
|
2019-11-08 10:39:46 +11:00
|
|
|
add_test("get_html_for_draft", get_html_for_draft);
|
2017-01-02 10:23:35 +11:00
|
|
|
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);
|
2018-12-31 11:36:41 -07:00
|
|
|
add_test("get_text_with_named_link", get_text_with_named_link);
|
|
|
|
|
add_test("get_text_with_url_link", get_text_with_named_link);
|
2019-01-14 19:54:14 -07:00
|
|
|
add_test("get_text_with_surrounding_nbsps", get_text_with_surrounding_nbsps);
|
2019-03-11 11:59:11 +11:00
|
|
|
add_test("update_signature", update_signature);
|
2017-01-02 10:23:35 +11:00
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void load_resources() throws Error {
|
2017-01-30 23:09:02 +11:00
|
|
|
try {
|
2019-11-10 09:35:58 +11:00
|
|
|
WebView.load_resources();
|
2017-01-30 23:09:02 +11:00
|
|
|
} catch (Error err) {
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void edit_context() throws Error {
|
2020-01-14 22:35:18 -06:00
|
|
|
assert(!(new WebView.EditContext("0;;;;").is_link));
|
|
|
|
|
assert(new WebView.EditContext("1;;;;").is_link);
|
|
|
|
|
assert(new WebView.EditContext("1;url;;;").link_url == "url");
|
2017-01-19 01:48:03 +11:00
|
|
|
|
2020-01-14 22:35:18 -06:00
|
|
|
assert(new WebView.EditContext("0;;Helvetica;;").font_family == "sans");
|
|
|
|
|
assert(new WebView.EditContext("0;;Times New Roman;;").font_family == "serif");
|
|
|
|
|
assert(new WebView.EditContext("0;;Courier;;").font_family == "monospace");
|
Replace composer link dialog with a popover.
* src/client/composer/composer-link-popover.vala: New GtkPopover subclass
for creating/editing links.
* src/client/composer/composer-web-view.vala (EditContext): Add is_link
and link_uri properties, decode them from the message string, add
decoding tests.
(ComposerWebView): Add some as-yet un-implemented methods for
inserting/deleting links.
* src/client/composer/composer-widget.vala (ComposerWidget): Add
cursor_url for storing current text cursor link, update it from the
cursor_context_changed signal param, rename hover_url to pointer_url to
match. Add link_activated signal to let user's open links they are
adding, hook that up in the controller. Rename
::update_selection_actions to ::update_cursor_actions, since that's a
little more apt now, also enable insert link action if there is a
cursor_url set as well as a selection. Remove ::link_dialog, replace
with ::new_link_popover, hook up the new popover's signals there as
appropriate.
(ComposerWidget::on_insert_link): Create and show a lin popover instead
of a dialog.
* ui/composer-web-view.js: Take note of whther the context node is a link
and if so, also it's href. Include both when serialsing for the
cursorContextChanged message. Add serialisation tests.
* ui/composer-link-popover.ui: New UI for link popover.
2017-01-19 02:23:57 +11:00
|
|
|
|
2020-01-14 22:35:18 -06:00
|
|
|
assert(new WebView.EditContext("0;;;12;").font_size == 12);
|
|
|
|
|
|
|
|
|
|
assert(new WebView.EditContext("0;;;;rgb(0, 0, 0)").font_color == Util.Gtk.rgba(0, 0, 0, 1));
|
|
|
|
|
assert(new WebView.EditContext("0;;;;rgb(255, 0, 0)").font_color == Util.Gtk.rgba(1, 0, 0, 1));
|
|
|
|
|
assert(new WebView.EditContext("0;;;;rgb(0, 255, 0)").font_color == Util.Gtk.rgba(0, 1, 0, 1));
|
|
|
|
|
assert(new WebView.EditContext("0;;;;rgb(0, 0, 255)").font_color == Util.Gtk.rgba(0, 0, 1, 1));
|
2017-01-19 01:48:03 +11:00
|
|
|
}
|
|
|
|
|
|
2019-03-11 11:59:11 +11:00
|
|
|
public void get_html() throws GLib.Error {
|
|
|
|
|
string BODY = "<p>para</p>";
|
|
|
|
|
load_body_fixture(BODY);
|
2017-01-02 10:23:35 +11:00
|
|
|
this.test_view.get_html.begin((obj, ret) => { async_complete(ret); });
|
2019-03-11 11:59:11 +11:00
|
|
|
string html = this.test_view.get_html.end(async_result());
|
2019-11-10 09:35:58 +11:00
|
|
|
assert_string(PageStateTest.CLEAN_BODY_TEMPLATE.printf(BODY), html);
|
2019-11-08 10:39:46 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void get_html_for_draft() throws GLib.Error {
|
|
|
|
|
string BODY = "<p>para</p>";
|
|
|
|
|
load_body_fixture(BODY);
|
|
|
|
|
this.test_view.get_html_for_draft.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
string html = this.test_view.get_html.end(async_result());
|
2019-11-10 09:35:58 +11:00
|
|
|
assert_string(PageStateTest.COMPLETE_BODY_TEMPLATE.printf(BODY), html);
|
2017-01-02 10:23:35 +11:00
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
load_body_fixture("<p>para</p>");
|
|
|
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
try {
|
2017-02-07 12:09:29 +11:00
|
|
|
assert(this.test_view.get_text.end(async_result()) == "para\n\n\n\n\n");
|
2017-01-02 10:23:35 +11:00
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text_with_quote() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
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()) ==
|
2017-02-07 12:09:29 +11:00
|
|
|
"pre\n\n> quote\n> \npost\n\n\n\n\n");
|
2017-01-02 10:23:35 +11:00
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text_with_nested_quote() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
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()) ==
|
2017-02-07 12:09:29 +11:00
|
|
|
"pre\n\n> quote1\n> \n>> quote2\n>> \npost\n\n\n\n\n");
|
2017-01-02 10:23:35 +11:00
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text_with_long_line() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text_with_long_quote() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 17:30:14 +11:00
|
|
|
public void get_text_with_nbsp() throws Error {
|
2017-01-02 10:23:35 +11:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 11:36:41 -07:00
|
|
|
public void get_text_with_named_link() throws Error {
|
|
|
|
|
load_body_fixture("Check out <a href=\"https://wiki.gnome.org/Apps/Geary\">Geary</a>!");
|
|
|
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
try {
|
|
|
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
|
|
|
"Check out Geary <https://wiki.gnome.org/Apps/Geary>!\n\n\n\n");
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void get_text_with_url_link() throws Error {
|
|
|
|
|
load_body_fixture("Check out <a href=\"https://wiki.gnome.org/Apps/Geary\">https://wiki.gnome.org/Apps/Geary</a>!");
|
|
|
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
try {
|
|
|
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
|
|
|
"Check out <https://wiki.gnome.org/Apps/Geary>!\n\n\n\n");
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 19:54:14 -07:00
|
|
|
public void get_text_with_surrounding_nbsps() throws Error {
|
|
|
|
|
load_body_fixture(" I like my space ");
|
|
|
|
|
this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
try {
|
|
|
|
|
assert(this.test_view.get_text.end(async_result()) ==
|
|
|
|
|
" I like my space\n\n\n\n");
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
print("Error: %s\n", err.message);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 11:59:11 +11:00
|
|
|
public void update_signature() throws GLib.Error {
|
|
|
|
|
const string BODY = "<p>para</p>";
|
|
|
|
|
load_body_fixture(BODY);
|
|
|
|
|
string html = "";
|
|
|
|
|
|
|
|
|
|
const string SIG1 = "signature text 1";
|
|
|
|
|
this.test_view.update_signature(SIG1);
|
|
|
|
|
this.test_view.get_html.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
html = this.test_view.get_html.end(async_result());
|
|
|
|
|
assert_true(BODY in html, "Body not present");
|
|
|
|
|
assert_true(SIG1 in html, "Signature 1 not present");
|
|
|
|
|
|
|
|
|
|
const string SIG2 = "signature text 2";
|
|
|
|
|
this.test_view.update_signature(SIG2);
|
|
|
|
|
this.test_view.get_html.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
html = this.test_view.get_html.end(async_result());
|
|
|
|
|
assert_true(BODY in html, "Body not present");
|
|
|
|
|
assert_false(SIG1 in html, "Signature 1 still present");
|
|
|
|
|
assert_true(SIG2 in html, "Signature 2 not present");
|
|
|
|
|
|
|
|
|
|
this.test_view.update_signature("");
|
|
|
|
|
this.test_view.get_html.begin((obj, ret) => { async_complete(ret); });
|
|
|
|
|
html = this.test_view.get_html.end(async_result());
|
|
|
|
|
assert_true(BODY in html, "Body not present");
|
|
|
|
|
assert_false(SIG1 in html, "Signature 1 still present");
|
|
|
|
|
assert_false(SIG2 in html, "Signature 2 still present");
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 09:35:58 +11:00
|
|
|
protected override Composer.WebView set_up_test_view() {
|
|
|
|
|
return new Composer.WebView(this.config);
|
2017-01-02 10:23:35 +11:00
|
|
|
}
|
|
|
|
|
|
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 override void load_body_fixture(string html = "") {
|
2019-03-11 11:59:11 +11:00
|
|
|
this.test_view.load_html(html, "", false, false);
|
2017-01-02 10:23:35 +11:00
|
|
|
while (this.test_view.is_loading) {
|
|
|
|
|
Gtk.main_iteration();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|