未验证 提交 1551b742 编写于 作者: F Filip Filmar 提交者: GitHub

[shell] Adds a shell test for timezone fetches (#19108)

Adds a test that verifies that the view of the local time is the same in
the Dart isolate and the process that is running the test.

Specifically, this test is useful to verify that the code paths for
timezone retrieval do not break while the underlying FIDL protocols are
being refactored.

However, since the check is generally useful, the test is written as a
general flutter test.

Running this on Fuchsia required adding `fuchsia.intl.ProfileProvider`
to the CMX file that is used for all build Fuchsia packages.

Testing is a bit involved on Fuchsia.  You must build the Fuchsia
package `fluter/shell/common:shell_tests` and publish it to the dev
repository for your Fuchsia device.  It seems that a way to do so is to
modify the script `flutter/tools/fuchsia/build_fuchsia_artifacts.py` and
modify its function `GetTargetsToBuild` like so:

```
def GetTargetsToBuild(product=False):
  targets_to_build = [
    'flutter/shell/platform/fuchsia:fuchsia',
    'flutter/shell/common:shell_tests',
  ]
  return targets_to_build
```

Next, the Fuchsia packages need to be compiled and published.

Once done, the following `fx` invocation will run the test, assuming
that you have your Fuchsia setup:

```
fx shell run \
    fuchsia-pkg://fuchsia.com/shell_tests#meta/shell_tests.cmx \
    -- --gtest_filter=ShellTest.LocaltimesMatch
```
上级 5157a6b2
......@@ -138,3 +138,15 @@ void canDecompressImageFromAsset() {
}
List<int> 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]);
}
......@@ -4,6 +4,7 @@
#define FML_USED_ON_EMBEDDER
#include <time.h>
#include <algorithm>
#include <functional>
#include <future>
......@@ -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<std::string>::FromDart(
Dart_GetNativeArgument(args, 0));
latch.Signal();
}));
auto settings = CreateSettingsForFixture();
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("localtimesMatch");
std::unique_ptr<Shell> 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(&timestamp);
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) {
......
......@@ -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"
]
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册