- 新增 RDEPUBReaderSearchCoordinator 与 RDEPUBSelectionState 管理搜索和选中状态 - 新增 BookmarkChromeStateTests、NavigationBackwardTests、SelectionAnnotateTests 等 UI 测试 - 新增多个边界测试 epub 样本(损坏结构、空归档、缺失文件、流式外链验证) - 重构阅读器 chrome 状态管理,统一 tool bar 与 search bar 交互 - 优化大书分页缓存策略(RDEPUBChapterSummaryDiskCache、RDEPUBPageCountCache) - 移除废弃的 RDEPUBLocationConverter 和 RDEPUBPageBreakPolicy - 更新 epub-bridge.js 与 JS bridge 通信协议 - 全面更新现有 UI 测试以适配新的 helper 和状态管理
151 lines
5.9 KiB
Swift
151 lines
5.9 KiB
Swift
import XCTest
|
|
|
|
final class ErrorAndEdgeCaseTests: XCTestCase {
|
|
private let app = XCUIApplication()
|
|
|
|
override func setUpWithError() throws {
|
|
continueAfterFailure = false
|
|
}
|
|
|
|
func testVerticalScrollSwipeNavigation() throws {
|
|
app.launchAndOpenSampleBook(displayType: "verticalscroll")
|
|
app.waitForReader(timeout: 12)
|
|
|
|
let paging = app.collectionViews[IDs.readerPaging]
|
|
if paging.waitForExistence(timeout: 5) { paging.swipeUp() }
|
|
|
|
app.waitForDemoReaderState(timeout: 5, description: "reader=opened") { $0.isOpened }
|
|
}
|
|
|
|
func testOpenAndCloseMultipleTimes() throws {
|
|
for iteration in 1...3 {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
app.showReaderChromeIfNeeded()
|
|
let backButton = app.buttons[IDs.readerBack]
|
|
XCTAssertTrue(backButton.waitForExistence(timeout: 3), "返回按钮不存在")
|
|
backButton.tap()
|
|
|
|
let booksTable = app.tables[IDs.demoBooksTable]
|
|
XCTAssertTrue(booksTable.waitForExistence(timeout: 5), "书列表未出现")
|
|
}
|
|
}
|
|
|
|
func testRapidPageNavigation() throws {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
app.waitForReaderPage(1, timeout: 5)
|
|
|
|
let paging = app.collectionViews[IDs.readerPaging]
|
|
guard paging.waitForExistence(timeout: 5) else { throw XCTSkip("分页视图不存在") }
|
|
|
|
for _ in 1...5 { paging.swipeLeft() }
|
|
|
|
app.waitForDemoReaderState(timeout: 8, description: "reader=opened") { $0.isOpened }
|
|
}
|
|
|
|
func testSettingsPanelScrollReachesAllControls() throws {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
app.showReaderChromeIfNeeded()
|
|
app.buttons[IDs.readerSettings].tap()
|
|
|
|
let settingsScroll = app.scrollViews[IDs.settingsScroll]
|
|
XCTAssertTrue(settingsScroll.waitForExistence(timeout: 5), "设置面板未出现")
|
|
|
|
XCTAssertTrue(app.buttons[IDs.settingsFontIncrease].waitForExistence(timeout: 3))
|
|
XCTAssertTrue(app.buttons[IDs.settingsBrightness].waitForExistence(timeout: 3))
|
|
|
|
settingsScroll.swipeUp()
|
|
XCTAssertTrue(app.segmentedControls[IDs.settingsDisplayType].waitForExistence(timeout: 5))
|
|
|
|
settingsScroll.swipeUp()
|
|
XCTAssertTrue(app.buttons[IDs.settingsTheme(5)].waitForExistence(timeout: 5))
|
|
|
|
app.buttons[IDs.settingsDone].tap()
|
|
}
|
|
|
|
func testHTTPSExternalLinkShowsConfirmationAlert() throws {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
|
app.waitForReader(timeout: 20)
|
|
|
|
let httpsLink = externalLinkElement(named: "HTTPS Link")
|
|
guard httpsLink.waitForExistence(timeout: 8) else {
|
|
throw XCTSkip("HTTPS 外链元素未暴露")
|
|
}
|
|
httpsLink.tap()
|
|
|
|
XCTAssertTrue(app.alerts["打开外部链接"].waitForExistence(timeout: 5), "HTTPS 外链应弹出确认框")
|
|
XCTAssertTrue(app.buttons["打开"].waitForExistence(timeout: 2), "确认框应提供打开按钮")
|
|
app.buttons["取消"].tap()
|
|
}
|
|
|
|
func testMailtoExternalLinkBlockedByDefaultPolicy() throws {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
|
app.waitForReader(timeout: 20)
|
|
|
|
let mailtoLink = externalLinkElement(named: "Mailto Link")
|
|
guard mailtoLink.waitForExistence(timeout: 8) else {
|
|
throw XCTSkip("Mailto 外链元素未暴露")
|
|
}
|
|
mailtoLink.tap()
|
|
|
|
XCTAssertFalse(app.alerts["打开外部链接"].waitForExistence(timeout: 2), "默认策略下 mailto 不应弹出确认框")
|
|
let state = app.waitForDemoReaderState(timeout: 5, description: "mailto activation recorded") { state in
|
|
(state.externalLinks ?? 0) >= 1 && state.lastExternalURL != nil
|
|
}
|
|
XCTAssertTrue(state.lastExternalURL?.contains("mailto:test@example.com") == true, "应记录 mailto 激活但不继续打开")
|
|
}
|
|
|
|
func testLargeWebResourceUsesStreamingPath() throws {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
|
app.waitForReader(timeout: 20)
|
|
|
|
let state = app.waitForDemoReaderState(timeout: 15, description: "streamedResources>0") { state in
|
|
(state.streamedResources ?? 0) > 0
|
|
}
|
|
XCTAssertGreaterThan(state.streamedResources ?? 0, 0, "大资源应走流式传输路径")
|
|
}
|
|
|
|
func testInvalidEPUBReportsFailure() {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "损坏结构样本", resetsReaderState: true)
|
|
|
|
let state = app.waitForDemoReaderState(timeout: 12, description: "invalid epub failure") { state in
|
|
state.lastError != nil && state.lastError != "none"
|
|
}
|
|
XCTAssertNotEqual(state.lastError, "none")
|
|
}
|
|
|
|
func testEmptyArchiveReportsFailure() {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "空归档样本", resetsReaderState: true)
|
|
|
|
let state = app.waitForDemoReaderState(timeout: 12, description: "empty archive failure") { state in
|
|
state.lastError != nil && state.lastError != "none"
|
|
}
|
|
XCTAssertNotEqual(state.lastError, "none")
|
|
}
|
|
|
|
func testMissingSpineDocumentReportsFailure() {
|
|
app.launchAndOpenSampleBook(bookTitleQuery: "缺失文件样本", resetsReaderState: true)
|
|
|
|
let state = app.waitForDemoReaderState(timeout: 12, description: "missing file failure") { state in
|
|
state.lastError != nil && state.lastError != "none"
|
|
}
|
|
XCTAssertNotEqual(state.lastError, "none")
|
|
}
|
|
|
|
private func externalLinkElement(named label: String) -> XCUIElement {
|
|
let link = app.links[label]
|
|
if link.exists {
|
|
return link
|
|
}
|
|
let staticText = app.staticTexts[label]
|
|
if staticText.exists {
|
|
return staticText
|
|
}
|
|
return link
|
|
}
|
|
}
|