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