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 "platform/graphics/paint/DrawingDisplayItem.h" | |
6 | |
7 #include "SkTypes.h" | |
8 #include "platform/graphics/paint/PaintRecorder.h" | |
9 #include "platform/graphics/skia/SkiaUtils.h" | |
10 #include "platform/testing/FakeDisplayItemClient.h" | |
11 #include "public/platform/WebDisplayItemList.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace blink { | |
16 namespace { | |
17 | |
18 using testing::_; | |
19 | |
20 class DrawingDisplayItemTest : public ::testing::Test { | |
21 protected: | |
22 FakeDisplayItemClient client_; | |
23 }; | |
24 | |
25 class MockWebDisplayItemList : public WebDisplayItemList { | |
26 public: | |
27 MOCK_METHOD2(AppendDrawingItem, | |
28 void(const WebRect& visual_rect, sk_sp<const cc::PaintRecord>)); | |
29 }; | |
30 | |
31 static sk_sp<PaintRecord> CreateRectRecord(const LayoutRect& bounds) { | |
32 PaintRecorder recorder; | |
33 PaintCanvas* canvas = | |
34 recorder.beginRecording(bounds.Width(), bounds.Height()); | |
35 canvas->drawRect( | |
36 SkRect::MakeXYWH(bounds.X(), bounds.Y(), bounds.Width(), bounds.Height()), | |
37 PaintFlags()); | |
38 return recorder.finishRecordingAsPicture(); | |
39 } | |
40 | |
41 TEST_F(DrawingDisplayItemTest, VisualRectAndDrawingBounds) { | |
42 LayoutRect drawing_bounds(LayoutUnit(5.5), LayoutUnit(6.6), LayoutUnit(7.7), | |
43 LayoutUnit(8.8)); | |
44 client_.SetVisualRect(drawing_bounds); | |
45 | |
46 DrawingDisplayItem item(client_, DisplayItem::Type::kDocumentBackground, | |
47 CreateRectRecord(drawing_bounds)); | |
48 EXPECT_EQ(drawing_bounds, item.VisualRect()); | |
49 | |
50 MockWebDisplayItemList list1; | |
51 WebRect expected_rect = EnclosingIntRect(drawing_bounds); | |
52 EXPECT_CALL(list1, AppendDrawingItem(expected_rect, _)).Times(1); | |
53 item.AppendToWebDisplayItemList(LayoutSize(), &list1); | |
54 | |
55 LayoutSize offset(LayoutUnit(2.1), LayoutUnit(3.6)); | |
56 LayoutRect visual_rect_with_offset = drawing_bounds; | |
57 visual_rect_with_offset.Move(-offset); | |
58 WebRect expected_visual_rect = EnclosingIntRect(visual_rect_with_offset); | |
59 MockWebDisplayItemList list2; | |
60 EXPECT_CALL(list2, AppendDrawingItem(expected_visual_rect, _)).Times(1); | |
61 item.AppendToWebDisplayItemList(offset, &list2); | |
62 } | |
63 | |
64 } // namespace | |
65 } // namespace blink | |
OLD | NEW |