mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
more legacy test fixes
This commit is contained in:
@@ -135,7 +135,7 @@ pub fn callWithThis(self: *const Function, comptime T: type, this: anytype, args
|
||||
.pointer => blk: {
|
||||
var values = try context.call_arena.alloc(v8.Value, args.len);
|
||||
for (args, 0..) |a, i| {
|
||||
values[i] = try context.zigValueToJs(a);
|
||||
values[i] = try context.zigValueToJs(a, .{});
|
||||
}
|
||||
break :blk values;
|
||||
},
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=location>
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html', location.href);
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html', document.location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html', location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html', document.location.href);
|
||||
|
||||
testing.expectEqual("localhost:9589", location.host);
|
||||
testing.expectEqual("localhost", location.hostname);
|
||||
@@ -17,17 +17,17 @@
|
||||
<script id=location_hash>
|
||||
location.hash = "";
|
||||
testing.expectEqual("", location.hash);
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html', location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html', location.href);
|
||||
|
||||
location.hash = "#abcdef";
|
||||
testing.expectEqual("#abcdef", location.hash);
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html#abcdef', location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html#abcdef', location.href);
|
||||
|
||||
location.hash = "xyzxyz";
|
||||
testing.expectEqual("#xyzxyz", location.hash);
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html#xyzxyz', location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html#xyzxyz', location.href);
|
||||
|
||||
location.hash = "";
|
||||
testing.expectEqual("", location.hash);
|
||||
testing.expectEqual('"http://localhost:9589/html/location.html', location.href);
|
||||
testing.expectEqual('http://localhost:9589/html/location.html', location.href);
|
||||
</script>
|
||||
|
||||
@@ -9,5 +9,4 @@
|
||||
<script id=frames>
|
||||
testing.expectEqual(2, frames.length);
|
||||
testing.expectEqual(undefined, frames[3])
|
||||
testing.expectError('Error: TODO', () => { frames[1] });
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../testing.js"></script>
|
||||
<body style=height:4000px;width:4000px></body>
|
||||
|
||||
<script id=aliases>
|
||||
testing.expectEqual(window, window.self);
|
||||
testing.expectEqual(window, window.parent);
|
||||
@@ -26,23 +27,6 @@
|
||||
testing.eventually(() => testing.expectEqual(true, start > 0));
|
||||
</script>
|
||||
|
||||
<script id=dimensions>
|
||||
testing.expectEqual(5, innerHeight);
|
||||
// Width is 5 even if there are no elements
|
||||
testing.expectEqual(5, innerWidth);
|
||||
|
||||
let div1 = document.createElement('div');
|
||||
document.body.appendChild(div1);
|
||||
div1.getClientRects()
|
||||
|
||||
let div2 = document.createElement('div');
|
||||
document.body.appendChild(div2);
|
||||
div2.getClientRects();
|
||||
|
||||
testing.expectEqual(5, innerHeight);
|
||||
testing.expectEqual(10, innerWidth);
|
||||
</script>
|
||||
|
||||
<script id=setTimeout>
|
||||
let longCall = false;
|
||||
window.setTimeout(() => {longCall = true}, 5001);
|
||||
@@ -53,7 +37,9 @@
|
||||
testing.eventually(() => testing.expectEqual(1, wst1));
|
||||
|
||||
let wst2 = 1;
|
||||
window.setTimeout((a, b) => {wst2 = a+ b}, 1, 2, 3);
|
||||
window.setTimeout((a, b) => {
|
||||
wst2 = a + b;
|
||||
}, 1, 2, 3);
|
||||
testing.eventually(() => testing.expectEqual(5, wst2));
|
||||
</script>
|
||||
|
||||
@@ -81,46 +67,6 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<script id=scroll>
|
||||
let scroll = false;
|
||||
let scrollend = false
|
||||
|
||||
window.addEventListener('scroll', () => {scroll = true});
|
||||
document.addEventListener('scrollend', () => {scrollend = true});
|
||||
window.scrollTo(0, 0);
|
||||
testing.expectEqual(0, scrollX);
|
||||
testing.expectEqual(0, pageXOffset);
|
||||
testing.expectEqual(0, scrollY);
|
||||
testing.expectEqual(0, pageYOffset);
|
||||
|
||||
testing.expectEqual(true, scroll);
|
||||
testing.expectEqual(true, scrollend);
|
||||
|
||||
window.scrollTo(10, 20);
|
||||
testing.expectEqual(10, scrollX);
|
||||
testing.expectEqual(10, pageXOffset);
|
||||
testing.expectEqual(20, scrollY);
|
||||
testing.expectEqual(20, pageYOffset);
|
||||
|
||||
window.scrollTo(-10, -20);
|
||||
testing.expectEqual(0, scrollX);
|
||||
testing.expectEqual(0, pageXOffset);
|
||||
testing.expectEqual(0, scrollY);
|
||||
testing.expectEqual(0, pageYOffset);
|
||||
|
||||
window.scrollTo({top: 30, left: 40});
|
||||
testing.expectEqual(40, scrollX);
|
||||
testing.expectEqual(40, pageXOffset);
|
||||
testing.expectEqual(30, scrollY);
|
||||
testing.expectEqual(30, pageYOffset);
|
||||
|
||||
window.scrollTo({top: -30, left: -40});
|
||||
testing.expectEqual(0, scrollX);
|
||||
testing.expectEqual(0, pageXOffset);
|
||||
testing.expectEqual(0, scrollY);
|
||||
testing.expectEqual(0, pageYOffset);
|
||||
</script>
|
||||
|
||||
<script id=queueMicroTask>
|
||||
var qm = false;
|
||||
window.queueMicrotask(() => {qm = true });
|
||||
@@ -137,9 +83,11 @@
|
||||
</script>
|
||||
|
||||
<script id=window.onload>
|
||||
let isWindowTarget = false;
|
||||
let isDocumentTarget = false;
|
||||
|
||||
const callback = (e) => isWindowTarget = e.target === window;
|
||||
const callback = (e) => {
|
||||
isDocumentTarget = e.target === document;
|
||||
};
|
||||
// Callback is not set yet.
|
||||
testing.expectEqual(null, window.onload);
|
||||
// Setting an object.
|
||||
@@ -149,7 +97,7 @@
|
||||
window.onload = callback;
|
||||
testing.expectEqual(callback, window.onload);
|
||||
|
||||
testing.eventually(() => testing.expectEqual(true, isWindowTarget));
|
||||
testing.eventually(() => testing.expectEqual(true, isDocumentTarget));
|
||||
</script>
|
||||
|
||||
<script id=reportError>
|
||||
|
||||
@@ -22,3 +22,12 @@
|
||||
testing.expectEqual(false, set_interval2);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script id=setTimeout>
|
||||
let wst2 = 1;
|
||||
window.setTimeout((a, b) => {
|
||||
wst2 = a + b;
|
||||
}, 1, 2, 3);
|
||||
testing.eventually(() => testing.expectEqual(5, wst2));
|
||||
</script>
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
testing.expectEqual(window, globalThis);
|
||||
testing.expectEqual(window, self);
|
||||
testing.expectEqual(window, window.self);
|
||||
|
||||
testing.expectEqual(1080, innerHeight);
|
||||
testing.expectEqual(1920, innerWidth);
|
||||
</script>
|
||||
|
||||
<script id=load>
|
||||
|
||||
@@ -149,60 +149,40 @@ pub fn getOnLoad(self: *const Window) ?js.Function {
|
||||
return self._on_load;
|
||||
}
|
||||
|
||||
pub fn setOnLoad(self: *Window, cb_: ?js.Function) !void {
|
||||
if (cb_) |cb| {
|
||||
self._on_load = cb;
|
||||
} else {
|
||||
self._on_load = null;
|
||||
}
|
||||
pub fn setOnLoad(self: *Window, setter: ?FunctionSetter) !void {
|
||||
self._on_load = getFunctionFromSetter(setter);
|
||||
}
|
||||
|
||||
pub fn getOnPageShow(self: *const Window) ?js.Function {
|
||||
return self._on_pageshow;
|
||||
}
|
||||
|
||||
pub fn setOnPageShow(self: *Window, cb_: ?js.Function) !void {
|
||||
if (cb_) |cb| {
|
||||
self._on_pageshow = cb;
|
||||
} else {
|
||||
self._on_pageshow = null;
|
||||
}
|
||||
pub fn setOnPageShow(self: *Window, setter: ?FunctionSetter) !void {
|
||||
self._on_pageshow = getFunctionFromSetter(setter);
|
||||
}
|
||||
|
||||
pub fn getOnPopState(self: *const Window) ?js.Function {
|
||||
return self._on_popstate;
|
||||
}
|
||||
|
||||
pub fn setOnPopState(self: *Window, cb_: ?js.Function) !void {
|
||||
if (cb_) |cb| {
|
||||
self._on_popstate = cb;
|
||||
} else {
|
||||
self._on_popstate = null;
|
||||
}
|
||||
pub fn setOnPopState(self: *Window, setter: ?FunctionSetter) !void {
|
||||
self._on_popstate = getFunctionFromSetter(setter);
|
||||
}
|
||||
|
||||
pub fn getOnError(self: *const Window) ?js.Function {
|
||||
return self._on_error;
|
||||
}
|
||||
|
||||
pub fn setOnError(self: *Window, cb_: ?js.Function) !void {
|
||||
if (cb_) |cb| {
|
||||
self._on_error = cb;
|
||||
} else {
|
||||
self._on_error = null;
|
||||
}
|
||||
pub fn setOnError(self: *Window, setter: ?FunctionSetter) !void {
|
||||
self._on_error = getFunctionFromSetter(setter);
|
||||
}
|
||||
|
||||
pub fn getOnUnhandledRejection(self: *const Window) ?js.Function {
|
||||
return self._on_unhandled_rejection;
|
||||
}
|
||||
|
||||
pub fn setOnUnhandledRejection(self: *Window, cb_: ?js.Function) !void {
|
||||
if (cb_) |cb| {
|
||||
self._on_unhandled_rejection = cb;
|
||||
} else {
|
||||
self._on_unhandled_rejection = null;
|
||||
}
|
||||
pub fn setOnUnhandledRejection(self: *Window, setter: ?FunctionSetter) !void {
|
||||
self._on_unhandled_rejection = getFunctionFromSetter(setter);
|
||||
}
|
||||
|
||||
pub fn fetch(_: *const Window, input: Fetch.Input, options: ?Fetch.InitOpts, page: *Page) !js.Promise {
|
||||
@@ -351,9 +331,9 @@ pub fn btoa(_: *const Window, input: []const u8, page: *Page) ![]const u8 {
|
||||
}
|
||||
|
||||
pub fn atob(_: *const Window, input: []const u8, page: *Page) ![]const u8 {
|
||||
const decoded_len = try std.base64.standard.Decoder.calcSizeForSlice(input);
|
||||
const decoded_len = std.base64.standard.Decoder.calcSizeForSlice(input) catch return error.InvalidCharacterError;
|
||||
const decoded = try page.call_arena.alloc(u8, decoded_len);
|
||||
try std.base64.standard.Decoder.decode(decoded, input);
|
||||
std.base64.standard.Decoder.decode(decoded, input) catch return error.InvalidCharacterError;
|
||||
return decoded;
|
||||
}
|
||||
|
||||
@@ -575,7 +555,7 @@ const ScheduleCallback = struct {
|
||||
};
|
||||
},
|
||||
.normal => {
|
||||
self.cb.call(void, .{self.params}) catch |err| {
|
||||
self.cb.call(void, self.params) catch |err| {
|
||||
log.warn(.js, "window.timer", .{ .name = self.name, .err = err });
|
||||
};
|
||||
},
|
||||
@@ -621,6 +601,22 @@ const PostMessageCallback = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const FunctionSetter = union(enum) {
|
||||
func: js.Function,
|
||||
anything: js.Value,
|
||||
};
|
||||
|
||||
// window.onload = {}; doesn't fail, but it doesn't do anything.
|
||||
// seems like setting to null is ok (though, at least on Firefix, it preserves
|
||||
// the original value, which we could do, but why?)
|
||||
fn getFunctionFromSetter(setter_: ?FunctionSetter) ?js.Function {
|
||||
const setter = setter_ orelse return null;
|
||||
return switch (setter) {
|
||||
.func => |func| func,
|
||||
.anything => null,
|
||||
};
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(Window);
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
// These are crashing, comment this out to skip them.
|
||||
|
||||
// if (std.mem.indexOf(u8, entry.basename, "navigation") != null) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user