aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--embed/ephy-embed-private.h3
-rw-r--r--embed/ephy-web-view.c29
-rw-r--r--tests/ephy-web-view-test.c41
3 files changed, 62 insertions, 11 deletions
diff --git a/embed/ephy-embed-private.h b/embed/ephy-embed-private.h
index f9cac0835..b23c5a3e0 100644
--- a/embed/ephy-embed-private.h
+++ b/embed/ephy-embed-private.h
@@ -65,6 +65,9 @@ GdkPixbuf * ephy_web_view_get_snapshot (EphyWebView
int height);
gboolean ephy_web_view_is_loading_homepage (EphyWebView *view);
+char* ephy_web_view_normalize_or_autosearch_url (EphyWebView *view,
+ const char *url);
+
G_END_DECLS
#endif
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index dfc05aa15..1d74862b3 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2815,19 +2815,26 @@ ephy_web_view_new (void)
return GTK_WIDGET (g_object_new (EPHY_TYPE_WEB_VIEW, NULL));
}
-/*
- * Returns a normalized representation of @url, or an autosearch string
- * for it if it has no scheme.
- *
- * Returns: the normalized @url or autosearch string
- */
-static char*
-normalize_or_autosearch_url (EphyWebView *view, const char *url)
+/**
+ * ephy_web_view_normalize_or_autosearch_url:
+ * @view: an %EphyWebView
+ * @url: a URI
+ *
+ * Returns a normalized representation of @url, or an autosearch
+ * string for it when necessary.
+ *
+ * Returns: the normalized @url or autosearch string.
+ **/
+char*
+ephy_web_view_normalize_or_autosearch_url (EphyWebView *view, const char *url)
{
char *effective_url;
char *scheme;
EphyWebViewPrivate *priv = view->priv;
+ g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), NULL);
+ g_return_val_if_fail (url, NULL);
+
scheme = g_uri_parse_scheme (url);
/* If the string doesn't look like an URI, let's search it; */
@@ -2889,7 +2896,7 @@ ephy_web_view_load_request (EphyWebView *view,
g_return_if_fail (WEBKIT_IS_URI_REQUEST(request));
url = webkit_uri_request_get_uri (request);
- effective_url = normalize_or_autosearch_url (view, url);
+ effective_url = ephy_web_view_normalize_or_autosearch_url (view, url);
// TODO: webkit_uri_request_set_uri?
webkit_web_view_load_uri (WEBKIT_WEB_VIEW(view), effective_url);
@@ -2898,7 +2905,7 @@ ephy_web_view_load_request (EphyWebView *view,
g_return_if_fail (WEBKIT_IS_NETWORK_REQUEST(request));
url = webkit_network_request_get_uri (request);
- effective_url = normalize_or_autosearch_url (view, url);
+ effective_url = ephy_web_view_normalize_or_autosearch_url (view, url);
webkit_network_request_set_uri (request, effective_url);
g_free (effective_url);
@@ -2963,7 +2970,7 @@ ephy_web_view_load_url (EphyWebView *view,
g_return_if_fail (EPHY_IS_WEB_VIEW (view));
g_return_if_fail (url);
- effective_url = normalize_or_autosearch_url (view, url);
+ effective_url = ephy_web_view_normalize_or_autosearch_url (view, url);
/* After normalization there are still some cases that are
* impossible to tell apart. One example is <URI>:<PORT> and <NON
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index 0d5f627bd..19c9fdf7f 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -264,6 +264,44 @@ test_ephy_web_view_non_search_regex ()
g_regex_unref (regex);
}
+/* FIXME: we hardcode the google search for now, since it's the
+ * default. */
+static struct {
+ char *url;
+ char *expected;
+} normalize_or_autosearch[] = {
+ { "google.com", "http://google.com" },
+ { "http://google.com", "http://google.com" },
+ { "search", "http://www.google.com/search?q=search&ie=UTF-8&oe=UTF-8" },
+ { "search.me", "http://search.me" },
+ { "lala.lala", "http://lala.lala" }, /* FIXME: should autosearch. */
+ { "127.0.0.1", "http://127.0.0.1" },
+ { "http://127.0.0.1", "http://127.0.0.1" },
+ { "totalgarbage0xdeadbeef", "http://www.google.com/search?q=totalgarbage0xdeadbeef&ie=UTF-8&oe=UTF-8" }
+};
+
+static void
+test_ephy_web_view_normalize_or_autosearch ()
+{
+ int i;
+ EphyWebView *view;
+
+ view = EPHY_WEB_VIEW (ephy_web_view_new ());
+
+ for (i = 0; i < G_N_ELEMENTS (normalize_or_autosearch); i++) {
+ char *url, *result;
+
+ url = normalize_or_autosearch[i].url;
+
+ result = ephy_web_view_normalize_or_autosearch_url (view, url);
+ g_assert_cmpstr (result, ==, normalize_or_autosearch[i].expected);
+
+ g_free (result);
+ }
+
+ g_object_unref (g_object_ref_sink (view));
+}
+
int
main (int argc, char *argv[])
{
@@ -291,6 +329,9 @@ main (int argc, char *argv[])
g_test_add_func ("/embed/ephy-web-view/non_search_regex",
test_ephy_web_view_non_search_regex);
+ g_test_add_func ("/embed/ephy-web-view/normalize_or_autosearch",
+ test_ephy_web_view_normalize_or_autosearch);
+
g_test_add_func ("/embed/ephy-web-view/load_url",
test_ephy_web_view_load_url);