[Xfce4-commits] <midori:master> Fix url completion highlight regression and add test cases
Christian Dywan
noreply at xfce.org
Fri Dec 7 14:12:03 CET 2012
Updating branch refs/heads/master
to 2d9bfff212b882e272509557b4e1ad7fedfd5804 (commit)
from b862afd9c630ea8b6c24dcfa5a459ba2dbb61457 (commit)
commit 2d9bfff212b882e272509557b4e1ad7fedfd5804
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Dec 7 01:30:04 2012 +0100
Fix url completion highlight regression and add test cases
Fixes: https://bugs.launchpad.net/midori/+bug/1087251
midori/midori-locationaction.c | 66 ++++++++++++++++++++++++----------------
midori/midori-locationaction.h | 8 +++++
midori/midori.vapi | 6 ++++
tests/completion.vala | 28 +++++++++++++++++
4 files changed, 82 insertions(+), 26 deletions(-)
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index 79b3731..52b96d3 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -224,9 +224,9 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
-static gchar*
-midori_location_entry_render_uri (gchar** keys,
- const gchar* uri_escaped)
+gchar*
+midori_location_action_render_uri (gchar** keys,
+ const gchar* uri_escaped)
{
gchar* uri_unescaped = midori_uri_unescape (uri_escaped);
gchar* uri = g_strescape (uri_unescaped, NULL);
@@ -238,19 +238,28 @@ midori_location_entry_render_uri (gchar** keys,
gchar* desc_iter = stripped_uri;
gint key_idx = 0;
gchar* key = keys[key_idx];
- gint offset = 0;
gchar* start;
gchar* desc_uri = NULL;
- while (key && (start = strstr (temp_iter, key)) && start)
+ while (key && (start = strstr (temp_iter, key)))
{
gsize len = strlen (key);
if (len)
{
- offset = (start - temp_iter);
+ gint offset = (start - temp_iter);
gchar* skey = g_strndup (desc_iter + offset, len);
gchar** parts = g_strsplit (desc_iter, skey, 2);
if (parts[0] && parts[1])
- desc_uri = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ {
+ if (desc_uri)
+ {
+ gchar* temp_markup = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ gchar* temp_concat = g_strconcat (desc_uri, temp_markup, NULL);
+ g_free (temp_markup);
+ katze_assign (desc_uri, temp_concat);
+ }
+ else
+ desc_uri = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ }
g_strfreev (parts);
g_free (skey);
@@ -264,43 +273,50 @@ midori_location_entry_render_uri (gchar** keys,
break;
}
if (key)
- katze_assign (desc_uri, NULL);
- if (desc_uri)
+ katze_assign (desc_uri,g_markup_escape_text (stripped_uri, -1));
+ else
{
gchar* temp_markup = g_markup_escape_text (desc_iter, -1);
gchar* temp_concat = g_strconcat (desc_uri, temp_markup, NULL);
g_free (temp_markup);
katze_assign (desc_uri, temp_concat);
}
- else
- desc_uri = g_markup_escape_text (stripped_uri, -1);
g_free (temp);
g_free (stripped_uri);
return desc_uri;
}
-static gchar*
-midori_location_entry_render_title (gchar** keys,
- const gchar* title)
+gchar*
+midori_location_action_render_title (gchar** keys,
+ const gchar* title)
{
gchar* temp;
gchar* temp_iter = temp = g_utf8_strdown (title, -1);
const gchar* desc_iter = title;
gint key_idx = 0;
gchar* key = keys[key_idx];
- gint offset = 0;
gchar* start;
gchar* desc_title = NULL;
- while (key && (start = strstr (temp_iter, key)) && start)
+ while (key && (start = strstr (temp_iter, key)))
{
gsize len = strlen (key);
if (len)
{
- offset = (start - temp_iter);
+ gint offset = (start - temp_iter);
gchar* skey = g_strndup (desc_iter + offset, len);
gchar** parts = g_strsplit (desc_iter, skey, 2);
if (parts[0] && parts[1])
- desc_title = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ {
+ if (desc_title)
+ {
+ gchar* temp_markup = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ gchar* temp_concat = g_strconcat (desc_title, temp_markup, NULL);
+ g_free (temp_markup);
+ katze_assign (desc_title, temp_concat);
+ }
+ else
+ desc_title = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+ }
g_strfreev (parts);
g_free (skey);
@@ -314,16 +330,14 @@ midori_location_entry_render_title (gchar** keys,
break;
}
if (key)
- katze_assign (desc_title, NULL);
- if (desc_title)
+ katze_assign (desc_title, g_markup_escape_text (title, -1));
+ else
{
gchar* temp_markup = g_markup_escape_text (desc_iter, -1);
gchar* temp_concat = g_strconcat (desc_title, temp_markup, NULL);
g_free (temp_markup);
katze_assign (desc_title, temp_concat);
}
- else
- desc_title = g_markup_escape_text (title, -1);
g_free (temp);
return desc_title;
}
@@ -358,7 +372,7 @@ midori_location_entry_render_title_cb (GtkCellLayout* layout,
gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
gchar** keys = g_strsplit_set (key, " %", -1);
g_free (key);
- desc = midori_location_entry_render_title (keys, title);
+ desc = midori_location_action_render_title (keys, title);
g_strfreev (keys);
}
@@ -399,7 +413,7 @@ midori_location_entry_render_uri_cb (GtkCellLayout* layout,
gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
gchar** keys = g_strsplit_set (key, " %", -1);
g_free (key);
- desc = midori_location_entry_render_uri (keys, uri_escaped);
+ desc = midori_location_action_render_uri (keys, uri_escaped);
g_strfreev (keys);
g_free (uri_escaped);
}
@@ -440,8 +454,8 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
gchar** keys = g_strsplit_set (key, " %", -1);
g_free (key);
- gchar* desc_uri = midori_location_entry_render_uri (keys, uri_escaped);
- gchar* desc_title = midori_location_entry_render_title (keys, title);
+ gchar* desc_uri = midori_location_action_render_uri (keys, uri_escaped);
+ gchar* desc_title = midori_location_action_render_title (keys, title);
desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>", desc_title, desc_uri);
g_free (uri_escaped);
g_free (title);
diff --git a/midori/midori-locationaction.h b/midori/midori-locationaction.h
index 2a8dac2..7fad42b 100644
--- a/midori/midori-locationaction.h
+++ b/midori/midori-locationaction.h
@@ -74,6 +74,14 @@ void
midori_location_action_set_security_hint (MidoriLocationAction* location_action,
MidoriSecurity hint);
+gchar*
+midori_location_action_render_uri (gchar** keys,
+ const gchar* uri_escaped);
+
+gchar*
+midori_location_action_render_title (gchar** keys,
+ const gchar* title);
+
G_END_DECLS
#endif /* __MIDORI_LOCATION_ACTION_H__ */
diff --git a/midori/midori.vapi b/midori/midori.vapi
index fd4ced7..b3c70f6 100644
--- a/midori/midori.vapi
+++ b/midori/midori.vapi
@@ -187,6 +187,12 @@ namespace Midori {
}
[CCode (cheader_filename = "midori/midori.h")]
+ public class LocationAction : Gtk.Action {
+ public static string render_uri ([CCode (array_length = false)] string[] keys, string uri_escaped);
+ public static string render_title ([CCode (array_length = false)] string[] keys, string title);
+ }
+
+ [CCode (cheader_filename = "midori/midori.h")]
public class SearchAction : Gtk.Action {
public static Katze.Item? get_engine_for_form (WebKit.WebView web_view, Pango.EllipsizeMode ellipsize);
}
diff --git a/tests/completion.vala b/tests/completion.vala
index 0a6261d..df51b8a 100644
--- a/tests/completion.vala
+++ b/tests/completion.vala
@@ -122,11 +122,39 @@ void completion_history () {
complete_spec.begin (completion, spec);
}
+struct TestCaseRender {
+ public string keys;
+ public string uri;
+ public string title;
+ public string expected_uri;
+ public string expected_title;
+}
+
+const TestCaseRender[] renders = {
+ { "debian", "planet.debian.org", "Planet Debian", "planet.<b>debian</b>.org", "Planet <b>Debian</b>" },
+ { "p debian o", "planet.debian.org", "Planet Debian", "<b>p</b>lanet.<b>debian</b>.<b>o</b>rg", "Planet Debian" },
+ { "pla deb o", "planet.debian.org", "Planet Debian", "<b>pla</b>net.<b>deb</b>ian.<b>o</b>rg", "Planet Debian" },
+ { "ebi", "planet.debian.org", "Planet Debian", "planet.d<b>ebi</b>an.org", "Planet D<b>ebi</b>an" },
+ { "an ebi", "planet.debian.org", "Planet Debian", "pl<b>an</b>et.d<b>ebi</b>an.org", "Pl<b>an</b>et D<b>ebi</b>an" }
+};
+
+void completion_location_action () {
+ foreach (var spec in renders) {
+ string uri = Midori.LocationAction.render_uri (spec.keys.split (" ", 0), spec.uri);
+ string title = Midori.LocationAction.render_title (spec.keys.split (" ", 0), spec.title);
+ if (uri != spec.expected_uri || title != spec.expected_title)
+ error ("\nExpected: %s/ %s\nInput : %s/ %s/ %s\nResult : %s/ %s",
+ spec.expected_uri, spec.expected_title,
+ spec.keys, spec.uri, spec.title, uri, title);
+ }
+}
+
void main (string[] args) {
Test.init (ref args);
Midori.App.setup (ref args, null);
Test.add_func ("/completion/autocompleter", completion_autocompleter);
Test.add_func ("/completion/history", completion_history);
+ Test.add_func ("/completion/location-action", completion_location_action);
Test.run ();
}
More information about the Xfce4-commits
mailing list