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

Side by Side Diff: ui/app_list/views/search_result_list_view_unittest.cc

Issue 2379863002: Fix object ownership in ui/base/models. (Closed)
Patch Set: fix Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/app_list/views/search_result_list_view.h" 5 #include "ui/app_list/views/search_result_list_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "ui/app_list/app_list_model.h" 15 #include "ui/app_list/app_list_model.h"
15 #include "ui/app_list/test/app_list_test_view_delegate.h" 16 #include "ui/app_list/test/app_list_test_view_delegate.h"
16 #include "ui/app_list/test/test_search_result.h" 17 #include "ui/app_list/test/test_search_result.h"
17 #include "ui/app_list/views/search_result_list_view_delegate.h" 18 #include "ui/app_list/views/search_result_list_view_delegate.h"
18 #include "ui/app_list/views/search_result_view.h" 19 #include "ui/app_list/views/search_result_view.h"
19 #include "ui/views/controls/progress_bar.h" 20 #include "ui/views/controls/progress_bar.h"
20 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
21 22
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 view_delegate_.set_auto_launch_timeout(base::TimeDelta::FromDays(1)); 56 view_delegate_.set_auto_launch_timeout(base::TimeDelta::FromDays(1));
56 } 57 }
57 58
58 base::TimeDelta GetAutoLaunchTimeout() { 59 base::TimeDelta GetAutoLaunchTimeout() {
59 return view_delegate_.GetAutoLaunchTimeout(); 60 return view_delegate_.GetAutoLaunchTimeout();
60 } 61 }
61 62
62 void SetUpSearchResults() { 63 void SetUpSearchResults() {
63 AppListModel::SearchResults* results = GetResults(); 64 AppListModel::SearchResults* results = GetResults();
64 for (int i = 0; i < kDefaultSearchItems; ++i) { 65 for (int i = 0; i < kDefaultSearchItems; ++i) {
65 TestSearchResult* result = new TestSearchResult(); 66 std::unique_ptr<TestSearchResult> result =
67 base::MakeUnique<TestSearchResult>();
66 result->set_display_type(SearchResult::DISPLAY_LIST); 68 result->set_display_type(SearchResult::DISPLAY_LIST);
67 result->set_title(base::UTF8ToUTF16(base::StringPrintf("Result %d", i))); 69 result->set_title(base::UTF8ToUTF16(base::StringPrintf("Result %d", i)));
68 if (i < 2) 70 if (i < 2)
69 result->set_details(base::ASCIIToUTF16("Detail")); 71 result->set_details(base::ASCIIToUTF16("Detail"));
70 results->Add(result); 72 results->Add(std::move(result));
71 } 73 }
72 74
73 // Adding results will schedule Update(). 75 // Adding results will schedule Update().
74 RunPendingMessages(); 76 RunPendingMessages();
75 view_->OnContainerSelected(false, false); 77 view_->OnContainerSelected(false, false);
76 } 78 }
77 79
78 int GetOpenResultCountAndReset(int ranking) { 80 int GetOpenResultCountAndReset(int ranking) {
79 int result = view_delegate_.open_search_result_counts()[ranking]; 81 int result = view_delegate_.open_search_result_counts()[ranking];
80 view_delegate_.open_search_result_counts().clear(); 82 view_delegate_.open_search_result_counts().clear();
81 return result; 83 return result;
82 } 84 }
83 85
84 int GetResultCount() { return view_->num_results(); } 86 int GetResultCount() { return view_->num_results(); }
85 87
86 int GetSelectedIndex() { return view_->selected_index(); } 88 int GetSelectedIndex() { return view_->selected_index(); }
87 89
88 void ResetSelectedIndex() { 90 void ResetSelectedIndex() {
89 view_->SetSelectedIndex(0); 91 view_->SetSelectedIndex(0);
90 } 92 }
91 93
92 void AddTestResultAtIndex(int index) { 94 void AddTestResultAtIndex(int index) {
93 GetResults()->Add(new TestSearchResult()); 95 GetResults()->Add(base::MakeUnique<TestSearchResult>());
94 } 96 }
95 97
96 void DeleteResultAt(int index) { GetResults()->DeleteAt(index); } 98 void DeleteResultAt(int index) { GetResults()->DeleteAt(index); }
97 99
98 bool KeyPress(ui::KeyboardCode key_code) { 100 bool KeyPress(ui::KeyboardCode key_code) {
99 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 101 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
100 return view_->OnKeyPressed(event); 102 return view_->OnKeyPressed(event);
101 } 103 }
102 104
103 bool IsAutoLaunching() { return !!view_->auto_launch_animation_; } 105 bool IsAutoLaunching() { return !!view_->auto_launch_animation_; }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value()); 248 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value());
247 GetResults()->GetItemAt(0)->SetPercentDownloaded(10); 249 GetResults()->GetItemAt(0)->SetPercentDownloaded(10);
248 250
249 DeleteResultAt(0); 251 DeleteResultAt(0);
250 RunPendingMessages(); 252 RunPendingMessages();
251 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value()); 253 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value());
252 } 254 }
253 255
254 } // namespace test 256 } // namespace test
255 } // namespace app_list 257 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_view_unittest.cc ('k') | ui/app_list/views/search_result_page_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698