Flutter Engine
The Flutter Engine
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
12namespace flutter {
13
14namespace {
15
16// Stub implementation to validate calls to the API.
17class TestWindowsApi : public testing::StubFlutterWindowsApi {
18 public:
19 // |flutter::testing::StubFlutterWindowsApi|
20 FlutterDesktopViewControllerRef ViewControllerCreate(
21 int width,
22 int height,
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
61TEST(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 { FlutterViewController controller(100, 100, project); }
67 EXPECT_TRUE(test_api->view_controller_destroyed());
68 // Per the C API, once a view controller has taken ownership of an engine
69 // the engine destruction method should not be called.
70 EXPECT_FALSE(test_api->engine_destroyed());
71}
72
74 DartProject project(L"data");
76 std::make_unique<TestWindowsApi>());
77 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
78 FlutterViewController controller(100, 100, project);
79 EXPECT_EQ(controller.view_id(), 1);
80}
81
83 DartProject project(L"data");
85 std::make_unique<TestWindowsApi>());
86 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
87 FlutterViewController controller(100, 100, project);
88 EXPECT_NE(controller.engine(), nullptr);
89}
90
92 DartProject project(L"data");
94 std::make_unique<TestWindowsApi>());
95 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
96 FlutterViewController controller(100, 100, project);
97 EXPECT_NE(controller.view(), nullptr);
98}
99
101 DartProject project(L"data");
103 std::make_unique<TestWindowsApi>());
104 auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
105 FlutterViewController controller(100, 100, project);
106
107 controller.ForceRedraw();
108 EXPECT_TRUE(test_api->view_controller_force_redrawed());
109}
110
111} // namespace flutter
FlutterEngine engine
Definition: main.cc:68
struct FlutterDesktopViewController * FlutterDesktopViewControllerRef
TEST(FrameTimingsRecorderTest, RecordVsync)
int32_t height
int32_t width
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678