Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 id="configure-title">Choose an experiment</h2>
</div>
<p class="hint" id="bounds">Choose 1 to 10,000 values and a wait of 0 to 1,000 ms.</p>
<p id="error" role="alert" hidden></p>
<div class="actions"><button id="start" type="submit">Run example</button><button id="cancel" type="button" disabled>Cancel</button></div>
<div class="actions"><button id="start" type="submit" disabled>Run example</button><button id="cancel" type="button" disabled>Cancel</button></div>
</form>
<h2>What the C++ does</h2>
<p id="explanation"></p>
Expand Down
2 changes: 2 additions & 0 deletions example/browser/workbench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ const start = event => {
document.body.appendChild(frame)
}
document.querySelector('form').addEventListener('submit', start)
// index.html disables Start until this handler is attached, so that no click submits the form natively.
if (!workerBuild) element('start').disabled = false
element('cancel').addEventListener('click', () => {
if (!active) return
element('cancel').disabled = true
Expand Down
29 changes: 25 additions & 4 deletions test/browser/pages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ const wait = async expression => {
}
throw Error(`Timed out: ${expression}; state=${JSON.stringify(await evaluate('window.cobaltReport'))}`)
}
// The page's module, workbench.mjs, attaches the form's handler; until it has run, the Start button
// is disabled, so that an early click cannot submit the form natively and reload the page (which a
// driver on a loaded machine once did: its fill and click landed before the module, and the page it
// then watched was a fresh one, status ready, run 0). The server below serves the module late, so
// that every navigation crosses that window; loaded() checks the button there and waits the module.
const moduleDelay = 1000
const loaded = async () => {
const until = Date.now() + 15000
while (Date.now() < until) {
const state = await evaluate(`({started: !!document.querySelector('#start'),
disabled: document.querySelector('#start')?.disabled,
module: window.cobaltReport !== undefined})`)
if (state.module) return
if (state.started) assert.equal(state.disabled, true, 'Start is enabled before the page module ran')
await delay(20)
}
throw Error('Timed out: the page module did not run')
}
const click = async selector => {
const point = await evaluate(`(() => { const r = document.querySelector(${JSON.stringify(selector)}).getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+r.height/2}; })()`)
await send('Input.dispatchMouseEvent', {type: 'mousePressed', button: 'left', clickCount: 1, ...point})
Expand All @@ -77,7 +95,10 @@ const terminal = async status => {
}

try {
server = createServer((request, response) => {
server = createServer(async (request, response) => {
if (request.url.startsWith('/workbench.mjs') || request.url.startsWith('/unisolated/workbench.mjs')) {
await delay(moduleDelay)
}
try {
const requested = decodeURIComponent(new URL(request.url, 'http://localhost').pathname)
const unisolated = requested.startsWith('/unisolated/')
Expand Down Expand Up @@ -159,7 +180,7 @@ try {
await send('Emulation.setDeviceMetricsOverride', {width: 1240, height: 900, deviceScaleFactor: 1, mobile: false})
const page = `${base}/index.html?program=/build/${basename(program)}&variant=${variant}&threads=${multi ? 'multi' : 'single'}&kind=${workers ? 'spsc' : 'timer'}`
await send('Page.navigate', {url: page})
await wait('!!document.querySelector("#start")')
await loaded()
if (workers) {
await wait('window.cobaltReport?.status === "unavailable"')
assert.match(await evaluate('document.querySelector("#explanation").textContent'), /can lose values/)
Expand Down Expand Up @@ -250,7 +271,7 @@ try {
// Actual response headers, rather than a mocked crossOriginIsolated value.
if (multi) {
await send('Page.navigate', {url: page.replace('/index.html?', '/unisolated/index.html?')})
await wait('!!document.querySelector("#start")')
await loaded()
assert.equal(await evaluate('crossOriginIsolated'), false)
await click('#start')
await wait('!document.querySelector("#error").hidden')
Expand All @@ -259,7 +280,7 @@ try {
}
if (variant === 'jspi') {
await send('Page.navigate', {url: page})
await wait('!!document.querySelector("#start")')
await loaded()
await evaluate('delete WebAssembly.Suspending')
await click('#start')
await wait('!document.querySelector("#error").hidden')
Expand Down
Loading