From 0bb94699d2ff1f6f586fea9efad48343e73a751f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Gravel Date: Sun, 19 Apr 2026 15:51:46 -0700 Subject: [PATCH] Extend context loss/restoration test coverage to desynchronized canvas Desynchronize canvases use a resource dispatcher to push frames and since the dispatcher is descarded on context loss [1], it's worth adding test coverage for this. Note that the frame dispatcher is never recreated after the context is restored, so the canvas doesn't fully recover from the context loss. The canvas can be read back though, so the tests still works and we can at least validate that the context state transitions work properly. Also note that the OffscreenCanvas doesn't do much with the `desynchronized` flag, but the test coverage is still useful given that this flag is listed as supported in MDN [1] and the specification [2]. [1] https://crsrc.org/c/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc;l=290;drc=8abea14deda089834ba142a35e8342014812df55 [2] https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext [3] https://html.spec.whatwg.org/multipage/canvas.html#canvas-setting-init-bitmap Change-Id: I300d1f2827406120896cc7dc38794cb450ea3ed5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7770647 Reviewed-by: Vasiliy Telezhnikov Commit-Queue: Jean-Philippe Gravel Cr-Commit-Position: refs/heads/main@{#1617254} --- html/canvas/resources/canvas-promise-test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/html/canvas/resources/canvas-promise-test.js b/html/canvas/resources/canvas-promise-test.js index 63aaa11f563693..0c843565ecbdb1 100644 --- a/html/canvas/resources/canvas-promise-test.js +++ b/html/canvas/resources/canvas-promise-test.js @@ -144,7 +144,13 @@ function runCanvasTestsInWorker({dependencies = []} = {}) { const dependencyScripts = await Promise.all(allDeps.map(dep => fetch(dep).then(r => r.text()))); const canvasTests = currentScript.textContent; - const allScripts = dependencyScripts.concat([canvasTests, 'done();']); + const allScripts = [ + // Forward `location.search` to the worker so that it could run the right + // test variants. `location.search` is read-only in workers, so the whole + // object has to be replaced. + `var location = {search: '${self.location.search}'};`, + ].concat(dependencyScripts) + .concat([canvasTests, 'done();']); const workerBlob = new Blob(allScripts); const worker = new Worker(URL.createObjectURL(workerBlob));