File: ink_drop_mask_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 2,750 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/animation/ink_drop_mask.h"

#include <algorithm>
#include <memory>
#include <vector>

#include "cc/paint/display_item_list.h"
#include "cc/paint/paint_op_buffer_iterator.h"
#include "cc/paint/paint_record.h"
#include "cc/test/paint_op_matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "ui/compositor/paint_context.h"

namespace views {

using ::cc::PaintOpIs;
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::ExplainMatchResult;
using ::testing::ResultOf;
using ::testing::UnorderedElementsAreArray;

MATCHER_P(PointsAre, expected, "") {
  int expected_size = expected.size();
  if (arg.countPoints() != expected_size) {
    *result_listener << "Expected path to have " << expected_size
                     << " points, but had " << arg.countPoints() << ".";
    return false;
  }

  std::vector<SkPoint> actual(expected_size);
  if (arg.getPoints(&actual.front(), expected_size) != expected_size) {
    *result_listener << "Failed extracting " << expected.size()
                     << " points from path.";
    return false;
  }

  return ExplainMatchResult(UnorderedElementsAreArray(expected), actual,
                            result_listener);
}

TEST(InkDropMaskTest, PathInkDropMaskPaintsTriangle) {
  gfx::Size layer_size(10, 10);
  SkPath path;
  std::vector<SkPoint> points = {SkPoint::Make(3, 3), SkPoint::Make(5, 6),
                                 SkPoint::Make(8, 1)};
  path.moveTo(points[0].x(), points[0].y());
  path.lineTo(points[1].x(), points[1].y());
  path.lineTo(points[2].x(), points[2].y());
  path.close();
  PathInkDropMask mask(layer_size, path);

  auto list = base::MakeRefCounted<cc::DisplayItemList>();
  mask.OnPaintLayer(
      ui::PaintContext(list.get(), 1.f, gfx::Rect(layer_size), false));
  EXPECT_EQ(1u, list->num_paint_ops()) << list->ToString();

  cc::PaintRecord record = list->FinalizeAndReleaseAsRecordForTesting();
  EXPECT_THAT(
      record,
      ElementsAre(AllOf(
          PaintOpIs<cc::DrawRecordOp>(),
          ResultOf(
              [](const cc::PaintOp& op) {
                return static_cast<const cc::DrawRecordOp&>(op).record;
              },
              ElementsAre(AllOf(
                  PaintOpIs<cc::DrawPathOp>(),
                  ResultOf(
                      [](const cc::PaintOp& op) {
                        return static_cast<const cc::DrawPathOp&>(op).path;
                      },
                      PointsAre(points))))))));
}

}  // namespace views