Clean up Throbber.
[chromium-blink-merge.git] / ui / views / view_model_utils_unittest.cc
blob92004b709af47ff8c66a1b65ee2bd084dfc1216a
1 // Copyright (c) 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 "ui/views/view_model_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/view.h"
9 #include "ui/views/view_model.h"
11 namespace views {
13 // Makes sure SetViewBoundsToIdealBounds updates the view appropriately.
14 TEST(ViewModelUtils, SetViewBoundsToIdealBounds) {
15 View v1;
16 ViewModel model;
17 model.Add(&v1, 0);
18 gfx::Rect v1_bounds(1, 2, 3, 4);
19 model.set_ideal_bounds(0, v1_bounds);
20 ViewModelUtils::SetViewBoundsToIdealBounds(model);
21 EXPECT_EQ(v1_bounds, v1.bounds());
24 // Assertions for DetermineMoveIndex.
25 TEST(ViewModelUtils, DetermineMoveIndex) {
26 View v1, v2, v3;
27 ViewModel model;
28 model.Add(&v1, 0);
29 model.Add(&v2, 1);
30 model.Add(&v3, 2);
31 model.set_ideal_bounds(0, gfx::Rect(0, 0, 10, 10));
32 model.set_ideal_bounds(1, gfx::Rect(10, 0, 1000, 10));
33 model.set_ideal_bounds(2, gfx::Rect(1010, 0, 2, 10));
35 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
36 model, &v1, ViewModelUtils::HORIZONTAL, -10, 0));
37 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
38 model, &v1, ViewModelUtils::HORIZONTAL, 4, 0));
39 EXPECT_EQ(1, ViewModelUtils::DetermineMoveIndex(
40 model, &v1, ViewModelUtils::HORIZONTAL, 506, 0));
41 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
42 model, &v1, ViewModelUtils::HORIZONTAL, 1010, 0));
43 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
44 model, &v1, ViewModelUtils::HORIZONTAL, 2000, 0));
46 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
47 model, &v2, ViewModelUtils::HORIZONTAL, -10, 0));
48 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
49 model, &v2, ViewModelUtils::HORIZONTAL, 4, 0));
50 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
51 model, &v2, ViewModelUtils::HORIZONTAL, 12, 0));
53 // Try the same when vertical.
54 model.set_ideal_bounds(0, gfx::Rect(0, 0, 10, 10));
55 model.set_ideal_bounds(1, gfx::Rect(0, 10, 10, 1000));
56 model.set_ideal_bounds(2, gfx::Rect(0, 1010, 10, 2));
58 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
59 model, &v1, ViewModelUtils::VERTICAL, 0, -10));
60 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
61 model, &v1, ViewModelUtils::VERTICAL, 0, 4));
62 EXPECT_EQ(1, ViewModelUtils::DetermineMoveIndex(
63 model, &v1, ViewModelUtils::VERTICAL, 0, 506));
64 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
65 model, &v1, ViewModelUtils::VERTICAL, 0, 1010));
66 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
67 model, &v1, ViewModelUtils::VERTICAL, 0, 2000));
69 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
70 model, &v2, ViewModelUtils::VERTICAL, 0, -10));
71 EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
72 model, &v2, ViewModelUtils::VERTICAL, 0, 4));
73 EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
74 model, &v2, ViewModelUtils::VERTICAL, 0, 12));
77 } // namespace views