Merge pull request #2683 from psychon/naughty_test_gio_dbus2

test-naughty-legacy: Use GDBus instead of spawning dbus-send
This commit is contained in:
mergify[bot] 2019-02-19 18:47:07 +00:00 committed by GitHub
commit 5908d9e108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 79 additions and 102 deletions

View File

@ -5,13 +5,35 @@ local naughty = require("naughty" )
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local cairo = require("lgi" ).cairo local cairo = require("lgi" ).cairo
local beautiful = require("beautiful") local beautiful = require("beautiful")
local Gio = require("lgi" ).Gio
local GLib = require("lgi" ).GLib
-- This module test deprecated APIs -- This module test deprecated APIs
require("gears.debug").deprecate = function() end require("gears.debug").deprecate = function() end
local dbus_connection = assert(Gio.bus_get_sync(Gio.BusType.SESSION))
local function send_notify(app, id, icon, summary, body, actions, hints, timeout, callback)
local parameters = GLib.Variant("(susssasa{sv}i)", {
app, id, icon, summary, body, actions, hints, timeout
})
local reply_type = GLib.VariantType.new("(u)")
local function invoke_callback(conn, result)
local new_id = conn:call_finish(result).value[1]
if callback then
callback(new_id)
end
end
dbus_connection:call("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "org.freedesktop.Notifications",
"Notify", parameters, reply_type, Gio.DBusCallFlags.NO_AUTO_START, -1,
nil, invoke_callback)
end
local steps = {} local steps = {}
local has_cmd_notify, has_cmd_send = false local has_cmd_notify = false
-- Use `notify-send` instead of the shimmed version to better test the dbus -- Use `notify-send` instead of the shimmed version to better test the dbus
-- to notification code. -- to notification code.
@ -30,25 +52,12 @@ local function check_cmd()
has_cmd_notify = true has_cmd_notify = true
end end
f = io.open(p.."dbus-send") if has_cmd_notify then return end
if f then
f:close()
has_cmd_send = true
end
if has_cmd_notify and has_cmd_send then return end
end end
end end
check_cmd() check_cmd()
-- Can't test anything of value the documentation example tests don't already
-- hit.
if not has_cmd_send then
require("gears.debug").print_warning("Did not find dbus-send, skipping test")
require("_runner").run_steps {}
return
end
if not has_cmd_notify then if not has_cmd_notify then
require("gears.debug").print_warning("Did not find notify-send, skipping some tests") require("gears.debug").print_warning("Did not find notify-send, skipping some tests")
end end
@ -564,30 +573,14 @@ table.insert(steps, function()
end) end)
-- Test more advanced features than what notify-send can provide. -- Test more advanced features than what notify-send can provide.
if has_cmd_send then
local cmd = { 'dbus-send',
'--type=method_call',
'--print-reply=literal',
'--dest=org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications.Notify',
'string:"Awesome test"',
'uint32:0',
'string:""',
'string:"title"',
'string:"message body"',
'array:string:1,one,2,two,3,three',
'dict:string:string:"",""',
'int32:25000'
}
-- Test the actions. -- Test the actions.
table.insert(steps, function() table.insert(steps, function()
assert(#active == 0) assert(#active == 0)
spawn(cmd) send_notify("Awesome test", 0, "", "title", "message body",
{ "1", "one", "2", "two", "3", "three" }, {}, 25000)
return true return true
end) end)
@ -617,8 +610,9 @@ if has_cmd_send then
-- Test updating a notification. -- Test updating a notification.
table.insert(steps, function() table.insert(steps, function()
spawn.easy_async(cmd, function(out) send_notify("Awesome test", 0, "", "title", "message body",
nid = tonumber(out:match(" [0-9]+"):match("[0-9]+")) { "1", "one", "2", "two", "3", "three" }, {}, 25000, function(id)
nid = id
end) end)
return true return true
@ -633,23 +627,8 @@ if has_cmd_send then
n:connect_signal("property::message", function() message_u = true end) n:connect_signal("property::message", function() message_u = true end)
n:connect_signal("property::actions", function() actions_u = true end) n:connect_signal("property::actions", function() actions_u = true end)
local update = { 'dbus-send', send_notify("Awesome test", nid, "", "updated title", "updated message body",
'--type=method_call', { "1", "four", "2", "five", "3", "six" }, {}, 25000)
'--print-reply=literal',
'--dest=org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications.Notify',
'string:"Awesome test"',
'uint32:' .. nid,
'string:""',
'string:updated title',
'string:updated message body',
'array:string:1,four,2,five,3,six',
'dict:string:string:"",""',
'int32:25000',
}
spawn(update)
return true return true
end) end)
@ -676,8 +655,6 @@ if has_cmd_send then
return true return true
end) end)
end
-- Now check if the old deprecated (but still supported) APIs don't have errors. -- Now check if the old deprecated (but still supported) APIs don't have errors.
table.insert(steps, function() table.insert(steps, function()
-- Tests are (by default) not allowed to call deprecated APIs -- Tests are (by default) not allowed to call deprecated APIs