2016-02-22 01:46:19 +00:00
|
|
|
describe("Readerpaging module", function()
|
|
|
|
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
2023-08-13 11:30:54 +00:00
|
|
|
local readerui, UIManager, Event, DocumentRegistry, ReaderUI, Screen
|
|
|
|
local paging
|
2016-02-22 01:46:19 +00:00
|
|
|
|
2016-08-12 06:05:18 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
UIManager = require("ui/uimanager")
|
2022-11-20 04:33:44 +00:00
|
|
|
stub(UIManager, "getNthTopWidget")
|
|
|
|
UIManager.getNthTopWidget.returns({})
|
2016-08-12 06:05:18 +00:00
|
|
|
Event = require("ui/event")
|
2016-11-24 02:48:00 +00:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2016-08-12 06:05:18 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
|
2023-08-13 11:30:54 +00:00
|
|
|
describe("Page mode", function()
|
|
|
|
setup(function()
|
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-11-24 02:48:00 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
2016-02-22 01:46:19 +00:00
|
|
|
}
|
2023-08-13 11:30:54 +00:00
|
|
|
paging = readerui.paging
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
2023-08-13 11:30:54 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2020-12-19 04:32:23 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
|
2016-08-12 06:05:18 +00:00
|
|
|
it("should emit EndOfBook event at the end", function()
|
2023-08-13 11:30:54 +00:00
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
UIManager:nextTick(function()
|
2023-08-13 11:30:54 +00:00
|
|
|
UIManager:close(readerui)
|
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
2021-05-18 18:54:54 +00:00
|
|
|
end)
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:run()
|
2016-07-18 06:12:53 +00:00
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
2016-02-22 01:46:19 +00:00
|
|
|
readerui.zooming:setZoomMode("pageheight")
|
2016-03-27 22:39:47 +00:00
|
|
|
paging:onGotoPage(readerui.document:getPageCount())
|
2023-08-13 11:30:54 +00:00
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
2019-03-01 15:05:03 +00:00
|
|
|
paging:onGotoViewRel(1)
|
2023-08-13 11:30:54 +00:00
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
|
|
|
UIManager:quit()
|
2016-07-18 06:12:53 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
|
|
|
|
2023-08-13 11:30:54 +00:00
|
|
|
describe("Scroll mode", function()
|
2016-02-22 01:46:19 +00:00
|
|
|
setup(function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local purgeDir = require("ffi/util").purgeDir
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
purgeDir(DocSettings:getSidecarDir(sample_pdf))
|
|
|
|
os.remove(DocSettings:getHistoryPath(sample_pdf))
|
2023-08-13 11:30:54 +00:00
|
|
|
|
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-11-24 02:48:00 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
2016-02-22 01:46:19 +00:00
|
|
|
}
|
2023-08-13 11:30:54 +00:00
|
|
|
paging = readerui.paging
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
2023-08-13 11:30:54 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2020-12-19 04:32:23 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
|
|
|
|
it("should emit EndOfBook event at the end", function()
|
2023-08-13 11:30:54 +00:00
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
UIManager:nextTick(function()
|
2023-08-13 11:30:54 +00:00
|
|
|
UIManager:close(readerui)
|
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
2021-05-18 18:54:54 +00:00
|
|
|
end)
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:run()
|
|
|
|
paging.page_positions = {}
|
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
2016-03-27 22:39:47 +00:00
|
|
|
paging:onGotoPage(readerui.document:getPageCount())
|
2016-02-22 01:46:19 +00:00
|
|
|
readerui.zooming:setZoomMode("pageheight")
|
2023-08-13 11:30:54 +00:00
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
2019-03-01 15:05:03 +00:00
|
|
|
paging:onGotoViewRel(1)
|
|
|
|
paging:onGotoViewRel(1)
|
2023-08-13 11:30:54 +00:00
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
|
|
|
UIManager:quit()
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
2016-11-24 02:48:00 +00:00
|
|
|
|
2023-08-13 11:30:54 +00:00
|
|
|
it("should scroll backward on the first page without crash", function()
|
|
|
|
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
|
|
|
|
-- Unsafe second // ReaderUI instance!
|
|
|
|
local tmp_readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-11-24 02:48:00 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_djvu),
|
|
|
|
}
|
2023-08-13 11:30:54 +00:00
|
|
|
tmp_readerui.paging:onScrollPanRel(-100)
|
|
|
|
tmp_readerui:closeDocument()
|
|
|
|
tmp_readerui:onClose()
|
|
|
|
-- Restore the ref to the original ReaderUI instance
|
|
|
|
ReaderUI.instance = readerui
|
2016-11-24 02:48:00 +00:00
|
|
|
end)
|
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
it("should scroll forward on the last page without crash", function()
|
2023-08-13 11:30:54 +00:00
|
|
|
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
|
|
|
|
-- Unsafe second // ReaderUI instance!
|
|
|
|
local tmp_readerui = ReaderUI:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
document = DocumentRegistry:openDocument(sample_djvu),
|
|
|
|
}
|
|
|
|
paging = tmp_readerui.paging
|
|
|
|
paging:onGotoPage(tmp_readerui.document:getPageCount())
|
2016-11-24 02:48:00 +00:00
|
|
|
paging:onScrollPanRel(120)
|
|
|
|
paging:onScrollPanRel(-1)
|
|
|
|
paging:onScrollPanRel(120)
|
2023-08-13 11:30:54 +00:00
|
|
|
tmp_readerui:closeDocument()
|
|
|
|
tmp_readerui:onClose()
|
|
|
|
-- Restore the ref to the original ReaderUI instance
|
|
|
|
ReaderUI.instance = readerui
|
2016-11-24 02:48:00 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
|
|
|
end)
|