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..d0109ab41557acda6671860b1618a040e2272375 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/graphics/paint/PaintChunkTest.cpp |
@@ -0,0 +1,80 @@ |
+// 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, IdMatchesSame) |
+{ |
+ PaintChunkProperties properties; |
+ FakeDisplayItemClient client; |
+ client.updateCacheGeneration(); |
+ DisplayItem::Id id(client, DisplayItem::DrawingFirst); |
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, &id, properties))); |
+} |
+ |
+TEST(PaintChunkTest, IdMatchesEqual) |
+{ |
+ PaintChunkProperties properties; |
+ FakeDisplayItemClient client; |
+ client.updateCacheGeneration(); |
+ DisplayItem::Id id(client, DisplayItem::DrawingFirst); |
+ DisplayItem::Id idEqual = id; |
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, &idEqual, properties))); |
+ EXPECT_TRUE(PaintChunk(0, 1, &idEqual, properties).idMatches(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).idMatches(PaintChunk(0, 1, &id1b, properties))); |
+ EXPECT_FALSE(PaintChunk(0, 1, &id1b, properties).idMatches(PaintChunk(0, 1, &id1a, properties))); |
+ |
+ FakeDisplayItemClient client2; |
+ client2.updateCacheGeneration(); |
+ DisplayItem::Id id2(client2, DisplayItem::DrawingFirst); |
+ EXPECT_FALSE(PaintChunk(0, 1, &id1a, properties).idMatches(PaintChunk(0, 1, &id2, properties))); |
+ EXPECT_FALSE(PaintChunk(0, 1, &id2, properties).idMatches(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).idMatches(PaintChunk(0, 1, &id, properties))); |
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, nullptr, properties))); |
+ EXPECT_FALSE(PaintChunk(0, 1, nullptr, properties).idMatches(PaintChunk(0, 1, nullptr, properties))); |
+} |
+ |
+TEST(PaintChunkTest, IdNotMatchesJustCreated) |
+{ |
+ PaintChunkProperties properties; |
+ Optional<FakeDisplayItemClient> client; |
+ client.emplace(); |
pdr.
2016/07/15 19:11:28
What would happen if an invalidation occurred righ
Xianzhu
2016/07/15 23:48:00
Changed CacheGenerationOrInvalidationReason::inval
|
+ DisplayItem::Id id(*client, DisplayItem::DrawingFirst); |
+ // A chunk of a newly create client doesn't match any chunk because it's never cached. |
pdr.
2016/07/15 19:11:28
Nit: "newly create" -> "newly created"
Xianzhu
2016/07/15 23:48:00
Done.
|
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, &id, properties))); |
+ |
+ client->updateCacheGeneration(); |
+ EXPECT_TRUE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, &id, properties))); |
+ |
+ // Delete the current object and create a new object is created at the same address. |
pdr.
2016/07/15 19:11:28
Nit: remove "is created" so this reads "// Delete
Xianzhu
2016/07/15 23:48:00
Done.
|
+ client = WTF::nullopt; |
+ client.emplace(); |
+ EXPECT_FALSE(PaintChunk(0, 1, &id, properties).idMatches(PaintChunk(0, 1, &id, properties))); |
+} |
+ |
+} // namespace blink |