| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | const frames = new Map(), clicks = []; |
| 5 | let fixed = false; |
| 6 | const { page, browser, errors } = await createWorkbench({ |
| 7 | viewport: {width:1280, height:882}, deviceScaleFactor:2, |
| 8 | async beforeNavigate(page, state) { |
| 9 | state.account.guest_system = "macos"; |
| 10 | state.status.vm_running = state.status.ready = true; |
| 11 | await page.route("**/api/macos/claude/window", async route => { |
| 12 | const input = route.request().postDataJSON(); |
| 13 | if (input.action === "pointer" && input.phase === "down") clicks.push(input); |
| 14 | if (input.action !== "frame") return route.fulfill({json:{installed:true,running:true,screen:true,input:true}}); |
| 15 | const width = fixed ? 600 : input.width, height = fixed ? 560 : input.height; |
| 16 | assert.equal(input.scale, 2); |
| 17 | const geometry = width + "x" + height; |
| 18 | if (!frames.has(geometry)) frames.set(geometry, await page.evaluate(([w,h]) => { |
| 19 | const canvas = document.createElement("canvas"); |
| 20 | canvas.width=w*2; canvas.height=h*2; |
| 21 | const ctx=canvas.getContext("2d"); |
| 22 | ctx.fillStyle="#f7f5f1"; ctx.fillRect(0,0,canvas.width,canvas.height); |
| 23 | ctx.fillStyle="#202020"; ctx.font="32px sans-serif"; ctx.fillText("Claude",60,100); |
| 24 | return canvas.toDataURL().split(",")[1]; |
| 25 | }, [width,height])); |
| 26 | return route.fulfill({json:{window:70,pid:23,image:frames.get(geometry),contentWidth:width,contentHeight:height,geometry}}); |
| 27 | }); |
| 28 | }, |
| 29 | }); |
| 30 | try { |
| 31 | await page.getByRole("button",{name:"Claude Desktop",exact:true}).click(); |
| 32 | const pane = page.locator(".mac-claude-frame"); |
| 33 | const img = pane.getByRole("img"); |
| 34 | async function fillsPane() { |
| 35 | await page.waitForFunction(() => { |
| 36 | const box=document.querySelector(".mac-claude-frame"), img=box?.querySelector("img"); |
| 37 | if (!img?.complete || !img.naturalWidth) return false; |
| 38 | const a=img.getBoundingClientRect(), b=box.getBoundingClientRect(); |
| 39 | return Math.abs(a.width-b.width)<2 && Math.abs(a.height-b.height)<2 && |
| 40 | Math.abs(img.naturalWidth-2*b.width)<3 && Math.abs(img.naturalHeight-2*b.height)<3; |
| 41 | }); |
| 42 | } |
| 43 | await fillsPane(); |
| 44 | await page.setViewportSize({width:1110,height:750}); |
| 45 | await fillsPane(); |
| 46 | fixed=true; |
| 47 | await page.waitForFunction(() => document.querySelector(".mac-claude-frame img")?.naturalWidth===1200 && |
| 48 | getComputedStyle(document.querySelector(".mac-claude-frame")).backgroundColor==="rgb(247, 245, 241)"); |
| 49 | const bounds = await img.boundingBox(); |
| 50 | assert.ok(Math.abs(bounds.width-600)<1); |
| 51 | await img.click({position:{x:bounds.width/2,y:bounds.height/2}}); |
| 52 | await page.waitForFunction(() => document.activeElement?.classList.contains("mac-claude-typing")); |
| 53 | for (let i=0; !clicks.length && i<40; i++) await new Promise(r=>setTimeout(r,25)); |
| 54 | assert.equal(clicks[0]?.geometry,"600x560"); |
| 55 | assert.ok(Math.abs(clicks[0].x-0.5)<0.005 && Math.abs(clicks[0].y-0.5)<0.005); |
| 56 | assert.equal(await img.evaluate(el=>getComputedStyle(el).outlineStyle),"none"); |
| 57 | assert.equal(await page.evaluate(()=>document.fullscreenElement),null); |
| 58 | assert.deepEqual(errors,[]); |
| 59 | console.log("2x pixels, panel resize, fixed-window background, focus and cropped-frame inputs passed."); |
| 60 | } finally { await browser.close(); } |