OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/paint_vector_icon.h" | 5 #include "ui/gfx/paint_vector_icon.h" |
6 | 6 |
7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/paint/paint_record.h" | |
11 #include "cc/paint/paint_recorder.h" | |
12 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkPath.h" | 11 #include "third_party/skia/include/core/SkPath.h" |
14 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/vector_icon_types.h" | 13 #include "ui/gfx/vector_icon_types.h" |
16 | 14 |
17 namespace gfx { | 15 namespace gfx { |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 class MockCanvas : public SkCanvas { | 19 class MockCanvas : public SkCanvas { |
22 public: | 20 public: |
23 MockCanvas(int width, int height) : SkCanvas(width, height) {} | 21 MockCanvas(int width, int height) : SkCanvas(width, height) {} |
24 | 22 |
25 // SkCanvas overrides: | 23 // SkCanvas overrides: |
26 void onDrawPath(const SkPath& path, const SkPaint& paint) override { | 24 void onDrawPath(const SkPath& path, const SkPaint& paint) override { |
27 paths_.push_back(path); | 25 paths_.push_back(path); |
28 } | 26 } |
29 | 27 |
30 const std::vector<SkPath>& paths() const { return paths_; } | 28 const std::vector<SkPath>& paths() const { return paths_; } |
31 | 29 |
32 private: | 30 private: |
33 std::vector<SkPath> paths_; | 31 std::vector<SkPath> paths_; |
34 | 32 |
35 DISALLOW_COPY_AND_ASSIGN(MockCanvas); | 33 DISALLOW_COPY_AND_ASSIGN(MockCanvas); |
36 }; | 34 }; |
37 | 35 |
38 // Tests that a relative move to command (R_MOVE_TO) after a close command | 36 // Tests that a relative move to command (R_MOVE_TO) after a close command |
39 // (CLOSE) uses the correct starting point. See crbug.com/697497 | 37 // (CLOSE) uses the correct starting point. See crbug.com/697497 |
40 TEST(VectorIconTest, RelativeMoveToAfterClose) { | 38 TEST(VectorIconTest, RelativeMoveToAfterClose) { |
41 cc::PaintRecorder recorder; | 39 MockCanvas mock(100, 100); |
42 Canvas canvas(recorder.beginRecording(100, 100), 1.0f); | 40 Canvas canvas(&mock, 1.0f); |
43 | 41 |
44 const PathElement elements[] = { | 42 const PathElement elements[] = { |
45 MOVE_TO, 4, 5, | 43 MOVE_TO, 4, 5, |
46 LINE_TO, 10, 11, | 44 LINE_TO, 10, 11, |
47 CLOSE, | 45 CLOSE, |
48 // This move should use (4, 5) as the start point rather than (10, 11). | 46 // This move should use (4, 5) as the start point rather than (10, 11). |
49 R_MOVE_TO, 20, 21, | 47 R_MOVE_TO, 20, 21, |
50 R_LINE_TO, 50, 51, | 48 R_LINE_TO, 50, 51, |
51 END, | 49 END, |
52 }; | 50 }; |
53 const VectorIcon icon = {elements, nullptr}; | 51 const VectorIcon icon = {elements, nullptr}; |
54 | 52 |
55 PaintVectorIcon(&canvas, icon, 100, SK_ColorMAGENTA); | 53 PaintVectorIcon(&canvas, icon, 100, SK_ColorMAGENTA); |
56 sk_sp<cc::PaintRecord> record = recorder.finishRecordingAsPicture(); | |
57 | |
58 MockCanvas mock(100, 100); | |
59 record->playback(&mock); | |
60 | |
61 ASSERT_EQ(1U, mock.paths().size()); | 54 ASSERT_EQ(1U, mock.paths().size()); |
62 SkPoint last_point; | 55 SkPoint last_point; |
63 EXPECT_TRUE(mock.paths()[0].getLastPt(&last_point)); | 56 EXPECT_TRUE(mock.paths()[0].getLastPt(&last_point)); |
64 EXPECT_EQ(SkIntToScalar(74), last_point.x()); | 57 EXPECT_EQ(SkIntToScalar(74), last_point.x()); |
65 EXPECT_EQ(SkIntToScalar(77), last_point.y()); | 58 EXPECT_EQ(SkIntToScalar(77), last_point.y()); |
66 } | 59 } |
67 | 60 |
68 } // namespace | 61 } // namespace |
69 | 62 |
70 } // namespace gfx | 63 } // namespace gfx |
OLD | NEW |