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  FontCollection& GetFontCollection() override { return font_collection_; }
34  void UpdateIsolateDescription(const std::string isolate_name,
35  int64_t isolate_port) override {}
36  void SetNeedsReportTimings(bool value) override {}
37  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override {
38  return isolate_data_;
39  }
40  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
41  const std::vector<std::string>& supported_locale_data) override {
42  return nullptr;
43  };
44 
45  private:
46  FontCollection font_collection_;
47  std::shared_ptr<const fml::Mapping> isolate_data_;
48 };
49 
50 TEST_F(ShellTest, PlatformConfigurationInitialization) {
51  auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
52 
53  auto nativeValidateConfiguration = [message_latch](
54  Dart_NativeArguments args) {
55  PlatformConfiguration* configuration =
57  ASSERT_NE(configuration->window(), nullptr);
58  ASSERT_EQ(configuration->window()->viewport_metrics().device_pixel_ratio,
59  1.0);
60  ASSERT_EQ(configuration->window()->viewport_metrics().physical_width, 0.0);
61  ASSERT_EQ(configuration->window()->viewport_metrics().physical_height, 0.0);
62 
63  message_latch->Signal();
64  };
65 
66  Settings settings = CreateSettingsForFixture();
67  TaskRunners task_runners("test", // label
68  GetCurrentTaskRunner(), // platform
69  CreateNewThread(), // raster
70  CreateNewThread(), // ui
71  CreateNewThread() // io
72  );
73 
74  AddNativeCallback("ValidateConfiguration",
75  CREATE_NATIVE_ENTRY(nativeValidateConfiguration));
76 
77  std::unique_ptr<Shell> shell =
78  CreateShell(std::move(settings), std::move(task_runners));
79 
80  ASSERT_TRUE(shell->IsSetup());
81  auto run_configuration = RunConfiguration::InferFromSettings(settings);
82  run_configuration.SetEntrypoint("validateConfiguration");
83 
84  shell->RunEngine(std::move(run_configuration), [&](auto result) {
85  ASSERT_EQ(result, Engine::RunStatus::Success);
86  });
87 
88  message_latch->Wait();
89  DestroyShell(std::move(shell), std::move(task_runners));
90 }
91 
92 TEST_F(ShellTest, PlatformConfigurationWindowMetricsUpdate) {
93  auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
94 
95  auto nativeValidateConfiguration = [message_latch](
96  Dart_NativeArguments args) {
97  PlatformConfiguration* configuration =
99 
100  ASSERT_NE(configuration->window(), nullptr);
101  configuration->window()->UpdateWindowMetrics(
102  ViewportMetrics{2.0, 10.0, 20.0});
103  ASSERT_EQ(configuration->window()->viewport_metrics().device_pixel_ratio,
104  2.0);
105  ASSERT_EQ(configuration->window()->viewport_metrics().physical_width, 10.0);
106  ASSERT_EQ(configuration->window()->viewport_metrics().physical_height,
107  20.0);
108 
109  message_latch->Signal();
110  };
111 
112  Settings settings = CreateSettingsForFixture();
113  TaskRunners task_runners("test", // label
114  GetCurrentTaskRunner(), // platform
115  CreateNewThread(), // raster
116  CreateNewThread(), // ui
117  CreateNewThread() // io
118  );
119 
120  AddNativeCallback("ValidateConfiguration",
121  CREATE_NATIVE_ENTRY(nativeValidateConfiguration));
122 
123  std::unique_ptr<Shell> shell =
124  CreateShell(std::move(settings), std::move(task_runners));
125 
126  ASSERT_TRUE(shell->IsSetup());
127  auto run_configuration = RunConfiguration::InferFromSettings(settings);
128  run_configuration.SetEntrypoint("validateConfiguration");
129 
130  shell->RunEngine(std::move(run_configuration), [&](auto result) {
131  ASSERT_EQ(result, Engine::RunStatus::Success);
132  });
133 
134  message_latch->Wait();
135  DestroyShell(std::move(shell), std::move(task_runners));
136 }
137 
138 } // namespace testing
139 } // namespace flutter
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 HandlePlatformMessage(fml::RefPtr< PlatformMessage > message) override
When the Flutter application has a message to send to the underlying platform, the message needs to b...
void SetNeedsReportTimings(bool value) override
Notifies this client that the application has an opinion about whether its frame timings need to be r...
Window * window() const
Retrieves the Window managed by the PlatformConfiguration.
void Render(Scene *scene) override
Updates the client&#39;s rendering on the GPU with the newly provided Scene.
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
Definition: ui_dart_state.h:48
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.
const ViewportMetrics & viewport_metrics() const
Definition: window.h:25
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:38