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/flow/testing/mock_texture.h"
6
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12TEST(MockTextureTest, Callbacks) {
13 auto texture = std::make_shared<MockTexture>(0);
14
15 ASSERT_FALSE(texture->gr_context_created());
16 texture->OnGrContextCreated();
17 ASSERT_TRUE(texture->gr_context_created());
18
19 ASSERT_FALSE(texture->gr_context_destroyed());
20 texture->OnGrContextDestroyed();
21 ASSERT_TRUE(texture->gr_context_destroyed());
22
23 ASSERT_FALSE(texture->unregistered());
24 texture->OnTextureUnregistered();
25 ASSERT_TRUE(texture->unregistered());
26}
27
28TEST(MockTextureTest, PaintCalls) {
29 SkCanvas canvas;
30 const SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
31 const SkRect paint_bounds2 = SkRect::MakeWH(2.0f, 2.0f);
32 const auto expected_paint_calls =
33 std::vector{MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr,
34 kNone_SkFilterQuality},
35 MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr,
36 kNone_SkFilterQuality}};
37 auto texture = std::make_shared<MockTexture>(0);
38
39 texture->Paint(canvas, paint_bounds1, false, nullptr, kNone_SkFilterQuality);
40 texture->Paint(canvas, paint_bounds2, true, nullptr, kNone_SkFilterQuality);
41 EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
42}
43
44TEST(MockTextureTest, PaintCallsWithLowFilterQuality) {
45 SkCanvas canvas;
46 const SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
47 const SkRect paint_bounds2 = SkRect::MakeWH(2.0f, 2.0f);
48 const auto expected_paint_calls =
49 std::vector{MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr,
50 kLow_SkFilterQuality},
51 MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr,
52 kLow_SkFilterQuality}};
53 auto texture = std::make_shared<MockTexture>(0);
54
55 texture->Paint(canvas, paint_bounds1, false, nullptr, kLow_SkFilterQuality);
56 texture->Paint(canvas, paint_bounds2, true, nullptr, kLow_SkFilterQuality);
57 EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
58}
59
60} // namespace testing
61} // namespace flutter
62