OLD | NEW |
1 // Copyright (c) 2011 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/base/models/list_model.h" | 5 #include "ui/base/models/list_model.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 ExpectCountsEqual(2, 0, 0); | 75 ExpectCountsEqual(2, 0, 0); |
76 | 76 |
77 // Insert FooItem(2) at position 0 | 77 // Insert FooItem(2) at position 0 |
78 model.AddAt(0, new FooItem(2)); | 78 model.AddAt(0, new FooItem(2)); |
79 ExpectCountsEqual(3, 0, 0); | 79 ExpectCountsEqual(3, 0, 0); |
80 | 80 |
81 // Total 3 items in mode. | 81 // Total 3 items in mode. |
82 EXPECT_EQ(3, model.item_count()); | 82 EXPECT_EQ(3, model.item_count()); |
83 | 83 |
84 // First one should be FooItem(2), followed by FooItem(0) and FooItem(1) | 84 // First one should be FooItem(2), followed by FooItem(0) and FooItem(1) |
85 EXPECT_EQ(2, model.item_at(0)->id()); | 85 EXPECT_EQ(2, model.GetItemAt(0)->id()); |
86 EXPECT_EQ(0, model.item_at(1)->id()); | 86 EXPECT_EQ(0, model.GetItemAt(1)->id()); |
87 EXPECT_EQ(1, model.item_at(2)->id()); | 87 EXPECT_EQ(1, model.GetItemAt(2)->id()); |
88 } | 88 } |
89 | 89 |
90 TEST_F(ListModelTest, Remove) { | 90 TEST_F(ListModelTest, Remove) { |
91 ListModel<FooItem> model; | 91 ListModel<FooItem> model; |
92 model.AddObserver(this); | 92 model.AddObserver(this); |
93 | 93 |
94 model.Add(new FooItem(0)); | 94 model.Add(new FooItem(0)); |
95 model.Add(new FooItem(1)); | 95 model.Add(new FooItem(1)); |
96 model.Add(new FooItem(2)); | 96 model.Add(new FooItem(2)); |
97 | 97 |
98 ClearCounts(); | 98 ClearCounts(); |
99 | 99 |
100 // Remove item at index 1 from model and release memory. | 100 // Remove item at index 1 from model and release memory. |
101 model.DeleteAt(1); | 101 model.DeleteAt(1); |
102 ExpectCountsEqual(0, 1, 0); | 102 ExpectCountsEqual(0, 1, 0); |
103 | 103 |
104 EXPECT_EQ(2, model.item_count()); | 104 EXPECT_EQ(2, model.item_count()); |
105 EXPECT_EQ(0, model.item_at(0)->id()); | 105 EXPECT_EQ(0, model.GetItemAt(0)->id()); |
106 EXPECT_EQ(2, model.item_at(1)->id()); | 106 EXPECT_EQ(2, model.GetItemAt(1)->id()); |
107 | 107 |
108 // Remove all items from model and delete them. | 108 // Remove all items from model and delete them. |
109 model.DeleteAll(); | 109 model.DeleteAll(); |
110 ExpectCountsEqual(0, 3, 0); | 110 ExpectCountsEqual(0, 3, 0); |
111 } | 111 } |
112 | 112 |
113 TEST_F(ListModelTest, RemoveAll) { | 113 TEST_F(ListModelTest, RemoveAll) { |
114 ListModel<FooItem> model; | 114 ListModel<FooItem> model; |
115 model.AddObserver(this); | 115 model.AddObserver(this); |
116 | 116 |
(...skipping 23 matching lines...) Expand all Loading... |
140 ClearCounts(); | 140 ClearCounts(); |
141 | 141 |
142 model.NotifyItemsChanged(0, 1); | 142 model.NotifyItemsChanged(0, 1); |
143 ExpectCountsEqual(0, 0, 1); | 143 ExpectCountsEqual(0, 0, 1); |
144 | 144 |
145 model.NotifyItemsChanged(1, 2); | 145 model.NotifyItemsChanged(1, 2); |
146 ExpectCountsEqual(0, 0, 3); | 146 ExpectCountsEqual(0, 0, 3); |
147 } | 147 } |
148 | 148 |
149 } // namespace ui | 149 } // namespace ui |
OLD | NEW |