Skip to content

Lightpanda: the headless browser designed for AI and automation

ci: do more chrome test cross validation

Karl Seguin04f0fb3eaef0
diff --git a/src/browser/tests/dommatrix.html b/src/browser/tests/dommatrix.html
index b54eef04b..c59b7f346 100644
--- a/src/browser/tests/dommatrix.html
+++ b/src/browser/tests/dommatrix.html
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<head>
<title>DOMMatrix Test</title>
- <script src="testing.js"></script>
<meta name=lp-mode content=test>
+ <script src="testing.js"></script>
</head>
<body>
diff --git a/src/browser/tests/element/html/event_listeners.html b/src/browser/tests/element/html/event_listeners.html
index cd95cdd04..b179079b2 100644
--- a/src/browser/tests/element/html/event_listeners.html
+++ b/src/browser/tests/element/html/event_listeners.html
@@ -742,16 +742,19 @@
}
</script>
-<img src="https://cdn.lightpanda.io/website/assets/images/docs/hn.png" />
+<script>
+ // Registered before the <img> so a fast local load can't be missed.
+ // We should get this fired at capturing phase when a resource loaded.
+ const documentElementLoad = new Promise((resolve) => {
+ document.documentElement.addEventListener("load", e => resolve(e.eventPhase), { capture: true, once: true });
+ });
+</script>
+
+<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />
<script id="document-element-load" type=module>
const state = await testing.async();
- const docElement = document.documentElement;
-
- // We should get this fired at capturing phase when a resource loaded.
- docElement.addEventListener("load", e => {
- state.resolve(e.eventPhase);
- }, true);
+ state.resolve(await documentElementLoad);
await state.done((eventPhase) => {
testing.expectEqual(Event.CAPTURING_PHASE, eventPhase);
diff --git a/src/browser/tests/element/html/textarea.html b/src/browser/tests/element/html/textarea.html
index e1c4d082c..4e9a3b3ff 100644
--- a/src/browser/tests/element/html/textarea.html
+++ b/src/browser/tests/element/html/textarea.html
@@ -303,8 +303,10 @@
}
</script>
-<script id="select_event">
+<script id="select_event" type=module>
{
+ // select is queued: it isn't ordered against the load event, so wait for it.
+ const state = await testing.async();
const textarea = document.createElement('textarea');
textarea.value = 'Hello World';
document.body.appendChild(textarea);
@@ -321,15 +323,18 @@
textarea.onselect = () => { onselectFired = true; };
let bubbledToBody = false;
- document.body.addEventListener('select', () => {
- bubbledToBody = true;
+ document.body.addEventListener('select', (e) => {
+ if (e.target === textarea) {
+ bubbledToBody = true;
+ state.resolve();
+ }
});
testing.expectEqual(0, eventCount);
textarea.select();
- testing.onload(() => {
+ await state.done(() => {
testing.expectEqual(1, eventCount);
testing.expectEqual('select', lastEvent.type);
testing.expectEqual(textarea, lastEvent.target);
@@ -341,37 +346,42 @@
}
</script>
-<script id="selectionchange_event">
+<script id="selectionchange_event" type=module>
{
+ // Fires asynchronously, not ordered against the load event, and changes
+ // before it fires fold into one event.
+ const state = await testing.async();
const textarea = document.createElement('textarea');
textarea.value = 'Hello World';
document.body.appendChild(textarea);
-
+
let eventCount = 0;
let lastEvent = null;
-
+
textarea.addEventListener('selectionchange', (e) => {
eventCount++;
lastEvent = e;
});
-
+
testing.expectEqual(0, eventCount);
-
+
textarea.setSelectionRange(0, 5);
textarea.select();
textarea.selectionStart = 3;
textarea.selectionEnd = 8;
-
+
let bubbledToBody = false;
- document.body.addEventListener('selectionchange', () => {
- bubbledToBody = true;
+ document.body.addEventListener('selectionchange', (e) => {
+ if (e.target === textarea) {
+ bubbledToBody = true;
+ state.resolve();
+ }
});
textarea.setSelectionRange(1, 4);
-
- // Fires asynchronously, and changes before it fires fold into one event.
+
testing.expectEqual(0, eventCount);
- testing.onload(() => {
+ await state.done(() => {
testing.expectEqual(1, eventCount);
testing.expectEqual('selectionchange', lastEvent.type);
testing.expectEqual(textarea, lastEvent.target);
diff --git a/src/browser/tests/file.html b/src/browser/tests/file.html
index edce56f86..6ddfdb486 100644
--- a/src/browser/tests/file.html
+++ b/src/browser/tests/file.html
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<head id="the_head">
<title>Test File Web API</title>
- <script src="./testing.js"></script>
<meta name=lp-mode content=test>
+ <script src="./testing.js"></script>
</head>
<script id=file_basic>
diff --git a/src/browser/tests/history_traverse.html b/src/browser/tests/history_traverse.html
index d9211f469..a5d386639 100644
--- a/src/browser/tests/history_traverse.html
+++ b/src/browser/tests/history_traverse.html
@@ -1,37 +1,56 @@
<!DOCTYPE html>
+<meta name=lp-mode content=test>
<script src="testing.js"></script>
-<script id=traverse_entries_of_one_document>
+<script id=traverse_entries_of_one_document type=module>
{
// Entries pushed by this document belong to it whatever their path or
- // query: traversing between them must stay in the document (location
- // updated synchronously, popstate fired) instead of loading the URL.
+ // query: traversing between them must stay in the document (popstate
+ // fired) instead of loading the URL.
+ const state = await testing.async();
const original = location.href;
const path = location.pathname;
const pops = [];
- const onpop = (e) => pops.push([location.pathname + location.search, e.state]);
- window.addEventListener('popstate', onpop);
+ const nextPop = () => new Promise((resolve) => {
+ window.addEventListener('popstate', (e) => {
+ pops.push([location.pathname + location.search, e.state]);
+ resolve();
+ }, {once: true});
+ });
history.pushState({n: 1}, '', '?n=1');
history.pushState({n: 2}, '', '/history-traverse-path');
+ let popped = nextPop();
history.back();
- testing.expectEqual(path + '?n=1', location.pathname + location.search);
- testing.expectEqual({n: 1}, history.state);
+ testing.diverges('Chrome queues the traversal: location and state change in a later task', () => {
+ testing.expectEqual(path + '?n=1', location.pathname + location.search);
+ testing.expectEqual({n: 1}, history.state);
+ });
+ await popped;
+ const back = [location.pathname + location.search, history.state];
+ popped = nextPop();
history.forward();
- testing.expectEqual('/history-traverse-path', location.pathname);
- testing.expectEqual({n: 2}, history.state);
-
- testing.expectEqual([
- [path + '?n=1', {n: 1}],
- ['/history-traverse-path', {n: 2}],
- ], pops);
+ testing.diverges('Chrome queues the traversal: location and state change in a later task', () => {
+ testing.expectEqual('/history-traverse-path', location.pathname);
+ testing.expectEqual({n: 2}, history.state);
+ });
+ await popped;
+ const forward = [location.pathname, history.state];
const pushed = navigation.entries().find((e) => e.url.endsWith('/history-traverse-path'));
- testing.expectEqual(true, pushed.sameDocument);
-
- window.removeEventListener('popstate', onpop);
history.replaceState(null, '', original);
+ state.resolve();
+
+ await state.done(() => {
+ testing.expectEqual([path + '?n=1', {n: 1}], back);
+ testing.expectEqual(['/history-traverse-path', {n: 2}], forward);
+ testing.expectEqual([
+ [path + '?n=1', {n: 1}],
+ ['/history-traverse-path', {n: 2}],
+ ], pops);
+ testing.expectEqual(true, pushed.sameDocument);
+ });
}
</script>
diff --git a/src/browser/tests/image_data.html b/src/browser/tests/image_data.html
index 327be0edb..d31122422 100644
--- a/src/browser/tests/image_data.html
+++ b/src/browser/tests/image_data.html
@@ -1,4 +1,5 @@
<!DOCTYPE html>
+<meta name=lp-mode content=test>
<script src="testing.js"></script>
<script id=constructor-basic>
@@ -101,7 +102,9 @@
// height is derived when omitted
const derived = new ImageData(arr, 3);
testing.expectEqual(2, derived.height);
- testing.expectEqual(2, new ImageData(arr, 3, undefined, { colorSpace: "srgb" }).height);
+ testing.diverges("Chrome converts an explicit undefined height to 0 when settings follow", () => {
+ testing.expectEqual(2, new ImageData(arr, 3, undefined, { colorSpace: "srgb" }).height);
+ });
testing.expectEqual(2, ImageData.length);
}
@@ -117,7 +120,8 @@
expectError('IndexSizeError', () => new ImageData(arr, 0));
expectError('InvalidStateError', () => new ImageData(new Uint8ClampedArray(0), 1));
expectError('InvalidStateError', () => new ImageData(new Uint8ClampedArray(5), 1));
- expectError('TypeError', () => new ImageData(new Uint8Array(4), 1));
+ // not an ImageDataArray: the (sw, sh) overload, with sw = 0
+ expectError('IndexSizeError', () => new ImageData(new Uint8Array(4), 1));
expectError('TypeError', () => new ImageData(arr, 3, 2, { colorSpace: "nope" }));
expectError('TypeError', () => new ImageData(10));
}
diff --git a/src/browser/tests/indexeddb.html b/src/browser/tests/indexeddb.html
index 764fd2d39..d0f3393b7 100644
--- a/src/browser/tests/indexeddb.html
+++ b/src/browser/tests/indexeddb.html
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<body>
+<meta name=lp-mode content=test>
<script src="testing.js"></script>
<!-- The bare-slice milestone: open a database, create an object store during
diff --git a/src/browser/tests/inject_script.html b/src/browser/tests/inject_script.html
index f7917a545..6a6339d1c 100644
--- a/src/browser/tests/inject_script.html
+++ b/src/browser/tests/inject_script.html
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <!-- this is testing a lightpanda specific feature, it cannot pass in Chrome -->
<script src="./testing.js"></script>
</head>
<body>
diff --git a/src/browser/tests/payment_request.html b/src/browser/tests/payment_request.html
index 894152cc0..220ce11f0 100644
--- a/src/browser/tests/payment_request.html
+++ b/src/browser/tests/payment_request.html
@@ -5,6 +5,8 @@
<script>
const METHODS = [{ supportedMethods: 'https://example.com/pay' }];
const DETAILS = { total: { label: 'Total', amount: { currency: 'USD', value: '10.00' } } };
+ // a URL method makes Chrome download its manifest before settling a promise
+ const OFFLINE = [{ supportedMethods: 'basic-card' }];
</script>
<script id=shape>
@@ -138,8 +140,8 @@
<script id=can_make_payment type=module>
{
const state = await testing.async();
- const result = await new PaymentRequest(METHODS, DETAILS).canMakePayment();
- const enrolled = await new PaymentRequest(METHODS, DETAILS).hasEnrolledInstrument();
+ const result = await new PaymentRequest(OFFLINE, DETAILS).canMakePayment();
+ const enrolled = await new PaymentRequest(OFFLINE, DETAILS).hasEnrolledInstrument();
state.resolve();
await state.done(() => {
testing.expectEqual(false, result);
@@ -151,7 +153,7 @@
<script id=show type=module>
{
const state = await testing.async();
- const req = new PaymentRequest(METHODS, DETAILS);
+ const req = new PaymentRequest(OFFLINE, DETAILS);
const errors = [];
await req.show().catch((e) => errors.push(e.name));
await req.show().catch((e) => errors.push(e.name));
diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig
index 9cdfb025f..12fa2f61f 100644
--- a/src/browser/webapi/ImageData.zig
+++ b/src/browser/webapi/ImageData.zig
@@ -183,16 +183,15 @@ pub const JsApi = struct {
/// new ImageData(dataArray, width, height)
/// new ImageData(dataArray, width, height, settings)
/// ```
- ///
- /// We currently support only the first 2.
pub const constructor = bridge.constructor(struct {
fn wrap(first: js.Value, second: u32, third: ?js.Value, fourth: ?ConstructorSettings, exec: *Execution) !*ImageData {
if (first.isUint8ClampedArray()) {
return initWithData(first, second, third, fourth, exec);
}
- if (first.isTypedArray()) {
+ if (first.isFloat16Array()) {
// Float16Array data needs the "rgba-float16" pixel format, which
- // we don't support.
+ // we don't support. Other typed arrays aren't ImageDataArrays, so
+ // they take the (sw, sh) overload.
return error.TypeError;
}