阅读器在多会话朗读、加密 EPUB 资源、并发打开同一本书和多 UserDefaults 容器等场景下,存在旧异步结果覆盖新状态、锁屏控制串会话、大型明文资源被误拒绝、解压半成品被复用及标注跨容器混用的风险;同时高亮、书签、搜索和设置面板的空状态与自动化可访问性入口不完整。\n\n本次为朗读会话引入代次和当前 utterance 校验,远程控制改为仅响应当前会话并按自身 token 清理;加密资源 provider 先判定是否实际返回解密数据,明文大资源继续流式读取;解压缓存串行化以避免并发复用未完成目录。书签与高亮迁移至受保护文件,按 UserDefaults 容器隔离命名空间,保留标准容器旧文件兼容并确保新副本成功落盘后才删除历史数据。\n\n同步调整缓存淘汰、FoundationModels 弱链接、搜索/标注/设置面板交互与 UI 测试,并更新 Pod 生成配置及 API、风险文档。已执行 git diff --check 和 ReadViewDemo Debug Simulator 构建,结果为 BUILD SUCCEEDED。
148 lines
5.7 KiB
Swift
148 lines
5.7 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 testSettingsPanelReachesAllControls() throws {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
app.showReaderChromeIfNeeded()
|
|
app.buttons[IDs.readerSettings].tap()
|
|
|
|
XCTAssertTrue(app.waitForSettingsPanel(), "设置面板未出现")
|
|
|
|
XCTAssertTrue(app.sliders[IDs.settingsFontSize].waitForExistence(timeout: 3))
|
|
XCTAssertTrue(app.sliders[IDs.settingsBrightness].waitForExistence(timeout: 3))
|
|
|
|
XCTAssertTrue(app.buttons[IDs.settingsDisplayType].waitForExistence(timeout: 5))
|
|
|
|
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
|
|
}
|
|
}
|