Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
android_context_gl_impeller_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 "flutter/shell/platform/android/android_context_gl_impeller.h"
6#include "gmock/gmock.h"
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12using ::testing::_;
13using ::testing::AllOf;
14using ::testing::ByMove;
15using ::testing::Field;
16using ::testing::Matcher;
17using ::testing::Return;
18
19using ::impeller::egl::Config;
20using ::impeller::egl::ConfigDescriptor;
21
22namespace {
24 public:
25 MOCK_METHOD(bool, IsValid, (), (const, override));
26 MOCK_METHOD(std::unique_ptr<Config>,
27 ChooseConfig,
28 (ConfigDescriptor),
29 (const, override));
30};
31} // namespace
32
33TEST(AndroidContextGLImpeller, MSAAFirstAttempt) {
34 auto display = std::make_unique<MockDisplay>();
35 EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
36 auto first_result = std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
37 auto second_result =
38 std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
39 EXPECT_CALL(
40 *display,
41 ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
42 Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
43 Field(&ConfigDescriptor::surface_type,
45 .WillOnce(Return(ByMove(std::move(first_result))));
46 EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
47 Field(&ConfigDescriptor::surface_type,
49 .WillOnce(Return(ByMove(std::move(second_result))));
50 ON_CALL(*display, ChooseConfig(_))
51 .WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
52 auto context =
53 std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
54 ASSERT_TRUE(context);
55}
56
57TEST(AndroidContextGLImpeller, FallbackForEmulator) {
58 auto display = std::make_unique<MockDisplay>();
59 EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
60 std::unique_ptr<Config> first_result;
61 auto second_result =
62 std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
63 auto third_result = std::make_unique<Config>(ConfigDescriptor(), EGLConfig());
64 EXPECT_CALL(
65 *display,
66 ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
67 Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
68 Field(&ConfigDescriptor::surface_type,
70 .WillOnce(Return(ByMove(std::move(first_result))));
71 EXPECT_CALL(
72 *display,
73 ChooseConfig(Matcher<ConfigDescriptor>(
74 AllOf(Field(&ConfigDescriptor::samples, impeller::egl::Samples::kOne),
75 Field(&ConfigDescriptor::surface_type,
77 .WillOnce(Return(ByMove(std::move(second_result))));
78 EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
79 Field(&ConfigDescriptor::surface_type,
81 .WillOnce(Return(ByMove(std::move(third_result))));
82 ON_CALL(*display, ChooseConfig(_))
83 .WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
84 auto context =
85 std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
86 ASSERT_TRUE(context);
87}
88} // namespace testing
89} // namespace flutter
#define TEST(S, s, D, expected)