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
@@ -44,9 +44,9 @@ enum IDs {
/// The text layer is the precise, image-coordinate based interaction surface.
static let pdfTextLayer = "pdf.reader.text.layer"
static let pdfOCRStatus = "pdf.reader.ocr.status"
/// PDF EPUB 使//
/// PDF EPUB 使/线/
static let pdfSelectionMenuCopy = "复制"
static let pdfSelectionMenuHighlight = "高亮"
static let pdfSelectionMenuHighlight = "划线"
static let pdfSelectionMenuAnnotate = "注释"
static let pdfCopyStatus = "pdf.reader.copy.status"
@@ -119,7 +119,9 @@ final class HighlightsManagementTests: XCTestCase {
let deleteControl = highlightsTable.buttons["删除"].firstMatch
XCTAssertTrue(deleteControl.waitForExistence(timeout: 3), "编辑状态应显示删除控件")
deleteControl.tap()
app.buttons["删除"].lastMatch.tap()
//
let deleteButtons = app.buttons.matching(identifier: "删除")
deleteButtons.element(boundBy: max(0, deleteButtons.count - 1)).tap()
XCTAssertTrue(app.staticTexts[IDs.readerHighlightsEmptyLabel].waitForExistence(timeout: 5), "删除后应显示空状态")
}
@@ -153,7 +153,7 @@ final class LocationPersistenceTests: XCTestCase {
}
func testHighlightNavigationSurvivesFontChoiceChange() throws {
app.launchAndOpenSampleBook(resetsReaderState: true, pageNumber: 3)
app.launchAndOpenSampleBook(pageNumber: 3, resetsReaderState: true)
app.waitForReader(timeout: 12)
let initialState = app.waitForDemoReaderState(timeout: 8, description: "初始位于第 3 页") { state in
@@ -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 }