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_METHOD3(AppendDrawingItem, |
| 28 void(const WebRect& visual_rect, |
| 29 sk_sp<const cc::PaintRecord>, |
| 30 const WebRect& record_bounds)); |
| 31 }; |
| 32 |
| 33 static sk_sp<PaintRecord> CreateRectRecord(const FloatRect& record_bounds) { |
| 34 PaintRecorder recorder; |
| 35 PaintCanvas* canvas = |
| 36 recorder.beginRecording(record_bounds.Width(), record_bounds.Height()); |
| 37 canvas->drawRect(record_bounds, PaintFlags()); |
| 38 return recorder.finishRecordingAsPicture(); |
| 39 } |
| 40 |
| 41 TEST_F(DrawingDisplayItemTest, VisualRectAndDrawingBounds) { |
| 42 FloatRect record_bounds(5.5, 6.6, 7.7, 8.8); |
| 43 LayoutRect drawing_bounds(record_bounds); |
| 44 client_.SetVisualRect(drawing_bounds); |
| 45 |
| 46 DrawingDisplayItem item(client_, DisplayItem::Type::kDocumentBackground, |
| 47 CreateRectRecord(record_bounds), record_bounds); |
| 48 EXPECT_EQ(drawing_bounds, item.VisualRect()); |
| 49 |
| 50 MockWebDisplayItemList list1; |
| 51 WebRect expected_rect = EnclosingIntRect(drawing_bounds); |
| 52 WebRect expected_record_rect = EnclosingIntRect(record_bounds); |
| 53 EXPECT_CALL(list1, AppendDrawingItem(expected_rect, _, expected_record_rect)) |
| 54 .Times(1); |
| 55 item.AppendToWebDisplayItemList(LayoutSize(), &list1); |
| 56 |
| 57 LayoutSize offset(LayoutUnit(2.1), LayoutUnit(3.6)); |
| 58 LayoutRect visual_rect_with_offset = drawing_bounds; |
| 59 visual_rect_with_offset.Move(-offset); |
| 60 WebRect expected_visual_rect = EnclosingIntRect(visual_rect_with_offset); |
| 61 MockWebDisplayItemList list2; |
| 62 EXPECT_CALL(list2, |
| 63 AppendDrawingItem(expected_visual_rect, _, expected_record_rect)) |
| 64 .Times(1); |
| 65 item.AppendToWebDisplayItemList(offset, &list2); |
| 66 } |
| 67 |
| 68 } // namespace |
| 69 } // namespace blink |
OLD | NEW |