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
3 // found in the LICENSE file.
5 #include "cc/tile_priority.h"
7 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(TilePriorityTest
, TimeForBoundsToIntersectWithScroll
) {
13 gfx::Rect
target(0, 0, 800, 600);
14 gfx::Rect
current(100, 100, 100, 100);
15 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
16 gfx::Rect(-200, 0, 100, 100), current
, 1, target
));
17 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
18 gfx::Rect(-100, 0, 100, 100), current
, 1, target
));
19 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
20 gfx::Rect(400, 400, 100, 100), current
, 1, target
));
22 current
= gfx::Rect(-300, -300, 100, 100);
23 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect(
24 gfx::Rect(0, 0, 100, 100), current
, 1, target
));
25 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect(
26 gfx::Rect(-200, -200, 100, 100), current
, 1, target
));
27 EXPECT_EQ(2, TilePriority::TimeForBoundsToIntersect(
28 gfx::Rect(-400, -400, 100, 100), current
, 1, target
));
31 TEST(TilePriorityTest
, TimeForBoundsToIntersectWithScale
) {
32 gfx::Rect
target(0, 0, 800, 600);
33 gfx::Rect
current(100, 100, 100, 100);
34 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
35 gfx::Rect(-200, 0, 200, 200), current
, 1, target
));
36 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
37 gfx::Rect(-100, 0, 50, 50), current
, 1, target
));
38 EXPECT_EQ(0, TilePriority::TimeForBoundsToIntersect(
39 gfx::Rect(400, 400, 400, 400), current
, 1, target
));
41 current
= gfx::Rect(-300, -300, 100, 100);
42 EXPECT_EQ(1000, TilePriority::TimeForBoundsToIntersect(
43 gfx::Rect(-400, -400, 300, 300), current
, 1, target
));
44 EXPECT_EQ(8, TilePriority::TimeForBoundsToIntersect(
45 gfx::Rect(-275, -275, 50, 50), current
, 1, target
));
46 EXPECT_EQ(1, TilePriority::TimeForBoundsToIntersect(
47 gfx::Rect(-450, -450, 50, 50), current
, 1, target
));
50 TEST(TilePriorityTest
, ManhattanDistanceBetweenRects
) {
51 EXPECT_EQ(0, TilePriority::manhattanDistance(
52 gfx::RectF(0, 0, 400, 400), gfx::RectF(0, 0, 100, 100)));
54 EXPECT_EQ(2, TilePriority::manhattanDistance(
55 gfx::Rect(0, 0, 400, 400), gfx::Rect(-100, -100, 100, 100)));
57 EXPECT_EQ(1, TilePriority::manhattanDistance(
58 gfx::Rect(0, 0, 400, 400), gfx::Rect(0, -100, 100, 100)));
60 EXPECT_EQ(202, TilePriority::manhattanDistance(
61 gfx::Rect(0, 0, 100, 100), gfx::Rect(200, 200, 100, 100)));