Add unit test for prefetching that tests which URIs to prefetch
This commit is contained in:
parent
1451026160
commit
5f30199df5
1 changed files with 44 additions and 10 deletions
|
@ -20,19 +20,16 @@
|
||||||
static gchar* hosts = NULL;
|
static gchar* hosts = NULL;
|
||||||
static int host_count;
|
static int host_count;
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
dnsprefetch_do_prefetch (WebKitWebView* web_view,
|
dnsprefetch_do_prefetch (const char* uri)
|
||||||
const gchar* title,
|
|
||||||
const char* uri,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
SoupURI* s_uri;
|
SoupURI* s_uri;
|
||||||
|
|
||||||
if (!uri)
|
if (!uri)
|
||||||
return;
|
return FALSE;
|
||||||
s_uri = soup_uri_new (uri);
|
s_uri = soup_uri_new (uri);
|
||||||
if (!s_uri || !s_uri->host)
|
if (!s_uri || !s_uri->host)
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
#if GLIB_CHECK_VERSION (2, 22, 0)
|
#if GLIB_CHECK_VERSION (2, 22, 0)
|
||||||
if (g_hostname_is_ip_address (s_uri->host))
|
if (g_hostname_is_ip_address (s_uri->host))
|
||||||
|
@ -41,12 +38,12 @@ dnsprefetch_do_prefetch (WebKitWebView* web_view,
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
soup_uri_free (s_uri);
|
soup_uri_free (s_uri);
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!g_str_has_prefix (uri, "http"))
|
if (!g_str_has_prefix (uri, "http"))
|
||||||
{
|
{
|
||||||
soup_uri_free (s_uri);
|
soup_uri_free (s_uri);
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_regex_match_simple (s_uri->host, hosts,
|
if (!g_regex_match_simple (s_uri->host, hosts,
|
||||||
|
@ -69,6 +66,16 @@ dnsprefetch_do_prefetch (WebKitWebView* web_view,
|
||||||
katze_assign (hosts, new_hosts);
|
katze_assign (hosts, new_hosts);
|
||||||
}
|
}
|
||||||
soup_uri_free (s_uri);
|
soup_uri_free (s_uri);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dnsprefetch_prefetch_cb (WebKitWebView* web_view,
|
||||||
|
const gchar* title,
|
||||||
|
const char* uri,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
dnsprefetch_do_prefetch (uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -77,7 +84,7 @@ dnsprefetch_add_tab_cb (MidoriBrowser* browser,
|
||||||
{
|
{
|
||||||
GtkWidget* web_view = gtk_bin_get_child (GTK_BIN (view));
|
GtkWidget* web_view = gtk_bin_get_child (GTK_BIN (view));
|
||||||
g_signal_connect (web_view, "hovering-over-link",
|
g_signal_connect (web_view, "hovering-over-link",
|
||||||
G_CALLBACK (dnsprefetch_do_prefetch), 0);
|
G_CALLBACK (dnsprefetch_prefetch_cb), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -153,6 +160,33 @@ dnsprefetch_activate_cb (MidoriExtension* extension,
|
||||||
g_object_unref (browsers);
|
g_object_unref (browsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if G_ENABLE_DEBUG
|
||||||
|
static void
|
||||||
|
dnsprefetch_parse (void)
|
||||||
|
{
|
||||||
|
g_assert (!dnsprefetch_do_prefetch (NULL));
|
||||||
|
g_assert (dnsprefetch_do_prefetch ("http://google.com"));
|
||||||
|
g_assert (dnsprefetch_do_prefetch ("http://google.com"));
|
||||||
|
g_assert (dnsprefetch_do_prefetch ("http://googlecom"));
|
||||||
|
g_assert (dnsprefetch_do_prefetch ("http://1kino.com"));
|
||||||
|
g_assert (dnsprefetch_do_prefetch ("http://"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("http:/"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("http"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("ftp://ftphost.org"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("http://10.0.0.1"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("about:blank"));
|
||||||
|
g_assert (!dnsprefetch_do_prefetch ("javascript: alert()"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
extension_test (void)
|
||||||
|
{
|
||||||
|
katze_assign (hosts, g_strdup (""));
|
||||||
|
host_count = 0;
|
||||||
|
g_test_add_func ("/extensions/dnsprefetch/parse", dnsprefetch_parse);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
MidoriExtension*
|
MidoriExtension*
|
||||||
extension_init (void)
|
extension_init (void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue