Skip to content

Commit 4ede2cd

Browse files
Lubrsigmta
authored andcommitted
LibWebView+WebContent: Allow setting the default time zone
This is used by tests to set the default time zone to UTC. This is because certain tests create JavaScript Date objects, which are in the current timezone.
1 parent d0bfb85 commit 4ede2cd

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

Libraries/LibWebView/Application.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
109109
Optional<StringView> webdriver_content_ipc_path;
110110
Optional<StringView> user_agent_preset;
111111
Optional<StringView> dns_server_address;
112+
Optional<StringView> default_time_zone;
112113
Optional<u16> dns_server_port;
113114
bool use_dns_over_tls = false;
114115
bool layout_test_mode = false;
@@ -178,6 +179,7 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
178179
args_parser.add_option(dns_server_port, "Set the DNS server port", "dns-port", 0, "port (default: 53 or 853 if --dot)");
179180
args_parser.add_option(use_dns_over_tls, "Use DNS over TLS", "dot");
180181
args_parser.add_option(validate_dnssec_locally, "Validate DNSSEC locally", "dnssec");
182+
args_parser.add_option(default_time_zone, "Default time zone", "default-time-zone", 0, "time-zone-id");
181183

182184
args_parser.add_option(Core::ArgsParser::Option {
183185
.argument_mode = Core::ArgsParser::OptionArgumentMode::Optional,
@@ -276,6 +278,7 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
276278
.enable_autoplay = enable_autoplay ? EnableAutoplay::Yes : EnableAutoplay::No,
277279
.collect_garbage_on_every_allocation = collect_garbage_on_every_allocation ? CollectGarbageOnEveryAllocation::Yes : CollectGarbageOnEveryAllocation::No,
278280
.paint_viewport_scrollbars = disable_scrollbar_painting ? PaintViewportScrollbars::No : PaintViewportScrollbars::Yes,
281+
.default_time_zone = default_time_zone,
279282
};
280283

281284
create_platform_options(m_browser_options, m_web_content_options);

Libraries/LibWebView/HelperProcess.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ static ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_proc
128128
arguments.append(ByteString::number(maybe_echo_server_port.value()));
129129
}
130130

131+
if (web_content_options.default_time_zone.has_value()) {
132+
arguments.append("--default-time-zone");
133+
arguments.append(web_content_options.default_time_zone.value());
134+
}
135+
131136
if (auto server = mach_server_name(); server.has_value()) {
132137
arguments.append("--mach-server-name"sv);
133138
arguments.append(server.value());

Libraries/LibWebView/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct WebContentOptions {
169169
CollectGarbageOnEveryAllocation collect_garbage_on_every_allocation { CollectGarbageOnEveryAllocation::No };
170170
Optional<u16> echo_server_port {};
171171
PaintViewportScrollbars paint_viewport_scrollbars { PaintViewportScrollbars::Yes };
172+
Optional<StringView> default_time_zone {};
172173
};
173174

174175
}

