vomebook commited on
Commit ·
479bcbd
1
Parent(s): 2834080
Restore compact toolbar and set browser filename early
Browse files- static/reader.css +12 -30
- static/reader.html +1 -1
- static/reader/core/reader-bindings.mjs +0 -10
- static/reader/core/reader-source.mjs +1 -2
- static/search/reader-navigation.js +15 -3
- tests/test_browser.py +1 -1
- tests/test_reader_close_responsiveness.py +37 -2
- tests/test_reader_navigation_host.py +29 -1
- tests/test_reader_performance.py +1 -1
- tests/test_reader_refactor.py +3 -3
- tests/test_reader_style.py +44 -70
static/reader.css
CHANGED
|
@@ -51,10 +51,6 @@ body {
|
|
| 51 |
font-size: 14px;
|
| 52 |
line-height: 18px;
|
| 53 |
}
|
| 54 |
-
.reader-heading strong:focus-visible {
|
| 55 |
-
outline: 2px solid var(--reader-focus-color);
|
| 56 |
-
outline-offset: 1px;
|
| 57 |
-
}
|
| 58 |
.reader-heading span,
|
| 59 |
.reader-path {
|
| 60 |
color: #9ba3aa;
|
|
@@ -1603,8 +1599,8 @@ body {
|
|
| 1603 |
/* Mobile toolbar and bookmark placement */
|
| 1604 |
@media (max-width: 600px) {
|
| 1605 |
:root {
|
| 1606 |
-
--reader-toolbar-height:
|
| 1607 |
-
--reader-popover-top:
|
| 1608 |
}
|
| 1609 |
.reader-panel {
|
| 1610 |
width: 85vw;
|
|
@@ -1658,15 +1654,9 @@ body {
|
|
| 1658 |
min-width: 42px;
|
| 1659 |
}
|
| 1660 |
.reader-toolbar {
|
| 1661 |
-
|
| 1662 |
-
grid-template-areas: "back heading history" "actions actions actions";
|
| 1663 |
-
grid-template-columns: 26px minmax(0, 1fr) 26px;
|
| 1664 |
-
grid-template-rows: 30px 30px;
|
| 1665 |
-
gap: 0 1px;
|
| 1666 |
padding: 2px 5px;
|
| 1667 |
}
|
| 1668 |
-
.reader-toolbar > #back { grid-area: back; }
|
| 1669 |
-
.reader-toolbar > #history { grid-area: history; }
|
| 1670 |
.reader-content {
|
| 1671 |
padding: 10px;
|
| 1672 |
}
|
|
@@ -1689,29 +1679,21 @@ body {
|
|
| 1689 |
max-width: 100%;
|
| 1690 |
}
|
| 1691 |
.reader-heading {
|
| 1692 |
-
grid-area: heading;
|
| 1693 |
-
min-width: 0;
|
| 1694 |
-
}
|
| 1695 |
-
.reader-heading strong {
|
| 1696 |
-
overflow-x: auto;
|
| 1697 |
-
overflow-y: hidden;
|
| 1698 |
-
text-overflow: clip;
|
| 1699 |
-
scrollbar-width: none;
|
| 1700 |
-
overscroll-behavior-x: contain;
|
| 1701 |
-
-webkit-overflow-scrolling: touch;
|
| 1702 |
-
user-select: text;
|
| 1703 |
-
-webkit-user-select: text;
|
| 1704 |
-
}
|
| 1705 |
-
.reader-heading strong::-webkit-scrollbar { display: none; }
|
| 1706 |
-
.reader-heading > :not(strong) {
|
| 1707 |
display: none;
|
| 1708 |
}
|
| 1709 |
.reader-actions {
|
| 1710 |
-
|
| 1711 |
-
justify-content: flex-
|
| 1712 |
gap: 1px;
|
| 1713 |
min-width: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1714 |
}
|
|
|
|
|
|
|
|
|
|
| 1715 |
.reader-actions .control-group {
|
| 1716 |
gap: 0;
|
| 1717 |
}
|
|
|
|
| 51 |
font-size: 14px;
|
| 52 |
line-height: 18px;
|
| 53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
.reader-heading span,
|
| 55 |
.reader-path {
|
| 56 |
color: #9ba3aa;
|
|
|
|
| 1599 |
/* Mobile toolbar and bookmark placement */
|
| 1600 |
@media (max-width: 600px) {
|
| 1601 |
:root {
|
| 1602 |
+
--reader-toolbar-height: 36px;
|
| 1603 |
+
--reader-popover-top: 78px;
|
| 1604 |
}
|
| 1605 |
.reader-panel {
|
| 1606 |
width: 85vw;
|
|
|
|
| 1654 |
min-width: 42px;
|
| 1655 |
}
|
| 1656 |
.reader-toolbar {
|
| 1657 |
+
gap: 1px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1658 |
padding: 2px 5px;
|
| 1659 |
}
|
|
|
|
|
|
|
| 1660 |
.reader-content {
|
| 1661 |
padding: 10px;
|
| 1662 |
}
|
|
|
|
| 1679 |
max-width: 100%;
|
| 1680 |
}
|
| 1681 |
.reader-heading {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1682 |
display: none;
|
| 1683 |
}
|
| 1684 |
.reader-actions {
|
| 1685 |
+
flex: 1;
|
| 1686 |
+
justify-content: flex-start;
|
| 1687 |
gap: 1px;
|
| 1688 |
min-width: 0;
|
| 1689 |
+
overflow-x: auto;
|
| 1690 |
+
scrollbar-width: none;
|
| 1691 |
+
overscroll-behavior-x: contain;
|
| 1692 |
+
-webkit-overflow-scrolling: touch;
|
| 1693 |
}
|
| 1694 |
+
.reader-actions::-webkit-scrollbar { display: none; }
|
| 1695 |
+
.reader-actions > * { flex-shrink: 0; }
|
| 1696 |
+
.reader-actions::before { content: ""; margin-left: auto; }
|
| 1697 |
.reader-actions .control-group {
|
| 1698 |
gap: 0;
|
| 1699 |
}
|
static/reader.html
CHANGED
|
@@ -70,7 +70,7 @@
|
|
| 70 |
</svg>
|
| 71 |
</button>
|
| 72 |
<div class="reader-heading">
|
| 73 |
-
<strong id="title"
|
| 74 |
<button id="reader-path" class="reader-path" type="button" hidden></button>
|
| 75 |
<span id="status">正在准备...</span>
|
| 76 |
</div>
|
|
|
|
| 70 |
</svg>
|
| 71 |
</button>
|
| 72 |
<div class="reader-heading">
|
| 73 |
+
<strong id="title">在线阅读</strong>
|
| 74 |
<button id="reader-path" class="reader-path" type="button" hidden></button>
|
| 75 |
<span id="status">正在准备...</span>
|
| 76 |
</div>
|
static/reader/core/reader-bindings.mjs
CHANGED
|
@@ -358,16 +358,6 @@ export function createReaderBindings(readerContext) {
|
|
| 358 |
readerContext.applyReaderTheme(readerContext.readerTheme, false, false);
|
| 359 |
|
| 360 |
readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);
|
| 361 |
-
document.querySelector("#title").addEventListener("keydown", (event) => {
|
| 362 |
-
const amount = event.currentTarget.clientWidth * 0.8;
|
| 363 |
-
if (event.currentTarget.scrollWidth <= event.currentTarget.clientWidth) return;
|
| 364 |
-
if (event.key === "ArrowRight") event.currentTarget.scrollLeft += amount;
|
| 365 |
-
else if (event.key === "ArrowLeft") event.currentTarget.scrollLeft -= amount;
|
| 366 |
-
else if (event.key === "Home") event.currentTarget.scrollLeft = 0;
|
| 367 |
-
else if (event.key === "End") event.currentTarget.scrollLeft = event.currentTarget.scrollWidth;
|
| 368 |
-
else return;
|
| 369 |
-
event.preventDefault();
|
| 370 |
-
});
|
| 371 |
document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);
|
| 372 |
let closing = false;
|
| 373 |
window.addEventListener("pageshow", event => { if (event.persisted) closing = false; });
|
|
|
|
| 358 |
readerContext.applyReaderTheme(readerContext.readerTheme, false, false);
|
| 359 |
|
| 360 |
readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);
|
| 362 |
let closing = false;
|
| 363 |
window.addEventListener("pageshow", event => { if (event.persisted) closing = false; });
|
static/reader/core/reader-source.mjs
CHANGED
|
@@ -126,8 +126,7 @@ export function createReaderSource(readerContext) {
|
|
| 126 |
heading.scrollLeft = 0;
|
| 127 |
}
|
| 128 |
heading.title = displayName;
|
| 129 |
-
|
| 130 |
-
document.title = `${displayName} - VoiceOfML Reader`;
|
| 131 |
if (readerContext.isReaderOverlayFrame())
|
| 132 |
window.parent.postMessage({ type: "voice-reader-title", title: document.title }, location.origin);
|
| 133 |
readerContext.applyReaderPathMetadata(readerContext.resolvedReaderData);
|
|
|
|
| 126 |
heading.scrollLeft = 0;
|
| 127 |
}
|
| 128 |
heading.title = displayName;
|
| 129 |
+
document.title = displayName;
|
|
|
|
| 130 |
if (readerContext.isReaderOverlayFrame())
|
| 131 |
window.parent.postMessage({ type: "voice-reader-title", title: document.title }, location.origin);
|
| 132 |
readerContext.applyReaderPathMetadata(readerContext.resolvedReaderData);
|
static/search/reader-navigation.js
CHANGED
|
@@ -53,8 +53,13 @@
|
|
| 53 |
function showTitle(target, title) {
|
| 54 |
if (frame !== target || titleDismissed || typeof title !== "string" || !title.trim()) return;
|
| 55 |
target.title = title;
|
|
|
|
| 56 |
document.title = title;
|
| 57 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
// A Reader closed while reading aloud stays alive, hidden, with a small
|
| 59 |
// player on the search page; reopening the same book reuses it.
|
| 60 |
let parked = null;
|
|
@@ -278,6 +283,9 @@
|
|
| 278 |
next.classList.add("reader-overlay-pending");
|
| 279 |
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
| 280 |
frame = next;
|
|
|
|
|
|
|
|
|
|
| 281 |
opening = document.createElement("div");
|
| 282 |
opening.className = "reader-overlay-opening";
|
| 283 |
const back = document.createElement("button");
|
|
@@ -306,16 +314,20 @@
|
|
| 306 |
};
|
| 307 |
window.addEventListener("message", onShell);
|
| 308 |
releaseOpening = () => { window.removeEventListener("message", onShell); releaseOpening = null; };
|
| 309 |
-
document.body.append(next, opening);
|
| 310 |
-
back.focus();
|
| 311 |
-
shade(next);
|
| 312 |
next.addEventListener(
|
| 313 |
"load",
|
| 314 |
() => {
|
| 315 |
if (next.contentDocument?.URL === "about:blank") return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
reveal();
|
| 317 |
}
|
| 318 |
);
|
|
|
|
|
|
|
|
|
|
| 319 |
return next;
|
| 320 |
}
|
| 321 |
function dismiss() {
|
|
|
|
| 53 |
function showTitle(target, title) {
|
| 54 |
if (frame !== target || titleDismissed || typeof title !== "string" || !title.trim()) return;
|
| 55 |
target.title = title;
|
| 56 |
+
if (document.title === title) return;
|
| 57 |
document.title = title;
|
| 58 |
}
|
| 59 |
+
function initialTitle(url) {
|
| 60 |
+
const title = url.searchParams.get("title");
|
| 61 |
+
return title && title.trim() ? title : "";
|
| 62 |
+
}
|
| 63 |
// A Reader closed while reading aloud stays alive, hidden, with a small
|
| 64 |
// player on the search page; reopening the same book reuses it.
|
| 65 |
let parked = null;
|
|
|
|
| 283 |
next.classList.add("reader-overlay-pending");
|
| 284 |
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
| 285 |
frame = next;
|
| 286 |
+
// The initial filename is known at the search click. Publish it before
|
| 287 |
+
// creating the history entry, instead of waiting for the iframe lookup.
|
| 288 |
+
showTitle(next, initialTitle(url));
|
| 289 |
opening = document.createElement("div");
|
| 290 |
opening.className = "reader-overlay-opening";
|
| 291 |
const back = document.createElement("button");
|
|
|
|
| 314 |
};
|
| 315 |
window.addEventListener("message", onShell);
|
| 316 |
releaseOpening = () => { window.removeEventListener("message", onShell); releaseOpening = null; };
|
|
|
|
|
|
|
|
|
|
| 317 |
next.addEventListener(
|
| 318 |
"load",
|
| 319 |
() => {
|
| 320 |
if (next.contentDocument?.URL === "about:blank") return;
|
| 321 |
+
try {
|
| 322 |
+
const title = next.contentDocument?.title;
|
| 323 |
+
if (title && title !== "VoiceOfML Reader") showTitle(next, title);
|
| 324 |
+
} catch (_) {}
|
| 325 |
reveal();
|
| 326 |
}
|
| 327 |
);
|
| 328 |
+
document.body.append(next, opening);
|
| 329 |
+
back.focus();
|
| 330 |
+
shade(next);
|
| 331 |
return next;
|
| 332 |
}
|
| 333 |
function dismiss() {
|
tests/test_browser.py
CHANGED
|
@@ -980,7 +980,7 @@ class BrowserInteractionTests(unittest.TestCase):
|
|
| 980 |
path = reader.locator('#reader-panel-path')
|
| 981 |
path.wait_for(state='visible')
|
| 982 |
self.assertEqual(path.locator('.reader-panel-folder').inner_text(), '所在目录:VOMEBOOK/一级目录/二级目录')
|
| 983 |
-
self.assertIn('测试', reader.locator('#title').
|
| 984 |
path.click()
|
| 985 |
page.locator('iframe.reader-overlay').wait_for(state='detached')
|
| 986 |
page.wait_for_function("STATE.browserPath==='一级目录/二级目录' && STATE.filterFolderSelfs.join()==='一级目录/二级目录'")
|
|
|
|
| 980 |
path = reader.locator('#reader-panel-path')
|
| 981 |
path.wait_for(state='visible')
|
| 982 |
self.assertEqual(path.locator('.reader-panel-folder').inner_text(), '所在目录:VOMEBOOK/一级目录/二级目录')
|
| 983 |
+
self.assertIn('测试', reader.locator('#title').text_content())
|
| 984 |
path.click()
|
| 985 |
page.locator('iframe.reader-overlay').wait_for(state='detached')
|
| 986 |
page.wait_for_function("STATE.browserPath==='一级目录/二级目录' && STATE.filterFolderSelfs.join()==='一级目录/二级目录'")
|
tests/test_reader_close_responsiveness.py
CHANGED
|
@@ -32,7 +32,7 @@ class ReaderCloseResponsivenessTests(unittest.TestCase):
|
|
| 32 |
self.page.evaluate('url => navigateToReader(url)', url)
|
| 33 |
frame = self.page.frame_locator('iframe.reader-overlay')
|
| 34 |
frame.locator('html[data-reader-phase="ready"]').wait_for()
|
| 35 |
-
self.page.wait_for_function("()=>document.title==='真实书名.txt
|
| 36 |
self.assertEqual(frame.locator('#title').inner_text(), '真实书名.txt')
|
| 37 |
self.assertEqual(frame.locator('body').evaluate('()=>document.title'), self.page.title())
|
| 38 |
self.page.evaluate('history.back()')
|
|
@@ -40,11 +40,46 @@ class ReaderCloseResponsivenessTests(unittest.TestCase):
|
|
| 40 |
self.assertEqual(self.page.title(), original)
|
| 41 |
self.page.evaluate('history.forward()')
|
| 42 |
frame.locator('html[data-reader-phase="ready"]').wait_for()
|
| 43 |
-
self.page.wait_for_function("()=>document.title==='真实书名.txt
|
| 44 |
frame.locator('#back').click()
|
| 45 |
self.page.locator('iframe.reader-overlay').wait_for(state='detached')
|
| 46 |
self.assertEqual(self.page.title(), original)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
def test_slow_old_write_cannot_delay_close_or_overwrite_last_position(self):
|
| 49 |
source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/responsive.txt'
|
| 50 |
self.page.route('**/api/reader-content**', lambda route: route.fulfill(
|
|
|
|
| 32 |
self.page.evaluate('url => navigateToReader(url)', url)
|
| 33 |
frame = self.page.frame_locator('iframe.reader-overlay')
|
| 34 |
frame.locator('html[data-reader-phase="ready"]').wait_for()
|
| 35 |
+
self.page.wait_for_function("()=>document.title==='真实书名.txt'")
|
| 36 |
self.assertEqual(frame.locator('#title').inner_text(), '真实书名.txt')
|
| 37 |
self.assertEqual(frame.locator('body').evaluate('()=>document.title'), self.page.title())
|
| 38 |
self.page.evaluate('history.back()')
|
|
|
|
| 40 |
self.assertEqual(self.page.title(), original)
|
| 41 |
self.page.evaluate('history.forward()')
|
| 42 |
frame.locator('html[data-reader-phase="ready"]').wait_for()
|
| 43 |
+
self.page.wait_for_function("()=>document.title==='真实书名.txt'")
|
| 44 |
frame.locator('#back').click()
|
| 45 |
self.page.locator('iframe.reader-overlay').wait_for(state='detached')
|
| 46 |
self.assertEqual(self.page.title(), original)
|
| 47 |
|
| 48 |
+
def test_html_filename_titles_search_history_before_embedded_reader_loads(self):
|
| 49 |
+
self.page.set_viewport_size({'width':390,'height':844})
|
| 50 |
+
source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/bb_204.html'
|
| 51 |
+
self.page.route('**/api/reader-content**', lambda route: route.fulfill(content_type='text/html',
|
| 52 |
+
body='<html><head><title>页面文章标题</title></head><body><h1>文章标题</h1><p>正文</p></body></html>'))
|
| 53 |
+
original = self.page.title()
|
| 54 |
+
url = '/static/reader.html?' + urlencode(dict(url=source, ext='html', title='bb_204.html'))
|
| 55 |
+
state=self.page.evaluate('''url=>{
|
| 56 |
+
const native=history.pushState;let atPush=null;
|
| 57 |
+
history.pushState=function(...args){atPush=document.title;return native.apply(this,args)};
|
| 58 |
+
try{navigateToReader(url);return {atPush,title:document.title}}finally{history.pushState=native}
|
| 59 |
+
}''',url)
|
| 60 |
+
self.assertEqual(state, dict(atPush='bb_204.html',title='bb_204.html'))
|
| 61 |
+
frame=self.page.frame_locator('iframe.reader-overlay')
|
| 62 |
+
frame.locator('html[data-reader-phase="ready"]').wait_for()
|
| 63 |
+
self.page.wait_for_function("()=>document.title==='bb_204.html'")
|
| 64 |
+
self.assertEqual(frame.locator('iframe.html-frame').content_frame.locator('h1').inner_text(),'文章标题')
|
| 65 |
+
self.assertEqual(frame.locator('#title').text_content(),'bb_204.html')
|
| 66 |
+
self.assertTrue(frame.locator('#title').is_hidden())
|
| 67 |
+
self.assertEqual(frame.locator('.reader-toolbar').bounding_box()['height'],36)
|
| 68 |
+
frame.locator('#back').click()
|
| 69 |
+
self.page.locator('iframe.reader-overlay').wait_for(state='detached')
|
| 70 |
+
self.assertEqual(self.page.title(),original)
|
| 71 |
+
|
| 72 |
+
def test_standalone_html_uses_original_filename_as_title(self):
|
| 73 |
+
self.page.set_viewport_size({'width':390,'height':844})
|
| 74 |
+
source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/bb_204.html'
|
| 75 |
+
self.page.route('**/api/reader-content**', lambda route: route.fulfill(content_type='text/html',
|
| 76 |
+
body='<h1>文章标题</h1><p>正文</p>'))
|
| 77 |
+
self.page.goto(self.fixture.origin+'/static/reader.html?'+urlencode(dict(url=source,ext='html',title='bb_204.html')))
|
| 78 |
+
self.page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")
|
| 79 |
+
self.assertEqual(self.page.title(),'bb_204.html')
|
| 80 |
+
self.assertTrue(self.page.locator('#title').is_hidden())
|
| 81 |
+
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'],36)
|
| 82 |
+
|
| 83 |
def test_slow_old_write_cannot_delay_close_or_overwrite_last_position(self):
|
| 84 |
source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/responsive.txt'
|
| 85 |
self.page.route('**/api/reader-content**', lambda route: route.fulfill(
|
tests/test_reader_navigation_host.py
CHANGED
|
@@ -102,9 +102,37 @@ process.stdout.write(stripBundledScripts(readFileSync('static/index.html','utf8'
|
|
| 102 |
}''')
|
| 103 |
self.assertEqual(result, dict(firstTitle='第一本.txt - VoiceOfML Reader',
|
| 104 |
frameTitle='第一本.txt - VoiceOfML Reader', rejected='第一本.txt - VoiceOfML Reader',
|
| 105 |
-
duringReplace='
|
| 106 |
dismissed='搜索原始标题', closed='搜索原始标题'))
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
def test_parked_reader_title_is_restored_only_when_reopened(self):
|
| 109 |
self.page.evaluate('navigateToReader("/static/reader.html?id=speech-title&ext=txt")')
|
| 110 |
self.page.frame_locator('.reader-overlay').locator('body').wait_for()
|
|
|
|
| 102 |
}''')
|
| 103 |
self.assertEqual(result, dict(firstTitle='第一本.txt - VoiceOfML Reader',
|
| 104 |
frameTitle='第一本.txt - VoiceOfML Reader', rejected='第一本.txt - VoiceOfML Reader',
|
| 105 |
+
duringReplace='second', stale='second', next='第二本.pdf - VoiceOfML Reader',
|
| 106 |
dismissed='搜索原始标题', closed='搜索原始标题'))
|
| 107 |
|
| 108 |
+
def test_filename_is_set_before_reader_history_entry(self):
|
| 109 |
+
result = self.page.evaluate('''() => {
|
| 110 |
+
const before=document.title, original=history.pushState, seen=[];
|
| 111 |
+
history.pushState=function(...args){seen.push({title:document.title,url:String(args[2])});return original.apply(this,args)};
|
| 112 |
+
try {
|
| 113 |
+
navigateToReader('/static/reader.html?id=sample&ext=html&title=bb_204.html');
|
| 114 |
+
const title=document.title, share=location.href;
|
| 115 |
+
closeReaderOverlay();
|
| 116 |
+
return {before,title,share,seen,restored:document.title};
|
| 117 |
+
} finally {history.pushState=original}
|
| 118 |
+
}''')
|
| 119 |
+
self.assertEqual(result['title'], 'bb_204.html')
|
| 120 |
+
self.assertEqual(result['seen'][0]['title'], 'bb_204.html')
|
| 121 |
+
self.assertIn('title=bb_204.html', result['share'])
|
| 122 |
+
self.assertEqual(result['restored'], result['before'])
|
| 123 |
+
|
| 124 |
+
def test_older_embedded_reader_still_refreshes_host_title_on_load(self):
|
| 125 |
+
self.page.unroute('**/static/reader.html?**')
|
| 126 |
+
self.page.evaluate("()=>caches.keys().then(keys=>Promise.all(keys.map(key=>caches.delete(key))))")
|
| 127 |
+
self.fixture.context.route('**/static/reader.html?**', lambda route: route.fulfill(content_type='text/html',
|
| 128 |
+
body='<title>旧阅读器文档.txt</title><body>reader</body>'))
|
| 129 |
+
before=self.page.title()
|
| 130 |
+
self.page.evaluate('navigateToReader("/static/reader.html?id=older&ext=txt")')
|
| 131 |
+
self.page.frame_locator('iframe.reader-overlay').locator('body').wait_for()
|
| 132 |
+
self.page.wait_for_function("()=>document.title==='旧阅读器文档.txt'")
|
| 133 |
+
self.page.evaluate('closeReaderOverlay()')
|
| 134 |
+
self.assertEqual(self.page.title(),before)
|
| 135 |
+
|
| 136 |
def test_parked_reader_title_is_restored_only_when_reopened(self):
|
| 137 |
self.page.evaluate('navigateToReader("/static/reader.html?id=speech-title&ext=txt")')
|
| 138 |
self.page.frame_locator('.reader-overlay').locator('body').wait_for()
|
tests/test_reader_performance.py
CHANGED
|
@@ -2344,7 +2344,7 @@ class ReaderPerformanceTest(unittest.TestCase):
|
|
| 2344 |
path=page.locator('#reader-panel-path')
|
| 2345 |
path.wait_for(state='visible')
|
| 2346 |
self.assertTrue(path.evaluate("n=>n.closest('#reader-panel-location').parentElement.id==='history-panel'"))
|
| 2347 |
-
self.assertTrue(page.locator('#title').
|
| 2348 |
self.assertEqual(path.locator('.reader-panel-folder').inner_text(),'所在目录:Test/音乐')
|
| 2349 |
page.locator('#bookmarks-tab').click()
|
| 2350 |
self.assertTrue(path.is_visible())
|
|
|
|
| 2344 |
path=page.locator('#reader-panel-path')
|
| 2345 |
path.wait_for(state='visible')
|
| 2346 |
self.assertTrue(path.evaluate("n=>n.closest('#reader-panel-location').parentElement.id==='history-panel'"))
|
| 2347 |
+
self.assertTrue(page.locator('#title').is_hidden())
|
| 2348 |
self.assertEqual(path.locator('.reader-panel-folder').inner_text(),'所在目录:Test/音乐')
|
| 2349 |
page.locator('#bookmarks-tab').click()
|
| 2350 |
self.assertTrue(path.is_visible())
|
tests/test_reader_refactor.py
CHANGED
|
@@ -3144,7 +3144,7 @@ class ReaderRefactorTest(unittest.TestCase):
|
|
| 3144 |
self.serve("Folder document")
|
| 3145 |
self.open(self.origin + "/static/reader.html?id=mobile-folder&ext=txt")
|
| 3146 |
self.assertTrue(self.page.locator('#reader-path').is_hidden())
|
| 3147 |
-
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'],
|
| 3148 |
self.assertTrue(self.page.locator('#history-panel').evaluate('node=>node.inert'))
|
| 3149 |
self.page.locator('#reader-panel-path').evaluate('node=>node.focus()')
|
| 3150 |
self.assertNotEqual(self.page.evaluate('document.activeElement.id'), 'reader-panel-path')
|
|
@@ -3154,8 +3154,8 @@ class ReaderRefactorTest(unittest.TestCase):
|
|
| 3154 |
action = self.page.locator('#reader-panel-path')
|
| 3155 |
action.wait_for(state='visible')
|
| 3156 |
self.assertIn('打开所在目录:Test/docs/子', action.get_attribute('aria-label'))
|
| 3157 |
-
self.assertEqual(self.page.locator('#title').
|
| 3158 |
-
self.assertEqual(self.page.title(), '原件.txt.txt
|
| 3159 |
self.page.keyboard.press('Tab')
|
| 3160 |
action.focus()
|
| 3161 |
self.assertNotEqual(action.evaluate('node=>getComputedStyle(node).outlineStyle'), 'none')
|
|
|
|
| 3144 |
self.serve("Folder document")
|
| 3145 |
self.open(self.origin + "/static/reader.html?id=mobile-folder&ext=txt")
|
| 3146 |
self.assertTrue(self.page.locator('#reader-path').is_hidden())
|
| 3147 |
+
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36)
|
| 3148 |
self.assertTrue(self.page.locator('#history-panel').evaluate('node=>node.inert'))
|
| 3149 |
self.page.locator('#reader-panel-path').evaluate('node=>node.focus()')
|
| 3150 |
self.assertNotEqual(self.page.evaluate('document.activeElement.id'), 'reader-panel-path')
|
|
|
|
| 3154 |
action = self.page.locator('#reader-panel-path')
|
| 3155 |
action.wait_for(state='visible')
|
| 3156 |
self.assertIn('打开所在目录:Test/docs/子', action.get_attribute('aria-label'))
|
| 3157 |
+
self.assertEqual(self.page.locator('#title').text_content(), '原件.txt.txt')
|
| 3158 |
+
self.assertEqual(self.page.title(), '原件.txt.txt')
|
| 3159 |
self.page.keyboard.press('Tab')
|
| 3160 |
action.focus()
|
| 3161 |
self.assertNotEqual(action.evaluate('node=>getComputedStyle(node).outlineStyle'), 'none')
|
tests/test_reader_style.py
CHANGED
|
@@ -406,7 +406,7 @@ class ReaderStyleTests(unittest.TestCase):
|
|
| 406 |
minHeight: parseFloat(style.minHeight), padding: style.padding,
|
| 407 |
video: content.firstChild?.getBoundingClientRect().height};
|
| 408 |
}""", mode)
|
| 409 |
-
expected_toolbar =
|
| 410 |
self.assertEqual(metrics["toolbar"], expected_toolbar)
|
| 411 |
self.assertAlmostEqual(metrics["height"], height - expected_toolbar, delta=1)
|
| 412 |
self.assertEqual(metrics["padding"], "0px")
|
|
@@ -420,9 +420,9 @@ class ReaderStyleTests(unittest.TestCase):
|
|
| 420 |
for width, height in ((320, 568), (390, 844), (600, 500), (601, 500)):
|
| 421 |
with self.subTest(width=width, height=height):
|
| 422 |
self.page.set_viewport_size({'width': width, 'height': height})
|
| 423 |
-
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'],
|
| 424 |
self.assertEqual(self.page.locator('#reader-path').is_visible(), width > 600)
|
| 425 |
-
self.
|
| 426 |
self.page.locator('#history').click()
|
| 427 |
self.page.wait_for_function("()=>document.querySelector('#history').getAttribute('aria-expanded') === 'true'")
|
| 428 |
info=self.page.locator('#reader-panel-location')
|
|
@@ -467,12 +467,50 @@ class ReaderStyleTests(unittest.TestCase):
|
|
| 467 |
return {id:n.id,left:r.left,right:r.right,top:r.top,bottom:r.bottom,
|
| 468 |
inside:r.left>=toolbar.left&&r.right<=toolbar.right&&r.top>=toolbar.top&&r.bottom<=toolbar.bottom};});
|
| 469 |
}''')
|
|
|
|
|
|
|
| 470 |
self.assertTrue(all(box['inside'] for box in boxes), boxes)
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
overlap=min(a['right'], b['right'])-max(a['left'], b['left'])
|
| 474 |
vertical=min(a['bottom'], b['bottom'])-max(a['top'], b['top'])
|
| 475 |
self.assertFalse(overlap > 0.5 and vertical > 0.5, (a, b))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
def test_mobile_folder_action_has_contrast_and_stays_out_of_header(self):
|
| 478 |
self.page.set_viewport_size({'width': 320, 'height': 568})
|
|
@@ -501,7 +539,7 @@ class ReaderStyleTests(unittest.TestCase):
|
|
| 501 |
self.page.locator('#history').click()
|
| 502 |
self.assertEqual(self.page.get_by_role('button',name='文件信息',exact=True).count(), 0)
|
| 503 |
self.assertTrue(self.page.locator('#reader-panel-path').is_disabled())
|
| 504 |
-
self.assertTrue(self.page.locator('#title').
|
| 505 |
self.assertTrue(self.page.locator('#reader-panel-location').is_visible())
|
| 506 |
self.page.locator('#history-tab').click()
|
| 507 |
self.assertTrue(self.page.locator('#reader-panel-location').is_visible())
|
|
@@ -546,70 +584,6 @@ class ReaderStyleTests(unittest.TestCase):
|
|
| 546 |
self.page.wait_for_function("()=>document.querySelector('#history-panel').hidden")
|
| 547 |
self.assertTrue(info.is_hidden())
|
| 548 |
|
| 549 |
-
def test_mobile_long_filename_scrolls_without_expanding_or_hiding_folder(self):
|
| 550 |
-
self.page.set_viewport_size({'width':320,'height':700})
|
| 551 |
-
self.page.emulate_media(reduced_motion='reduce')
|
| 552 |
-
self.assertIn('Style.txt', self.page.locator('#title').get_attribute('aria-label'))
|
| 553 |
-
self.page.evaluate("()=>document.querySelector('#title').textContent=('很长的文件名称'.repeat(15))+'.pdf'")
|
| 554 |
-
self.page.locator('#history').click()
|
| 555 |
-
name=self.page.locator('#title')
|
| 556 |
-
self.assertTrue(name.evaluate('n=>n.scrollWidth>n.clientWidth'))
|
| 557 |
-
before=name.bounding_box()['height']
|
| 558 |
-
name.focus()
|
| 559 |
-
self.page.keyboard.press('Tab')
|
| 560 |
-
name.focus()
|
| 561 |
-
self.assertEqual(name.evaluate('n=>getComputedStyle(n).outlineStyle'),'solid')
|
| 562 |
-
name.press('End')
|
| 563 |
-
self.assertGreater(name.evaluate('n=>n.scrollLeft'),0)
|
| 564 |
-
self.assertEqual(name.evaluate('n=>getComputedStyle(n).whiteSpace'),'nowrap')
|
| 565 |
-
self.assertAlmostEqual(name.bounding_box()['height'],before,delta=1)
|
| 566 |
-
self.assertTrue(self.page.locator('#reader-panel-path').is_visible())
|
| 567 |
-
self.assertTrue(self.page.locator('#history-panel').is_visible())
|
| 568 |
-
|
| 569 |
-
def test_mobile_filename_accepts_horizontal_touch_swipe(self):
|
| 570 |
-
context=self.browser.new_context(viewport={'width':320,'height':700},is_mobile=True,has_touch=True)
|
| 571 |
-
try:
|
| 572 |
-
page=context.new_page()
|
| 573 |
-
page.route('**/api/reader-content**',lambda route:route.fulfill(content_type='text/plain',body='Readable text'))
|
| 574 |
-
source=urllib.parse.quote('https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/touch.txt',safe='')
|
| 575 |
-
page.goto(f'{self.origin}/static/reader.html?url={source}&ext=txt&title=Touch')
|
| 576 |
-
page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")
|
| 577 |
-
page.evaluate("()=>document.querySelector('#title').textContent=('非常长的文件名称'.repeat(20))+'.pdf'")
|
| 578 |
-
page.locator('#history').click()
|
| 579 |
-
name=page.locator('#title')
|
| 580 |
-
box=name.bounding_box()
|
| 581 |
-
session=context.new_cdp_session(page)
|
| 582 |
-
x,y=box['x']+box['width']-20,box['y']+box['height']/2
|
| 583 |
-
session.send('Input.dispatchTouchEvent',{'type':'touchStart','touchPoints':[{'x':x,'y':y}]})
|
| 584 |
-
for delta in (30,60,90,120):
|
| 585 |
-
session.send('Input.dispatchTouchEvent',{'type':'touchMove','touchPoints':[{'x':x-delta,'y':y}]})
|
| 586 |
-
page.wait_for_timeout(25)
|
| 587 |
-
session.send('Input.dispatchTouchEvent',{'type':'touchEnd','touchPoints':[]})
|
| 588 |
-
page.wait_for_function("()=>document.querySelector('#title').scrollLeft>0")
|
| 589 |
-
self.assertTrue(page.locator('#reader-panel-path').is_visible())
|
| 590 |
-
self.assertTrue(page.locator('#reader-panel-location').is_visible())
|
| 591 |
-
finally:
|
| 592 |
-
context.close()
|
| 593 |
-
|
| 594 |
-
def test_mobile_short_filename_does_not_scroll_and_long_name_adapts_on_resize(self):
|
| 595 |
-
self.page.set_viewport_size({'width':390,'height':700})
|
| 596 |
-
self.page.emulate_media(reduced_motion='reduce')
|
| 597 |
-
self.page.locator('#history').click()
|
| 598 |
-
name=self.page.locator('#title')
|
| 599 |
-
self.page.evaluate("()=>document.querySelector('#title').textContent='短文.txt'")
|
| 600 |
-
self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth===document.querySelector('#title').clientWidth")
|
| 601 |
-
self.assertEqual(name.evaluate('n=>getComputedStyle(n).display'),'block')
|
| 602 |
-
self.assertEqual(name.evaluate('n=>n.scrollWidth'),name.evaluate('n=>n.clientWidth'))
|
| 603 |
-
self.assertEqual(self.page.locator('.reader-panel-filename').count(),0)
|
| 604 |
-
self.page.evaluate("()=>document.querySelector('#title').textContent=('很长的文件名称'.repeat(15))+'.pdf'")
|
| 605 |
-
self.assertGreater(name.evaluate('n=>n.scrollWidth'),name.evaluate('n=>n.clientWidth'))
|
| 606 |
-
self.page.evaluate("()=>document.querySelector('#title').textContent=('宽度测试'.repeat(7))+'.pdf'")
|
| 607 |
-
self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth>document.querySelector('#title').clientWidth")
|
| 608 |
-
self.page.set_viewport_size({'width':600,'height':700})
|
| 609 |
-
self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth===document.querySelector('#title').clientWidth")
|
| 610 |
-
self.page.set_viewport_size({'width':320,'height':700})
|
| 611 |
-
self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth>document.querySelector('#title').clientWidth")
|
| 612 |
-
|
| 613 |
def test_theme_transition_preserves_drawer_and_filter_motion(self):
|
| 614 |
self.page.locator("#history").click()
|
| 615 |
self.page.locator("#bookmarks-tab").click()
|
|
|
|
| 406 |
minHeight: parseFloat(style.minHeight), padding: style.padding,
|
| 407 |
video: content.firstChild?.getBoundingClientRect().height};
|
| 408 |
}""", mode)
|
| 409 |
+
expected_toolbar = 36 if width <= 600 else 44
|
| 410 |
self.assertEqual(metrics["toolbar"], expected_toolbar)
|
| 411 |
self.assertAlmostEqual(metrics["height"], height - expected_toolbar, delta=1)
|
| 412 |
self.assertEqual(metrics["padding"], "0px")
|
|
|
|
| 420 |
for width, height in ((320, 568), (390, 844), (600, 500), (601, 500)):
|
| 421 |
with self.subTest(width=width, height=height):
|
| 422 |
self.page.set_viewport_size({'width': width, 'height': height})
|
| 423 |
+
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36 if width <= 600 else 44)
|
| 424 |
self.assertEqual(self.page.locator('#reader-path').is_visible(), width > 600)
|
| 425 |
+
self.assertEqual(self.page.locator('#title').is_visible(), width > 600)
|
| 426 |
self.page.locator('#history').click()
|
| 427 |
self.page.wait_for_function("()=>document.querySelector('#history').getAttribute('aria-expanded') === 'true'")
|
| 428 |
info=self.page.locator('#reader-panel-location')
|
|
|
|
| 467 |
return {id:n.id,left:r.left,right:r.right,top:r.top,bottom:r.bottom,
|
| 468 |
inside:r.left>=toolbar.left&&r.right<=toolbar.right&&r.top>=toolbar.top&&r.bottom<=toolbar.bottom};});
|
| 469 |
}''')
|
| 470 |
+
self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36)
|
| 471 |
+
self.assertTrue(self.page.locator('#title').is_hidden())
|
| 472 |
self.assertTrue(all(box['inside'] for box in boxes), boxes)
|
| 473 |
+
actions=self.page.locator('.reader-actions')
|
| 474 |
+
metrics=actions.evaluate('''n=>{const r=n.getBoundingClientRect(),back=document.querySelector('#back').getBoundingClientRect(),
|
| 475 |
+
menu=document.querySelector('#history').getBoundingClientRect();
|
| 476 |
+
return {left:r.left,right:r.right,back:back.right,menu:menu.left,scroll:n.scrollWidth>n.clientWidth}}''')
|
| 477 |
+
self.assertGreaterEqual(metrics['left'],metrics['back']-.5)
|
| 478 |
+
self.assertLessEqual(metrics['right'],metrics['menu']+.5)
|
| 479 |
+
inside=[b for b in boxes if b['id'] in ('back','history') or
|
| 480 |
+
b['left'] >= metrics['left']-.5 and b['right'] <= metrics['right']+.5]
|
| 481 |
+
for i, a in enumerate(inside):
|
| 482 |
+
for b in inside[i+1:]:
|
| 483 |
overlap=min(a['right'], b['right'])-max(a['left'], b['left'])
|
| 484 |
vertical=min(a['bottom'], b['bottom'])-max(a['top'], b['top'])
|
| 485 |
self.assertFalse(overlap > 0.5 and vertical > 0.5, (a, b))
|
| 486 |
+
if metrics['scroll']:
|
| 487 |
+
actions.evaluate('n=>n.scrollLeft=n.scrollWidth')
|
| 488 |
+
self.assertGreater(actions.evaluate('n=>n.scrollLeft'),0)
|
| 489 |
+
|
| 490 |
+
def test_mobile_overflowing_toolbar_supports_touch_swipe(self):
|
| 491 |
+
context=self.browser.new_context(viewport={'width':280,'height':700},is_mobile=True,has_touch=True)
|
| 492 |
+
try:
|
| 493 |
+
page=context.new_page()
|
| 494 |
+
page.route('**/api/reader-content**',lambda route:route.fulfill(content_type='text/plain',body='Readable text'))
|
| 495 |
+
source=urllib.parse.quote('https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/touch.txt',safe='')
|
| 496 |
+
page.goto(f'{self.origin}/static/reader.html?url={source}&ext=txt&title=Touch')
|
| 497 |
+
page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")
|
| 498 |
+
page.evaluate('''()=>{document.querySelector('.page-controls').hidden=false;
|
| 499 |
+
const ocr=document.createElement('a');ocr.className='text-button';ocr.textContent='OCR';
|
| 500 |
+
document.querySelector('.reader-actions').prepend(ocr)}''')
|
| 501 |
+
actions=page.locator('.reader-actions')
|
| 502 |
+
self.assertGreater(actions.evaluate('n=>n.scrollWidth'),actions.evaluate('n=>n.clientWidth'))
|
| 503 |
+
box=actions.bounding_box();session=context.new_cdp_session(page)
|
| 504 |
+
x,y=box['x']+box['width']-15,box['y']+box['height']/2
|
| 505 |
+
session.send('Input.dispatchTouchEvent',{'type':'touchStart','touchPoints':[{'x':x,'y':y}]})
|
| 506 |
+
for delta in (25,50,75,100):
|
| 507 |
+
session.send('Input.dispatchTouchEvent',{'type':'touchMove','touchPoints':[{'x':x-delta,'y':y}]})
|
| 508 |
+
page.wait_for_timeout(25)
|
| 509 |
+
session.send('Input.dispatchTouchEvent',{'type':'touchEnd','touchPoints':[]})
|
| 510 |
+
page.wait_for_function("()=>document.querySelector('.reader-actions').scrollLeft>0")
|
| 511 |
+
self.assertEqual(page.locator('.reader-toolbar').bounding_box()['height'],36)
|
| 512 |
+
finally:
|
| 513 |
+
context.close()
|
| 514 |
|
| 515 |
def test_mobile_folder_action_has_contrast_and_stays_out_of_header(self):
|
| 516 |
self.page.set_viewport_size({'width': 320, 'height': 568})
|
|
|
|
| 539 |
self.page.locator('#history').click()
|
| 540 |
self.assertEqual(self.page.get_by_role('button',name='文件信息',exact=True).count(), 0)
|
| 541 |
self.assertTrue(self.page.locator('#reader-panel-path').is_disabled())
|
| 542 |
+
self.assertTrue(self.page.locator('#title').is_hidden())
|
| 543 |
self.assertTrue(self.page.locator('#reader-panel-location').is_visible())
|
| 544 |
self.page.locator('#history-tab').click()
|
| 545 |
self.assertTrue(self.page.locator('#reader-panel-location').is_visible())
|
|
|
|
| 584 |
self.page.wait_for_function("()=>document.querySelector('#history-panel').hidden")
|
| 585 |
self.assertTrue(info.is_hidden())
|
| 586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
def test_theme_transition_preserves_drawer_and_filter_motion(self):
|
| 588 |
self.page.locator("#history").click()
|
| 589 |
self.page.locator("#bookmarks-tab").click()
|