Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItemTest.cpp

Issue 2894093002: Don't access DisplayItemClient::VisualRect() for cached display items. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 LayoutRect& bounds) {
34 PaintRecorder recorder;
35 PaintCanvas* canvas =
36 recorder.beginRecording(bounds.Width(), bounds.Height());
37 canvas->drawRect(
38 SkRect::MakeXYWH(bounds.X(), bounds.Y(), bounds.Width(), bounds.Height()),
39 PaintFlags());
40 return recorder.finishRecordingAsPicture();
41 }
42
43 TEST_F(DrawingDisplayItemTest, VisualRectAndDrawingBounds) {
44 LayoutRect drawing_bounds(LayoutUnit(5.5), LayoutUnit(6.6), LayoutUnit(7.7),
45 LayoutUnit(8.8));
46 client_.SetVisualRect(drawing_bounds);
47
48 DrawingDisplayItem item(client_, DisplayItem::Type::kDocumentBackground,
49 CreateRectRecord(drawing_bounds),
50 FloatRect(drawing_bounds));
51 EXPECT_EQ(drawing_bounds, item.VisualRect());
52
53 MockWebDisplayItemList list1;
54 WebRect expected_rect = EnclosingIntRect(drawing_bounds);
55 EXPECT_CALL(list1, AppendDrawingItem(expected_rect, _, expected_rect))
56 .Times(1);
57 item.AppendToWebDisplayItemList(LayoutSize(), &list1);
58
59 LayoutSize offset(LayoutUnit(2.1), LayoutUnit(3.6));
60 LayoutRect visual_rect_with_offset = drawing_bounds;
61 visual_rect_with_offset.Move(-offset);
62 WebRect expected_visual_rect = EnclosingIntRect(visual_rect_with_offset);
63 MockWebDisplayItemList list2;
64 EXPECT_CALL(list2, AppendDrawingItem(expected_visual_rect, _, expected_rect))
65 .Times(1);
66 item.AppendToWebDisplayItemList(offset, &list2);
67 }
68
69 } // namespace
70 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698