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

Unified Diff: ui/base/models/list_model_unittest.cc

Issue 2379863002: Fix object ownership in ui/base/models. (Closed)
Patch Set: fix Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/models/list_model.h ('k') | ui/base/models/tree_node_iterator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/models/list_model_unittest.cc
diff --git a/ui/base/models/list_model_unittest.cc b/ui/base/models/list_model_unittest.cc
index 7d4d998b2103ca18df4b92394e172f5146d0ede9..acb00da37c5d1151bddb71034a97454adfdbcfb8 100644
--- a/ui/base/models/list_model_unittest.cc
+++ b/ui/base/models/list_model_unittest.cc
@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ui {
@@ -77,15 +78,15 @@ TEST_F(ListModelTest, Add) {
model.AddObserver(this);
// Append FooItem(0)
- model.Add(new FooItem(0));
+ model.Add(base::MakeUnique<FooItem>(0));
ExpectCountsEqual(1, 0, 0, 0);
// Append FooItem(1)
- model.Add(new FooItem(1));
+ model.Add(base::MakeUnique<FooItem>(1));
ExpectCountsEqual(2, 0, 0, 0);
// Insert FooItem(2) at position 0
- model.AddAt(0, new FooItem(2));
+ model.AddAt(0, base::MakeUnique<FooItem>(2));
ExpectCountsEqual(3, 0, 0, 0);
// Total 3 items in model.
@@ -101,9 +102,9 @@ TEST_F(ListModelTest, Remove) {
ListModel<FooItem> model;
model.AddObserver(this);
- model.Add(new FooItem(0));
- model.Add(new FooItem(1));
- model.Add(new FooItem(2));
+ model.Add(base::MakeUnique<FooItem>(0));
+ model.Add(base::MakeUnique<FooItem>(1));
+ model.Add(base::MakeUnique<FooItem>(2));
ClearCounts();
@@ -120,22 +121,18 @@ TEST_F(ListModelTest, Remove) {
ExpectCountsEqual(0, 3, 0, 0);
}
-TEST_F(ListModelTest, RemoveAll) {
+TEST_F(ListModelTest, DeleteAll) {
ListModel<FooItem> model;
model.AddObserver(this);
- std::unique_ptr<FooItem> foo0(new FooItem(0));
- std::unique_ptr<FooItem> foo1(new FooItem(1));
- std::unique_ptr<FooItem> foo2(new FooItem(2));
-
- model.Add(foo0.get());
- model.Add(foo1.get());
- model.Add(foo2.get());
+ model.Add(base::MakeUnique<FooItem>(0));
+ model.Add(base::MakeUnique<FooItem>(1));
+ model.Add(base::MakeUnique<FooItem>(2));
ClearCounts();
- // Remove all items and scoped_ptr above would release memory.
- model.RemoveAll();
+ // Delete all items.
+ model.DeleteAll();
ExpectCountsEqual(0, 3, 0, 0);
}
@@ -143,9 +140,9 @@ TEST_F(ListModelTest, Move) {
ListModel<FooItem> model;
model.AddObserver(this);
- model.Add(new FooItem(0));
- model.Add(new FooItem(1));
- model.Add(new FooItem(2));
+ model.Add(base::MakeUnique<FooItem>(0));
+ model.Add(base::MakeUnique<FooItem>(1));
+ model.Add(base::MakeUnique<FooItem>(2));
ClearCounts();
@@ -161,9 +158,9 @@ TEST_F(ListModelTest, FakeUpdate) {
ListModel<FooItem> model;
model.AddObserver(this);
- model.Add(new FooItem(0));
- model.Add(new FooItem(1));
- model.Add(new FooItem(2));
+ model.Add(base::MakeUnique<FooItem>(0));
+ model.Add(base::MakeUnique<FooItem>(1));
+ model.Add(base::MakeUnique<FooItem>(2));
ClearCounts();
« no previous file with comments | « ui/base/models/list_model.h ('k') | ui/base/models/tree_node_iterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698