feat: optimize reader caching and document formats

This commit is contained in:
shenlei
2026-07-20 17:22:06 +09:00
parent 52f803e8db
commit 68d9363f0a
35 changed files with 3771 additions and 2229 deletions
@@ -58,6 +58,46 @@ final class PDFDrawingModeTests: XCTestCase {
)
}
///
func testZoomedPageDragsOnlyWhenDrawingToolIsDeselected() {
app.launchAndOpenSampleBook(bookTitleQuery: "英汉大词典", displayType: "pagecurl")
app.waitForReader()
let content = app.otherElements[IDs.readerContent].firstMatch
XCTAssertTrue(content.waitForExistence(timeout: 8), "PDF 阅读页面未出现")
app.showReaderChromeIfNeeded(requiredButtonIDs: [IDs.pdfDrawing])
let drawing = app.buttons[IDs.pdfDrawing]
XCTAssertTrue(drawing.waitForExistence(timeout: 5), "画笔入口未出现")
drawing.tap()
let pen = app.buttons[IDs.pdfDrawingPen]
XCTAssertTrue(pen.waitForExistence(timeout: 5), "画笔工具未出现")
//
content.pinch(withScale: 2.5, velocity: 1)
RunLoop.current.run(until: Date().addingTimeInterval(1.0))
let zoomedFrame = content.frame
XCTAssertGreaterThan(zoomedFrame.width, app.windows.firstMatch.frame.width * 1.2, "画笔面板打开时无法双指放大页面")
//
let start = content.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let end = content.coordinate(withNormalizedOffset: CGVector(dx: 0.3, dy: 0.3))
start.press(forDuration: 0.05, thenDragTo: end)
RunLoop.current.run(until: Date().addingTimeInterval(0.8))
let draggedFrame = content.frame
XCTAssertNotEqual(draggedFrame.origin, zoomedFrame.origin, "未选中工具时,放大页面无法单指拖动")
//
pen.tap()
let frameBeforeStroke = content.frame
let strokeStart = content.coordinate(withNormalizedOffset: CGVector(dx: 0.45, dy: 0.45))
let strokeEnd = content.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.6))
strokeStart.press(forDuration: 0.05, thenDragTo: strokeEnd)
RunLoop.current.run(until: Date().addingTimeInterval(0.8))
XCTAssertEqual(content.frame.origin, frameBeforeStroke.origin, "选中画笔后,单指仍拖动了放大页面而不是绘制")
}
private func waitForLandscapeLayout() -> Bool {
let deadline = Date().addingTimeInterval(8)
while Date() < deadline {
@@ -69,8 +109,12 @@ final class PDFDrawingModeTests: XCTestCase {
}
private func scrollToAnotherPage(_ content: XCUIElement, from page: Int) -> Bool {
let window = app.windows.firstMatch
for _ in 0..<5 {
content.swipeUp()
//
let start = window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.35))
let end = window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.05))
start.press(forDuration: 0.05, thenDragTo: end, withVelocity: .fast, thenHoldForDuration: 0)
let deadline = Date().addingTimeInterval(1.5)
while Date() < deadline {
if let current = app.currentDemoReaderState()?.page, current != page { return true }