2016-09-12 18:49:48 +00:00
|
|
|
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()
|
2019-02-08 21:29:11 +00:00
|
|
|
G_reader_settings:saveSetting("auto_restore_wifi", true)
|
2016-09-12 18:49:48 +00:00
|
|
|
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
|
2023-07-12 00:42:16 +00:00
|
|
|
function Device:hasWifiRestore()
|
|
|
|
return true
|
|
|
|
end
|
2016-09-12 18:49:48 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should restore wifi in init if wifi was on", function()
|
2016-09-12 21:52:22 +00:00
|
|
|
package.loaded["ui/network/manager"] = nil
|
2016-09-12 18:49:48 +00:00
|
|
|
clearState()
|
|
|
|
G_reader_settings:saveSetting("wifi_was_on", true)
|
2017-08-08 20:35:40 +00:00
|
|
|
local network_manager = require("ui/network/manager") --luacheck: ignore
|
2016-09-12 18:49:48 +00:00
|
|
|
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()
|
2016-09-12 21:52:22 +00:00
|
|
|
package.loaded["ui/network/manager"] = nil
|
2016-09-12 18:49:48 +00:00
|
|
|
clearState()
|
|
|
|
G_reader_settings:saveSetting("wifi_was_on", false)
|
2017-08-08 20:35:40 +00:00
|
|
|
local network_manager = require("ui/network/manager") --luacheck: ignore
|
2016-09-12 18:49:48 +00:00
|
|
|
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)
|
2016-09-12 21:52:22 +00:00
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
function Device:initNetworkManager() end
|
2023-07-12 00:42:16 +00:00
|
|
|
function Device:hasWifiRestore() return false end
|
2016-09-12 21:52:22 +00:00
|
|
|
package.loaded["ui/network/manager"] = nil
|
|
|
|
end)
|
2016-09-12 18:49:48 +00:00
|
|
|
end)
|