2009-02-04 23:12:26 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "midori.h"
|
|
|
|
|
|
|
|
const gpointer magic = (gpointer)0xdeadbeef;
|
|
|
|
|
|
|
|
static void
|
|
|
|
extension_activate_cb (MidoriExtension* extension,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (extension), "activated", magic);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extension_deactivate_cb (MidoriExtension* extension)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (extension), "deactivated", magic);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extension_create (void)
|
|
|
|
{
|
2009-03-25 01:11:16 +00:00
|
|
|
MidoriApp* app;
|
2009-02-04 23:12:26 +00:00
|
|
|
MidoriExtension* extension;
|
|
|
|
|
2009-03-25 01:11:16 +00:00
|
|
|
app = midori_app_new ();
|
2009-02-04 23:12:26 +00:00
|
|
|
extension = g_object_new (MIDORI_TYPE_EXTENSION, NULL);
|
|
|
|
g_assert (!midori_extension_is_prepared (extension));
|
|
|
|
g_object_set (extension, "name", "TestExtension",
|
|
|
|
"version", "1.0", NULL);
|
|
|
|
g_assert (!midori_extension_is_prepared (extension));
|
|
|
|
g_object_set (extension, "description", "Nothing but a test.",
|
|
|
|
"authors", "John Doe", NULL);
|
|
|
|
/* FIXME: We should require to connect to "activate"
|
|
|
|
g_assert (!midori_extension_is_prepared (extension)); */
|
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (extension_activate_cb), NULL);
|
|
|
|
g_assert (midori_extension_is_prepared (extension));
|
|
|
|
g_assert (!midori_extension_is_active (extension));
|
2009-03-25 01:11:16 +00:00
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
2009-02-04 23:12:26 +00:00
|
|
|
g_assert (midori_extension_is_active (extension));
|
2009-03-25 01:11:16 +00:00
|
|
|
g_assert (midori_extension_get_app (extension) == app);
|
2009-02-04 23:12:26 +00:00
|
|
|
g_assert (g_object_get_data (G_OBJECT (extension), "activated") == magic);
|
|
|
|
g_signal_connect (extension, "deactivate",
|
|
|
|
G_CALLBACK (extension_deactivate_cb), NULL);
|
|
|
|
midori_extension_deactivate (extension);
|
|
|
|
g_assert (!midori_extension_is_active (extension));
|
|
|
|
g_assert (g_object_get_data (G_OBJECT (extension), "deactivated") == magic);
|
|
|
|
}
|
|
|
|
|
2009-02-20 19:24:13 +00:00
|
|
|
static MidoriExtension*
|
|
|
|
extension_mock_object (void)
|
2009-02-04 23:12:26 +00:00
|
|
|
{
|
|
|
|
MidoriExtension* extension;
|
|
|
|
|
|
|
|
extension = g_object_new (MIDORI_TYPE_EXTENSION,
|
|
|
|
"name", "TestExtension",
|
|
|
|
"version", "1.0",
|
|
|
|
"description", "Nothing but a test.",
|
|
|
|
"authors", "John Doe",
|
|
|
|
NULL);
|
2009-02-20 19:24:13 +00:00
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
2009-04-25 14:03:10 +00:00
|
|
|
static void
|
|
|
|
katze_assert_cmpstrv (gchar** values1,
|
|
|
|
gsize length1,
|
|
|
|
gchar** values2,
|
|
|
|
gsize length2)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_assert ((values1 && values2) || (!values1 && !values2));
|
|
|
|
/* g_assert_cmpint (length1, ==, length2); */
|
|
|
|
|
|
|
|
for (i = 0; i < length1; i++)
|
|
|
|
g_assert_cmpstr (values1[i], ==, values2[i]);
|
|
|
|
}
|
|
|
|
|
2009-02-20 19:24:13 +00:00
|
|
|
static void
|
|
|
|
extension_settings (void)
|
|
|
|
{
|
2009-03-25 01:11:16 +00:00
|
|
|
MidoriApp* app;
|
2009-02-20 19:24:13 +00:00
|
|
|
MidoriExtension* extension;
|
|
|
|
gboolean nihilist;
|
|
|
|
gint age;
|
|
|
|
const gchar* lastname;
|
2009-04-25 14:03:10 +00:00
|
|
|
gchar* pet_names[] = {"Tiger", "Bonzo", "Streuner", NULL};
|
|
|
|
gchar** names;
|
|
|
|
gsize names_n;
|
2009-02-20 19:24:13 +00:00
|
|
|
|
2009-03-25 01:11:16 +00:00
|
|
|
app = midori_app_new ();
|
2009-02-20 19:24:13 +00:00
|
|
|
extension = extension_mock_object ();
|
|
|
|
midori_extension_install_boolean (extension, "nihilist", TRUE);
|
|
|
|
nihilist = midori_extension_get_boolean (extension, "nihilist");
|
|
|
|
g_assert (!nihilist);
|
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (extension_activate_cb), NULL);
|
2009-03-25 01:11:16 +00:00
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
2009-02-20 19:24:13 +00:00
|
|
|
nihilist = midori_extension_get_boolean (extension, "nihilist");
|
|
|
|
g_assert (nihilist);
|
|
|
|
midori_extension_set_boolean (extension, "nihilist", FALSE);
|
|
|
|
nihilist = midori_extension_get_boolean (extension, "nihilist");
|
|
|
|
g_assert (!nihilist);
|
|
|
|
midori_extension_deactivate (extension);
|
|
|
|
|
|
|
|
extension = extension_mock_object ();
|
|
|
|
midori_extension_install_integer (extension, "age", 88);
|
|
|
|
age = midori_extension_get_integer (extension, "age");
|
|
|
|
g_assert_cmpint (age, ==, 0);
|
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (extension_activate_cb), NULL);
|
2009-03-25 01:11:16 +00:00
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
2009-02-20 19:24:13 +00:00
|
|
|
age = midori_extension_get_integer (extension, "age");
|
|
|
|
g_assert_cmpint (age, ==, 88);
|
|
|
|
midori_extension_set_integer (extension, "age", 66);
|
|
|
|
age = midori_extension_get_integer (extension, "age");
|
|
|
|
g_assert_cmpint (age, ==, 66);
|
|
|
|
midori_extension_deactivate (extension);
|
|
|
|
|
|
|
|
extension = extension_mock_object ();
|
2009-02-04 23:12:26 +00:00
|
|
|
midori_extension_install_string (extension, "lastname", "Thomas Mann");
|
|
|
|
lastname = midori_extension_get_string (extension, "lastname");
|
|
|
|
g_assert_cmpstr (lastname, ==, NULL);
|
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (extension_activate_cb), NULL);
|
2009-03-25 01:11:16 +00:00
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
2009-02-04 23:12:26 +00:00
|
|
|
lastname = midori_extension_get_string (extension, "lastname");
|
|
|
|
g_assert_cmpstr (lastname, ==, "Thomas Mann");
|
|
|
|
midori_extension_set_string (extension, "lastname", "Theodor Fontane");
|
|
|
|
lastname = midori_extension_get_string (extension, "lastname");
|
|
|
|
g_assert_cmpstr (lastname, ==, "Theodor Fontane");
|
2009-02-20 19:24:13 +00:00
|
|
|
midori_extension_deactivate (extension);
|
2009-04-25 14:03:10 +00:00
|
|
|
|
|
|
|
extension = extension_mock_object ();
|
|
|
|
midori_extension_install_string_list (extension, "pets", pet_names, 3);
|
|
|
|
names = midori_extension_get_string_list (extension, "pets", &names_n);
|
|
|
|
katze_assert_cmpstrv (NULL, 0, names, names_n);
|
|
|
|
g_strfreev (names);
|
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
|
|
|
names = midori_extension_get_string_list (extension, "pets", &names_n);
|
|
|
|
katze_assert_cmpstrv (pet_names, 3, names, names_n);
|
|
|
|
g_strfreev (names);
|
|
|
|
/* names = g_strsplit ("Carla,Fluffy,Goro,Kitty", ",", 0);
|
|
|
|
midori_extension_set_string_list (extension, "pets", names, G_MAXSIZE);
|
|
|
|
g_strfreev (names);
|
|
|
|
names = midori_extension_get_string_list (extension, "pets", &names_n);
|
|
|
|
g_assert_cmpint (names_n, ==, 4); */
|
|
|
|
names = g_strsplit ("Carla,Fluffy,Goro,Kitty", ",", 0);
|
|
|
|
midori_extension_set_string_list (extension, "pets", names, 2);
|
|
|
|
g_strfreev (names);
|
|
|
|
names = midori_extension_get_string_list (extension, "pets", &names_n);
|
|
|
|
g_assert_cmpint (names_n, ==, 2);
|
|
|
|
midori_extension_deactivate (extension);
|
2009-02-04 23:12:26 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 21:49:10 +00:00
|
|
|
static void
|
|
|
|
extension_activate (gconstpointer data)
|
|
|
|
{
|
|
|
|
MidoriApp* app = midori_app_new ();
|
|
|
|
MidoriExtension* extension = MIDORI_EXTENSION (data);
|
2011-01-16 13:04:56 +00:00
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
|
|
|
midori_extension_deactivate (extension);
|
2009-07-16 21:49:10 +00:00
|
|
|
g_object_unref (app);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_extensions (void)
|
|
|
|
{
|
|
|
|
if (g_module_supported ())
|
|
|
|
{
|
|
|
|
GDir* extension_dir = g_dir_open (EXTENSION_PATH, 0, NULL);
|
|
|
|
if (extension_dir != NULL)
|
|
|
|
{
|
|
|
|
const gchar* filename;
|
|
|
|
|
|
|
|
while ((filename = g_dir_read_name (extension_dir)))
|
|
|
|
{
|
|
|
|
gchar* fullname;
|
|
|
|
GModule* module;
|
|
|
|
typedef MidoriExtension* (*extension_init_func)(void);
|
|
|
|
extension_init_func extension_init;
|
|
|
|
|
|
|
|
/* Ignore files which don't have the correct suffix */
|
|
|
|
if (!g_str_has_suffix (filename, G_MODULE_SUFFIX))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fullname = g_build_filename (EXTENSION_PATH, filename, NULL);
|
|
|
|
module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
|
|
|
|
g_free (fullname);
|
|
|
|
|
|
|
|
if (module && g_module_symbol (module, "extension_init",
|
|
|
|
(gpointer) &extension_init))
|
|
|
|
{
|
|
|
|
guint length;
|
|
|
|
gchar* name;
|
|
|
|
gchar* path;
|
|
|
|
typedef MidoriExtension* (*extension_test_func)(const gchar* path);
|
|
|
|
extension_test_func extension_test;
|
|
|
|
|
|
|
|
if (g_str_has_prefix (filename, "lib"))
|
|
|
|
filename = &filename[3];
|
|
|
|
length = strlen (filename);
|
|
|
|
name = g_strdup (filename);
|
|
|
|
name[length - strlen (G_MODULE_SUFFIX) - 1] = '\0';
|
|
|
|
path = g_strconcat ("/extensions/", name, "/activate", NULL);
|
|
|
|
g_free (name);
|
|
|
|
g_test_add_data_func (path, extension_init (), extension_activate);
|
|
|
|
g_free (path);
|
|
|
|
if (g_module_symbol (module, "extension_test",
|
|
|
|
(gpointer) &extension_test))
|
|
|
|
extension_test (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_dir_close (extension_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 23:12:26 +00:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char** argv)
|
|
|
|
{
|
2011-10-28 20:18:05 +00:00
|
|
|
midori_app_setup (argv);
|
2009-02-04 23:12:26 +00:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
2009-02-19 01:22:00 +00:00
|
|
|
gtk_init_check (&argc, &argv);
|
2011-01-16 12:52:07 +00:00
|
|
|
soup_session_add_feature_by_type (webkit_get_default_session (),
|
|
|
|
SOUP_TYPE_COOKIE_JAR);
|
2009-02-04 23:12:26 +00:00
|
|
|
|
|
|
|
g_test_add_func ("/extensions/create", extension_create);
|
|
|
|
g_test_add_func ("/extensions/settings", extension_settings);
|
|
|
|
|
2009-07-16 21:49:10 +00:00
|
|
|
load_extensions ();
|
|
|
|
|
2009-02-04 23:12:26 +00:00
|
|
|
return g_test_run ();
|
|
|
|
}
|