Flutter Engine
plugin_registrar_glfw_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/glfw/client_wrapper/include/flutter/plugin_registrar_glfw.h"
9 #include "flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h"
10 #include "gtest/gtest.h"
11 
12 namespace flutter {
13 
14 namespace {
15 
16 // A test plugin that tries to access registrar state during destruction and
17 // reports it out via a flag provided at construction.
18 class TestPlugin : public Plugin {
19  public:
20  // registrar_valid_at_destruction will be set at destruction to indicate
21  // whether or not |registrar->window()| was non-null.
22  TestPlugin(PluginRegistrarGlfw* registrar,
23  bool* registrar_valid_at_destruction)
24  : registrar_(registrar),
25  registrar_valid_at_destruction_(registrar_valid_at_destruction) {}
26  virtual ~TestPlugin() {
27  *registrar_valid_at_destruction_ = registrar_->window() != nullptr;
28  }
29 
30  private:
31  PluginRegistrarGlfw* registrar_;
32  bool* registrar_valid_at_destruction_;
33 };
34 
35 } // namespace
36 
37 TEST(PluginRegistrarGlfwTest, GetView) {
38  testing::ScopedStubFlutterGlfwApi scoped_api_stub(
39  std::make_unique<testing::StubFlutterGlfwApi>());
40  PluginRegistrarGlfw registrar(
41  reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1));
42  EXPECT_NE(registrar.window(), nullptr);
43 }
44 
45 // Tests that the registrar runs plugin destructors before its own teardown.
46 TEST(PluginRegistrarGlfwTest, PluginDestroyedBeforeRegistrar) {
47  auto dummy_registrar_handle =
48  reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
49  bool registrar_valid_at_destruction = false;
50  {
51  PluginRegistrarGlfw registrar(dummy_registrar_handle);
52 
53  auto plugin = std::make_unique<TestPlugin>(&registrar,
54  &registrar_valid_at_destruction);
55  registrar.AddPlugin(std::move(plugin));
56  }
57  EXPECT_TRUE(registrar_valid_at_destruction);
58 }
59 
60 } // namespace flutter
TEST(DartServiceIsolateTest, CanAddAndRemoveHandles)