2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00
koreader/spec/unit/network_manager_spec.lua
NiLuJe 011370882f [chore] Some Wi-Fi tweaks (#4564)
* On Kobo, kill WiFi on startup if we detect an inconsistent state...

Untested, not terribly pretty.

The other solution is to slow down the Wi-Fi meny by doing the same
check for the "Wi-Fi connection" checkbox as in the later wifi_status
one...

* Don't enable auto_restore_wifi by default

It's liable to silently murder batteries for no good reason, given that
we prompt to enable WiFi by default when needed, and we otherwise have
no actual need to keep WiFi on in the background.

re #2215 (in particular, this directly contradicts @houqp in
https://github.com/koreader/koreader/pull/2215#discussion_r74696133 ;)).
2019-02-08 22:29:11 +01:00

78 lines
2.6 KiB
Lua

describe("network_manager module", function()
local Device
local turn_on_wifi_called
local turn_off_wifi_called
local obtain_ip_called
local release_ip_called
local function clearState()
G_reader_settings:saveSetting("auto_restore_wifi", true)
turn_on_wifi_called = 0
turn_off_wifi_called = 0
obtain_ip_called = 0
release_ip_called = 0
end
setup(function()
require("commonrequire")
Device = require("device")
function Device:initNetworkManager(NetworkMgr)
function NetworkMgr:turnOnWifi(callback)
turn_on_wifi_called = turn_on_wifi_called + 1
if callback then
callback()
end
end
function NetworkMgr:turnOffWifi(callback)
turn_off_wifi_called = turn_off_wifi_called + 1
if callback then
callback()
end
end
function NetworkMgr:obtainIP(callback)
obtain_ip_called = obtain_ip_called + 1
if callback then
callback()
end
end
function NetworkMgr:releaseIP(callback)
release_ip_called = release_ip_called + 1
if callback then
callback()
end
end
function NetworkMgr:restoreWifiAsync()
self:turnOnWifi()
self:obtainIP()
end
end
end)
it("should restore wifi in init if wifi was on", function()
package.loaded["ui/network/manager"] = nil
clearState()
G_reader_settings:saveSetting("wifi_was_on", true)
local network_manager = require("ui/network/manager") --luacheck: ignore
assert.is.same(turn_on_wifi_called, 1)
assert.is.same(turn_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 1)
assert.is.same(release_ip_called, 0)
end)
it("should not restore wifi in init if wifi was off", function()
package.loaded["ui/network/manager"] = nil
clearState()
G_reader_settings:saveSetting("wifi_was_on", false)
local network_manager = require("ui/network/manager") --luacheck: ignore
assert.is.same(turn_on_wifi_called, 0)
assert.is.same(turn_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 0)
assert.is.same(release_ip_called, 0)
end)
teardown(function()
function Device:initNetworkManager() end
package.loaded["ui/network/manager"] = nil
end)
end)