Changeset 52986 in webkit


Ignore:
Timestamp:
Jan 8, 2010 3:54:29 AM (14 years ago)
Author:
kov@webkit.org
Message:

2010-01-08 Gustavo Noronha Silva <Gustavo Noronha Silva>

Reviewed by Xan Lopez.

[GTK] loading test should use SoupServer instead of actual sites
https://bugs.webkit.org/show_bug.cgi?id=33353

Make all the loading tests use SoupServer, instead of fetching
stuff from the Internet.

  • tests/testloading.c: (server_callback): (get_uri_for_path): (test_loading_status): (test_loading_error): (test_loading_cancelled): (load_wentback_status_changed_cb): (load_error_test): (test_loading_goback): (main):
Location:
trunk/WebKit/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r52890 r52986  
     12010-01-08  Gustavo Noronha Silva  <gns@gnome.org>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] loading test should use SoupServer instead of actual sites
     6        https://bugs.webkit.org/show_bug.cgi?id=33353
     7
     8        Make all the loading tests use SoupServer, instead of fetching
     9        stuff from the Internet.
     10
     11        * tests/testloading.c:
     12        (server_callback):
     13        (get_uri_for_path):
     14        (test_loading_status):
     15        (test_loading_error):
     16        (test_loading_cancelled):
     17        (load_wentback_status_changed_cb):
     18        (load_error_test):
     19        (test_loading_goback):
     20        (main):
     21
    1222010-01-06  Joanmarie Diggs  <joanmarie.diggs@gmail.com>
    223
  • trunk/WebKit/gtk/tests/testloading.c

    r52422 r52986  
    11/*
    2  * Copyright (C) 2009 Gustavo Noronha Silva
     2 * Copyright (C) 2009, 2010 Gustavo Noronha Silva
    33 * Copyright (C) 2009 Igalia S.L.
    44 *
     
    2020
    2121#include <gtk/gtk.h>
     22#include <libsoup/soup.h>
     23#include <string.h>
    2224#include <webkit/webkit.h>
    2325
    2426#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
     27
     28/* This string has to be rather big because of the cancelled test - it
     29 * looks like soup refuses to send or receive a too small chunk */
     30#define HTML_STRING "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!</body></html>"
     31
     32SoupURI* base_uri;
     33
     34/* For real request testing */
     35static void
     36server_callback(SoupServer* server, SoupMessage* msg,
     37                const char* path, GHashTable* query,
     38                SoupClientContext* context, gpointer data)
     39{
     40    if (msg->method != SOUP_METHOD_GET) {
     41        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
     42        return;
     43    }
     44
     45    soup_message_set_status(msg, SOUP_STATUS_OK);
     46
     47    if (g_str_equal(path, "/test_loading_status") || g_str_equal(path, "/test_loading_status2"))
     48        soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
     49    else if (g_str_equal(path, "/test_load_error")) {
     50        soup_message_set_status(msg, SOUP_STATUS_CANT_CONNECT);
     51    } else if (g_str_equal(path, "/test_loading_cancelled")) {
     52        soup_message_headers_set_encoding(msg->response_headers, SOUP_ENCODING_CHUNKED);
     53        soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
     54        soup_server_unpause_message(server, msg);
     55        return;
     56    }
     57
     58    soup_message_body_complete(msg->response_body);
     59}
    2560
    2661typedef struct {
     
    5489}
    5590
     91static char* get_uri_for_path(const char* path)
     92{
     93    SoupURI* uri;
     94    char* uri_string;
     95
     96    uri = soup_uri_new_with_base(base_uri, path);
     97    uri_string = soup_uri_to_string(uri, FALSE);
     98    soup_uri_free (uri);
     99
     100    return uri_string;
     101}
     102
    56103static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebLoadingFixture* fixture)
    57104{
     
    99146static void test_loading_status(WebLoadingFixture* fixture, gconstpointer data)
    100147{
     148    char* uri_string;
     149
    101150    g_assert_cmpint(webkit_web_view_get_load_status(fixture->webView), ==, WEBKIT_LOAD_PROVISIONAL);
    102151
     
    106155                     NULL);
    107156
     157    uri_string = get_uri_for_path("/test_loading_status");
     158
    108159    /* load_uri will trigger the navigation-policy-decision-requested
    109160     * signal emission;
    110161     */
    111     webkit_web_view_load_uri(fixture->webView, "http://gnome.org/");
     162    webkit_web_view_load_uri(fixture->webView, uri_string);
     163    g_free(uri_string);
    112164
    113165    g_main_loop_run(fixture->loop);
     
    154206static void test_loading_error(WebLoadingFixture* fixture, gconstpointer data)
    155207{
     208    char* uri_string;
     209
    156210    g_test_bug("28842");
    157211
     
    159213    g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_error_status_changed_cb), fixture);
    160214
    161     webkit_web_view_load_uri(fixture->webView, "http://snoetuhsetuhseoutoeutc.com/");
     215    uri_string = get_uri_for_path("/test_load_error");
     216    webkit_web_view_load_uri(fixture->webView, uri_string);
     217    g_free(uri_string);
     218
    162219    g_main_loop_run(fixture->loop);
    163220}
     
    212269static void test_loading_cancelled(WebLoadingFixture* fixture, gconstpointer data)
    213270{
     271    char* uri_string;
     272
    214273    g_test_bug("29644");
    215274
     
    217276    g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_cancelled_status_changed_cb), fixture);
    218277
    219     webkit_web_view_load_uri(fixture->webView, "http://google.com/");
     278    uri_string = get_uri_for_path("/test_loading_cancelled");
     279    webkit_web_view_load_uri(fixture->webView, uri_string);
     280    g_free(uri_string);
     281
    220282    g_main_loop_run(fixture->loop);
    221283}
     
    251313{
    252314    WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
     315    char* uri_string;
     316    char* uri_string2;
     317
     318    uri_string = get_uri_for_path("/test_loading_status");
     319    uri_string2 = get_uri_for_path("/test_loading_status2");
    253320
    254321    switch(status) {
    255322    case WEBKIT_LOAD_PROVISIONAL:
    256         g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, "http://www.debian.org/distrib/");
     323        g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string2);
    257324        break;
    258325    case WEBKIT_LOAD_COMMITTED:
    259         g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, "http://www.debian.org/");
     326        g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string);
    260327        break;
    261328    case WEBKIT_LOAD_FAILED:
     
    263330        break;
    264331    case WEBKIT_LOAD_FINISHED:
    265         g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, "http://www.debian.org/");
     332        g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string);
    266333        g_main_loop_quit(fixture->loop);
    267334        break;
     
    269336        break;
    270337    }
     338
     339    g_free(uri_string);
     340    g_free(uri_string2);
     341}
     342
     343static void load_error_test(WebKitWebView* webview, WebKitWebFrame* frame, const char* uri, GError* error)
     344{
     345    g_debug("Error: %s", error->message);
    271346}
    272347
    273348static void test_loading_goback(WebLoadingFixture* fixture, gconstpointer data)
    274349{
     350    char* uri_string;
     351
    275352    g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_goback_status_changed_cb), fixture);
    276353
    277     webkit_web_view_load_uri(fixture->webView, "http://www.debian.org/");
     354    g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_error_test), fixture);
     355
     356    uri_string = get_uri_for_path("/test_loading_status");
     357    webkit_web_view_load_uri(fixture->webView, uri_string);
     358    g_free(uri_string);
     359
    278360    g_main_loop_run(fixture->loop);
    279361
     
    285367    fixture->has_been_load_error = FALSE;
    286368
    287     webkit_web_view_load_uri(fixture->webView, "http://debian.org/distrib/");
    288     g_main_loop_run(fixture->loop);
     369    uri_string = get_uri_for_path("/test_loading_status2");
     370    webkit_web_view_load_uri(fixture->webView, uri_string);
     371    g_free(uri_string);
     372
     373    g_main_loop_run(fixture->loop);
     374
     375    g_signal_handlers_disconnect_by_func(fixture->webView, load_goback_status_changed_cb, fixture);
    289376
    290377    fixture->has_been_provisional = FALSE;
     
    297384    g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_wentback_status_changed_cb), fixture);
    298385    webkit_web_view_go_back(fixture->webView);
     386
     387    g_main_loop_run(fixture->loop);
     388
     389    g_signal_handlers_disconnect_by_func(fixture->webView, load_wentback_status_changed_cb, fixture);
    299390}
    300391
    301392int main(int argc, char** argv)
    302393{
     394    SoupServer* server;
     395
    303396    g_thread_init(NULL);
    304397    gtk_test_init(&argc, &argv, NULL);
     398
     399    server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
     400    soup_server_run_async(server);
     401
     402    soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
     403
     404    base_uri = soup_uri_new("http://127.0.0.1/");
     405    soup_uri_set_port(base_uri, soup_server_get_port(server));
    305406
    306407    g_test_bug_base("https://bugs.webkit.org/");
Note: See TracChangeset for help on using the changeset viewer.