2017-06-14 17:32:16 +00:00
|
|
|
describe("AutoFrontlight widget tests", function()
|
2017-07-28 14:48:19 +00:00
|
|
|
local Device, PowerD, MockTime, class, AutoFrontlight, UIManager
|
2017-06-14 17:32:16 +00:00
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2017-06-14 17:32:16 +00:00
|
|
|
|
|
|
|
MockTime = require("mock_time")
|
|
|
|
MockTime:install()
|
|
|
|
|
|
|
|
PowerD = require("device/generic/powerd"):new{
|
|
|
|
frontlight = 0,
|
|
|
|
}
|
|
|
|
PowerD.frontlightIntensityHW = function()
|
|
|
|
return 2
|
|
|
|
end
|
|
|
|
PowerD.setIntensityHW = function(self, intensity)
|
|
|
|
self.frontlight = intensity
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
MockTime:uninstall()
|
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2017-06-14 17:32:16 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
Device = require("device")
|
|
|
|
Device.isKindle = function() return true end
|
|
|
|
Device.model = "KindleVoyage"
|
|
|
|
Device.brightness = 0
|
|
|
|
Device.hasFrontlight = function() return true end
|
2023-12-24 16:15:30 +00:00
|
|
|
Device.hasLightSensor = function() return true end
|
2017-06-14 17:32:16 +00:00
|
|
|
Device.powerd = PowerD:new{
|
|
|
|
device = Device,
|
|
|
|
}
|
|
|
|
Device.ambientBrightnessLevel = function(self)
|
|
|
|
return self.brightness
|
|
|
|
end
|
|
|
|
Device.input.waitEvent = function() end
|
|
|
|
require("luasettings"):
|
|
|
|
open(require("datastorage"):getSettingsDir() .. "/autofrontlight.lua"):
|
2021-03-06 21:44:18 +00:00
|
|
|
saveSetting("enable", true):
|
2017-06-14 17:32:16 +00:00
|
|
|
close()
|
2017-07-28 14:48:19 +00:00
|
|
|
|
|
|
|
UIManager = require("ui/uimanager")
|
2022-10-27 20:08:38 +00:00
|
|
|
UIManager:setRunForeverMode()
|
2017-07-28 14:48:19 +00:00
|
|
|
|
|
|
|
requireBackgroundRunner()
|
|
|
|
class = dofile("plugins/autofrontlight.koplugin/main.lua")
|
2020-08-31 14:48:29 +00:00
|
|
|
notifyBackgroundJobsUpdated()
|
2017-07-28 14:48:19 +00:00
|
|
|
|
|
|
|
-- Ensure the background runner has succeeded set the job.insert_sec.
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
2017-06-24 07:55:31 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
AutoFrontlight:deprecateLastTask()
|
|
|
|
-- Ensure the scheduled task from this test case won't impact others.
|
|
|
|
MockTime:increase(2)
|
2017-07-28 14:48:19 +00:00
|
|
|
UIManager:handleInput()
|
2017-06-24 07:55:31 +00:00
|
|
|
AutoFrontlight = nil
|
2017-07-28 14:48:19 +00:00
|
|
|
stopBackgroundRunner()
|
2017-06-24 07:55:31 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should automatically turn on or off frontlight", function()
|
|
|
|
AutoFrontlight = class:new()
|
2017-06-14 17:32:16 +00:00
|
|
|
Device.brightness = 3
|
2017-06-24 07:55:31 +00:00
|
|
|
MockTime:increase(2)
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 0
|
2017-06-24 07:55:31 +00:00
|
|
|
MockTime:increase(2)
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 1
|
2017-06-24 07:55:31 +00:00
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 2
|
|
|
|
MockTime:increase(2)
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
2017-06-24 07:55:31 +00:00
|
|
|
Device.brightness = 3
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 4
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 3
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
2017-06-14 17:32:16 +00:00
|
|
|
Device.brightness = 2
|
2017-06-24 07:55:31 +00:00
|
|
|
MockTime:increase(2)
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
2017-06-24 07:55:31 +00:00
|
|
|
Device.brightness = 1
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
Device.brightness = 0
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should turn on frontlight at the begining", function()
|
2019-04-08 21:05:08 +00:00
|
|
|
Device:getPowerDevice():turnOffFrontlight()
|
2017-06-24 07:55:31 +00:00
|
|
|
Device.brightness = 0
|
|
|
|
AutoFrontlight = class:new()
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should turn off frontlight at the begining", function()
|
2019-04-08 21:05:08 +00:00
|
|
|
Device:getPowerDevice():turnOnFrontlight()
|
2017-06-14 17:32:16 +00:00
|
|
|
Device.brightness = 3
|
2017-06-24 07:55:31 +00:00
|
|
|
AutoFrontlight = class:new()
|
|
|
|
MockTime:increase(2)
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(0, Device:getPowerDevice().frontlight)
|
|
|
|
end)
|
2017-06-24 07:55:31 +00:00
|
|
|
|
|
|
|
it("should handle configuration update", function()
|
2019-04-08 21:05:08 +00:00
|
|
|
Device:getPowerDevice():turnOffFrontlight()
|
2017-06-24 07:55:31 +00:00
|
|
|
Device.brightness = 0
|
|
|
|
AutoFrontlight = class:new()
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
AutoFrontlight:flipSetting()
|
|
|
|
Device.brightness = 3
|
|
|
|
MockTime:increase(2)
|
|
|
|
UIManager:handleInput()
|
|
|
|
assert.are.equal(2, Device:getPowerDevice().frontlight)
|
|
|
|
end)
|
2017-06-14 17:32:16 +00:00
|
|
|
end)
|