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