Flutter Engine
mock_layer_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/flow/testing/mock_layer.h"
6 
7 #include "flutter/flow/testing/layer_test.h"
8 #include "flutter/fml/macros.h"
9 #include "flutter/testing/mock_canvas.h"
10 
11 namespace flutter {
12 namespace testing {
13 
15 
16 #ifndef NDEBUG
17 TEST_F(MockLayerTest, PaintBeforePreollDies) {
18  SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f);
19  auto layer = std::make_shared<MockLayer>(path, SkPaint());
20 
21  EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
22  "needs_painting\\(\\)");
23 }
24 
25 TEST_F(MockLayerTest, PaintingEmptyLayerDies) {
26  auto layer = std::make_shared<MockLayer>(SkPath(), SkPaint());
27 
28  layer->Preroll(preroll_context(), SkMatrix());
29  EXPECT_EQ(layer->paint_bounds(), SkPath().getBounds());
30 
31  EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
32  "needs_painting\\(\\)");
33 }
34 #endif
35 
36 TEST_F(MockLayerTest, SimpleParams) {
37  const SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f);
38  const SkPaint paint = SkPaint(SkColors::kBlue);
39  const SkMatrix start_matrix = SkMatrix::Translate(1.0f, 2.0f);
40  const SkMatrix scale_matrix = SkMatrix::Scale(0.5f, 0.5f);
41  const SkRect cull_rect = SkRect::MakeWH(5.0f, 5.0f);
42  const bool parent_has_platform_view = true;
43  auto layer = std::make_shared<MockLayer>(path, paint);
44 
45  preroll_context()->mutators_stack.PushTransform(scale_matrix);
46  preroll_context()->cull_rect = cull_rect;
47  preroll_context()->has_platform_view = parent_has_platform_view;
48  layer->Preroll(preroll_context(), start_matrix);
49  EXPECT_EQ(preroll_context()->has_platform_view, false);
50  EXPECT_EQ(layer->paint_bounds(), path.getBounds());
51  EXPECT_TRUE(layer->needs_painting());
52  EXPECT_FALSE(layer->needs_system_composite());
53  EXPECT_EQ(layer->parent_mutators(), std::vector{Mutator(scale_matrix)});
54  EXPECT_EQ(layer->parent_matrix(), start_matrix);
55  EXPECT_EQ(layer->parent_cull_rect(), cull_rect);
56  EXPECT_EQ(layer->parent_has_platform_view(), parent_has_platform_view);
57 
58  layer->Paint(paint_context());
59  EXPECT_EQ(mock_canvas().draw_calls(),
60  std::vector({MockCanvas::DrawCall{
61  0, MockCanvas::DrawPathData{path, paint}}}));
62 }
63 
64 TEST_F(MockLayerTest, FakePlatformView) {
65  auto layer = std::make_shared<MockLayer>(SkPath(), SkPaint(),
66  true /* fake_has_platform_view */);
67  EXPECT_EQ(preroll_context()->has_platform_view, false);
68 
69  layer->Preroll(preroll_context(), SkMatrix());
70  EXPECT_EQ(preroll_context()->has_platform_view, true);
71 }
72 
73 TEST_F(MockLayerTest, FakeSystemComposite) {
74  auto layer = std::make_shared<MockLayer>(
75  SkPath(), SkPaint(), false /* fake_has_platform_view */,
76  true /* fake_needs_system_composite */);
77  EXPECT_EQ(layer->needs_system_composite(), false);
78 
79  layer->Preroll(preroll_context(), SkMatrix());
80  EXPECT_EQ(layer->needs_system_composite(), true);
81 }
82 
83 } // namespace testing
84 } // namespace flutter
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
LayerTestBase<::testing::Test > LayerTest
Definition: layer_test.h:151
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)