Meta/WPT.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ WPT_ARGS=(
8585
"--webdriver-binary=${WEBDRIVER_BINARY}"
8686
"--install-webdriver"
8787
"--webdriver-arg=--force-cpu-painting"
88+
"--webdriver-arg=--default-time-zone=UTC"
8889
"--no-pause-after-test"
8990
"--install-fonts"
9091
"${EXTRA_WPT_ARGS[@]}"

Services/WebContent/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <LibMain/Main.h>
1919
#include <LibMedia/Audio/Loader.h>
2020
#include <LibRequests/RequestClient.h>
21+
#include <LibUnicode/TimeZone.h>
2122
#include <LibWeb/Bindings/MainThreadVM.h>
2223
#include <LibWeb/Fetch/Fetching/Fetching.h>
2324
#include <LibWeb/HTML/Window.h>
@@ -107,6 +108,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
107108
bool is_headless = false;
108109
bool disable_scrollbar_painting = false;
109110
StringView echo_server_port_string_view {};
111+
StringView default_time_zone {};
110112

111113
Core::ArgsParser args_parser;
112114
args_parser.add_option(command_line, "Browser process command line", "command-line", 0, "command_line");
@@ -129,13 +131,19 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
129131
args_parser.add_option(disable_scrollbar_painting, "Don't paint horizontal or vertical viewport scrollbars", "disable-scrollbar-painting");
130132
args_parser.add_option(echo_server_port_string_view, "Echo server port used in test internals", "echo-server-port", 0, "echo_server_port");
131133
args_parser.add_option(is_headless, "Report that the browser is running in headless mode", "headless");
134+
args_parser.add_option(default_time_zone, "Default time zone", "default-time-zone", 0, "time-zone-id");
132135

133136
args_parser.parse(arguments);
134137

135138
if (wait_for_debugger) {
136139
Core::Process::wait_for_debugger_and_break();
137140
}
138141

142+
if (!default_time_zone.is_empty()) {
143+
if (auto result = Unicode::set_current_time_zone(default_time_zone); result.is_error())
144+
dbgln("Failed to set default time zone: {}", result.error());
145+
}
146+
139147
auto& font_provider = static_cast<Gfx::PathFontProvider&>(Gfx::FontDatabase::the().install_system_font_provider(make<Gfx::PathFontProvider>()));
140148
if (force_fontconfig) {
141149
font_provider.set_name_but_fixme_should_create_custom_system_font_provider("FontConfig"_string);

Services/WebDriver/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static ErrorOr<Core::Process> launch_process(StringView application, ReadonlySpa
3333
return result;
3434
}
3535

36-
static Vector<ByteString> create_arguments(ByteString const& socket_path, bool headless, bool force_cpu_painting, Optional<StringView> debug_process)
36+
static Vector<ByteString> create_arguments(ByteString const& socket_path, bool headless, bool force_cpu_painting, Optional<StringView> debug_process, Optional<StringView> default_time_zone)
3737
{
3838
Vector<ByteString> arguments {
3939
"--webdriver-content-path"sv,
@@ -59,6 +59,9 @@ static Vector<ByteString> create_arguments(ByteString const& socket_path, bool h
5959
if (debug_process.has_value())
6060
arguments.append(ByteString::formatted("--debug-process={}", debug_process.value()));
6161

62+
if (default_time_zone.has_value())
63+
arguments.append(ByteString::formatted("--default-time-zone={}", default_time_zone.value()));
64+
6265
// FIXME: WebDriver does not yet handle the WebContent process switch brought by site isolation.
6366
arguments.append("--disable-site-isolation"sv);
6467

@@ -75,6 +78,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
7578
bool force_cpu_painting = false;
7679
bool headless = false;
7780
Optional<StringView> debug_process;
81+
Optional<StringView> default_time_zone;
7882

7983
Core::ArgsParser args_parser;
8084
args_parser.add_option(listen_address, "IP address to listen on", "listen-address", 'l', "listen_address");
@@ -83,6 +87,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
8387
args_parser.add_option(force_cpu_painting, "Launch browser with GPU painting disabled", "force-cpu-painting");
8488
args_parser.add_option(debug_process, "Wait for a debugger to attach to the given process name (WebContent, RequestServer, etc.)", "debug-process", 0, "process-name");
8589
args_parser.add_option(headless, "Launch browser without a graphical interface", "headless");
90+
args_parser.add_option(default_time_zone, "Default time zone", "default-time-zone", 0, "time-zone-id");
8691
args_parser.parse(arguments);
8792

8893
auto ipv4_address = IPv4Address::from_string(listen_address);
@@ -123,7 +128,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
123128
}
124129

125130
auto launch_browser_callback = [&](ByteString const& socket_path, bool headless) {
126-
auto arguments = create_arguments(socket_path, headless, force_cpu_painting, debug_process);
131+
auto arguments = create_arguments(socket_path, headless, force_cpu_painting, debug_process, default_time_zone);
127132
return launch_process("Ladybird"sv, arguments.span());
128133
};
129134

Tests/LibWeb/test-web/Application.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ void Application::create_platform_options(WebView::BrowserOptions& browser_optio
7373
// Ensure tests are resilient to minor changes to the viewport scrollbar.
7474
web_content_options.paint_viewport_scrollbars = WebView::PaintViewportScrollbars::No;
7575

76+
// Ensure consistent time zone operations across different machine configurations.
77+
web_content_options.default_time_zone = "UTC"sv;
78+
7679
if (dump_gc_graph) {
7780
// Force all tests to run in serial if we are interested in the GC graph.
7881
test_concurrency = 1;

0 commit comments

Comments
 (0)