Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: ui/views/view_model_unittest.cc

Issue 10267023: Gets tab dragging to work in touch mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/view_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ui/views/view_model.h" 5 #include "ui/views/view_model.h"
6 6
7 #include "base/string_number_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/view.h" 9 #include "ui/views/view.h"
9 10
10 namespace views { 11 namespace views {
11 12
13 namespace {
14
15 // Returns a string containing the x-coordinate of each of the views in |model|.
16 std::string BoundsString(const ViewModel& model) {
17 std::string result;
18 for (int i = 0; i < model.view_size(); ++i) {
19 if (i != 0)
20 result += " ";
21 result += base::IntToString(model.ideal_bounds(i).x());
22 }
23 return result;
24 }
25
26 // Returns a string containing the id of each of the views in |model|.
27 std::string ViewIDsString(const ViewModel& model) {
28 std::string result;
29 for (int i = 0; i < model.view_size(); ++i) {
30 if (i != 0)
31 result += " ";
32 result += base::IntToString(model.view_at(i)->id());
33 }
34 return result;
35 }
36
37 } // namespace
38
12 TEST(ViewModel, BasicAssertions) { 39 TEST(ViewModel, BasicAssertions) {
13 View v1; 40 View v1;
14 ViewModel model; 41 ViewModel model;
15 model.Add(&v1, 0); 42 model.Add(&v1, 0);
16 EXPECT_EQ(1, model.view_size()); 43 EXPECT_EQ(1, model.view_size());
17 EXPECT_EQ(&v1, model.view_at(0)); 44 EXPECT_EQ(&v1, model.view_at(0));
18 gfx::Rect v1_bounds(1, 2, 3, 4); 45 gfx::Rect v1_bounds(1, 2, 3, 4);
19 model.set_ideal_bounds(0, v1_bounds); 46 model.set_ideal_bounds(0, v1_bounds);
20 EXPECT_EQ(v1_bounds, model.ideal_bounds(0)); 47 EXPECT_EQ(v1_bounds, model.ideal_bounds(0));
21 EXPECT_EQ(0, model.GetIndexOfView(&v1)); 48 EXPECT_EQ(0, model.GetIndexOfView(&v1));
22 } 49 }
23 50
24 TEST(ViewModel, Move) { 51 TEST(ViewModel, Move) {
25 View v1, v2, v3; 52 View v1, v2, v3;
53 v1.set_id(0);
54 v2.set_id(1);
55 v3.set_id(2);
26 ViewModel model; 56 ViewModel model;
27 model.Add(&v1, 0); 57 model.Add(&v1, 0);
28 model.Add(&v2, 1); 58 model.Add(&v2, 1);
29 model.Add(&v3, 2); 59 model.Add(&v3, 2);
30 model.Move(0, 2); 60 model.Move(0, 2);
31 EXPECT_EQ(&v1, model.view_at(2)); 61 EXPECT_EQ("1 2 0", ViewIDsString(model));
32 EXPECT_EQ(&v2, model.view_at(0));
33 EXPECT_EQ(&v3, model.view_at(1));
34 62
35 model.Move(2, 0); 63 model.Move(2, 0);
36 EXPECT_EQ(&v1, model.view_at(0)); 64 EXPECT_EQ("0 1 2", ViewIDsString(model));
37 EXPECT_EQ(&v2, model.view_at(1)); 65 }
38 EXPECT_EQ(&v3, model.view_at(2)); 66
67 TEST(ViewModel, MoveViewOnly) {
68 View v1, v2, v3;
69 v1.set_id(0);
70 v2.set_id(1);
71 v3.set_id(2);
72 ViewModel model;
73 model.Add(&v1, 0);
74 model.Add(&v2, 1);
75 model.Add(&v3, 2);
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));
82
83 model.MoveViewOnly(2, 0);
84 EXPECT_EQ("0 1 2", ViewIDsString(model));
85 EXPECT_EQ("10 11 12", BoundsString(model));
86
87 model.MoveViewOnly(0, 1);
88 EXPECT_EQ("1 0 2", ViewIDsString(model));
89 EXPECT_EQ("10 11 12", BoundsString(model));
90
91 model.MoveViewOnly(1, 0);
92 EXPECT_EQ("0 1 2", ViewIDsString(model));
93 EXPECT_EQ("10 11 12", BoundsString(model));
39 } 94 }
40 95
41 } // namespace views 96 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698