| Flutter Windows Embedder |

flutter_view_controller_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 #include <memory>
6 #include <string>
7
8 #include "flutter/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h"
9 #include "flutter/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h"
10 #include "gtest/gtest.h"
11
12 namespace flutter {
13
14 namespace {
15
16 // Stub implementation to validate calls to the API.
17 class TestWindowsApi : public testing::StubFlutterWindowsApi {
18 public:
19 // |flutter::testing::StubFlutterWindowsApi|
20 FlutterDesktopViewControllerRef ViewControllerCreate(
21 int width,
22 int height,
23 FlutterDesktopEngineRef engine) override {
24 return reinterpret_cast<FlutterDesktopViewControllerRef>(2);
25 }
26
27 // |flutter::testing::StubFlutterWindowsApi|
28 void ViewControllerDestroy() override { view_controller_destroyed_ = true; }
29
30 // |flutter::testing::StubFlutterWindowsApi|
31 void ViewControllerForceRedraw() override {
32 view_controller_force_redrawed_ = true;
33 }
34
35 // |flutter::testing::StubFlutterWindowsApi|
36 FlutterDesktopEngineRef EngineCreate(
37 const FlutterDesktopEngineProperties& engine_properties) override {
38 return reinterpret_cast<FlutterDesktopEngineRef>(1);
39 }
40
41 // |flutter::testing::StubFlutterWindowsApi|
42 bool EngineDestroy() override {
43 engine_destroyed_ = true;
44 return true;
45 }
46
47 bool engine_destroyed() { return engine_destroyed_; }
48 bool view_controller_destroyed() { return view_controller_destroyed_; }
49 bool view_controller_force_redrawed() {
50 return view_controller_force_redrawed_;
51 }
52
53 private:
54 bool engine_destroyed_ = false;
55 bool view_controller_destroyed_ = false;
56 bool view_controller_force_redrawed_ = false;
57 };
58
59 } // namespace
60
61 TEST(FlutterViewControllerTest, CreateDestroy) {
62 DartProject project(L"data");
63 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
64 std::make_unique<TestWindowsApi>());
65 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
66 {
67 FlutterViewController controller(100, 100, project);
68 }
69 EXPECT_TRUE(test_api->view_controller_destroyed());
70 // Per the C API, once a view controller has taken ownership of an engine
71 // the engine destruction method should not be called.
72 EXPECT_FALSE(test_api->engine_destroyed());
73 }
74
75 TEST(FlutterViewControllerTest, GetViewId) {
76 DartProject project(L"data");
77 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
78 std::make_unique<TestWindowsApi>());
79 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
80 FlutterViewController controller(100, 100, project);
81 EXPECT_EQ(controller.view_id(), 1);
82 }
83
84 TEST(FlutterViewControllerTest, GetEngine) {
85 DartProject project(L"data");
86 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
87 std::make_unique<TestWindowsApi>());
88 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
89 FlutterViewController controller(100, 100, project);
90 EXPECT_NE(controller.engine(), nullptr);
91 }
92
93 TEST(FlutterViewControllerTest, GetView) {
94 DartProject project(L"data");
95 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
96 std::make_unique<TestWindowsApi>());
97 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
98 FlutterViewController controller(100, 100, project);
99 EXPECT_NE(controller.view(), nullptr);
100 }
101
102 TEST(FlutterViewControllerTest, ForceRedraw) {
103 DartProject project(L"data");
104 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
105 std::make_unique<TestWindowsApi>());
106 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
107 FlutterViewController controller(100, 100, project);
108
109 controller.ForceRedraw();
110 EXPECT_TRUE(test_api->view_controller_force_redrawed());
111 }
112
113 } // namespace flutter
flutter::DartProject
Definition: dart_project.h:35
flutter::FlutterViewController
Definition: flutter_view_controller.h:25
flutter::FlutterViewController::ForceRedraw
void ForceRedraw()
Definition: flutter_view_controller.cc:38
flutter::FlutterViewController::view
FlutterView * view() const
Definition: flutter_view_controller.h:48
flutter::FlutterViewController::view_id
FlutterViewId view_id() const
Definition: flutter_view_controller.cc:32
flutter::FlutterViewController::engine
FlutterEngine * engine() const
Definition: flutter_view_controller.h:45
flutter_view_controller.h
FlutterDesktopViewControllerRef
struct FlutterDesktopViewController * FlutterDesktopViewControllerRef
Definition: flutter_windows.h:25
FlutterDesktopEngineRef
struct FlutterDesktopEngine * FlutterDesktopEngineRef
Definition: flutter_windows.h:33
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::TEST
TEST(FlutterEngineTest, CreateDestroy)
Definition: flutter_engine_unittests.cc:103
FlutterDesktopEngineProperties
Definition: flutter_windows.h:60