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,119 +573,87 @@ 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', -- Test the actions.
'--type=method_call', table.insert(steps, function()
'--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. assert(#active == 0)
table.insert(steps, function()
assert(#active == 0) send_notify("Awesome test", 0, "", "title", "message body",
{ "1", "one", "2", "two", "3", "three" }, {}, 25000)
spawn(cmd) return true
end)
return true table.insert(steps, function()
end) if #active == 0 then return end
table.insert(steps, function() assert(#active == 1)
if #active == 0 then return end local n = active[1]
assert(#active == 1) assert(n.box)
local n = active[1] assert(#n.actions == 3)
assert(n.actions[1].name == "one" )
assert(n.actions[2].name == "two" )
assert(n.actions[3].name == "three")
assert(n.box) n:destroy()
assert(#n.actions == 3)
assert(n.actions[1].name == "one" )
assert(n.actions[2].name == "two" )
assert(n.actions[3].name == "three")
n:destroy() return true
end)
return true --TODO Test too many actions.
end)
--TODO Test too many actions. --TODO Test action with long names.
--TODO Test action with long names. local nid, name_u, message_u, actions_u = nil
local nid, name_u, message_u, actions_u = nil -- Test updating a notification.
table.insert(steps, function()
-- Test updating a notification. send_notify("Awesome test", 0, "", "title", "message body",
table.insert(steps, function() { "1", "one", "2", "two", "3", "three" }, {}, 25000, function(id)
spawn.easy_async(cmd, function(out) nid = id
nid = tonumber(out:match(" [0-9]+"):match("[0-9]+"))
end) end)
return true return true
end) end)
table.insert(steps, function() table.insert(steps, function()
if #active == 0 or not nid then return end if #active == 0 or not nid then return end
local n = active[1] local n = active[1]
n:connect_signal("property::title" , function() name_u = true end) n:connect_signal("property::title" , function() name_u = true end)
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
end)
return true -- Test if all properties have been updated.
end) table.insert(steps, function()
if not name_u then return end
if not message_u then return end
if not actions_u then return end
-- Test if all properties have been updated. -- No new notification should have been created.
table.insert(steps, function() assert(#active == 1)
if not name_u then return end
if not message_u then return end
if not actions_u then return end
-- No new notification should have been created. local n = active[1]
assert(#active == 1)
local n = active[1] assert(n.title == "updated title" )
assert(n.message == "updated message body")
assert(n.title == "updated title" ) assert(#n.actions == 3)
assert(n.message == "updated message body") assert(n.actions[1].name == "four" )
assert(n.actions[2].name == "five" )
assert(n.actions[3].name == "six" )
assert(#n.actions == 3) return true
assert(n.actions[1].name == "four" ) end)
assert(n.actions[2].name == "five" )
assert(n.actions[3].name == "six" )
return true
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()