OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/PaintChunk.h" |
| 6 |
| 7 #include "platform/RuntimeEnabledFeatures.h" |
| 8 #include "platform/testing/FakeDisplayItemClient.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "wtf/Optional.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 TEST(PaintChunkTest, matchesSame) |
| 15 { |
| 16 PaintChunkProperties properties; |
| 17 FakeDisplayItemClient client; |
| 18 client.updateCacheGeneration(); |
| 19 DisplayItem::Id id(client, DisplayItem::DrawingFirst); |
| 20 EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id,
properties))); |
| 21 } |
| 22 |
| 23 TEST(PaintChunkTest, matchesEqual) |
| 24 { |
| 25 PaintChunkProperties properties; |
| 26 FakeDisplayItemClient client; |
| 27 client.updateCacheGeneration(); |
| 28 DisplayItem::Id id(client, DisplayItem::DrawingFirst); |
| 29 DisplayItem::Id idEqual = id; |
| 30 EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &idEq
ual, properties))); |
| 31 EXPECT_TRUE(PaintChunk(0, 1, &idEqual, properties).matches(PaintChunk(0, 1,
&id, properties))); |
| 32 } |
| 33 |
| 34 TEST(PaintChunkTest, IdNotMatches) |
| 35 { |
| 36 PaintChunkProperties properties; |
| 37 FakeDisplayItemClient client1; |
| 38 client1.updateCacheGeneration(); |
| 39 DisplayItem::Id id1a(client1, DisplayItem::DrawingFirst); |
| 40 DisplayItem::Id id1b(client1, DisplayItem::Subsequence); |
| 41 EXPECT_FALSE(PaintChunk(0, 1, &id1a, properties).matches(PaintChunk(0, 1, &i
d1b, properties))); |
| 42 EXPECT_FALSE(PaintChunk(0, 1, &id1b, properties).matches(PaintChunk(0, 1, &i
d1a, properties))); |
| 43 |
| 44 FakeDisplayItemClient client2; |
| 45 client2.updateCacheGeneration(); |
| 46 DisplayItem::Id id2(client2, DisplayItem::DrawingFirst); |
| 47 EXPECT_FALSE(PaintChunk(0, 1, &id1a, properties).matches(PaintChunk(0, 1, &i
d2, properties))); |
| 48 EXPECT_FALSE(PaintChunk(0, 1, &id2, properties).matches(PaintChunk(0, 1, &id
1a, properties))); |
| 49 } |
| 50 |
| 51 TEST(PaintChunkTest, IdNotMatchesNull) |
| 52 { |
| 53 PaintChunkProperties properties; |
| 54 FakeDisplayItemClient client; |
| 55 client.updateCacheGeneration(); |
| 56 DisplayItem::Id id(client, DisplayItem::DrawingFirst); |
| 57 EXPECT_FALSE(PaintChunk(0, 1, nullptr, properties).matches(PaintChunk(0, 1,
&id, properties))); |
| 58 EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, null
ptr, properties))); |
| 59 EXPECT_FALSE(PaintChunk(0, 1, nullptr, properties).matches(PaintChunk(0, 1,
nullptr, properties))); |
| 60 } |
| 61 |
| 62 TEST(PaintChunkTest, IdNotMatchesJustCreated) |
| 63 { |
| 64 PaintChunkProperties properties; |
| 65 Optional<FakeDisplayItemClient> client; |
| 66 client.emplace(); |
| 67 EXPECT_TRUE(client->isJustCreated()); |
| 68 // Invalidation won't change the "just created" status. |
| 69 client->setDisplayItemsUncached(); |
| 70 EXPECT_TRUE(client->isJustCreated()); |
| 71 |
| 72 DisplayItem::Id id(*client, DisplayItem::DrawingFirst); |
| 73 // A chunk of a newly created client doesn't match any chunk because it's ne
ver cached. |
| 74 EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id,
properties))); |
| 75 |
| 76 client->updateCacheGeneration(); |
| 77 EXPECT_TRUE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id,
properties))); |
| 78 |
| 79 // Delete the current object and create a new object at the same address. |
| 80 client = WTF::nullopt; |
| 81 client.emplace(); |
| 82 EXPECT_TRUE(client->isJustCreated()); |
| 83 EXPECT_FALSE(PaintChunk(0, 1, &id, properties).matches(PaintChunk(0, 1, &id,
properties))); |
| 84 } |
| 85 |
| 86 } // namespace blink |
OLD | NEW |