20
20
#include " config.h"
21
21
#include " WebKitTestBus.h"
22
22
23
- #include < wtf/glib/GUniquePtr.h>
24
- #include < wtf/text/WTFString.h>
25
-
26
23
WebKitTestBus::WebKitTestBus ()
27
- : m_pid(- 1 )
24
+ : m_bus(adoptGRef(g_test_dbus_new(G_TEST_DBUS_NONE)) )
28
25
{
29
26
}
30
27
31
- bool WebKitTestBus::run ()
28
+ WebKitTestBus::~WebKitTestBus ()
32
29
{
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 ());
62
31
}
63
32
64
- WebKitTestBus::~WebKitTestBus ()
33
+ bool WebKitTestBus::run ()
65
34
{
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 ();
70
40
}
71
41
72
42
GDBusConnection* WebKitTestBus::getOrCreateConnection ()
@@ -77,7 +47,8 @@ GDBusConnection* WebKitTestBus::getOrCreateConnection()
77
47
g_assert (!m_address.isNull ());
78
48
m_connection = adoptGRef (g_dbus_connection_new_for_address_sync (m_address.data (),
79
49
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 ());
81
52
return m_connection.get ();
82
53
}
83
54
@@ -88,19 +59,19 @@ static void onNameAppeared(GDBusConnection*, const char*, const char*, gpointer
88
59
89
60
GDBusProxy* WebKitTestBus::createProxy (const char * serviceName, const char * objectPath, const char * interfaceName, GMainLoop* mainLoop)
90
61
{
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 );
92
63
g_main_loop_run (mainLoop);
93
64
g_bus_unwatch_name (watcherID);
94
65
95
66
GDBusProxy* proxy = g_dbus_proxy_new_sync (
96
67
connection (),
97
68
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
98
- 0 , // GDBusInterfaceInfo
69
+ nullptr , // GDBusInterfaceInfo
99
70
serviceName,
100
71
objectPath,
101
72
interfaceName,
102
- 0 , // GCancellable
103
- 0 );
73
+ nullptr , // GCancellable
74
+ nullptr );
104
75
g_assert (proxy);
105
76
return proxy;
106
77
}
0 commit comments