From 6d58d7b4a2a2e3e5fa8515d55bc7c06a90becdc3 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Jul 2019 01:14:47 -0400 Subject: [PATCH] tests: Test that the legacy naughty popup is used when the new API fails Displaying errors is important. If the notification popup caused the error, it was likely nothing could be displayed. --- tests/test-naughty-legacy.lua | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/test-naughty-legacy.lua b/tests/test-naughty-legacy.lua index 0940ca09..67fd80af 100644 --- a/tests/test-naughty-legacy.lua +++ b/tests/test-naughty-legacy.lua @@ -8,6 +8,8 @@ local cairo = require("lgi" ).cairo local beautiful = require("beautiful") local Gio = require("lgi" ).Gio local GLib = require("lgi" ).GLib +local gpcall = require("gears.protected_call") +local dwidget = require("naughty.widget._default") -- This module test deprecated APIs require("gears.debug").deprecate = function() end @@ -1000,6 +1002,82 @@ table.insert(steps, function() return true end) +-- Add a "new API" handler. +local current_template, had_error, handler_called = nil + +table.insert(steps, function() + assert(naughty.has_display_handler == false) + + naughty.connect_signal("request::display", function(n) + handler_called = true + + naughty.layout.box { + notification = n, + widget_template = current_template + } + end) + + return true +end) + +-- Make sure the legacy popup is used when the new APIs fails. +table.insert(steps, function() + assert(naughty.has_display_handler == true) + + function gpcall._error_handler() + had_error = true + end + + local n = naughty.notification { + title = nil, + message = nil, + timeout = 25000, + } + + assert(handler_called) + assert(not had_error) + assert(not n._private.widget_template_failed) + assert(not n.box) + + n:destroy() + handler_called = false + + -- Try with a broken template. + current_template = {widget = function() assert(false) end} + + n = naughty.notification { + title = "foo", + message = "bar", + timeout = 25000, + } + + assert(handler_called) + assert(had_error) + assert(not n.box) + + handler_called = false + had_error = false + + -- Break the default template + assert(dwidget.widget) + dwidget.widget = nil + dwidget.layout = function() assert(false) end + table.remove(dwidget, 1) + + n = naughty.notification { + title = "foo", + message = "bar", + timeout = 25000, + } + + assert(handler_called) + assert(n._private.widget_template_failed) + assert(had_error) + assert(n.box) + + return true +end) + -- Test many screens. require("_runner").run_steps(steps)