Flutter Engine
platform_configuration_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #define FML_USED_ON_EMBEDDER
6 
7 #include "flutter/lib/ui/window/platform_configuration.h"
8 
9 #include <memory>
10 
11 #include "flutter/common/task_runners.h"
12 #include "flutter/fml/synchronization/waitable_event.h"
13 #include "flutter/lib/ui/painting/vertices.h"
14 #include "flutter/runtime/dart_vm.h"
15 #include "flutter/shell/common/shell_test.h"
16 #include "flutter/shell/common/thread_host.h"
17 #include "flutter/testing/testing.h"
18 
19 namespace flutter {
20 namespace testing {
21 
23  public:
25  std::vector<uint8_t> data;
26  isolate_data_.reset(new ::fml::DataMapping(data));
27  }
28  std::string DefaultRouteName() override { return "TestRoute"; }
29  void ScheduleFrame() override {}
30  void Render(Scene* scene) override {}
31  void UpdateSemantics(SemanticsUpdate* update) override {}
33  std::unique_ptr<PlatformMessage> message) override {}
34  FontCollection& GetFontCollection() override { return font_collection_; }
35  void UpdateIsolateDescription(const std::string isolate_name,
36  int64_t isolate_port) override {}
37  void SetNeedsReportTimings(bool value) override {}
38  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override {
39  return isolate_data_;
40  }
41  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
42  const std::vector<std::string>& supported_locale_data) override {
43  return nullptr;
44  };
45 
46  private:
47  FontCollection font_collection_;
48  std::shared_ptr<const fml::Mapping> isolate_data_;
49 };
50 
51 TEST_F(ShellTest, PlatformConfigurationInitialization) {
52  auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
53 
54  auto nativeValidateConfiguration = [message_latch](
55  Dart_NativeArguments args) {
56  PlatformConfiguration* configuration =
58  ASSERT_NE(configuration->get_window(0), nullptr);
59  ASSERT_EQ(
60  configuration->get_window(0)->viewport_metrics().device_pixel_ratio,
61  1.0);
62  ASSERT_EQ(configuration->get_window(0)->viewport_metrics().physical_width,
63  0.0);
64  ASSERT_EQ(configuration->get_window(0)->viewport_metrics().physical_height,
65  0.0);
66 
67  message_latch->Signal();
68  };
69 
70  Settings settings = CreateSettingsForFixture();
71  TaskRunners task_runners("test", // label
72  GetCurrentTaskRunner(), // platform
73  CreateNewThread(), // raster
74  CreateNewThread(), // ui
75  CreateNewThread() // io
76  );
77 
78  AddNativeCallback("ValidateConfiguration",
79  CREATE_NATIVE_ENTRY(nativeValidateConfiguration));
80 
81  std::unique_ptr<Shell> shell =
82  CreateShell(std::move(settings), std::move(task_runners));
83 
84  ASSERT_TRUE(shell->IsSetup());
85  auto run_configuration = RunConfiguration::InferFromSettings(settings);
86  run_configuration.SetEntrypoint("validateConfiguration");
87 
88  shell->RunEngine(std::move(run_configuration), [&](auto result) {
90  });
91 
92  message_latch->Wait();
93  DestroyShell(std::move(shell), std::move(task_runners));
94 }
95 
96 TEST_F(ShellTest, PlatformConfigurationWindowMetricsUpdate) {
97  auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
98 
99  auto nativeValidateConfiguration = [message_latch](
100  Dart_NativeArguments args) {
101  PlatformConfiguration* configuration =
103 
104  ASSERT_NE(configuration->get_window(0), nullptr);
105  configuration->get_window(0)->UpdateWindowMetrics(
106  ViewportMetrics{2.0, 10.0, 20.0, 22});
107  ASSERT_EQ(
108  configuration->get_window(0)->viewport_metrics().device_pixel_ratio,
109  2.0);
110  ASSERT_EQ(configuration->get_window(0)->viewport_metrics().physical_width,
111  10.0);
112  ASSERT_EQ(configuration->get_window(0)->viewport_metrics().physical_height,
113  20.0);
114  ASSERT_EQ(
115  configuration->get_window(0)->viewport_metrics().physical_touch_slop,
116  22);
117 
118  message_latch->Signal();
119  };
120 
121  Settings settings = CreateSettingsForFixture();
122  TaskRunners task_runners("test", // label
123  GetCurrentTaskRunner(), // platform
124  CreateNewThread(), // raster
125  CreateNewThread(), // ui
126  CreateNewThread() // io
127  );
128 
129  AddNativeCallback("ValidateConfiguration",
130  CREATE_NATIVE_ENTRY(nativeValidateConfiguration));
131 
132  std::unique_ptr<Shell> shell =
133  CreateShell(std::move(settings), std::move(task_runners));
134 
135  ASSERT_TRUE(shell->IsSetup());
136  auto run_configuration = RunConfiguration::InferFromSettings(settings);
137  run_configuration.SetEntrypoint("validateConfiguration");
138 
139  shell->RunEngine(std::move(run_configuration), [&](auto result) {
141  });
142 
143  message_latch->Wait();
144  DestroyShell(std::move(shell), std::move(task_runners));
145 }
146 
147 } // namespace testing
148 } // namespace flutter
G_BEGIN_DECLS FlValue * args
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
When the Flutter application has a message to send to the underlying platform, the message needs to b...
void UpdateSemantics(SemanticsUpdate *update) override
Receives a updated semantics tree from the Framework.
std::shared_ptr< const fml::Mapping > GetPersistentIsolateData() override
The embedder can specify data that the isolate can request synchronously on launch. This accessor fetches that data.
void SetNeedsReportTimings(bool value) override
Notifies this client that the application has an opinion about whether its frame timings need to be r...
void Render(Scene *scene) override
Updates the client&#39;s rendering on the GPU with the newly provided Scene.
GAsyncResult * result
FontCollection & GetFontCollection() override
Returns the current collection of fonts available on the platform.
A client interface that the RuntimeController uses to define handlers for PlatformConfiguration reque...
static RunConfiguration InferFromSettings(const Settings &settings, fml::RefPtr< fml::TaskRunner > io_worker=nullptr)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
uint8_t value
#define CREATE_NATIVE_ENTRY(native_entry)
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data) override
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolv...
PlatformConfiguration * platform_configuration() const
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)
std::string DefaultRouteName() override
The route or path that the embedder requested when the application was launched.
A class for holding and distributing platform-level information to and from the Dart code in Flutter&#39;...
void ScheduleFrame() override
Requests that, at the next appropriate opportunity, a new frame be scheduled for rendering.
Window * get_window(int window_id)
Retrieves the Window with the given ID managed by the PlatformConfiguration.
const ViewportMetrics & viewport_metrics() const
Definition: window.h:29
void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port) override
Notifies this client of the name of the root isolate and its port when that isolate is launched...
static UIDartState * Current()
void UpdateWindowMetrics(const ViewportMetrics &metrics)
Definition: window.cc:57