Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const STUDIO_API_SAME_ORIGIN_CREDENTIALS = resolveStudioBooleanEnvFlag(
export const STUDIO_OPAQUE_PREVIEW_ENABLED = resolveStudioBooleanEnvFlag(
env,
["VITE_STUDIO_OPAQUE_PREVIEW_ENABLED"],
false,
true,
);

import { resolveEnabledSdkFamilies } from "../../utils/sdkCutoverPolicy";
66 changes: 39 additions & 27 deletions packages/studio/tests/e2e/aroll-backdrop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,40 @@ try {
await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded" });
// Ready when Play is enabled and the preview's A-roll has a frame to paint.
await page.waitForSelector('button[aria-label="Play"]:not([disabled])', { timeout: 60_000 });
const iframe = await page.waitForFunction(
() => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"),
{ timeout: 60_000 },
);
await page.waitForFunction(
(frame) => frame.contentDocument.getElementById("aroll")?.readyState >= 2,
{ timeout: 60_000, polling: 50 },
iframe,
);
// Looked up on every read: Studio can swap the preview's iframe. A sealed frame is reached as a frame, never through
// contentDocument, which Studio's page cannot read.
const previewIframe = async () =>
(
await page.waitForFunction(
() => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"),
{ timeout: 60_000 },
)
).asElement();
const previewFrame = async () => (await previewIframe()).contentFrame();
await (
await previewFrame()
).waitForFunction(() => document.getElementById("aroll")?.readyState >= 2, {
timeout: 60_000,
polling: 50,
});

// Playhead, the element on top at the frame's centre, and the plate's own state, in the preview.
const readPreview = () =>
page.evaluate(() => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const doc = frame.contentDocument;
const player = frame.contentWindow.__player;
const readPreview = async () => {
const box = await (
await previewIframe()
).evaluate((frame) => {
const rect = frame.getBoundingClientRect();
return [rect.x, rect.y, rect.width, rect.height].map(Math.round).join(",");
});
const inFrame = await (
await previewFrame()
).evaluate(() => {
const doc = document;
const player = window.__player;
const film = doc.getElementById("film").getBoundingClientRect();
const plate = doc.getElementById("plate");
const video = doc.getElementById("aroll");
const box = frame.getBoundingClientRect();
return {
box: [box.x, box.y, box.width, box.height].map(Math.round).join(","),
time: player.getTime(),
playing: player.isPlaying(),
topId: doc.elementFromPoint(film.x + film.width / 2, film.y + film.height * 0.45)?.id,
Expand All @@ -53,6 +65,8 @@ try {
videoReady: video.readyState >= 2 && !video.seeking,
};
});
return { box, ...inFrame };
};
// Mean chroma (max-min channel) and luma of the frame's centre: the A-roll is colour bars, the plate
// near black. Studio can re-fit the preview just after a pause, so a shot across that reflow is retaken.
const shoot = async (name) => {
Expand All @@ -63,7 +77,7 @@ try {
do {
attempts++;
before = await readPreview();
png = await screenshotInPlace(iframe, { encoding: "base64" });
png = await screenshotInPlace(await previewIframe(), { encoding: "base64" });
after = await readPreview();
} while (before.box !== after.box && attempts < 5);
if (OUT_DIR) writeFileSync(`${OUT_DIR}/${name}.png`, Buffer.from(png, "base64"));
Expand Down Expand Up @@ -102,13 +116,10 @@ try {
);
};
const outsidePlate = (t) => t < PLATE_START_S || t >= PLATE_END_S;
const playheadIn = (from, to) =>
page.waitForFunction(
const playheadIn = async (from, to) =>
(await previewFrame()).waitForFunction(
(lo, hi) => {
const frame = document
.querySelector("hyperframes-player")
.shadowRoot.querySelector("iframe");
const player = frame.contentWindow.__player;
const player = window.__player;
const t = player.getTime();
return player.isPlaying() && t >= lo && t < hi;
},
Expand Down Expand Up @@ -150,11 +161,12 @@ try {
evidence.step = "paused after the plate";
await playheadIn(PLATE_END_S + 0.2, 10);
await page.click('button[aria-label="Pause"]');
await page.waitForFunction(
await (
await previewFrame()
).waitForFunction(
() => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const video = frame.contentDocument.getElementById("aroll");
return !frame.contentWindow.__player.isPlaying() && video.readyState >= 2 && !video.seeking;
const video = document.getElementById("aroll");
return !window.__player.isPlaying() && video.readyState >= 2 && !video.seeking;
},
{ timeout: 10_000, polling: "raf" },
);
Expand Down
112 changes: 66 additions & 46 deletions packages/studio/tests/e2e/inline-text-caret.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,52 @@ const evidence = {};
const check = (ok, what) => ok || failures.push(what);
const pause = (ms) => new Promise((done) => setTimeout(done, ms));

// A sealed frame is reached as a frame, never through contentDocument, which Studio's page cannot read.
const previewIframe = async (page) =>
(
await page.waitForFunction(
() => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"),
{ timeout: 60_000 },
)
).asElement();
const previewFrame = async (page) => (await previewIframe(page)).contentFrame();

/** The preview's box on Studio's screen, and the player's scale from the film's pixels to it. */
async function framePlacement(page) {
const box = await (await previewIframe(page)).evaluate((f) => f.getBoundingClientRect().toJSON());
const innerWidth = await (await previewFrame(page)).evaluate(() => window.innerWidth);
return { box, scale: box.width / innerWidth };
}

/** The drawn caret's box on screen, and the box the preview's own selection maps to there. */
async function read(page) {
// A selection change is told to listeners a task later.
await pause(150);
const seen = await page.evaluate(() => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const doc = frame.contentDocument;
const selection = doc.getSelection();
const inFrame = await (
await previewFrame(page)
).evaluate(() => {
const selection = document.getSelection();
const rects = selection.rangeCount ? [...selection.getRangeAt(0).getClientRects()] : [];
const caret = document.querySelector("[data-inline-text-caret]");
return {
editing: doc.querySelector("[contenteditable]") !== null,
editing: document.querySelector("[contenteditable]") !== null,
collapsed: selection.isCollapsed,
box: frame.getBoundingClientRect().toJSON(),
scale: frame.getBoundingClientRect().width / frame.contentWindow.innerWidth,
at: rects.at(-1)?.toJSON() ?? null,
drawn: caret && {
};
});
const drawn = await page.evaluate(() => {
const caret = document.querySelector("[data-inline-text-caret]");
return (
caret && {
box: caret.getBoundingClientRect().toJSON(),
animation: getComputedStyle(caret).animationName,
},
};
}
);
});
const { box, scale, at, drawn } = seen;
const { box, scale } = await framePlacement(page);
const { at } = inFrame;
return {
editing: seen.editing,
collapsed: seen.collapsed,
editing: inFrame.editing,
collapsed: inFrame.collapsed,
caret: drawn && {
left: drawn.box.left,
top: drawn.box.top,
Expand All @@ -62,33 +82,33 @@ async function read(page) {
}

/** The character before the caret, on Studio's screen: its right edge is where a line's end stands. */
const charBefore = (page) =>
page.evaluate(() => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const box = frame.getBoundingClientRect();
const scale = box.width / frame.contentWindow.innerWidth;
const { anchorNode, anchorOffset } = frame.contentDocument.getSelection();
const range = frame.contentDocument.createRange();
const charBefore = async (page) => {
const rect = await (
await previewFrame(page)
).evaluate(() => {
const { anchorNode, anchorOffset } = document.getSelection();
const range = document.createRange();
range.setStart(anchorNode, anchorOffset - 1);
range.setEnd(anchorNode, anchorOffset);
const rect = [...range.getClientRects()][0];
return { right: box.left + rect.right * scale, top: box.top + rect.top * scale };
return [...range.getClientRects()][0].toJSON();
});
const { box, scale } = await framePlacement(page);
return { right: box.left + rect.right * scale, top: box.top + rect.top * scale };
};

/** Where an element of the composition stands on Studio's screen. */
const onScreen = (page, selector) =>
page.evaluate((selector) => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const box = frame.getBoundingClientRect();
const scale = box.width / frame.contentWindow.innerWidth;
const rect = frame.contentDocument.querySelector(selector).getBoundingClientRect();
return {
x: box.left + rect.left * scale,
y: box.top + rect.top * scale,
w: rect.width * scale,
h: rect.height * scale,
};
}, selector);
const onScreen = async (page, selector) => {
const rect = await (
await previewFrame(page)
).evaluate((sel) => document.querySelector(sel).getBoundingClientRect().toJSON(), selector);
const { box, scale } = await framePlacement(page);
return {
x: box.left + rect.left * scale,
y: box.top + rect.top * scale,
w: rect.width * scale,
h: rect.height * scale,
};
};

// One press selects the element and Enter opens its text with the caret at the end: Studio's dependable way in, where
// a double press has to survive the canvas' gesture machinery.
Expand Down Expand Up @@ -145,14 +165,11 @@ try {
await page.setViewport({ width: 1440, height: 900 });
await page.emulateMediaFeatures([{ name: "prefers-reduced-motion", value: "no-preference" }]);
await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded" });
await page.waitForFunction(
() =>
document
.querySelector("hyperframes-player")
?.shadowRoot?.querySelector("iframe")
?.contentDocument?.querySelector("#body"),
{ timeout: 60_000 },
);
await (
await previewFrame(page)
).waitForFunction(() => document.querySelector("#body"), {
timeout: 60_000,
});
await pause(1000);

await openEdit(page, "#title");
Expand Down Expand Up @@ -273,8 +290,11 @@ try {
// What the preview showed without this change: the browser's own caret, the drawn one hidden.
await page.evaluate(() => {
document.querySelector("[data-inline-text-caret]").style.visibility = "hidden";
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
frame.contentDocument.querySelector("#title").style.caretColor = "";
});
await (
await previewFrame(page)
).evaluate(() => {
document.querySelector("#title").style.caretColor = "";
});
await page.screenshot({ path: join(EVIDENCE_DIR, "before-caret.png"), clip });
await page.screenshot({ path: join(EVIDENCE_DIR, "inline-text-caret-title.png") });
Expand Down
61 changes: 47 additions & 14 deletions packages/studio/tests/e2e/preview-failure-retry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,34 @@ const SELECTION_BOX = '[data-dom-edit-selection-box="true"]';
const CANVAS_MENU = "body > div.fixed.z-200";
const TEXT_TOOLBAR = '[role="toolbar"][aria-label="Text formatting"]';

// Studio handles the frame's load after the player paints, and that load clears a failure shown before it.
function countFrameLoads() {
window.__frameLoads = 0;
const onLoad = (event) => {
if (event.target.src || event.target.srcdoc) window.__frameLoads++;
};
const attach = Element.prototype.attachShadow;
Element.prototype.attachShadow = function (init) {
const root = attach.call(this, init);
if (this.localName !== "hyperframes-player") return root;
new MutationObserver(() =>
root.querySelector("iframe")?.addEventListener("load", onLoad),
).observe(root, { childList: true, subtree: true });
return root;
};
}

const frameLoads = (page) => page.evaluate(() => window.__frameLoads ?? 0);
const frameLoadedSince = (page, before) =>
page.waitForFunction((before) => window.__frameLoads > before, { timeout: 60_000 }, before);

const painted = (page) =>
page.waitForFunction(() => document.querySelector("hyperframes-player")?.painted === true, {
timeout: 60_000,
});

async function open(page, project) {
await page.evaluate(() => (window.__frameLoads = 0));
await page.goto(`${ORIGIN}/#project/${project}`, { waitUntil: "domcontentloaded" });
await page.waitForFunction(
(project) => {
Expand All @@ -31,16 +53,27 @@ async function open(page, project) {
{ timeout: 60_000 },
project,
);
await frameLoadedSince(page, 0);
}

// A sealed frame is reached as a frame, never through contentDocument, which Studio's page cannot read.
async function previewFrame(page) {
const iframe = await page.waitForFunction(
() => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"),
{ timeout: 60_000 },
);
return { iframe: iframe.asElement(), frame: await iframe.asElement().contentFrame() };
}

async function stagePoint(page, id) {
return page.evaluate((id) => {
const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
const el = frame.contentDocument.getElementById(id).getBoundingClientRect();
const box = frame.getBoundingClientRect();
const scale = box.width / frame.contentWindow.innerWidth;
return { x: box.x + (el.x + el.width / 2) * scale, y: box.y + (el.y + el.height / 2) * scale };
const { iframe, frame } = await previewFrame(page);
const box = await iframe.boundingBox();
const el = await frame.evaluate((id) => {
const rect = document.getElementById(id).getBoundingClientRect();
return { x: rect.x, y: rect.y, width: rect.width, height: rect.height, viewport: innerWidth };
}, id);
const scale = box.width / el.viewport;
return { x: box.x + (el.x + el.width / 2) * scale, y: box.y + (el.y + el.height / 2) * scale };
}

// As the player reports a film with no timeline by its load limit; then a real click on its retry button.
Expand Down Expand Up @@ -75,6 +108,7 @@ async function failThenRetry(page) {
};
}, center);
assert.ok(onTop.isRetry, `a click at the retry button lands on ${onTop.hit}`);
const before = await frameLoads(page);
await page.mouse.click(center.x, center.y);
await page.waitForFunction(
() =>
Expand All @@ -85,6 +119,7 @@ async function failThenRetry(page) {
{ timeout: 10_000 },
);
await painted(page);
await frameLoadedSince(page, before);
await page.waitForFunction(
() => !document.querySelector('[aria-label="Composition canvas"]')?.closest("[inert]"),
{ timeout: 10_000 },
Expand All @@ -97,6 +132,7 @@ const selectedId = (page) =>
const { browser } = await launchStudioChrome();
try {
const page = await browser.newPage();
await page.evaluateOnNewDocument(countFrameLoads);
await page.setViewport({ width: 1440, height: 900 });

await open(page, "fade-handles");
Expand Down Expand Up @@ -135,14 +171,11 @@ try {
{ timeout: 10_000 },
);
await page.keyboard.press("Enter");
await page.waitForFunction(
() =>
document
.querySelector("hyperframes-player")
.shadowRoot.querySelector("iframe")
.contentDocument.querySelector("[contenteditable]") !== null,
{ timeout: 10_000 },
);
await (
await previewFrame(page)
).frame.waitForFunction(() => document.querySelector("[contenteditable]") !== null, {
timeout: 10_000,
});
await page.keyboard.press("End");
await page.keyboard.type(" kept");
// The toolbar shows only over a selection, never a bare caret.
Expand Down
Loading
Loading