OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/tile_priority.h" | 5 #include "cc/tile_priority.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 namespace { | 10 namespace { |
11 | 11 |
12 TEST(TilePriorityTest, TimeForBoundsToIntersectWithScroll) { | 12 TEST(TilePriorityTest, TimeForBoundsToIntersectWithScroll) { |
| 13 const float inf = std::numeric_limits<float>::infinity(); |
13 gfx::Rect target(0, 0, 800, 600); | 14 gfx::Rect target(0, 0, 800, 600); |
14 gfx::Rect current(100, 100, 100, 100); | 15 gfx::Rect current(100, 100, 100, 100); |
15 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 16 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
16 gfx::Rect(-200, 0, 100, 100), current, 1, target)); | 17 gfx::Rect(-200, 0, 100, 100), current, 1, target)); |
17 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 18 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
18 gfx::Rect(-100, 0, 100, 100), current, 1, target)); | 19 gfx::Rect(-100, 0, 100, 100), current, 1, target)); |
19 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 20 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
20 gfx::Rect(400, 400, 100, 100), current, 1, target)); | 21 gfx::Rect(400, 400, 100, 100), current, 1, target)); |
21 | 22 |
22 current = gfx::Rect(-300, -300, 100, 100); | 23 current = gfx::Rect(-300, -300, 100, 100); |
23 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect( | 24 EXPECT_EQ(inf, TilePriority::TimeForBoundsToIntersect( |
24 gfx::Rect(0, 0, 100, 100), current, 1, target)); | 25 gfx::Rect(0, 0, 100, 100), current, 1, target)); |
25 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect( | 26 EXPECT_EQ(inf, TilePriority::TimeForBoundsToIntersect( |
26 gfx::Rect(-200, -200, 100, 100), current, 1, target)); | 27 gfx::Rect(-200, -200, 100, 100), current, 1, target)); |
27 EXPECT_EQ(2, TilePriority::TimeForBoundsToIntersect( | 28 EXPECT_EQ(2, TilePriority::TimeForBoundsToIntersect( |
28 gfx::Rect(-400, -400, 100, 100), current, 1, target)); | 29 gfx::Rect(-400, -400, 100, 100), current, 1, target)); |
29 } | 30 } |
30 | 31 |
31 TEST(TilePriorityTest, TimeForBoundsToIntersectWithScale) { | 32 TEST(TilePriorityTest, TimeForBoundsToIntersectWithScale) { |
| 33 const float inf = std::numeric_limits<float>::infinity(); |
32 gfx::Rect target(0, 0, 800, 600); | 34 gfx::Rect target(0, 0, 800, 600); |
33 gfx::Rect current(100, 100, 100, 100); | 35 gfx::Rect current(100, 100, 100, 100); |
34 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 36 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
35 gfx::Rect(-200, 0, 200, 200), current, 1, target)); | 37 gfx::Rect(-200, 0, 200, 200), current, 1, target)); |
36 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 38 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
37 gfx::Rect(-100, 0, 50, 50), current, 1, target)); | 39 gfx::Rect(-100, 0, 50, 50), current, 1, target)); |
38 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( | 40 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect( |
39 gfx::Rect(400, 400, 400, 400), current, 1, target)); | 41 gfx::Rect(400, 400, 400, 400), current, 1, target)); |
40 | 42 |
41 current = gfx::Rect(-300, -300, 100, 100); | 43 current = gfx::Rect(-300, -300, 100, 100); |
42 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect( | 44 EXPECT_EQ(inf, TilePriority::TimeForBoundsToIntersect( |
43 gfx::Rect(-400, -400, 300, 300), current, 1, target)); | 45 gfx::Rect(-400, -400, 300, 300), current, 1, target)); |
44 EXPECT_EQ(8, TilePriority::TimeForBoundsToIntersect( | 46 EXPECT_EQ(8, TilePriority::TimeForBoundsToIntersect( |
45 gfx::Rect(-275, -275, 50, 50), current, 1, target)); | 47 gfx::Rect(-275, -275, 50, 50), current, 1, target)); |
46 EXPECT_EQ(1, TilePriority::TimeForBoundsToIntersect( | 48 EXPECT_EQ(1, TilePriority::TimeForBoundsToIntersect( |
47 gfx::Rect(-450, -450, 50, 50), current, 1, target)); | 49 gfx::Rect(-450, -450, 50, 50), current, 1, target)); |
48 } | 50 } |
49 | 51 |
50 TEST(TilePriorityTest, ManhattanDistanceBetweenRects) { | 52 TEST(TilePriorityTest, ManhattanDistanceBetweenRects) { |
51 EXPECT_EQ(0, TilePriority::manhattanDistance( | 53 EXPECT_EQ(0, TilePriority::manhattanDistance( |
52 gfx::RectF(0, 0, 400, 400), gfx::RectF(0, 0, 100, 100))); | 54 gfx::RectF(0, 0, 400, 400), gfx::RectF(0, 0, 100, 100))); |
53 | 55 |
54 EXPECT_EQ(2, TilePriority::manhattanDistance( | 56 EXPECT_EQ(2, TilePriority::manhattanDistance( |
55 gfx::Rect(0, 0, 400, 400), gfx::Rect(-100, -100, 100, 100))); | 57 gfx::Rect(0, 0, 400, 400), gfx::Rect(-100, -100, 100, 100))); |
56 | 58 |
57 EXPECT_EQ(1, TilePriority::manhattanDistance( | 59 EXPECT_EQ(1, TilePriority::manhattanDistance( |
58 gfx::Rect(0, 0, 400, 400), gfx::Rect(0, -100, 100, 100))); | 60 gfx::Rect(0, 0, 400, 400), gfx::Rect(0, -100, 100, 100))); |
59 | 61 |
60 EXPECT_EQ(202, TilePriority::manhattanDistance( | 62 EXPECT_EQ(202, TilePriority::manhattanDistance( |
61 gfx::Rect(0, 0, 100, 100), gfx::Rect(200, 200, 100, 100))); | 63 gfx::Rect(0, 0, 100, 100), gfx::Rect(200, 200, 100, 100))); |
62 } | 64 } |
63 | 65 |
64 } // namespace | 66 } // namespace |
65 } // namespace cc | 67 } // namespace cc |
OLD | NEW |