diff --git a/engine/src/flutter/shell/common/fixtures/shell_test.dart b/engine/src/flutter/shell/common/fixtures/shell_test.dart index 8f8dcab38c..ceeee77a4e 100644 --- a/engine/src/flutter/shell/common/fixtures/shell_test.dart +++ b/engine/src/flutter/shell/common/fixtures/shell_test.dart @@ -138,3 +138,15 @@ void canDecompressImageFromAsset() { } List getFixtureImage() native 'GetFixtureImage'; + +void notifyLocalTime(String string) native 'NotifyLocalTime'; + +@pragma('vm:entry-point') +void localtimesMatch() { + final now = DateTime.now().toLocal(); + // This is: "$y-$m-$d $h:$min:$sec.$ms$us"; + final timeStr = now.toString(); + // Forward only "$y-$m-$d $h" for timestamp comparison. Not using DateTime + // formatting since package:intl is not available. + notifyLocalTime(timeStr.split(":")[0]); +} diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index 083393a4f6..6b0e370023 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -4,6 +4,7 @@ #define FML_USED_ON_EMBEDDER +#include #include #include #include @@ -1149,6 +1150,54 @@ TEST_F(ShellTest, CanConvertToAndFromMappings) { DestroyShell(std::move(shell)); } +// Compares local times as seen by the dart isolate and as seen by this test +// fixture, to a resolution of 1 hour. +// +// This verifies that (1) the isolate is able to get a timezone (doesn't lock +// up for example), and (2) that the host and the isolate agree on what the +// timezone is. +TEST_F(ShellTest, LocaltimesMatch) { + fml::AutoResetWaitableEvent latch; + std::string dart_isolate_time_str; + + // See fixtures/shell_test.dart, the callback NotifyLocalTime is declared + // there. + AddNativeCallback("NotifyLocalTime", CREATE_NATIVE_ENTRY([&](auto args) { + dart_isolate_time_str = + tonic::DartConverter::FromDart( + Dart_GetNativeArgument(args, 0)); + latch.Signal(); + })); + + auto settings = CreateSettingsForFixture(); + auto configuration = RunConfiguration::InferFromSettings(settings); + configuration.SetEntrypoint("localtimesMatch"); + std::unique_ptr shell = CreateShell(settings); + ASSERT_NE(shell.get(), nullptr); + RunEngine(shell.get(), std::move(configuration)); + latch.Wait(); + + char timestr[200]; + const time_t timestamp = time(nullptr); + const struct tm* local_time = localtime(×tamp); + ASSERT_NE(local_time, nullptr) + << "Could not get local time: errno=" << errno << ": " << strerror(errno); + // Example: "2020-02-26 14" for 2pm on February 26, 2020. + const size_t format_size = + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H", local_time); + ASSERT_NE(format_size, 0UL) + << "strftime failed: host time: " << std::string(timestr) + << " dart isolate time: " << dart_isolate_time_str; + + const std::string host_local_time_str = timestr; + + ASSERT_EQ(dart_isolate_time_str, host_local_time_str) + << "Local times in the dart isolate and the local time seen by the test " + << "differ by more than 1 hour, but are expected to be about equal"; + + DestroyShell(std::move(shell)); +} + TEST_F(ShellTest, CanDecompressImageFromAsset) { fml::AutoResetWaitableEvent latch; AddNativeCallback("NotifyWidthHeight", CREATE_NATIVE_ENTRY([&](auto args) { diff --git a/engine/src/flutter/testing/fuchsia/meta/fuchsia_test.cmx b/engine/src/flutter/testing/fuchsia/meta/fuchsia_test.cmx index 9a01e290f2..c1f1fa71c4 100644 --- a/engine/src/flutter/testing/fuchsia/meta/fuchsia_test.cmx +++ b/engine/src/flutter/testing/fuchsia/meta/fuchsia_test.cmx @@ -17,7 +17,8 @@ "fuchsia.sysmem.Allocator", "fuchsia.vulkan.loader.Loader", "fuchsia.logger.LogSink", - "fuchsia.tracing.provider.Registry" + "fuchsia.tracing.provider.Registry", + "fuchsia.intl.PropertyProvider" ] } }