summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests/testdownload.c
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-02-02 14:57:50 +0000
committerSteve Block <steveblock@google.com>2010-02-04 15:06:55 +0000
commitd0825bca7fe65beaee391d30da42e937db621564 (patch)
tree7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebKit/gtk/tests/testdownload.c
parent3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff)
downloadexternal_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip
external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz
external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebKit/gtk/tests/testdownload.c')
-rw-r--r--WebKit/gtk/tests/testdownload.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/WebKit/gtk/tests/testdownload.c b/WebKit/gtk/tests/testdownload.c
index 0d964ed..05c3a8d 100644
--- a/WebKit/gtk/tests/testdownload.c
+++ b/WebKit/gtk/tests/testdownload.c
@@ -26,6 +26,7 @@
GMainLoop* loop;
char* temporaryFilename = NULL;
+WebKitDownload* theDownload = NULL;
static void
test_webkit_download_create(void)
@@ -87,6 +88,7 @@ download_requested_cb(WebKitWebView* web_view,
WebKitDownload* download,
gboolean* beenThere)
{
+ theDownload = download;
*beenThere = TRUE;
if (temporaryFilename) {
gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL);
@@ -101,8 +103,19 @@ download_requested_cb(WebKitWebView* web_view,
return TRUE;
}
+static gboolean
+set_filename(gchar* filename)
+{
+ gchar *uri = g_filename_to_uri(filename, NULL, NULL);
+ webkit_download_set_destination_uri(theDownload, uri);
+ g_free(uri);
+ temporaryFilename = filename;
+ webkit_download_start(theDownload);
+ return FALSE;
+}
+
static void
-test_webkit_download_perform(void)
+test_webkit_download_perform(gboolean asynch)
{
WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
@@ -121,16 +134,23 @@ test_webkit_download_perform(void)
* 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);
+ gchar* filename;
+ int fd = g_file_open_tmp("webkit-testwebdownload-XXXXXX", &filename, &error);
close(fd);
if (error)
g_critical("Failed to open a temporary file for writing: %s.", error->message);
- if (g_unlink(temporaryFilename) == -1)
+ if (g_unlink(filename) == -1)
g_critical("Failed to delete the temporary file: %s.", g_strerror(errno));
+ if (asynch)
+ g_idle_add((GSourceFunc)set_filename, filename);
+ else
+ temporaryFilename = filename;
+
+ theDownload = NULL;
+
loop = g_main_loop_new(NULL, TRUE);
webkit_web_view_load_uri(webView, "http://gnome.org/");
g_main_loop_run(loop);
@@ -145,6 +165,18 @@ test_webkit_download_perform(void)
g_object_unref(webView);
}
+static void
+test_webkit_download_synch(void)
+{
+ test_webkit_download_perform(FALSE);
+}
+
+static void
+test_webkit_download_asynch(void)
+{
+ test_webkit_download_perform(TRUE);
+}
+
int main(int argc, char** argv)
{
g_thread_init(NULL);
@@ -152,7 +184,8 @@ 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);
+ g_test_add_func("/webkit/download/synch", test_webkit_download_synch);
+ g_test_add_func("/webkit/download/asynch", test_webkit_download_asynch);
return g_test_run ();
}