OLD | NEW |
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/base/models/list_model.h" | 5 #include "ui/base/models/list_model.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 class FooItem { | 17 class FooItem { |
17 public: | 18 public: |
18 explicit FooItem(int id) : id_(id) {} | 19 explicit FooItem(int id) : id_(id) {} |
19 | 20 |
20 int id() const { return id_; } | 21 int id() const { return id_; } |
21 | 22 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 117 |
117 // Remove all items from model and delete them. | 118 // Remove all items from model and delete them. |
118 model.DeleteAll(); | 119 model.DeleteAll(); |
119 ExpectCountsEqual(0, 3, 0, 0); | 120 ExpectCountsEqual(0, 3, 0, 0); |
120 } | 121 } |
121 | 122 |
122 TEST_F(ListModelTest, RemoveAll) { | 123 TEST_F(ListModelTest, RemoveAll) { |
123 ListModel<FooItem> model; | 124 ListModel<FooItem> model; |
124 model.AddObserver(this); | 125 model.AddObserver(this); |
125 | 126 |
126 scoped_ptr<FooItem> foo0(new FooItem(0)); | 127 std::unique_ptr<FooItem> foo0(new FooItem(0)); |
127 scoped_ptr<FooItem> foo1(new FooItem(1)); | 128 std::unique_ptr<FooItem> foo1(new FooItem(1)); |
128 scoped_ptr<FooItem> foo2(new FooItem(2)); | 129 std::unique_ptr<FooItem> foo2(new FooItem(2)); |
129 | 130 |
130 model.Add(foo0.get()); | 131 model.Add(foo0.get()); |
131 model.Add(foo1.get()); | 132 model.Add(foo1.get()); |
132 model.Add(foo2.get()); | 133 model.Add(foo2.get()); |
133 | 134 |
134 ClearCounts(); | 135 ClearCounts(); |
135 | 136 |
136 // Remove all items and scoped_ptr above would release memory. | 137 // Remove all items and scoped_ptr above would release memory. |
137 model.RemoveAll(); | 138 model.RemoveAll(); |
138 ExpectCountsEqual(0, 3, 0, 0); | 139 ExpectCountsEqual(0, 3, 0, 0); |
(...skipping 28 matching lines...) Expand all Loading... |
167 ClearCounts(); | 168 ClearCounts(); |
168 | 169 |
169 model.NotifyItemsChanged(0, 1); | 170 model.NotifyItemsChanged(0, 1); |
170 ExpectCountsEqual(0, 0, 0, 1); | 171 ExpectCountsEqual(0, 0, 0, 1); |
171 | 172 |
172 model.NotifyItemsChanged(1, 2); | 173 model.NotifyItemsChanged(1, 2); |
173 ExpectCountsEqual(0, 0, 0, 3); | 174 ExpectCountsEqual(0, 0, 0, 3); |
174 } | 175 } |
175 | 176 |
176 } // namespace ui | 177 } // namespace ui |
OLD | NEW |