Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4e76459

Browse files
committed
Added tests
1 parent c0e1ff1 commit 4e76459

File tree

7 files changed

+117
-52
lines changed

7 files changed

+117
-52
lines changed

lib/ui/fixtures/ui_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void createVertices() {
3434
);
3535
_validateVertices(vertices);
3636
}
37+
3738
void _validateVertices(Vertices vertices) native 'ValidateVertices';
3839

3940
@pragma('vm:entry-point')
@@ -42,5 +43,6 @@ void frameCallback(FrameInfo info) {
4243
}
4344

4445
@pragma('vm:entry-point')
45-
void messageCallback(dynamic data) {
46-
}
46+
void messageCallback(dynamic data) {}
47+
48+
void validateConfiguration() native 'ValidateConfiguration';

lib/ui/window/platform_configuration.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class FontCollection;
3838
class PlatformMessage;
3939
class Scene;
4040

41-
4241
//--------------------------------------------------------------------------
4342
/// @brief An enum for defining the different kinds of accessibility features
4443
/// that can be enabled by the platform.
@@ -228,14 +227,15 @@ class PlatformConfiguration final {
228227
/// @brief Access to the platform configuration client (which typically
229228
/// is implemented by the RuntimeController).
230229
///
231-
/// @return Returns the client used to construct this PlatformConfiguration.
230+
/// @return Returns the client used to construct this
231+
/// PlatformConfiguration.
232232
///
233233
PlatformConfigurationClient* client() const { return client_; }
234234

235235
//----------------------------------------------------------------------------
236236
/// @brief Called by the RuntimeController once it has created the root
237-
/// isolate, so that the PlatformController can get a handle to the
238-
/// 'dart:ui' library.
237+
/// isolate, so that the PlatformController can get a handle to
238+
/// the 'dart:ui' library.
239239
///
240240
/// It uses the handle to call the hooks in hooks.dart.
241241
///
@@ -274,10 +274,10 @@ class PlatformConfiguration final {
274274

275275
//----------------------------------------------------------------------------
276276
/// @brief Notifies the PlatformConfiguration that the embedder has
277-
/// expressed an opinion about whether the accessibility tree should
278-
/// be generated or not. This call originates in the platform view
279-
/// and is forwarded to the PlatformConfiguration here by the
280-
/// engine.
277+
/// expressed an opinion about whether the accessibility tree
278+
/// should be generated or not. This call originates in the
279+
/// platform view and is forwarded to the PlatformConfiguration
280+
/// here by the engine.
281281
///
282282
/// @param[in] enabled Whether the accessibility tree is enabled or
283283
/// disabled.
@@ -295,8 +295,8 @@ class PlatformConfiguration final {
295295

296296
//----------------------------------------------------------------------------
297297
/// @brief Notifies the PlatformConfiguration that the client has sent
298-
/// it a message. This call originates in the platform view and has
299-
/// been forwarded through the engine to here.
298+
/// it a message. This call originates in the platform view and
299+
/// has been forwarded through the engine to here.
300300
///
301301
/// @param[in] message The message sent from the embedder to the Dart
302302
/// application.
@@ -319,7 +319,8 @@ class PlatformConfiguration final {
319319
std::vector<uint8_t> args);
320320

321321
//----------------------------------------------------------------------------
322-
/// @brief Notifies the framework that it is time to begin working on a new
322+
/// @brief Notifies the framework that it is time to begin working on a
323+
/// new
323324
/// frame previously scheduled via a call to
324325
/// `PlatformConfigurationClient::ScheduleFrame`. This call
325326
/// originates in the animator.
@@ -413,7 +414,6 @@ class PlatformConfiguration final {
413414
int next_response_id_ = 1;
414415
std::unordered_map<int, fml::RefPtr<PlatformMessageResponse>>
415416
pending_responses_;
416-
417417
};
418418

419419
} // namespace flutter

lib/ui/window/platform_configuration_unittests.cc

Lines changed: 90 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "dart_api.h"
6-
#include "runtime/dart_isolate.h"
75
#define FML_USED_ON_EMBEDDER
86

97
#include <memory>
108

119
#include "flutter/lib/ui/window/platform_configuration.h"
1210

13-
#include "flutter/fml/mapping.h"
11+
#include "flutter/common/task_runners.h"
12+
#include "flutter/fml/synchronization/waitable_event.h"
13+
#include "flutter/lib/ui/painting/vertices.h"
1414
#include "flutter/runtime/dart_vm.h"
15+
#include "flutter/shell/common/shell_test.h"
16+
#include "flutter/shell/common/thread_host.h"
1517
#include "flutter/testing/testing.h"
16-
#include "gtest/gtest.h"
17-
#include "lib/ui/text/font_collection.h"
1818

1919
namespace flutter {
2020
namespace testing {
@@ -48,29 +48,91 @@ class DummyPlatformConfigurationClient : public PlatformConfigurationClient {
4848
std::shared_ptr<const fml::Mapping> isolate_data_;
4949
};
5050

51-
// TEST(PlatformConfigurationTest, PlatformConfigurationInitialization) {
52-
// DummyPlatformConfigurationClient client;
53-
// PlatformConfiguration configuration(&client);
54-
55-
// ASSERT_EQ(configuration.client(), &client);
56-
// ASSERT_EQ(configuration.window()->viewport_metrics().device_pixel_ratio, 1.0);
57-
// ASSERT_EQ(configuration.window()->viewport_metrics().physical_width, 0.0);
58-
// ASSERT_EQ(configuration.window()->viewport_metrics().physical_height, 0.0);
59-
// }
60-
61-
// This doesn't actually work until I figure out how to instantiate an Isolate
62-
// and set it up properly.
63-
64-
// TEST(PlatformConfigurationTest, PlatformConfigurationWindowMetricsUpdate) {
65-
// DummyPlatformConfigurationClient client;
66-
// PlatformConfiguration configuration(&client);
67-
// configuration.DidCreateIsolate();
68-
//
69-
// configuration.window()->UpdateWindowMetrics(ViewportMetrics{2.0, 10.0, 20.0});
70-
// ASSERT_EQ(configuration.window()->viewport_metrics().device_pixel_ratio, 2.0);
71-
// ASSERT_EQ(configuration.window()->viewport_metrics().physical_width, 10.0);
72-
// ASSERT_EQ(configuration.window()->viewport_metrics().physical_height, 20.0);
73-
// }
51+
TEST_F(ShellTest, PlatformConfigurationInitialization) {
52+
fml::AutoResetWaitableEvent message_latch;
53+
54+
auto nativeValidateConfiguration = [&](Dart_NativeArguments args) {
55+
PlatformConfiguration* configuration =
56+
UIDartState::Current()->platform_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+
fml::AutoResetWaitableEvent message_latch;
94+
95+
auto nativeValidateConfiguration = [&](Dart_NativeArguments args) {
96+
PlatformConfiguration* configuration =
97+
UIDartState::Current()->platform_configuration();
98+
99+
ASSERT_NE(configuration->window(), nullptr);
100+
configuration->window()->UpdateWindowMetrics(
101+
ViewportMetrics{2.0, 10.0, 20.0});
102+
ASSERT_EQ(configuration->window()->viewport_metrics().device_pixel_ratio,
103+
2.0);
104+
ASSERT_EQ(configuration->window()->viewport_metrics().physical_width, 10.0);
105+
ASSERT_EQ(configuration->window()->viewport_metrics().physical_height,
106+
20.0);
107+
108+
message_latch.Signal();
109+
};
110+
111+
Settings settings = CreateSettingsForFixture();
112+
TaskRunners task_runners("test", // label
113+
GetCurrentTaskRunner(), // platform
114+
CreateNewThread(), // raster
115+
CreateNewThread(), // ui
116+
CreateNewThread() // io
117+
);
118+
119+
AddNativeCallback("ValidateConfiguration",
120+
CREATE_NATIVE_ENTRY(nativeValidateConfiguration));
121+
122+
std::unique_ptr<Shell> shell =
123+
CreateShell(std::move(settings), std::move(task_runners));
124+
125+
ASSERT_TRUE(shell->IsSetup());
126+
auto run_configuration = RunConfiguration::InferFromSettings(settings);
127+
run_configuration.SetEntrypoint("validateConfiguration");
128+
129+
shell->RunEngine(std::move(run_configuration), [&](auto result) {
130+
ASSERT_EQ(result, Engine::RunStatus::Success);
131+
});
132+
133+
message_latch.Wait();
134+
DestroyShell(std::move(shell), std::move(task_runners));
135+
}
74136

75137
} // namespace testing
76138
} // namespace flutter

lib/ui/window/window.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Window::Window(ViewportMetrics metrics) : viewport_metrics_(metrics) {
1818

1919
Window::~Window() {}
2020

21-
void Window::DispatchPointerDataPacket(
22-
const PointerDataPacket& packet) {
21+
void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) {
2322
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
2423
if (!dart_state) {
2524
return;
2625
}
2726
tonic::DartState::Scope scope(dart_state);
2827

2928
const std::vector<uint8_t>& buffer = packet.data();
30-
Dart_Handle data_handle = tonic::DartByteData::Create(buffer.data(), buffer.size());
29+
Dart_Handle data_handle =
30+
tonic::DartByteData::Create(buffer.data(), buffer.size());
3131
if (Dart_IsError(data_handle)) {
3232
return;
3333
}

runtime/runtime_controller.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ FontCollection& RuntimeController::GetFontCollection() {
324324
return client_.GetFontCollection();
325325
}
326326

327-
328327
// |PlatformConfigurationClient|
329328
void RuntimeController::UpdateIsolateDescription(const std::string isolate_name,
330329
int64_t isolate_port) {

shell/common/engine.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,10 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
701701

702702
//----------------------------------------------------------------------------
703703
/// @brief Notifies the engine that the embedder has expressed an opinion
704-
/// about whether the accessibility tree should be generated or not.
705-
/// This call originates in the platform view and is forwarded to
706-
/// the engine here on the UI task runner by the shell.
704+
/// about whether the accessibility tree should be generated or
705+
/// not. This call originates in the platform view and is
706+
/// forwarded to the engine here on the UI task runner by the
707+
/// shell.
707708
///
708709
/// @param[in] enabled Whether the accessibility tree is enabled or
709710
/// disabled.

shell/testing/tester_main.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,17 @@ int RunTester(const flutter::Settings& settings,
236236

237237
flutter::ViewportMetrics metrics{};
238238
metrics.device_pixel_ratio = 3.0;
239-
metrics.physical_width = 2400.0; // 800 at 3x resolution.
239+
metrics.physical_width = 2400.0; // 800 at 3x resolution.
240240
metrics.physical_height = 1800.0; // 600 at 3x resolution.
241241
shell->GetPlatformView()->SetViewportMetrics(metrics);
242242

243243
// Run the message loop and wait for the script to do its thing.
244244
fml::MessageLoop::GetCurrent().Run();
245245

246246
// Cleanup the completion observer synchronously as it is living on the
247-
// stack.#include "lib/ui/window/viewport_metrics.h"
248-
247+
// stack.
248+
fml::TaskRunner::RunNowOrPostTask(ui_task_runner, task_observer_remove);
249+
latch.Wait();
249250

250251
if (!engine_did_run) {
251252
// If the engine itself didn't have a chance to run, there is no point in

0 commit comments

Comments
 (0)