Commit a031390d authored by kov@webkit.org's avatar kov@webkit.org

2009-06-11 Gustavo Noronha Silva <gns@gnome.org>

        Reviewed by Xan Lopez.

        Add a test to perform an actual download.

        * tests/testdownload.c:
        (navigation_policy_decision_requested_cb):
        (notify_status_cb):
        (download_requested_cb):
        (test_webkit_download_perform):
        (main):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44620 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0c0f45f1
2009-06-11 Gustavo Noronha Silva <gns@gnome.org>
Reviewed by Xan Lopez.
Add a test to perform an actual download.
* tests/testdownload.c:
(navigation_policy_decision_requested_cb):
(notify_status_cb):
(download_requested_cb):
(test_webkit_download_perform):
(main):
2009-06-11 Gustavo Noronha Silva <gns@gnome.org>
Reviewed by Xan Lopez.
......
......@@ -17,10 +17,16 @@
* Boston, MA 02110-1301, USA.
*/
#include <errno.h>
#include <unistd.h>
#include <glib/gstdio.h>
#include <webkit/webkit.h>
#if GTK_CHECK_VERSION(2, 14, 0)
GMainLoop* loop;
char* temporaryFilename = NULL;
static void
test_webkit_download_create(void)
{
......@@ -47,6 +53,98 @@ test_webkit_download_create(void)
g_object_unref(download);
}
static gboolean
navigation_policy_decision_requested_cb(WebKitWebView* web_view,
WebKitWebFrame* web_frame,
WebKitNetworkRequest* request,
WebKitWebNavigationAction* action,
WebKitWebPolicyDecision* decision,
gpointer data)
{
webkit_web_policy_decision_download(decision);
return TRUE;
}
static void
notify_status_cb(GObject* object, GParamSpec* pspec, gpointer data)
{
WebKitDownload* download = WEBKIT_DOWNLOAD(object);
switch (webkit_download_get_status(download)) {
case WEBKIT_DOWNLOAD_STATUS_FINISHED:
case WEBKIT_DOWNLOAD_STATUS_ERROR:
g_main_loop_quit(loop);
break;
case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
g_assert_not_reached();
break;
default:
break;
}
}
static gboolean
download_requested_cb(WebKitWebView* web_view,
WebKitDownload* download,
gboolean* beenThere)
{
*beenThere = TRUE;
if (temporaryFilename) {
gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL);
if (uri)
webkit_download_set_destination_uri(download, uri);
g_free(uri);
}
g_signal_connect(download, "notify::status",
G_CALLBACK(notify_status_cb), NULL);
return TRUE;
}
static void
test_webkit_download_perform(void)
{
WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
g_object_ref_sink(G_OBJECT(webView));
g_signal_connect(webView, "navigation-policy-decision-requested",
G_CALLBACK(navigation_policy_decision_requested_cb),
NULL);
gboolean beenThere = FALSE;
g_signal_connect(webView, "download-requested",
G_CALLBACK(download_requested_cb),
&beenThere);
/* Preparation; FIXME: we should move this code to a test
* utilities file, because we have a very similar one in
* testwebframe.c */
GError *error = NULL;
int fd = g_file_open_tmp ("webkit-testwebdownload-XXXXXX",
&temporaryFilename, &error);
close(fd);
if (error)
g_critical("Failed to open a temporary file for writing: %s.", error->message);
if (g_unlink(temporaryFilename) == -1)
g_critical("Failed to delete the temporary file: %s.", g_strerror(errno));
loop = g_main_loop_new(NULL, TRUE);
webkit_web_view_load_uri(webView, "http://gnome.org/");
g_main_loop_run(loop);
g_assert_cmpint(beenThere, ==, TRUE);
g_assert_cmpint(g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR), ==, TRUE);
g_unlink(temporaryFilename);
g_free(temporaryFilename);
g_main_loop_unref(loop);
g_object_unref(webView);
}
int main(int argc, char** argv)
{
g_thread_init(NULL);
......@@ -54,6 +152,7 @@ int main(int argc, char** argv)
g_test_bug_base("https://bugs.webkit.org/");
g_test_add_func("/webkit/download/create", test_webkit_download_create);
g_test_add_func("/webkit/download/perform", test_webkit_download_perform);
return g_test_run ();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment