vomebook commited on
Commit ·
5e29397
1
Parent(s): 152be87
Update Reader actions only when metadata changes
Browse files- static/app.js +61 -16
- tests/search/browser/test_scroll_stability.py +189 -0
static/app.js
CHANGED
|
@@ -3793,32 +3793,77 @@ function buildResultHTML(rec, idx) {
|
|
| 3793 |
</div>`;
|
| 3794 |
}
|
| 3795 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3796 |
function refreshResultReaderActions() {
|
| 3797 |
-
|
| 3798 |
-
|
| 3799 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3800 |
if (!record) continue;
|
| 3801 |
-
const
|
| 3802 |
-
const readerReady = isReadableRecord(readerRecord);
|
| 3803 |
let button = row.querySelector('[data-action="read"]');
|
| 3804 |
-
if (
|
| 3805 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3806 |
continue;
|
| 3807 |
}
|
| 3808 |
-
const actionRecord = readerReady ? readerRecord : record;
|
| 3809 |
if (!button) {
|
| 3810 |
button = document.createElement("button"); button.className = "result-action-btn"; button.dataset.action = "read";
|
| 3811 |
row.querySelector(".result-actions").appendChild(button);
|
| 3812 |
-
VSCROLL.measuredRowKeys[index] = null;
|
| 3813 |
}
|
| 3814 |
-
|
| 3815 |
-
|
| 3816 |
-
if (button.textContent !== label)
|
| 3817 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3818 |
}
|
| 3819 |
-
VSCROLL.measuredWindowKey = "";
|
| 3820 |
-
VSCROLL.renderStart = -1; VSCROLL.renderEnd = -1;
|
| 3821 |
-
scheduleVirtualRender();
|
| 3822 |
}
|
| 3823 |
|
| 3824 |
function getResultsHTMLCacheKey() {
|
|
|
|
| 3793 |
</div>`;
|
| 3794 |
}
|
| 3795 |
|
| 3796 |
+
let refreshedReaderAssets = null;
|
| 3797 |
+
function readerActionForRefresh(record, assets = readerAssets) {
|
| 3798 |
+
const fields = assets !== readerAssets && VoiceOfMLReader.assetFields(
|
| 3799 |
+
assets && assets[(record.Repo || "") + "\0" + buildRecordRelativePath(record)],
|
| 3800 |
+
"/api/reader-bucket-resource", String(record.Extension || record.extension || ""));
|
| 3801 |
+
const readerRecord = assets === readerAssets
|
| 3802 |
+
? applyReaderAsset(record, record.Repo || "", buildRecordRelativePath(record), getRecordLink(record))
|
| 3803 |
+
: (fields ? Object.assign({}, record, fields, { DownloadLink: getRecordLink(record) }) : record);
|
| 3804 |
+
const actionRecord = isReadableRecord(readerRecord) ? readerRecord : (isDefaultReadableRecord(record) ? record : null);
|
| 3805 |
+
const label = actionRecord ? (["audio", "video", "swf"].includes(
|
| 3806 |
+
VoiceOfMLReader.capability(actionRecord.ReaderExtension || actionRecord.Extension).mode) ? "在线播放" : "在线阅读") : "";
|
| 3807 |
+
return { record: actionRecord, label };
|
| 3808 |
+
}
|
| 3809 |
+
|
| 3810 |
function refreshResultReaderActions() {
|
| 3811 |
+
const visible = new Map(Array.from(DOM.resultsList.querySelectorAll(".result-item[data-index]"),
|
| 3812 |
+
row => [Number(row.dataset.index), row]));
|
| 3813 |
+
// Templates retain the actual old button even when their row is offscreen.
|
| 3814 |
+
const rows = new Map(VSCROLL.templateCache);
|
| 3815 |
+
for (const [index, row] of visible) rows.set(index, row);
|
| 3816 |
+
let layoutChanged = false, heightsInvalidated = false;
|
| 3817 |
+
const invalidateHeight = (index, record) => {
|
| 3818 |
+
VSCROLL.measuredRowKeys[index] = null;
|
| 3819 |
+
VSCROLL.heightCache.delete(getResultStableId(record));
|
| 3820 |
+
heightsInvalidated = true;
|
| 3821 |
+
if (visible.has(index)) layoutChanged = true;
|
| 3822 |
+
};
|
| 3823 |
+
for (const [index, row] of rows) {
|
| 3824 |
+
const record = STATE.results[index];
|
| 3825 |
if (!record) continue;
|
| 3826 |
+
const action = readerActionForRefresh(record);
|
|
|
|
| 3827 |
let button = row.querySelector('[data-action="read"]');
|
| 3828 |
+
if ((button ? button.textContent : "") !== action.label) invalidateHeight(index, record);
|
| 3829 |
+
if (!visible.has(index)) continue;
|
| 3830 |
+
if (!action.record) {
|
| 3831 |
+
if (button) {
|
| 3832 |
+
const focused = document.activeElement === button;
|
| 3833 |
+
button.remove();
|
| 3834 |
+
if (focused) row.focus({ preventScroll: true });
|
| 3835 |
+
}
|
| 3836 |
continue;
|
| 3837 |
}
|
|
|
|
| 3838 |
if (!button) {
|
| 3839 |
button = document.createElement("button"); button.className = "result-action-btn"; button.dataset.action = "read";
|
| 3840 |
row.querySelector(".result-actions").appendChild(button);
|
|
|
|
| 3841 |
}
|
| 3842 |
+
const url = getReaderLink(action.record, undefined, false);
|
| 3843 |
+
if (button.dataset.readerUrl !== url) button.dataset.readerUrl = url;
|
| 3844 |
+
if (button.textContent !== action.label) button.textContent = action.label;
|
| 3845 |
+
const ariaLabel = action.label + ':' + record.File + (record.Extension ? '.' + record.Extension : '');
|
| 3846 |
+
if (button.getAttribute('aria-label') !== ariaLabel) button.setAttribute('aria-label', ariaLabel);
|
| 3847 |
+
}
|
| 3848 |
+
// A measured row may outlive the bounded template cache. Compare catalog
|
| 3849 |
+
// snapshots for those rows as well, retaining old heights as anchor estimates.
|
| 3850 |
+
if (refreshedReaderAssets !== readerAssets) {
|
| 3851 |
+
for (const key of Object.keys(VSCROLL.measuredRowKeys)) {
|
| 3852 |
+
const index = Number(key), record = STATE.results[index];
|
| 3853 |
+
if (!record || rows.has(index) || !VSCROLL.measuredRowKeys[index]) continue;
|
| 3854 |
+
if (readerActionForRefresh(record, refreshedReaderAssets).label !== readerActionForRefresh(record).label)
|
| 3855 |
+
invalidateHeight(index, record);
|
| 3856 |
+
}
|
| 3857 |
+
}
|
| 3858 |
+
refreshedReaderAssets = readerAssets;
|
| 3859 |
+
// Do not bump contentVersion: existing rows, focus and selection stay intact.
|
| 3860 |
+
VSCROLL.templateCache.clear();
|
| 3861 |
+
if (heightsInvalidated) measuredHeightRevision++;
|
| 3862 |
+
if (layoutChanged) {
|
| 3863 |
+
VSCROLL.measuredWindowKey = "";
|
| 3864 |
+
VSCROLL.renderStart = -1; VSCROLL.renderEnd = -1;
|
| 3865 |
+
scheduleVirtualRender();
|
| 3866 |
}
|
|
|
|
|
|
|
|
|
|
| 3867 |
}
|
| 3868 |
|
| 3869 |
function getResultsHTMLCacheKey() {
|
tests/search/browser/test_scroll_stability.py
CHANGED
|
@@ -232,3 +232,192 @@ class ScrollStabilityTests(unittest.TestCase):
|
|
| 232 |
self.assertLessEqual(sample['native'],1000001)
|
| 233 |
self.assertEqual(sample['number'],sample['actual'])
|
| 234 |
self.assertEqual(self.fixture.errors,[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
self.assertLessEqual(sample['native'],1000001)
|
| 233 |
self.assertEqual(sample['number'],sample['actual'])
|
| 234 |
self.assertEqual(self.fixture.errors,[])
|
| 235 |
+
|
| 236 |
+
class ReaderActionRefreshTests(unittest.TestCase):
|
| 237 |
+
@classmethod
|
| 238 |
+
def setUpClass(cls):
|
| 239 |
+
paging.PagingRecoveryTests.setUpClass()
|
| 240 |
+
|
| 241 |
+
@classmethod
|
| 242 |
+
def tearDownClass(cls):
|
| 243 |
+
paging.PagingRecoveryTests.tearDownClass()
|
| 244 |
+
|
| 245 |
+
def setUp(self):
|
| 246 |
+
self.fixture = paging.PagingRecoveryTests()
|
| 247 |
+
self.fixture.setUp()
|
| 248 |
+
self.page = self.fixture.page
|
| 249 |
+
self.page.route('**/static/reader.html?**', lambda route: route.fulfill(
|
| 250 |
+
content_type='text/html', body='<body>reader</body>'))
|
| 251 |
+
self.page.evaluate('''() => {
|
| 252 |
+
readerAssets = {};
|
| 253 |
+
refreshResultReaderActions();
|
| 254 |
+
if (VSCROLL.renderFrame) cancelAnimationFrame(VSCROLL.renderFrame);
|
| 255 |
+
VSCROLL.renderFrame = 0;
|
| 256 |
+
renderVisible();
|
| 257 |
+
}''')
|
| 258 |
+
|
| 259 |
+
def tearDown(self):
|
| 260 |
+
try:
|
| 261 |
+
self.assertEqual(self.fixture.errors, [])
|
| 262 |
+
finally:
|
| 263 |
+
self.fixture.tearDown()
|
| 264 |
+
|
| 265 |
+
def test_identical_refresh_has_zero_dom_storage_and_render_work(self):
|
| 266 |
+
result = self.page.evaluate('''() => {
|
| 267 |
+
const row=DOM.resultsList.querySelector('.result-item[data-index]');
|
| 268 |
+
const button=row.querySelector('[data-action="read"]');
|
| 269 |
+
button.focus({preventScroll:true});
|
| 270 |
+
const checkbox=row.querySelector('input');checkbox.checked=true;
|
| 271 |
+
const title=row.querySelector('.result-title');
|
| 272 |
+
const range=document.createRange();range.selectNodeContents(title);
|
| 273 |
+
const selection=getSelection();selection.removeAllRanges();selection.addRange(range);
|
| 274 |
+
const before={start:VSCROLL.renderStart,end:VSCROLL.renderEnd,
|
| 275 |
+
measured:VSCROLL.measuredWindowKey,version:VSCROLL.contentVersion,
|
| 276 |
+
top:getResultScrollTop(),text:selection.toString(),revision:measuredHeightRevision};
|
| 277 |
+
let storage=0,renders=0,measures=0;
|
| 278 |
+
const native={set:Storage.prototype.setItem,remove:Storage.prototype.removeItem,
|
| 279 |
+
schedule:scheduleVirtualRender,measure:measureHeights};
|
| 280 |
+
const observer=new MutationObserver(()=>{});
|
| 281 |
+
observer.observe(DOM.resultsList,{subtree:true,childList:true,attributes:true,characterData:true});
|
| 282 |
+
Storage.prototype.setItem=function(...args){storage++;return native.set.apply(this,args)};
|
| 283 |
+
Storage.prototype.removeItem=function(...args){storage++;return native.remove.apply(this,args)};
|
| 284 |
+
scheduleVirtualRender=()=>{renders++};measureHeights=()=>{measures++};
|
| 285 |
+
try {
|
| 286 |
+
for(let i=0;i<5;i++) refreshResultReaderActions();
|
| 287 |
+
return {writes:observer.takeRecords().length,storage,renders,measures,
|
| 288 |
+
retained:row.isConnected && row.querySelector('[data-action="read"]')===button,
|
| 289 |
+
focus:document.activeElement===button,selected:checkbox.checked,
|
| 290 |
+
state:JSON.stringify(before)===JSON.stringify({start:VSCROLL.renderStart,end:VSCROLL.renderEnd,
|
| 291 |
+
measured:VSCROLL.measuredWindowKey,version:VSCROLL.contentVersion,
|
| 292 |
+
top:getResultScrollTop(),text:selection.toString(),revision:measuredHeightRevision})};
|
| 293 |
+
} finally {
|
| 294 |
+
observer.disconnect();Storage.prototype.setItem=native.set;Storage.prototype.removeItem=native.remove;
|
| 295 |
+
scheduleVirtualRender=native.schedule;measureHeights=native.measure;
|
| 296 |
+
}
|
| 297 |
+
}''')
|
| 298 |
+
self.assertEqual(result, dict(writes=0, storage=0, renders=0, measures=0,
|
| 299 |
+
retained=True, focus=True, selected=True, state=True))
|
| 300 |
+
|
| 301 |
+
def test_url_only_change_keeps_geometry_and_click_writes_fresh_metadata(self):
|
| 302 |
+
result = self.page.evaluate(r'''() => {
|
| 303 |
+
const row=DOM.resultsList.querySelector('.result-item[data-index]');
|
| 304 |
+
const index=Number(row.dataset.index),record=STATE.results[index];
|
| 305 |
+
const button=row.querySelector('[data-action="read"]'),url=button.dataset.readerUrl;
|
| 306 |
+
const id=getResultStableId(record),cache=VSCROLL.heightCache.get(id);
|
| 307 |
+
const measured=VSCROLL.measuredRowKeys[index],windowKey=VSCROLL.measuredWindowKey;
|
| 308 |
+
const start=VSCROLL.renderStart,end=VSCROLL.renderEnd;
|
| 309 |
+
const key=(record.Repo||'')+'\0'+buildRecordRelativePath(record);
|
| 310 |
+
readerAssets={[key]:{s:2,m:'h',p:'objects/00/'+'0'.repeat(64)+'/profile/document.html'}};
|
| 311 |
+
button.focus({preventScroll:true});
|
| 312 |
+
let writes=0,renders=0;
|
| 313 |
+
const native={set:Storage.prototype.setItem,schedule:scheduleVirtualRender};
|
| 314 |
+
Storage.prototype.setItem=function(...args){writes++;return native.set.apply(this,args)};
|
| 315 |
+
scheduleVirtualRender=()=>{renders++};
|
| 316 |
+
try {
|
| 317 |
+
refreshResultReaderActions();
|
| 318 |
+
const expected=getReaderLink(applyReaderAsset(record,record.Repo||'',buildRecordRelativePath(record),getRecordLink(record)),undefined,false);
|
| 319 |
+
const metadataId=new URL(expected,location.origin).searchParams.get('id');
|
| 320 |
+
const zeroWrites=writes===0;
|
| 321 |
+
const geometry=VSCROLL.heightCache.get(id)===cache && VSCROLL.measuredRowKeys[index]===measured &&
|
| 322 |
+
VSCROLL.measuredWindowKey===windowKey && VSCROLL.renderStart===start && VSCROLL.renderEnd===end;
|
| 323 |
+
const retained=document.activeElement===button && row.querySelector('[data-action="read"]')===button;
|
| 324 |
+
const updated=button.dataset.readerUrl===expected && expected!==url;
|
| 325 |
+
const freshTemplate=createResultRow(record,index).querySelector('[data-action="read"]').dataset.readerUrl===expected;
|
| 326 |
+
button.click();
|
| 327 |
+
const metadata=JSON.parse(sessionStorage.getItem('reader-source:'+metadataId));
|
| 328 |
+
return {zeroWrites,geometry,retained,updated,freshTemplate,renders,
|
| 329 |
+
clicked:!!readerOverlay && new URL(readerOverlay.src).searchParams.get('id')===metadataId,
|
| 330 |
+
source:metadata.url,expectedSource:applyReaderAsset(record,record.Repo||'',buildRecordRelativePath(record),getRecordLink(record)).ReaderLink,
|
| 331 |
+
original:metadata.download===getRecordLink(record),clickWrites:writes>0};
|
| 332 |
+
} finally {Storage.prototype.setItem=native.set;scheduleVirtualRender=native.schedule;}
|
| 333 |
+
}''')
|
| 334 |
+
self.assertEqual(result.pop('source'), result.pop('expectedSource'))
|
| 335 |
+
self.assertEqual(result.pop('renders'), 0)
|
| 336 |
+
self.assertTrue(all(result.values()), result)
|
| 337 |
+
|
| 338 |
+
def test_layout_change_remeasures_and_preserves_scrolled_anchor(self):
|
| 339 |
+
self.page.evaluate(r'''() => {
|
| 340 |
+
const style=document.createElement('style');
|
| 341 |
+
style.textContent='.result-item[data-index="0"]:has([data-action="read"]) {min-height:400px !important}';
|
| 342 |
+
document.head.append(style);
|
| 343 |
+
STATE.results[0]={Repo:'VoiceOfML/Test',File:'f3-anchor',Extension:'f3unsupported',Folder:[],Size:1};
|
| 344 |
+
VSCROLL.templateCache.clear();
|
| 345 |
+
DOM.resultsList.querySelector('[data-index="0"]').replaceWith(createResultRow(STATE.results[0],0));
|
| 346 |
+
VSCROLL.measuredRowKeys[0]=null;VSCROLL.measuredWindowKey='';
|
| 347 |
+
VSCROLL.renderStart=-1;VSCROLL.renderEnd=-1;renderVisible();
|
| 348 |
+
setResultScrollTop(getVirtualOffset(5)+7);renderVisible();
|
| 349 |
+
}''')
|
| 350 |
+
result = self.page.evaluate(r'''() => {
|
| 351 |
+
const top=getResultScrollTop(),index=findVirtualIndex(top),offset=top-getVirtualOffset(index);
|
| 352 |
+
const row=DOM.resultsList.querySelector('[data-index="'+index+'"]');
|
| 353 |
+
const button=row.querySelector('[data-action="read"]');button.focus({preventScroll:true});
|
| 354 |
+
const checkbox=row.querySelector('input');checkbox.checked=true;
|
| 355 |
+
const before=VSCROLL.heights[0];
|
| 356 |
+
readerAssets={[getResultStableId(STATE.results[0])]:{
|
| 357 |
+
s:2,m:'h',p:'objects/00/'+'0'.repeat(64)+'/profile/document.html'}};
|
| 358 |
+
refreshResultReaderActions();renderVisible();
|
| 359 |
+
return {index,sameIndex:findVirtualIndex(getResultScrollTop())===index,
|
| 360 |
+
offsetError:Math.abs(getResultScrollTop()-getVirtualOffset(index)-offset),
|
| 361 |
+
remeasured:VSCROLL.heights[0]>before+100,
|
| 362 |
+
cache:VSCROLL.heightCache.get(getResultStableId(STATE.results[0])).height===VSCROLL.heights[0],
|
| 363 |
+
retained:row.isConnected && document.activeElement===button && checkbox.checked};
|
| 364 |
+
}''')
|
| 365 |
+
self.assertGreater(result['index'], 0)
|
| 366 |
+
self.assertTrue(result['sameIndex'], result)
|
| 367 |
+
self.assertLessEqual(result['offsetError'], 1, result)
|
| 368 |
+
for key in ('remeasured', 'cache', 'retained'):
|
| 369 |
+
self.assertTrue(result[key], result)
|
| 370 |
+
|
| 371 |
+
def test_add_remove_and_label_changes_invalidate_only_affected_heights(self):
|
| 372 |
+
result = self.page.evaluate(r'''() => {
|
| 373 |
+
// Controlled unsupported records make removal observable without changing
|
| 374 |
+
// native TXT fallback behavior. Two offscreen rows exercise both cache paths.
|
| 375 |
+
const indexes=[0,1,90,91];
|
| 376 |
+
for (const index of indexes) STATE.results[index]={Repo:'VoiceOfML/Test',File:'f3-'+index,
|
| 377 |
+
Extension:'f3unsupported',Folder:[],Size:1};
|
| 378 |
+
VSCROLL.templateCache.clear();
|
| 379 |
+
for (const index of [0,1]) {
|
| 380 |
+
const old=DOM.resultsList.querySelector('[data-index="'+index+'"]');
|
| 381 |
+
old.replaceWith(createResultRow(STATE.results[index],index));
|
| 382 |
+
}
|
| 383 |
+
createResultRow(STATE.results[90],90);
|
| 384 |
+
const key=getHeightMeasurementKey(),cache=new Map();
|
| 385 |
+
for (const index of [...indexes,2]) {
|
| 386 |
+
VSCROLL.measuredRowKeys[index]=key;
|
| 387 |
+
const value={height:VSCROLL.heights[index]||60,measurementKey:key};
|
| 388 |
+
VSCROLL.heightCache.set(getResultStableId(STATE.results[index]),value);cache.set(index,value);
|
| 389 |
+
}
|
| 390 |
+
const asset={s:2,m:'h',p:'objects/00/'+'0'.repeat(64)+'/profile/document.html'};
|
| 391 |
+
readerAssets=Object.fromEntries([0,90,91].map(i=>[getResultStableId(STATE.results[i]),asset]));
|
| 392 |
+
const row=DOM.resultsList.querySelector('[data-index="0"]'),checkbox=row.querySelector('input');
|
| 393 |
+
checkbox.checked=true;
|
| 394 |
+
const top=getResultScrollTop();
|
| 395 |
+
let renders=0,writes=0;
|
| 396 |
+
const native={schedule:scheduleVirtualRender,set:Storage.prototype.setItem};
|
| 397 |
+
scheduleVirtualRender=()=>{renders++};
|
| 398 |
+
Storage.prototype.setItem=function(...args){writes++;return native.set.apply(this,args)};
|
| 399 |
+
try {
|
| 400 |
+
refreshResultReaderActions();
|
| 401 |
+
const invalidated=[0,90,91].every(i=>VSCROLL.measuredRowKeys[i]===null && !VSCROLL.heightCache.has(getResultStableId(STATE.results[i])));
|
| 402 |
+
const untouched=[1,2].every(i=>VSCROLL.measuredRowKeys[i]===key && VSCROLL.heightCache.get(getResultStableId(STATE.results[i]))===cache.get(i));
|
| 403 |
+
const added=!!row.querySelector('[data-action="read"]');
|
| 404 |
+
const offscreen=createResultRow(STATE.results[90],90).querySelector('[data-action="read"]');
|
| 405 |
+
const button=row.querySelector('[data-action="read"]');button.focus({preventScroll:true});
|
| 406 |
+
// A mode/label change retains the existing button and invalidates height.
|
| 407 |
+
const digest='a'.repeat(64);
|
| 408 |
+
readerAssets={...readerAssets,[getResultStableId(STATE.results[0])]:{
|
| 409 |
+
s:2,m:'a',b:'vomebook/reader-assets-v2',p:'media/audio/aac/'+digest+'/audio.mp3'}};
|
| 410 |
+
VSCROLL.measuredRowKeys[0]=key;VSCROLL.heightCache.set(getResultStableId(STATE.results[0]),cache.get(0));
|
| 411 |
+
refreshResultReaderActions();
|
| 412 |
+
const label=button.textContent==='在线播放' && document.activeElement===button &&
|
| 413 |
+
VSCROLL.measuredRowKeys[0]===null && !VSCROLL.heightCache.has(getResultStableId(STATE.results[0]));
|
| 414 |
+
readerAssets={};refreshResultReaderActions();
|
| 415 |
+
const removed=!row.querySelector('[data-action="read"]') && document.activeElement===row;
|
| 416 |
+
const stale=!createResultRow(STATE.results[90],90).querySelector('[data-action="read"]');
|
| 417 |
+
return {invalidated,untouched,added,offscreen:!!offscreen,label,removed,stale,
|
| 418 |
+
selected:checkbox.checked,anchor:getResultScrollTop()===top,writes,renders};
|
| 419 |
+
} finally {scheduleVirtualRender=native.schedule;Storage.prototype.setItem=native.set;}
|
| 420 |
+
}''')
|
| 421 |
+
self.assertEqual(result.pop('writes'), 0)
|
| 422 |
+
self.assertEqual(result.pop('renders'), 3)
|
| 423 |
+
self.assertTrue(all(result.values()), result)
|