[epiphany] ephy-web-view: export the 'normalize or autosearch' method



commit 393d8167c8f10578044d4245a1927ab2d9416578
Author: Xan Lopez <xan igalia com>
Date:   Tue Aug 7 14:24:48 2012 +0200

    ephy-web-view: export the 'normalize or autosearch' method
    
    We are going to modify it a bit, and we really want to test it. Add
    some initial tests for the existing functionality.

 embed/ephy-embed-private.h |    3 +++
 embed/ephy-web-view.c      |   29 ++++++++++++++++++-----------
 tests/ephy-web-view-test.c |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 11 deletions(-)
---
diff --git a/embed/ephy-embed-private.h b/embed/ephy-embed-private.h
index f9cac08..b23c5a3 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 dfc05aa..1d74862 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 0d5f627..19c9fdf 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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]