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

Unified Diff: third_party/WebKit/Source/platform/graphics/paint/PaintChunkTest.cpp

Issue 2116693002: PaintChunk::id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CommitOnTheWay
Patch Set: Address chrishtr's comments. Created 4 years, 5 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/PaintChunkTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/PaintChunkTest.cpp b/third_party/WebKit/Source/platform/graphics/paint/PaintChunkTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a8e3970af02fbb0d8f8d546c54a23cf3e64642e1
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/paint/PaintChunkTest.cpp
@@ -0,0 +1,86 @@
+// Copyright 2016 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/PaintChunk.h"
+
+#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/testing/FakeDisplayItemClient.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/Optional.h"
+
+namespace blink {
+
+TEST(PaintChunkTest, matchesSame)
+{
+ PaintChunkProperties properties;
+ FakeDisplayItemClient client;
+ client.updateCacheGeneration();
+ DisplayItem::Id id(client, DisplayItem::DrawingFirst);
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id, properties)));
+}
+
+TEST(PaintChunkTest, matchesEqual)
+{
+ PaintChunkProperties properties;
+ FakeDisplayItemClient client;
+ client.updateCacheGeneration();
+ DisplayItem::Id id(client, DisplayItem::DrawingFirst);
+ DisplayItem::Id idEqual = id;
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &idEqual, properties)));
+ EXPECT_TRUE(PaintChunk(0, 1, &idEqual, properties).matches(PaintChunk(0, 1, &id, properties)));
+}
+
+TEST(PaintChunkTest, IdNotMatches)
+{
+ PaintChunkProperties properties;
+ FakeDisplayItemClient client1;
+ client1.updateCacheGeneration();
+ DisplayItem::Id id1a(client1, DisplayItem::DrawingFirst);
+ DisplayItem::Id id1b(client1, DisplayItem::Subsequence);
+ EXPECT_FALSE(PaintChunk(0, 1, &id1a, properties).matches(PaintChunk(0, 1, &id1b, properties)));
+ EXPECT_FALSE(PaintChunk(0, 1, &id1b, properties).matches(PaintChunk(0, 1, &id1a, properties)));
+
+ FakeDisplayItemClient client2;
+ client2.updateCacheGeneration();
+ DisplayItem::Id id2(client2, DisplayItem::DrawingFirst);
+ EXPECT_FALSE(PaintChunk(0, 1, &id1a, properties).matches(PaintChunk(0, 1, &id2, properties)));
+ EXPECT_FALSE(PaintChunk(0, 1, &id2, properties).matches(PaintChunk(0, 1, &id1a, properties)));
+}
+
+TEST(PaintChunkTest, IdNotMatchesNull)
+{
+ PaintChunkProperties properties;
+ FakeDisplayItemClient client;
+ client.updateCacheGeneration();
+ DisplayItem::Id id(client, DisplayItem::DrawingFirst);
+ EXPECT_FALSE(PaintChunk(0, 1, nullptr, properties).matches(PaintChunk(0, 1, &id, properties)));
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, nullptr, properties)));
+ EXPECT_FALSE(PaintChunk(0, 1, nullptr, properties).matches(PaintChunk(0, 1, nullptr, properties)));
+}
+
+TEST(PaintChunkTest, IdNotMatchesJustCreated)
+{
+ PaintChunkProperties properties;
+ Optional<FakeDisplayItemClient> client;
+ client.emplace();
+ EXPECT_TRUE(client->isJustCreated());
+ // Invalidation won't change the "just created" status.
+ client->setDisplayItemsUncached();
+ EXPECT_TRUE(client->isJustCreated());
+
+ DisplayItem::Id id(*client, DisplayItem::DrawingFirst);
+ // A chunk of a newly created client doesn't match any chunk because it's never cached.
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id, properties)));
+
+ client->updateCacheGeneration();
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id, properties)));
+
+ // Delete the current object and create a new object at the same address.
+ client = WTF::nullopt;
+ client.emplace();
+ EXPECT_TRUE(client->isJustCreated());
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id, properties)));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698