Skip to content

Commit cf85d4f

Browse files
[GTK] Use GTestDBus instead of dbus-launch in WebKitTestBus.cpp
https://bugs.webkit.org/show_bug.cgi?id=161481 Reviewed by Michael Catanzaro. * TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp: (WebKitTestBus::WebKitTestBus): (WebKitTestBus::~WebKitTestBus): (WebKitTestBus::run): (WebKitTestBus::getOrCreateConnection): (WebKitTestBus::createProxy): * TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208284 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 186e6ab commit cf85d4f

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
lines changed

Tools/ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2016-11-02 Carlos Garcia Campos <[email protected]>
2+
3+
[GTK] Use GTestDBus instead of dbus-launch in WebKitTestBus.cpp
4+
https://bugs.webkit.org/show_bug.cgi?id=161481
5+
6+
Reviewed by Michael Catanzaro.
7+
8+
* TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp:
9+
(WebKitTestBus::WebKitTestBus):
10+
(WebKitTestBus::~WebKitTestBus):
11+
(WebKitTestBus::run):
12+
(WebKitTestBus::getOrCreateConnection):
13+
(WebKitTestBus::createProxy):
14+
* TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h:
15+
116
2016-11-02 Carlos Garcia Campos <[email protected]>
217

318
Unreviewed. Fix /webkit2/WebKitWebContext/get-plugins in the bots after r208273.

Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp

+15-44
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,23 @@
2020
#include "config.h"
2121
#include "WebKitTestBus.h"
2222

23-
#include <wtf/glib/GUniquePtr.h>
24-
#include <wtf/text/WTFString.h>
25-
2623
WebKitTestBus::WebKitTestBus()
27-
: m_pid(-1)
24+
: m_bus(adoptGRef(g_test_dbus_new(G_TEST_DBUS_NONE)))
2825
{
2926
}
3027

31-
bool WebKitTestBus::run()
28+
WebKitTestBus::~WebKitTestBus()
3229
{
33-
// FIXME: Use GTestDBus when we bump glib to 2.34.
34-
GUniquePtr<char> dbusLaunch(g_find_program_in_path("dbus-launch"));
35-
if (!dbusLaunch) {
36-
g_warning("Error starting DBUS daemon: dbus-launch not found in path");
37-
return false;
38-
}
39-
40-
GUniqueOutPtr<char> output;
41-
GUniqueOutPtr<GError> error;
42-
if (!g_spawn_command_line_sync(dbusLaunch.get(), &output.outPtr(), 0, 0, &error.outPtr())) {
43-
g_warning("Error starting DBUS daemon: %s", error->message);
44-
return false;
45-
}
46-
47-
String outputString = String::fromUTF8(output.get());
48-
Vector<String> lines;
49-
outputString.split(UChar('\n'), /* allowEmptyEntries */ false, lines);
50-
for (size_t i = 0; i < lines.size(); ++i) {
51-
char** keyValue = g_strsplit(lines[i].utf8().data(), "=", 2);
52-
g_assert_cmpuint(g_strv_length(keyValue), ==, 2);
53-
if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_ADDRESS")) {
54-
m_address = keyValue[1];
55-
g_setenv("DBUS_SESSION_BUS_ADDRESS", keyValue[1], TRUE);
56-
} else if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_PID"))
57-
m_pid = g_ascii_strtoll(keyValue[1], 0, 10);
58-
g_strfreev(keyValue);
59-
}
60-
61-
return m_pid > 0;
30+
g_test_dbus_down(m_bus.get());
6231
}
6332

64-
WebKitTestBus::~WebKitTestBus()
33+
bool WebKitTestBus::run()
6534
{
66-
g_unsetenv("DBUS_SESSION_BUS_ADDRESS");
67-
68-
if (m_pid != -1)
69-
kill(m_pid, SIGTERM);
35+
CString display = g_getenv("DISPLAY");
36+
g_test_dbus_up(m_bus.get());
37+
m_address = g_test_dbus_get_bus_address(m_bus.get());
38+
g_setenv("DISPLAY", display.data(), FALSE);
39+
return !m_address.isNull();
7040
}
7141

7242
GDBusConnection* WebKitTestBus::getOrCreateConnection()
@@ -77,7 +47,8 @@ GDBusConnection* WebKitTestBus::getOrCreateConnection()
7747
g_assert(!m_address.isNull());
7848
m_connection = adoptGRef(g_dbus_connection_new_for_address_sync(m_address.data(),
7949
static_cast<GDBusConnectionFlags>(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
80-
0, 0, 0));
50+
nullptr, nullptr, nullptr));
51+
g_assert(m_connection.get());
8152
return m_connection.get();
8253
}
8354

@@ -88,19 +59,19 @@ static void onNameAppeared(GDBusConnection*, const char*, const char*, gpointer
8859

8960
GDBusProxy* WebKitTestBus::createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop* mainLoop)
9061
{
91-
unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
62+
unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, nullptr, mainLoop, nullptr);
9263
g_main_loop_run(mainLoop);
9364
g_bus_unwatch_name(watcherID);
9465

9566
GDBusProxy* proxy = g_dbus_proxy_new_sync(
9667
connection(),
9768
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
98-
0, // GDBusInterfaceInfo
69+
nullptr, // GDBusInterfaceInfo
9970
serviceName,
10071
objectPath,
10172
interfaceName,
102-
0, // GCancellable
103-
0);
73+
nullptr, // GCancellable
74+
nullptr);
10475
g_assert(proxy);
10576
return proxy;
10677
}

Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class WebKitTestBus {
2828
public:
2929
WebKitTestBus();
30-
virtual ~WebKitTestBus();
30+
~WebKitTestBus();
3131

3232
bool run();
3333
GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*);
@@ -36,7 +36,7 @@ class WebKitTestBus {
3636
private:
3737
GDBusConnection* getOrCreateConnection();
3838

39-
pid_t m_pid;
39+
GRefPtr<GTestDBus> m_bus;
4040
CString m_address;
4141
GRefPtr<GDBusConnection> m_connection;
4242
};

0 commit comments

Comments
 (0)