5#include "flutter/shell/platform/windows/public/flutter_windows.h"
11#include "flutter/fml/synchronization/count_down_latch.h"
12#include "flutter/fml/synchronization/waitable_event.h"
13#include "flutter/shell/platform/common/app_lifecycle_state.h"
14#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
15#include "flutter/shell/platform/windows/egl/manager.h"
16#include "flutter/shell/platform/windows/testing/engine_modifier.h"
17#include "flutter/shell/platform/windows/testing/windows_test.h"
18#include "flutter/shell/platform/windows/testing/windows_test_config_builder.h"
19#include "flutter/shell/platform/windows/testing/windows_test_context.h"
20#include "flutter/shell/platform/windows/windows_lifecycle_manager.h"
21#include "flutter/testing/stream_capture.h"
22#include "gmock/gmock.h"
23#include "gtest/gtest.h"
32class HalfBrokenEGLManager :
public egl::Manager {
34 HalfBrokenEGLManager() : egl::Manager(
false) {}
36 std::unique_ptr<egl::WindowSurface>
37 CreateWindowSurface(HWND hwnd,
size_t width,
size_t height)
override {
42class MockWindowsLifecycleManager :
public WindowsLifecycleManager {
55 ::TranslateMessage(&msg);
64TEST(WindowsNoFixtureTest, GetTextureRegistrar) {
69 ASSERT_NE(
engine,
nullptr);
80 ASSERT_NE(controller,
nullptr);
92 ASSERT_NE(controller,
nullptr);
94 stdout_capture.
Stop();
95 stderr_capture.
Stop();
106 builder.SetDartEntrypoint(
"customEntrypoint");
108 ASSERT_NE(controller,
nullptr);
120 ASSERT_NE(
engine,
nullptr);
129 builder.SetDartEntrypoint(
"signalViewIds");
131 ASSERT_NE(
engine,
nullptr);
133 std::string view_ids;
135 context.AddNativeFunction(
144 ASSERT_NE(controller,
nullptr);
148 EXPECT_EQ(view_ids,
"View IDs: [0]");
156 ASSERT_NE(
engine,
nullptr);
165 ASSERT_NE(controller,
nullptr);
169 ASSERT_NE(
engine,
nullptr);
172 ASSERT_TRUE(engine_ptr->running());
185 UpdateAccessibilityFeatures, ([&called](
auto engine,
auto flags) {
204 builder.SetDartEntrypoint(
"customEntrypoint");
206 ASSERT_NE(
engine,
nullptr);
215 builder.SetDartEntrypoint(
"verifyNativeFunction");
220 context.AddNativeFunction(
"Signal", native_entry);
223 ASSERT_NE(controller,
nullptr);
234 builder.SetDartEntrypoint(
"verifyNativeFunctionWithParameters");
236 bool bool_value =
false;
243 context.AddNativeFunction(
"SignalBoolValue", native_entry);
246 ASSERT_NE(controller,
nullptr);
257 builder.SetDartEntrypoint(
"readPlatformExecutable");
259 std::string executable_name;
267 context.AddNativeFunction(
"SignalStringValue", native_entry);
270 ASSERT_NE(controller,
nullptr);
274 EXPECT_EQ(executable_name,
"flutter_windows_unittests.exe");
282 builder.SetDartEntrypoint(
"verifyNativeFunctionWithReturn");
284 bool bool_value_to_return =
true;
290 context.AddNativeFunction(
"SignalBoolReturn", bool_return_entry);
292 bool bool_value_passed =
false;
298 context.AddNativeFunction(
"SignalBoolValue", bool_pass_entry);
301 ASSERT_NE(controller,
nullptr);
319 captures.thread_id = std::this_thread::get_id();
323 builder.SetDartEntrypoint(
"drawHelloWorld");
326 ASSERT_FALSE(captures.frame_drawn_latch.IsSignaledForTest());
327 captures.frame_scheduled_latch.Signal();
329 context.AddNativeFunction(
"NotifyFirstFrameScheduled", native_entry);
332 ASSERT_NE(controller,
nullptr);
339 auto captures =
static_cast<Captures*
>(
user_data);
341 ASSERT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest());
344 ASSERT_EQ(std::this_thread::get_id(), captures->thread_id);
347 captures->done =
true;
348 captures->frame_drawn_latch.Signal();
353 while (!captures.done) {
358 captures.frame_drawn_latch.Wait();
366 builder.SetDartEntrypoint(
"renderImplicitView");
369 ASSERT_NE(
engine,
nullptr);
376 auto done = reinterpret_cast<std::atomic<bool>*>(user_data);
391 engine_ptr->SendWindowMetricsEvent(metrics);
404 ASSERT_NE(controller,
nullptr);
415 ASSERT_NE(controller,
nullptr);
418 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
420 ASSERT_NE(dxgi_adapter,
nullptr);
421 DXGI_ADAPTER_DESC
desc{};
430 ASSERT_NE(controller,
nullptr);
439 ASSERT_NE(implicit_view,
nullptr);
446 ASSERT_NE(controller,
nullptr);
461 ASSERT_NE(view,
nullptr);
462 ASSERT_EQ(view_123,
nullptr);
469 ASSERT_NE(
engine,
nullptr);
479 ASSERT_EQ(implicit_view,
nullptr);
480 ASSERT_EQ(view_123,
nullptr);
492 auto egl_manager = std::make_unique<HalfBrokenEGLManager>();
493 ASSERT_TRUE(egl_manager->IsValid());
494 modifier.SetEGLManager(std::move(egl_manager));
499 ASSERT_NE(controller,
nullptr);
510 auto lifecycle_manager =
511 std::make_unique<MockWindowsLifecycleManager>(windows_engine);
512 auto lifecycle_manager_ptr = lifecycle_manager.get();
513 modifier.SetLifecycleManager(std::move(lifecycle_manager));
515 EXPECT_CALL(*lifecycle_manager_ptr,
518 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
522 EXPECT_CALL(*lifecycle_manager_ptr,
525 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
536 ASSERT_NE(view,
nullptr);
539 ASSERT_NE(hwnd,
nullptr);
544 ::MoveWindow(hwnd, 0, 0, 100, 100,
551 builder.SetDartEntrypoint(
"sendGetKeyboardState");
553 std::atomic<bool>
done =
false;
554 context.AddNativeFunction(
559 EXPECT_EQ(
value,
"Success");
564 ASSERT_NE(controller,
nullptr);
576 std::string view_ids;
580 builder.SetDartEntrypoint(
"onMetricsChangedSignalViewIds");
583 context.AddNativeFunction(
587 context.AddNativeFunction(
592 std::scoped_lock lock{mutex};
598 ASSERT_NE(first_controller,
nullptr);
606 properties.
width = 100;
610 ASSERT_NE(second_controller,
nullptr);
615 std::scoped_lock lock{mutex};
616 if (view_ids ==
"View IDs: [0, 1]") {
623 second_controller.reset();
626 std::scoped_lock lock{mutex};
627 if (view_ids ==
"View IDs: [0]") {
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
void UpdateAccessibilityFeatures()
WindowsLifecycleManager(FlutterWindowsEngine *engine)
virtual void SetLifecycleState(AppLifecycleState state)
MOCK_METHOD(void, Quit,(std::optional< HWND >, std::optional< WPARAM >, std::optional< LPARAM >, UINT),(override))
MockWindowsLifecycleManager(FlutterWindowsEngine *engine)
std::string GetOutput() const
virtual void PostTask(const fml::closure &task) override
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, bool retval)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, int index, bool *value)
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlutterDesktopViewControllerRef FlutterDesktopEngineCreateViewController(FlutterDesktopEngineRef engine, const FlutterDesktopViewControllerProperties *properties)
int64_t FlutterDesktopViewId
struct FlutterDesktopView * FlutterDesktopViewRef
G_BEGIN_DECLS FlTextureRegistrar * texture_registrar
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
SK_API GrDirectContext * GetContext(const SkImage *src)
TEST_F(DisplayListTest, Defaults)
std::unique_ptr< FlutterDesktopEngine, EngineDeleter > EnginePtr
std::unique_ptr< FlutterDesktopViewController, ViewControllerDeleter > ViewControllerPtr
TEST(DisplayListComplexity, EmptyDisplayList)
constexpr int64_t kImplicitViewId
#define MOCK_ENGINE_PROC(proc, mock_impl)
const char * icu_data_path
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
size_t height
Physical height of the window.
int64_t view_id
The view that this event is describing.
double pixel_ratio
Scale factor for the physical screen.
size_t width
Physical width of the window.
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef controller)
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(FlutterDesktopViewControllerRef controller)
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef controller)
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller)
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef controller)
IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view)
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById(FlutterDesktopPluginRegistrarRef controller, FlutterDesktopViewId view_id)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
#define CREATE_NATIVE_ENTRY(native_entry)
#define EXPECT_TRUE(handle)