|
| 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 | +// Included first as it collides with the X11 headers. |
| 6 | +#include "flutter/shell/platform/linux/testing/linux_test.h" |
| 7 | +#include "gtest/gtest.h" |
| 8 | + |
| 9 | +#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" |
| 10 | +#include "flutter/shell/platform/linux/fl_engine_private.h" |
| 11 | +#include "flutter/shell/platform/linux/fl_view_renderer.h" |
| 12 | +#include "flutter/shell/platform/linux/fl_view_renderer_opengl.h" |
| 13 | +#include "flutter/shell/platform/linux/testing/mock_gtk.h" |
| 14 | + |
| 15 | +// MOCK_ENGINE_PROC is leaky by design |
| 16 | +// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape) |
| 17 | + |
| 18 | +class FlViewRendererOpenGLTest : public flutter::testing::LinuxTest { |
| 19 | + protected: |
| 20 | + // GTK queries the window state when widgets are realized. |
| 21 | + ::testing::NiceMock<flutter::testing::MockGtk> gtk; |
| 22 | +}; |
| 23 | + |
| 24 | +TEST_F(FlViewRendererOpenGLTest, New) { |
| 25 | + g_autoptr(FlViewRendererOpenGL) renderer = |
| 26 | + fl_view_renderer_opengl_new(engine, FALSE); |
| 27 | + ASSERT_NE(renderer, nullptr); |
| 28 | + g_object_ref_sink(renderer); |
| 29 | + EXPECT_TRUE(FL_IS_VIEW_RENDERER(renderer)); |
| 30 | + EXPECT_TRUE(GTK_IS_WIDGET(renderer)); |
| 31 | +} |
| 32 | + |
| 33 | +TEST_F(FlViewRendererOpenGLTest, PresentLayersAfterDestroy) { |
| 34 | + // Create a renderer and destroy it. |
| 35 | + FlViewRendererOpenGL* renderer = fl_view_renderer_opengl_new(engine, FALSE); |
| 36 | + g_object_ref_sink(renderer); |
| 37 | + fl_gtk_widget_destroy(GTK_WIDGET(renderer)); |
| 38 | + |
| 39 | + // Present a frame on a destroyed widget. |
| 40 | + fl_view_renderer_present_layers(FL_VIEW_RENDERER(renderer), nullptr, 0); |
| 41 | + |
| 42 | + g_object_unref(renderer); |
| 43 | +} |
| 44 | + |
| 45 | +// NOLINTEND(clang-analyzer-core.StackAddressEscape) |
0 commit comments