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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItemTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItemTest.cpp b/third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItemTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..65df3acaa40a5eecd78cb1c9b372f9ea30afb736
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItemTest.cpp
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/graphics/paint/DrawingDisplayItem.h"
+
+#include "SkTypes.h"
+#include "platform/graphics/paint/PaintRecorder.h"
+#include "platform/graphics/skia/SkiaUtils.h"
+#include "platform/testing/FakeDisplayItemClient.h"
+#include "public/platform/WebDisplayItemList.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+using testing::_;
+
+class DrawingDisplayItemTest : public ::testing::Test {
+ protected:
+ FakeDisplayItemClient client_;
+};
+
+class MockWebDisplayItemList : public WebDisplayItemList {
+ public:
+ MOCK_METHOD2(AppendDrawingItem,
+ void(const WebRect& visual_rect, sk_sp<const cc::PaintRecord>));
+};
+
+static sk_sp<PaintRecord> CreateRectRecord(const LayoutRect& bounds) {
+ PaintRecorder recorder;
+ PaintCanvas* canvas =
+ recorder.beginRecording(bounds.Width(), bounds.Height());
+ canvas->drawRect(
+ SkRect::MakeXYWH(bounds.X(), bounds.Y(), bounds.Width(), bounds.Height()),
+ PaintFlags());
+ return recorder.finishRecordingAsPicture();
+}
+
+TEST_F(DrawingDisplayItemTest, VisualRectAndDrawingBounds) {
+ LayoutRect drawing_bounds(LayoutUnit(5.5), LayoutUnit(6.6), LayoutUnit(7.7),
+ LayoutUnit(8.8));
+ client_.SetVisualRect(drawing_bounds);
+
+ DrawingDisplayItem item(client_, DisplayItem::Type::kDocumentBackground,
+ CreateRectRecord(drawing_bounds));
+ EXPECT_EQ(drawing_bounds, item.VisualRect());
+
+ MockWebDisplayItemList list1;
+ WebRect expected_rect = EnclosingIntRect(drawing_bounds);
+ EXPECT_CALL(list1, AppendDrawingItem(expected_rect, _)).Times(1);
+ item.AppendToWebDisplayItemList(LayoutSize(), &list1);
+
+ LayoutSize offset(LayoutUnit(2.1), LayoutUnit(3.6));
+ LayoutRect visual_rect_with_offset = drawing_bounds;
+ visual_rect_with_offset.Move(-offset);
+ WebRect expected_visual_rect = EnclosingIntRect(visual_rect_with_offset);
+ MockWebDisplayItemList list2;
+ EXPECT_CALL(list2, AppendDrawingItem(expected_visual_rect, _)).Times(1);
+ item.AppendToWebDisplayItemList(offset, &list2);
+}
+
+} // namespace
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698