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.h"
7 #include "base/string_number_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/views/view.h"
15 // Returns a string containing the x-coordinate of each of the views in |model|.
16 std::string
BoundsString(const ViewModel
& model
) {
18 for (int i
= 0; i
< model
.view_size(); ++i
) {
21 result
+= base::IntToString(model
.ideal_bounds(i
).x());
26 // Returns a string containing the id of each of the views in |model|.
27 std::string
ViewIDsString(const ViewModel
& model
) {
29 for (int i
= 0; i
< model
.view_size(); ++i
) {
32 result
+= base::IntToString(model
.view_at(i
)->id());
39 TEST(ViewModel
, BasicAssertions
) {
43 EXPECT_EQ(1, model
.view_size());
44 EXPECT_EQ(&v1
, model
.view_at(0));
45 gfx::Rect
v1_bounds(1, 2, 3, 4);
46 model
.set_ideal_bounds(0, v1_bounds
);
47 EXPECT_EQ(v1_bounds
, model
.ideal_bounds(0));
48 EXPECT_EQ(0, model
.GetIndexOfView(&v1
));
51 TEST(ViewModel
, Move
) {
61 EXPECT_EQ("1 2 0", ViewIDsString(model
));
64 EXPECT_EQ("0 1 2", ViewIDsString(model
));
67 TEST(ViewModel
, MoveViewOnly
) {
76 model
.set_ideal_bounds(0, gfx::Rect(10, 0, 1, 2));
77 model
.set_ideal_bounds(1, gfx::Rect(11, 0, 1, 2));
78 model
.set_ideal_bounds(2, gfx::Rect(12, 0, 1, 2));
79 model
.MoveViewOnly(0, 2);
80 EXPECT_EQ("1 2 0", ViewIDsString(model
));
81 EXPECT_EQ("10 11 12", BoundsString(model
));
83 model
.MoveViewOnly(2, 0);
84 EXPECT_EQ("0 1 2", ViewIDsString(model
));
85 EXPECT_EQ("10 11 12", BoundsString(model
));
87 model
.MoveViewOnly(0, 1);
88 EXPECT_EQ("1 0 2", ViewIDsString(model
));
89 EXPECT_EQ("10 11 12", BoundsString(model
));
91 model
.MoveViewOnly(1, 0);
92 EXPECT_EQ("0 1 2", ViewIDsString(model
));
93 EXPECT_EQ("10 11 12", BoundsString(model
));