2019-09-12 12:15:08 +00:00
|
|
|
describe("AutoSuspend", function()
|
2017-06-23 17:04:11 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2017-06-23 17:04:11 +00:00
|
|
|
end)
|
|
|
|
|
2019-09-12 12:15:08 +00:00
|
|
|
describe("suspend", function()
|
|
|
|
before_each(function()
|
|
|
|
local Device = require("device")
|
|
|
|
stub(Device, "isKobo")
|
|
|
|
Device.isKobo.returns(true)
|
|
|
|
Device.input.waitEvent = function() end
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(UIManager, "suspend")
|
|
|
|
UIManager._run_forever = true
|
|
|
|
G_reader_settings:saveSetting("auto_suspend_timeout_seconds", 10)
|
|
|
|
require("mock_time"):install()
|
|
|
|
end)
|
2017-06-23 17:04:11 +00:00
|
|
|
|
2019-09-12 12:15:08 +00:00
|
|
|
after_each(function()
|
|
|
|
require("device").isKobo:revert()
|
|
|
|
require("ui/uimanager").suspend:revert()
|
|
|
|
G_reader_settings:delSetting("auto_suspend_timeout_seconds")
|
|
|
|
require("mock_time"):uninstall()
|
|
|
|
end)
|
2017-06-23 17:04:11 +00:00
|
|
|
|
2019-09-12 12:15:08 +00:00
|
|
|
it("should be able to execute suspend when timing out", function()
|
|
|
|
local mock_time = require("mock_time")
|
|
|
|
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
|
|
|
|
local widget = widget_class:new() --luacheck: ignore
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
mock_time:increase(5)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.suspend).was.called(0)
|
|
|
|
mock_time:increase(6)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.suspend).was.called(1)
|
|
|
|
mock_time:uninstall()
|
|
|
|
end)
|
2017-06-23 17:04:11 +00:00
|
|
|
|
2019-09-12 12:15:08 +00:00
|
|
|
it("should be able to deprecate last task", function()
|
|
|
|
local mock_time = require("mock_time")
|
|
|
|
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
|
|
|
|
local widget = widget_class:new()
|
|
|
|
mock_time:increase(5)
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.suspend).was.called(0)
|
|
|
|
widget:onInputEvent()
|
|
|
|
widget:onSuspend()
|
|
|
|
widget:onResume()
|
|
|
|
mock_time:increase(6)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.suspend).was.called(0)
|
|
|
|
mock_time:increase(5)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.suspend).was.called(1)
|
|
|
|
mock_time:uninstall()
|
|
|
|
end)
|
2017-06-23 17:04:11 +00:00
|
|
|
end)
|
|
|
|
|
2019-09-12 12:15:08 +00:00
|
|
|
describe("shutdown", function()
|
|
|
|
--- @todo duplicate with above, elegant way to DRY?
|
|
|
|
before_each(function()
|
|
|
|
local Device = require("device")
|
|
|
|
stub(Device, "isKobo")
|
|
|
|
Device.isKobo.returns(true)
|
|
|
|
stub(Device, "canPowerOff")
|
|
|
|
Device.canPowerOff.returns(true)
|
|
|
|
Device.input.waitEvent = function() end
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(UIManager, "poweroff_action")
|
|
|
|
UIManager._run_forever = true
|
|
|
|
G_reader_settings:saveSetting("autoshutdown_timeout_seconds", 10)
|
|
|
|
require("mock_time"):install()
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
require("device").isKobo:revert()
|
|
|
|
require("ui/uimanager").poweroff_action:revert()
|
|
|
|
G_reader_settings:delSetting("autoshutdown_timeout_seconds")
|
|
|
|
require("mock_time"):uninstall()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should be able to execute suspend when timing out", function()
|
|
|
|
local mock_time = require("mock_time")
|
|
|
|
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
|
|
|
|
local widget = widget_class:new() --luacheck: ignore
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
mock_time:increase(5)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.poweroff_action).was.called(0)
|
|
|
|
mock_time:increase(6)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.poweroff_action).was.called(1)
|
|
|
|
mock_time:uninstall()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should be able to deprecate last task", function()
|
|
|
|
local mock_time = require("mock_time")
|
|
|
|
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
|
|
|
|
local widget = widget_class:new()
|
|
|
|
mock_time:increase(5)
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.poweroff_action).was.called(0)
|
|
|
|
widget:onInputEvent()
|
|
|
|
widget:onSuspend()
|
|
|
|
widget:onResume()
|
|
|
|
mock_time:increase(6)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.poweroff_action).was.called(0)
|
|
|
|
mock_time:increase(5)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.stub(UIManager.poweroff_action).was.called(1)
|
|
|
|
mock_time:uninstall()
|
|
|
|
end)
|
2017-06-23 17:04:11 +00:00
|
|
|
end)
|
|
|
|
end)
|