mirror of https://github.com/koreader/koreader
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.3 KiB
Lua
70 lines
2.3 KiB
Lua
8 years ago
|
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()
|
||
|
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()
|
||
|
clearState()
|
||
|
G_reader_settings:saveSetting("wifi_was_on", true)
|
||
|
local network_manager = require("ui/network/manager")
|
||
|
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()
|
||
|
clearState()
|
||
|
G_reader_settings:saveSetting("wifi_was_on", false)
|
||
|
local network_manager = require("ui/network/manager")
|
||
|
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)
|
||
|
end)
|