Add some more test coverage to get this PR to the requisite 91%.
This commit is contained in:
parent
8f7750e6f2
commit
75943e788b
|
@ -42,8 +42,6 @@ local function get_default_dir()
|
|||
if home_dir then
|
||||
home_dir = string.gsub(home_dir, '/*$', '/') .. 'Images/'
|
||||
if gears.filesystem.dir_writable(home_dir) then
|
||||
-- if os.execute("bash -c \"if [ -d \\\"" .. home_dir .. "\\\" -a -w \\\"" ..
|
||||
-- home_dir .. "\\\" ] ; then exit 0 ; else exit 1 ; fi ;\"") then
|
||||
return home_dir
|
||||
end
|
||||
end
|
||||
|
@ -78,10 +76,6 @@ local function check_directory(directory)
|
|||
-- Assure that we return exactly one trailing slash
|
||||
directory = string.gsub(directory, '/*$', '/')
|
||||
|
||||
-- If we use single quotes, we only need to deal with single quotes - (I
|
||||
-- promise that's meaningful if you think about it from a bash perspective)
|
||||
local bash_esc_dir = string.gsub(directory, "'", "'\\'\\\\\\'\\''")
|
||||
|
||||
if gears.filesystem.dir_writable(directory) then
|
||||
return directory
|
||||
else
|
||||
|
@ -252,7 +246,7 @@ end
|
|||
-- cases. It did not seem appropriate to make that change as a part of the pull
|
||||
-- request that was creating the screenshot API, as it would clutter and
|
||||
-- confuse the change.
|
||||
function show_frame(ss, geo)
|
||||
local function show_frame(ss, geo)
|
||||
|
||||
if not geo then
|
||||
if ss._private.frame then
|
||||
|
@ -385,7 +379,7 @@ end
|
|||
|
||||
-- Internal function to be passed as the default callback upon completion of
|
||||
-- the mousgrabber for the snipper if the user does not pass one.
|
||||
function default_on_success_cb(ss)
|
||||
local function default_on_success_cb(ss)
|
||||
ss:save()
|
||||
end
|
||||
|
||||
|
@ -498,9 +492,8 @@ local default_method_name = "root"
|
|||
-- @treturn boolean true or false depending on success
|
||||
function module.set_defaults(args)
|
||||
|
||||
local tmp
|
||||
|
||||
tmp = check_directory(args.directory)
|
||||
local args = (type(args) == "table" and args) or {}
|
||||
local tmp = check_directory(args.directory)
|
||||
|
||||
if tmp then
|
||||
module_default_directory = tmp
|
||||
|
|
|
@ -189,13 +189,40 @@ table.insert(steps, function()
|
|||
return true
|
||||
end)
|
||||
|
||||
--Check the root window with awful.screenshot.root() method
|
||||
table.insert(steps, function()
|
||||
|
||||
--Make sure client from last test is gone
|
||||
if #client.get() ~= 0 then return end
|
||||
|
||||
awful.screenshot.set_defaults({})
|
||||
awful.screenshot.set_defaults({directory = "/dev/null", prefix = "Screenshot-", frame_color = "#000000"})
|
||||
awful.screenshot.set_defaults({directory = "~/"})
|
||||
awful.screenshot.set_defaults({directory = fake_screenshot_dir})
|
||||
|
||||
local ss = awful.screenshot.root()
|
||||
local name_prfx = string.gsub(fake_screenshot_dir, "/*$", "/") .. "Screenshot-"
|
||||
|
||||
local f, l = string.find(ss.filepath, name_prfx)
|
||||
if f ~= 1 then
|
||||
print("First if: " .. ss.filepath .. " : " .. name_prfx)
|
||||
return false
|
||||
end
|
||||
|
||||
name_prfx = string.gsub(fake_screenshot_dir, "/*$", "/") .. "MyShot.png"
|
||||
ss.filepath = name_prfx
|
||||
|
||||
if ss.filepath ~= name_prfx then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end)
|
||||
|
||||
--Check the root window with awful.screenshot.root() method
|
||||
table.insert(steps, function()
|
||||
local root_width, root_height = root.size()
|
||||
local ss = awful.screenshot.root({directory = fake_screenshot_dir})
|
||||
local ss = awful.screenshot.root()
|
||||
local img = ss.surface
|
||||
|
||||
if get_pixel(img, 100, 100) ~= "#00ff00" then return end
|
||||
|
@ -218,7 +245,7 @@ table.insert(steps, function()
|
|||
for s in screen do
|
||||
|
||||
local geo = s.geometry
|
||||
local ss = awful.screenshot.screen({screen = s, directory = fake_screenshot_dir})
|
||||
local ss = awful.screenshot.screen({screen = s})
|
||||
local img = ss.surface
|
||||
|
||||
assert(get_pixel(img, 4, 4) == "#ff0000")
|
||||
|
@ -242,7 +269,7 @@ table.insert(steps, function()
|
|||
|
||||
local c = client.get()[1]
|
||||
local geo = c:geometry()
|
||||
local ss = awful.screenshot.client({client = c, directory = fake_screenshot_dir})
|
||||
local ss = awful.screenshot.client({client = c})
|
||||
local img = ss.surface
|
||||
|
||||
if get_pixel(img, math.floor(geo.width / 2), math.floor(geo.height / 2)) ~= "#0000ff" then
|
||||
|
@ -280,7 +307,7 @@ table.insert(steps, function()
|
|||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
awful.screenshot.snipper({directory = fake_screenshot_dir, on_success_cb = snipper_cb})
|
||||
awful.screenshot.snipper({on_success_cb = snipper_cb})
|
||||
return true
|
||||
end)
|
||||
|
||||
|
@ -345,10 +372,93 @@ table.insert(steps, function()
|
|||
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
|
||||
local ss = awful.screenshot.snip({geometry = {x = 100, y = 100, width = 100, height = 100},
|
||||
directory = fake_screenshot_dir})
|
||||
--Check the snipper collapse and cancel
|
||||
table.insert(steps, function()
|
||||
--Make sure client from last test is gone
|
||||
if #client.get() ~= 0 then return end
|
||||
--Ensure mousegrabber is satisfied
|
||||
root.fake_input("button_press",1)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
root.fake_input("button_release",1)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Ensure prior mouse presses go through
|
||||
local t0 = os.time()
|
||||
while os.time() - t0 < 1 do end
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
awful.screenshot.snipper({on_success_cb = snipper_cb})
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
mouse.coords {x = 110, y = 110}
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
root.fake_input("button_press",1)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
root.fake_input("button_release",1)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
mouse.coords {x = 150, y = 150}
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Ensure prior mouse presses and movements go through
|
||||
local t0 = os.time()
|
||||
while os.time() - t0 < 1 do end
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Cause a rectangle collapse
|
||||
mouse.coords {x = 150, y = 110}
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Ensure prior mouse presses and movements go through
|
||||
local t0 = os.time()
|
||||
while os.time() - t0 < 1 do end
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Cancel snipper tool
|
||||
root.fake_input("button_press",3)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
root.fake_input("button_release",3)
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
--Ensure prior mouse presses go through and callback runs
|
||||
local t0 = os.time()
|
||||
while os.time() - t0 < 1 do end
|
||||
return true
|
||||
end)
|
||||
|
||||
table.insert(steps, function()
|
||||
local ss = awful.screenshot.snip({geometry = {x = 100, y = 100, width = 100, height = 100}})
|
||||
local img = ss.surface
|
||||
if get_pixel(img, 10, 10) == "#00ff00" then
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue