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

Commit 9424fcc

Browse files
clarkeaagaaclarke
authored andcommitted
Added integration test for platform channels on windows.
1 parent cd2937e commit 9424fcc

File tree

2 files changed

+73
-18
lines changed

2 files changed

+73
-18
lines changed

shell/platform/windows/fixtures/main.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:io' as io;
6+
import 'dart:typed_data' show ByteData;
67
import 'dart:ui' as ui;
78

89
// Signals a waiting latch in the native test.
@@ -20,13 +21,21 @@ bool signalBoolReturn() native 'SignalBoolReturn';
2021
// Notify the native test that the first frame has been scheduled.
2122
void notifyFirstFrameScheduled() native 'NotifyFirstFrameScheduled';
2223

23-
void main() {
24-
}
24+
void main() {}
2525

2626
@pragma('vm:entry-point')
27-
void customEntrypoint() {
27+
void hiPlatformChannels() {
28+
ui.channelBuffers.setListener('hi',
29+
(ByteData? data, ui.PlatformMessageResponseCallback callback) async {
30+
ui.PlatformDispatcher.instance
31+
.sendPlatformMessage('hi', data, (ByteData? reply) {});
32+
callback(null);
33+
});
2834
}
2935

36+
@pragma('vm:entry-point')
37+
void customEntrypoint() {}
38+
3039
@pragma('vm:entry-point')
3140
void verifyNativeFunction() {
3241
signal();
@@ -51,8 +60,8 @@ void readPlatformExecutable() {
5160
@pragma('vm:entry-point')
5261
void drawHelloWorld() {
5362
ui.PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
54-
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(ui.ParagraphStyle())
55-
..addText('Hello world');
63+
final ui.ParagraphBuilder paragraphBuilder =
64+
ui.ParagraphBuilder(ui.ParagraphStyle())..addText('Hello world');
5665
final ui.Paragraph paragraph = paragraphBuilder.build();
5766

5867
paragraph.layout(const ui.ParagraphConstraints(width: 800.0));

shell/platform/windows/flutter_windows_engine_unittests.cc

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
99
#include "flutter/shell/platform/windows/testing/engine_modifier.h"
1010
#include "flutter/shell/platform/windows/testing/test_keyboard.h"
11+
#include "flutter/shell/platform/windows/testing/windows_test.h"
12+
#include "fml/synchronization/waitable_event.h"
1113
#include "gtest/gtest.h"
1214

1315
// winbase.h defines GetCurrentTime as a macro.
@@ -40,7 +42,9 @@ std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
4042
}
4143
} // namespace
4244

43-
TEST(FlutterWindowsEngine, RunDoesExpectedInitialization) {
45+
class FlutterWindowsEngineTest : public WindowsTest {};
46+
47+
TEST_F(FlutterWindowsEngineTest, RunDoesExpectedInitialization) {
4448
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
4549
EngineModifier modifier(engine.get());
4650

@@ -148,7 +152,7 @@ TEST(FlutterWindowsEngine, RunDoesExpectedInitialization) {
148152
modifier.ReleaseSurfaceManager();
149153
}
150154

151-
TEST(FlutterWindowsEngine, ConfiguresFrameVsync) {
155+
TEST_F(FlutterWindowsEngineTest, ConfiguresFrameVsync) {
152156
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
153157
EngineModifier modifier(engine.get());
154158
bool on_vsync_called = false;
@@ -174,7 +178,7 @@ TEST(FlutterWindowsEngine, ConfiguresFrameVsync) {
174178
EXPECT_TRUE(on_vsync_called);
175179
}
176180

177-
TEST(FlutterWindowsEngine, RunWithoutANGLEUsesSoftware) {
181+
TEST_F(FlutterWindowsEngineTest, RunWithoutANGLEUsesSoftware) {
178182
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
179183
EngineModifier modifier(engine.get());
180184

@@ -226,7 +230,7 @@ TEST(FlutterWindowsEngine, RunWithoutANGLEUsesSoftware) {
226230
modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
227231
}
228232

229-
TEST(FlutterWindowsEngine, SendPlatformMessageWithoutResponse) {
233+
TEST_F(FlutterWindowsEngineTest, SendPlatformMessageWithoutResponse) {
230234
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
231235
EngineModifier modifier(engine.get());
232236

@@ -252,7 +256,49 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithoutResponse) {
252256
EXPECT_TRUE(called);
253257
}
254258

255-
TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
259+
TEST_F(FlutterWindowsEngineTest, PlatformMessageRoundTrip) {
260+
FlutterDesktopEngineProperties properties = {};
261+
properties.assets_path = GetContext().GetAssetsPath().c_str();
262+
properties.icu_data_path = GetContext().GetIcuDataPath().c_str();
263+
properties.dart_entrypoint = "hiPlatformChannels";
264+
265+
FlutterProjectBundle project(properties);
266+
auto engine = std::make_unique<FlutterWindowsEngine>(project);
267+
268+
EngineModifier modifier(engine.get());
269+
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
270+
271+
auto binary_messenger =
272+
std::make_unique<BinaryMessengerImpl>(engine->messenger());
273+
274+
engine->Run();
275+
FlutterDesktopMessengerRef messenger = engine->messenger();
276+
bool did_call_callback = false;
277+
bool did_call_reply = false;
278+
std::string channel = "hi";
279+
binary_messenger->SetMessageHandler(
280+
"hi", [&did_call_callback](const uint8_t* message, size_t message_size,
281+
BinaryReply reply) {
282+
EXPECT_EQ(message_size, 5);
283+
char response[] = {'b', 'y', 'e'};
284+
reply(reinterpret_cast<uint8_t*>(response), 3);
285+
did_call_callback = true;
286+
});
287+
char payload[] = {'h', 'e', 'l', 'l', 'o'};
288+
binary_messenger->Send(
289+
"hi", reinterpret_cast<uint8_t*>(payload), 5,
290+
[&did_call_reply](const uint8_t* reply, size_t reply_size) {
291+
EXPECT_EQ(reply_size, 3);
292+
EXPECT_EQ(reply[0], static_cast<uint8_t>('b'));
293+
did_call_reply = true;
294+
});
295+
// Rely on timeout mechanism in CI.
296+
while (!did_call_callback && !did_call_reply) {
297+
engine->task_runner()->ProcessTasks();
298+
}
299+
}
300+
301+
TEST_F(FlutterWindowsEngineTest, SendPlatformMessageWithResponse) {
256302
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
257303
EngineModifier modifier(engine.get());
258304

@@ -310,7 +356,7 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
310356
EXPECT_TRUE(send_message_called);
311357
}
312358

313-
TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
359+
TEST_F(FlutterWindowsEngineTest, DispatchSemanticsAction) {
314360
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
315361
EngineModifier modifier(engine.get());
316362

@@ -334,7 +380,7 @@ TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
334380
EXPECT_TRUE(called);
335381
}
336382

337-
TEST(FlutterWindowsEngine, SetsThreadPriority) {
383+
TEST_F(FlutterWindowsEngineTest, SetsThreadPriority) {
338384
WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kBackground);
339385
EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
340386
THREAD_PRIORITY_BELOW_NORMAL);
@@ -355,7 +401,7 @@ TEST(FlutterWindowsEngine, SetsThreadPriority) {
355401
EXPECT_EQ(GetThreadPriority(GetCurrentThread()), THREAD_PRIORITY_NORMAL);
356402
}
357403

358-
TEST(FlutterWindowsEngine, AddPluginRegistrarDestructionCallback) {
404+
TEST_F(FlutterWindowsEngineTest, AddPluginRegistrarDestructionCallback) {
359405
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
360406
EngineModifier modifier(engine.get());
361407

@@ -385,7 +431,7 @@ TEST(FlutterWindowsEngine, AddPluginRegistrarDestructionCallback) {
385431
EXPECT_EQ(result2, 2);
386432
}
387433

388-
TEST(FlutterWindowsEngine, ScheduleFrame) {
434+
TEST_F(FlutterWindowsEngineTest, ScheduleFrame) {
389435
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
390436
EngineModifier modifier(engine.get());
391437

@@ -400,7 +446,7 @@ TEST(FlutterWindowsEngine, ScheduleFrame) {
400446
EXPECT_TRUE(called);
401447
}
402448

403-
TEST(FlutterWindowsEngine, SetNextFrameCallback) {
449+
TEST_F(FlutterWindowsEngineTest, SetNextFrameCallback) {
404450
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
405451
EngineModifier modifier(engine.get());
406452

@@ -415,14 +461,14 @@ TEST(FlutterWindowsEngine, SetNextFrameCallback) {
415461
EXPECT_TRUE(called);
416462
}
417463

418-
TEST(FlutterWindowsEngine, GetExecutableName) {
464+
TEST_F(FlutterWindowsEngineTest, GetExecutableName) {
419465
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
420466
EXPECT_EQ(engine->GetExecutableName(), "flutter_windows_unittests.exe");
421467
}
422468

423469
// Ensure that after setting or resetting the high contrast feature,
424470
// the corresponding status flag can be retrieved from the engine.
425-
TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
471+
TEST_F(FlutterWindowsEngineTest, UpdateHighContrastFeature) {
426472
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
427473
EngineModifier modifier(engine.get());
428474

@@ -447,7 +493,7 @@ TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
447493
EXPECT_FALSE(engine->high_contrast_enabled());
448494
}
449495

450-
TEST(FlutterWindowsEngine, PostRasterThreadTask) {
496+
TEST_F(FlutterWindowsEngineTest, PostRasterThreadTask) {
451497
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
452498
EngineModifier modifier(engine.get());
453499

0 commit comments

Comments
 (0)