| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 "chrome/renderer/paint_aggregator.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 TEST(PaintAggregator, InitialState) { |
| 9 PaintAggregator greg; |
| 10 EXPECT_FALSE(greg.HasPendingUpdate()); |
| 11 } |
| 12 |
| 13 TEST(PaintAggregator, SingleInvalidation) { |
| 14 PaintAggregator greg; |
| 15 |
| 16 gfx::Rect rect(2, 4, 10, 16); |
| 17 greg.InvalidateRect(rect); |
| 18 |
| 19 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 20 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); |
| 21 EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); |
| 22 |
| 23 EXPECT_EQ(rect.x(), greg.GetPendingUpdate().paint_rect.x()); |
| 24 EXPECT_EQ(rect.y(), greg.GetPendingUpdate().paint_rect.y()); |
| 25 EXPECT_EQ(rect.width(), greg.GetPendingUpdate().paint_rect.width()); |
| 26 EXPECT_EQ(rect.height(), greg.GetPendingUpdate().paint_rect.height()); |
| 27 } |
| 28 |
| 29 TEST(PaintAggregator, DoubleDisjointInvalidation) { |
| 30 PaintAggregator greg; |
| 31 |
| 32 gfx::Rect r1(2, 4, 2, 4); |
| 33 gfx::Rect r2(4, 2, 4, 2); |
| 34 |
| 35 greg.InvalidateRect(r1); |
| 36 greg.InvalidateRect(r2); |
| 37 |
| 38 gfx::Rect expected = r1.Union(r2); |
| 39 |
| 40 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 41 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); |
| 42 EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); |
| 43 |
| 44 EXPECT_EQ(expected.x(), greg.GetPendingUpdate().paint_rect.x()); |
| 45 EXPECT_EQ(expected.y(), greg.GetPendingUpdate().paint_rect.y()); |
| 46 EXPECT_EQ(expected.width(), greg.GetPendingUpdate().paint_rect.width()); |
| 47 EXPECT_EQ(expected.height(), greg.GetPendingUpdate().paint_rect.height()); |
| 48 } |
| 49 |
| 50 TEST(PaintAggregator, SingleScroll) { |
| 51 PaintAggregator greg; |
| 52 |
| 53 gfx::Rect rect(1, 2, 3, 4); |
| 54 gfx::Point delta(1, 0); |
| 55 greg.ScrollRect(delta.x(), delta.y(), rect); |
| 56 |
| 57 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 58 EXPECT_TRUE(greg.GetPendingUpdate().paint_rect.IsEmpty()); |
| 59 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); |
| 60 |
| 61 EXPECT_EQ(rect.x(), greg.GetPendingUpdate().scroll_rect.x()); |
| 62 EXPECT_EQ(rect.y(), greg.GetPendingUpdate().scroll_rect.y()); |
| 63 EXPECT_EQ(rect.width(), greg.GetPendingUpdate().scroll_rect.width()); |
| 64 EXPECT_EQ(rect.height(), greg.GetPendingUpdate().scroll_rect.height()); |
| 65 |
| 66 EXPECT_EQ(delta.x(), greg.GetPendingUpdate().scroll_delta.x()); |
| 67 EXPECT_EQ(delta.y(), greg.GetPendingUpdate().scroll_delta.y()); |
| 68 |
| 69 gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); |
| 70 gfx::Rect expected_damage(1, 2, 1, 4); |
| 71 EXPECT_EQ(expected_damage.x(), resulting_damage.x()); |
| 72 EXPECT_EQ(expected_damage.y(), resulting_damage.y()); |
| 73 EXPECT_EQ(expected_damage.width(), resulting_damage.width()); |
| 74 EXPECT_EQ(expected_damage.height(), resulting_damage.height()); |
| 75 } |
| 76 |
| 77 TEST(PaintAggregator, DoubleOverlappingScroll) { |
| 78 PaintAggregator greg; |
| 79 |
| 80 gfx::Rect rect(1, 2, 3, 4); |
| 81 gfx::Point delta1(1, 0); |
| 82 gfx::Point delta2(1, 0); |
| 83 greg.ScrollRect(delta1.x(), delta1.y(), rect); |
| 84 greg.ScrollRect(delta2.x(), delta2.y(), rect); |
| 85 |
| 86 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 87 EXPECT_TRUE(greg.GetPendingUpdate().paint_rect.IsEmpty()); |
| 88 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); |
| 89 |
| 90 EXPECT_EQ(rect.x(), greg.GetPendingUpdate().scroll_rect.x()); |
| 91 EXPECT_EQ(rect.y(), greg.GetPendingUpdate().scroll_rect.y()); |
| 92 EXPECT_EQ(rect.width(), greg.GetPendingUpdate().scroll_rect.width()); |
| 93 EXPECT_EQ(rect.height(), greg.GetPendingUpdate().scroll_rect.height()); |
| 94 |
| 95 gfx::Point expected_delta(delta1.x() + delta2.x(), |
| 96 delta1.y() + delta2.y()); |
| 97 EXPECT_EQ(expected_delta.x(), greg.GetPendingUpdate().scroll_delta.x()); |
| 98 EXPECT_EQ(expected_delta.y(), greg.GetPendingUpdate().scroll_delta.y()); |
| 99 |
| 100 gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); |
| 101 gfx::Rect expected_damage(1, 2, 2, 4); |
| 102 EXPECT_EQ(expected_damage.x(), resulting_damage.x()); |
| 103 EXPECT_EQ(expected_damage.y(), resulting_damage.y()); |
| 104 EXPECT_EQ(expected_damage.width(), resulting_damage.width()); |
| 105 EXPECT_EQ(expected_damage.height(), resulting_damage.height()); |
| 106 } |
| 107 |
| 108 TEST(PaintAggregator, DiagonalScroll) { |
| 109 PaintAggregator greg; |
| 110 |
| 111 // We don't support optimized diagonal scrolling, so this should result in |
| 112 // repainting. |
| 113 |
| 114 gfx::Rect rect(1, 2, 3, 4); |
| 115 gfx::Point delta(1, 1); |
| 116 greg.ScrollRect(delta.x(), delta.y(), rect); |
| 117 |
| 118 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 119 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); |
| 120 EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); |
| 121 |
| 122 EXPECT_EQ(rect.x(), greg.GetPendingUpdate().paint_rect.x()); |
| 123 EXPECT_EQ(rect.y(), greg.GetPendingUpdate().paint_rect.y()); |
| 124 EXPECT_EQ(rect.width(), greg.GetPendingUpdate().paint_rect.width()); |
| 125 EXPECT_EQ(rect.height(), greg.GetPendingUpdate().paint_rect.height()); |
| 126 } |
| 127 |
| 128 // TODO(darin): Add tests for mixed scrolling and invalidation |
| OLD | NEW |