Skip to content

Commit 96e958e

Browse files
committed
test(webui): select the tab's current identity in the two-page row
A new tab lands its first load after the tab was opened, and the provider reads that landing as a replaced page: the generation moves with it, so the identity `open_tab` answered with is already a generation behind by the time the row uses it. The service refuses such an identity and says what to do about it — select the target again — so the row reads the identity the service holds for the tab, selects that one, and watches that one.
1 parent b456b9e commit 96e958e

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎packages/webui/test/integration/isolated-chromium-two-pages.test.ts‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr
538538
"open_tab",
539539
{ url: pageUrl("second page") },
540540
);
541-
const second = opened.result as WebuiBrowserTargetId;
542-
expect(second.targetId).not.toBe(first!.targetId);
541+
const secondTab = opened.result as WebuiBrowserTargetId;
542+
expect(secondTab.targetId).not.toBe(first!.targetId);
543543

544544
const firstFrames: WebuiBrowserImageFrame[] = [];
545545
const secondFrames: WebuiBrowserImageFrame[] = [];
@@ -565,16 +565,34 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr
565565
await repaint();
566566
await waitFor(() => firstFrames.length > 0, "a picture of the first page");
567567

568+
// The page behind a new tab lands its first load after the tab was
569+
// opened, and the provider reads that landing as a replaced page: the
570+
// generation moves with it, and the identity `open_tab` answered with is a
571+
// generation behind by the time the row gets to use it. The service
572+
// refuses such an identity and says what to do about it — select the
573+
// target again — so the row reads the identity the service holds for the
574+
// tab, selects that one, and watches that one.
575+
let second: WebuiBrowserTargetId | undefined;
576+
await waitFor(async () => {
577+
const listed = await service.listTargets("isolated-chromium", "run-1");
578+
const current = listed.targets.find(
579+
(candidate) => candidate.id.targetId === secondTab.targetId,
580+
);
581+
if (!current) return false;
582+
await service.selectTarget(current.id, "run-1");
583+
second = current.id;
584+
return true;
585+
}, "the second page to become the run's selection");
586+
568587
const secondStream = (async () => {
569588
for await (const frame of service.watchFrames(
570589
"isolated-chromium",
571-
second,
590+
second!,
572591
controller.signal,
573592
)) {
574593
secondFrames.push(frame);
575594
}
576595
})();
577-
await service.selectTarget(second, "run-1");
578596
await repaint();
579597
await waitFor(() => secondFrames.length > 0, "a picture of the second page");
580598

@@ -585,7 +603,7 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr
585603
expect(secondFrames.length).toBeGreaterThan(0);
586604
// Neither stream received the other page's picture.
587605
expect(firstFrames.every((frame) => frame.target.targetId === first!.targetId)).toBe(true);
588-
expect(secondFrames.every((frame) => frame.target.targetId === second.targetId)).toBe(true);
606+
expect(secondFrames.every((frame) => frame.target.targetId === secondTab.targetId)).toBe(true);
589607
});
590608
});
591609

0 commit comments

Comments
 (0)