OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium 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 <gtest/gtest.h> | |
6 #include <vector> | |
7 | |
8 #include "third_party/skia/include/core/SkCanvas.h" | |
9 #include "third_party/skia/include/core/SkPath.h" | |
10 #include "ui/gfx/canvas.h" | |
11 #include "ui/gfx/paint_vector_icon.h" | |
sky
2017/03/02 20:13:26
Make this your first include.
Evan Stade
2017/03/03 00:08:52
Done.
| |
12 #include "ui/gfx/vector_icon_types.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 namespace { | |
17 | |
18 class MockCanvas : public SkCanvas { | |
19 public: | |
20 MockCanvas(int width, int height) : SkCanvas(width, height) {} | |
21 | |
22 // SkCanvas overrides: | |
23 void onDrawPath(const SkPath& path, const SkPaint& paint) override { | |
24 paths_.push_back(path); | |
25 } | |
26 | |
27 const std::vector<SkPath>& paths() const { return paths_; } | |
28 | |
29 private: | |
30 std::vector<SkPath> paths_; | |
31 | |
32 DISALLOW_COPY_AND_ASSIGN(MockCanvas); | |
33 }; | |
34 | |
35 // Tests that a relative move to command (R_MOVE_TO) after a close command | |
36 // (CLOSE) uses the correct starting point. See crbug.com/697497 | |
37 TEST(VectorIconTest, RelativeMoveToAfterClose) { | |
38 MockCanvas mock(100, 100); | |
39 Canvas canvas(&mock, 1.0f); | |
40 | |
41 const PathElement elements[] = { | |
42 MOVE_TO, 4, 5, | |
43 LINE_TO, 10, 11, | |
44 CLOSE, | |
45 // This move should use (4, 5) as the start point rather than (10, 11). | |
46 R_MOVE_TO, 20, 21, | |
47 R_LINE_TO, 50, 51, | |
48 END, | |
49 }; | |
50 const VectorIcon icon = {elements, nullptr}; | |
51 | |
52 PaintVectorIcon(&canvas, icon, 100, SK_ColorMAGENTA); | |
53 ASSERT_EQ(1U, mock.paths().size()); | |
54 SkPoint last_point; | |
55 EXPECT_TRUE(mock.paths()[0].getLastPt(&last_point)); | |
56 EXPECT_EQ(SkIntToScalar(74), last_point.x()); | |
57 EXPECT_EQ(SkIntToScalar(77), last_point.y()); | |
58 } | |
59 | |
60 } // namespace | |
61 | |
62 } // namespace gfx | |
OLD | NEW |