Changeset 160904 in webkit


Ignore:
Timestamp:
Dec 20, 2013 4:11:45 AM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Some unit tests using web extensions fail when run alone
https://bugs.webkit.org/show_bug.cgi?id=126002

Reviewed by Gustavo Noronha Silva.

The problem is that the page is created before the dbus connection
has been established, and we are connecting to web-page-created
signal once we have a valid dbus connection. We should connect to
the signal before connecting to dbus and queue any request to emit
a dbus signal until the connection is set. This also fixes the
WebExtensions tests when using the network process because a new
web process is launched for every test case.

  • UIProcess/API/gtk/tests/WebExtensionTest.cpp:

(DelayedSignal::DelayedSignal): Helper struct to queue signal
emissions requested before the dbus connection has been
established.
(emitDocumentLoaded): Emit the dbus DocumentLoaded signal.
(documentLoadedCallback): Queue the signal emission if we still
don't have a connection or call emitDocumentLoaded otherwise.
(emitURIChanged): Emit the dbus URIChanged signal.
(uriChangedCallback): Queue the signal emission if we still don't
have a connection or call emitURIChanged otherwise.
(pageCreatedCallback): Pass the web extension as user data to
document-loaded and uri-changed callbacks.
(busAcquiredCallback): Set the connection as user data of the web
extension and process any delayed signal emission pending.
(webkit_web_extension_initialize): Connect to web-page-create
signal before connecting to dbus.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r160882 r160904  
     12013-12-20  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Some unit tests using web extensions fail when run alone
     4        https://bugs.webkit.org/show_bug.cgi?id=126002
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        The problem is that the page is created before the dbus connection
     9        has been established, and we are connecting to web-page-created
     10        signal once we have a valid dbus connection. We should connect to
     11        the signal before connecting to dbus and queue any request to emit
     12        a dbus signal until the connection is set. This also fixes the
     13        WebExtensions tests when using the network process because a new
     14        web process is launched for every test case.
     15
     16        * UIProcess/API/gtk/tests/WebExtensionTest.cpp:
     17        (DelayedSignal::DelayedSignal): Helper struct to queue signal
     18        emissions requested before the dbus connection has been
     19        established.
     20        (emitDocumentLoaded): Emit the dbus DocumentLoaded signal.
     21        (documentLoadedCallback): Queue the signal emission if we still
     22        don't have a connection or call emitDocumentLoaded otherwise.
     23        (emitURIChanged): Emit the dbus URIChanged signal.
     24        (uriChangedCallback): Queue the signal emission if we still don't
     25        have a connection or call emitURIChanged otherwise.
     26        (pageCreatedCallback): Pass the web extension as user data to
     27        document-loaded and uri-changed callbacks.
     28        (busAcquiredCallback): Set the connection as user data of the web
     29        extension and process any delayed signal emission pending.
     30        (webkit_web_extension_initialize): Connect to web-page-create
     31        signal before connecting to dbus.
     32
    1332013-12-19  Benjamin Poulain  <bpoulain@apple.com>
    234
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp

    r154603 r160904  
    2626#include <string.h>
    2727#include <webkit2/webkit-web-extension.h>
     28#include <wtf/Deque.h>
     29#include <wtf/OwnPtr.h>
     30#include <wtf/PassOwnPtr.h>
    2831#include <wtf/gobject/GOwnPtr.h>
    2932#include <wtf/gobject/GRefPtr.h>
     33#include <wtf/text/CString.h>
    3034
    3135static const char introspectionXML[] =
     
    4953    "</node>";
    5054
    51 static void documentLoadedCallback(WebKitWebPage*, gpointer userData)
    52 {
    53     bool ok = g_dbus_connection_emit_signal(G_DBUS_CONNECTION(userData),
     55typedef enum {
     56    DocumentLoadedSignal,
     57    URIChangedSignal,
     58} DelayedSignalType;
     59
     60struct DelayedSignal {
     61    DelayedSignal(DelayedSignalType type)
     62        : type(type)
     63    {
     64    }
     65
     66    DelayedSignal(DelayedSignalType type, const char* uri)
     67        : type(type)
     68        , uri(uri)
     69    {
     70    }
     71
     72    DelayedSignalType type;
     73    CString uri;
     74};
     75
     76Deque<OwnPtr<DelayedSignal>> delayedSignalsQueue;
     77
     78static void emitDocumentLoaded(GDBusConnection* connection)
     79{
     80    bool ok = g_dbus_connection_emit_signal(
     81        connection,
    5482        0,
    5583        "/org/webkit/gtk/WebExtensionTest",
     
    6189}
    6290
    63 static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, gpointer userData)
     91static void documentLoadedCallback(WebKitWebPage*, WebKitWebExtension* extension)
     92{
     93    gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
     94    if (data)
     95        emitDocumentLoaded(G_DBUS_CONNECTION(data));
     96    else
     97        delayedSignalsQueue.append(adoptPtr(new DelayedSignal(DocumentLoadedSignal)));
     98}
     99
     100static void emitURIChanged(GDBusConnection* connection, const char* uri)
    64101{
    65102    bool ok = g_dbus_connection_emit_signal(
    66         G_DBUS_CONNECTION(userData),
     103        connection,
    67104        0,
    68105        "/org/webkit/gtk/WebExtensionTest",
    69106        "org.webkit.gtk.WebExtensionTest",
    70107        "URIChanged",
    71         g_variant_new("(s)", webkit_web_page_get_uri(webPage)),
     108        g_variant_new("(s)", uri),
    72109        0);
    73110    g_assert(ok);
     111}
     112
     113static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, WebKitWebExtension* extension)
     114{
     115    gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
     116    if (data)
     117        emitURIChanged(G_DBUS_CONNECTION(data), webkit_web_page_get_uri(webPage));
     118    else
     119        delayedSignalsQueue.append(adoptPtr(new DelayedSignal(URIChangedSignal, webkit_web_page_get_uri(webPage))));
    74120}
    75121
     
    93139}
    94140
    95 static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
    96 {
    97     g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
    98     g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData);
     141static void pageCreatedCallback(WebKitWebExtension* extension, WebKitWebPage* webPage, gpointer)
     142{
     143    g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), extension);
     144    g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), extension);
    99145    g_signal_connect(webPage, "send-request", G_CALLBACK(sendRequestCallback), 0);
    100146}
     
    192238        g_warning("Failed to register object: %s\n", error->message);
    193239
    194     g_signal_connect(WEBKIT_WEB_EXTENSION(userData), "page-created", G_CALLBACK(pageCreatedCallback), connection);
     240    g_object_set_data(G_OBJECT(userData), "dbus-connection", connection);
     241    while (delayedSignalsQueue.size()) {
     242        OwnPtr<DelayedSignal> delayedSignal = delayedSignalsQueue.takeFirst();
     243        switch (delayedSignal->type) {
     244        case DocumentLoadedSignal:
     245            emitDocumentLoaded(connection);
     246            break;
     247        case URIChangedSignal:
     248            emitURIChanged(connection, delayedSignal->uri.data());
     249            break;
     250        }
     251    }
     252}
     253
     254extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension)
     255{
     256    g_signal_connect(extension, "page-created", G_CALLBACK(pageCreatedCallback), extension);
    195257    g_signal_connect(webkit_script_world_get_default(), "window-object-cleared", G_CALLBACK(windowObjectCleared), 0);
    196 }
    197 
    198 extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension)
    199 {
     258
    200259    g_bus_own_name(
    201260        G_BUS_TYPE_SESSION,
Note: See TracChangeset for help on using the changeset viewer.