mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11:20 -08:00
refactor(dpip): [PKG-DPIP-03] own windows and DOM resources in strict TypeScript
This commit is contained in:
1 parent
202351934b
commit
80d37d66f8
31 files changed
+2335
-597
No files matched your search
@@ -1,48 +1,9 @@
|
||||
import { hash } from '../../refactor/scripts/releases.mjs'
|
||||
import { dpipHistorical } from '../helpers/dpip.js'
|
||||
import { setupDpip as setup } from './dpip-helpers.js'
|
||||
import { expect, test } from './fixtures.js'
|
||||
|
||||
const implementations = await dpipHistorical()
|
||||
|
||||
async function setup(page, core, implementation, testInfo) {
|
||||
await page.goto(`/test/player.html?core=${core}`)
|
||||
await page.evaluate(() => {
|
||||
window.dpipEvidence = { nativeCapability: typeof window.documentPictureInPicture?.requestWindow === 'function', scope: 'real DOM iframe with controlled requestWindow; not native Document PiP', windows: [], requests: [], events: [] }
|
||||
Object.defineProperty(window, 'documentPictureInPicture', { configurable: true, value: {
|
||||
requestWindow(option) {
|
||||
return new Promise((resolve) => {
|
||||
window.dpipEvidence.requests.push({ option, resolve })
|
||||
})
|
||||
},
|
||||
} })
|
||||
window.resolveDpip = (index) => {
|
||||
const frame = document.createElement('iframe')
|
||||
frame.width = '640'
|
||||
frame.height = '360'
|
||||
frame.style.cssText = 'display:block;border:0;width:640px;height:360px'
|
||||
document.body.appendChild(frame)
|
||||
const popup = frame.contentWindow
|
||||
const record = { frame, popup, closed: false }
|
||||
Object.defineProperty(popup, 'close', { configurable: true, value: () => {
|
||||
record.closed = true
|
||||
} })
|
||||
window.dpipEvidence.windows.push(record)
|
||||
window.dpipEvidence.requests[index].resolve(popup)
|
||||
}
|
||||
})
|
||||
await page.addScriptTag({ content: `(() => { const module = { exports: {} }; const exports = module.exports; ${implementation.code}; window.dpipFactory = module.exports.default || module.exports; })();` })
|
||||
await page.evaluate(() => {
|
||||
window.art = new window.Artplayer({ container: '.player', url: '/test/pattern.mp4', muted: true, plugins: [window.dpipFactory()] })
|
||||
window.dpip = window.art.plugins.artplayerPluginDocumentPip
|
||||
window.dpipPlayer = window.art.template.$player
|
||||
window.dpipVideo = window.art.video
|
||||
window.dpipParent = window.dpipPlayer.parentNode
|
||||
window.art.on('document-pip', active => window.dpipEvidence.events.push(active))
|
||||
})
|
||||
await expect.poll(() => page.evaluate(() => window.art.video.readyState)).toBeGreaterThanOrEqual(2)
|
||||
await testInfo.attach('dpip-input', { contentType: 'application/json', body: JSON.stringify({ implementation: implementation.name, sha256: hash(implementation.code), core, ...(await page.evaluate(() => ({ capability: window.dpipEvidence.nativeCapability, scope: window.dpipEvidence.scope }))) }) })
|
||||
}
|
||||
|
||||
for (const implementation of implementations) {
|
||||
for (const core of ['published', 'candidate']) {
|
||||
test(`Document PiP ${implementation.name}/${core}: real DOM migration and pagehide restore preserve media and controls`, async ({ page }, testInfo) => {
|
||||
|
||||
Reference in new issue
Block a user