|
| 1 | +// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) |
| 2 | +// |
| 3 | +// Francis Bouvier <[email protected]> |
| 4 | +// Pierre Tachoire <[email protected]> |
| 5 | +// |
| 6 | +// This program is free software: you can redistribute it and/or modify |
| 7 | +// it under the terms of the GNU Affero General Public License as |
| 8 | +// published by the Free Software Foundation, either version 3 of the |
| 9 | +// License, or (at your option) any later version. |
| 10 | +// |
| 11 | +// This program is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Affero General Public License for more details. |
| 15 | +// |
| 16 | +// You should have received a copy of the GNU Affero General Public License |
| 17 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +const std = @import("std"); |
| 20 | + |
| 21 | +const builtin = @import("builtin"); |
| 22 | +const parser = @import("netsurf"); |
| 23 | +const jsruntime = @import("jsruntime"); |
| 24 | +const Callback = jsruntime.Callback; |
| 25 | +const CallbackArg = jsruntime.CallbackArg; |
| 26 | +const Loop = jsruntime.Loop; |
| 27 | + |
| 28 | +const Case = jsruntime.test_utils.Case; |
| 29 | +const checkCases = jsruntime.test_utils.checkCases; |
| 30 | + |
| 31 | +const EventTarget = @import("../dom/event_target.zig").EventTarget; |
| 32 | + |
| 33 | +const storage = @import("../storage/storage.zig"); |
| 34 | + |
| 35 | +// https://html.spec.whatwg.org/multipage/system-state.html#navigator |
| 36 | +pub const Navigator = struct { |
| 37 | + pub const mem_guarantied = true; |
| 38 | + |
| 39 | + agent: []const u8 = "Lightpanda/1.0", |
| 40 | + version: []const u8 = "1.0", |
| 41 | + vendor: []const u8 = "", |
| 42 | + platform: []const u8 = std.fmt.comptimePrint("{any} {any}", .{ builtin.os.tag, builtin.cpu.arch }), |
| 43 | + |
| 44 | + language: []const u8 = "en-US", |
| 45 | + |
| 46 | + pub fn get_userAgent(self: *Navigator) []const u8 { |
| 47 | + return self.agent; |
| 48 | + } |
| 49 | + pub fn get_appCodeName(_: *Navigator) []const u8 { |
| 50 | + return "Mozilla"; |
| 51 | + } |
| 52 | + pub fn get_appName(_: *Navigator) []const u8 { |
| 53 | + return "Netscape"; |
| 54 | + } |
| 55 | + pub fn get_appVersion(self: *Navigator) []const u8 { |
| 56 | + return self.version; |
| 57 | + } |
| 58 | + pub fn get_platform(self: *Navigator) []const u8 { |
| 59 | + return self.platform; |
| 60 | + } |
| 61 | + pub fn get_product(_: *Navigator) []const u8 { |
| 62 | + return "Gecko"; |
| 63 | + } |
| 64 | + pub fn get_productSub(_: *Navigator) []const u8 { |
| 65 | + return "20030107"; |
| 66 | + } |
| 67 | + pub fn get_vendor(self: *Navigator) []const u8 { |
| 68 | + return self.vendor; |
| 69 | + } |
| 70 | + pub fn get_vendorSub(_: *Navigator) []const u8 { |
| 71 | + return ""; |
| 72 | + } |
| 73 | + pub fn get_language(self: *Navigator) []const u8 { |
| 74 | + return self.language; |
| 75 | + } |
| 76 | + // TODO wait for arrays. |
| 77 | + //pub fn get_languages(self: *Navigator) [][]const u8 { |
| 78 | + // return .{self.language}; |
| 79 | + //} |
| 80 | + pub fn get_online(_: *Navigator) bool { |
| 81 | + return true; |
| 82 | + } |
| 83 | + pub fn _registerProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void { |
| 84 | + _ = scheme; |
| 85 | + _ = url; |
| 86 | + } |
| 87 | + pub fn _unregisterProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void { |
| 88 | + _ = scheme; |
| 89 | + _ = url; |
| 90 | + } |
| 91 | + |
| 92 | + pub fn get_cookieEnabled(_: *Navigator) bool { |
| 93 | + return true; |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +// Tests |
| 98 | +// ----- |
| 99 | + |
| 100 | +pub fn testExecFn( |
| 101 | + _: std.mem.Allocator, |
| 102 | + js_env: *jsruntime.Env, |
| 103 | +) anyerror!void { |
| 104 | + var navigator = [_]Case{ |
| 105 | + .{ .src = "navigator.userAgent", .ex = "Lightpanda/1.0" }, |
| 106 | + .{ .src = "navigator.appVersion", .ex = "1.0" }, |
| 107 | + .{ .src = "navigator.language", .ex = "en-US" }, |
| 108 | + }; |
| 109 | + try checkCases(js_env, &navigator); |
| 110 | +} |
0 commit comments