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

Side by Side Diff: ui/app_list/views/search_result_page_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
« no previous file with comments | « ui/app_list/views/search_result_list_view_unittest.cc ('k') | ui/base/models/list_model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_page_view.h" 5 #include "ui/app_list/views/search_result_page_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "ui/app_list/app_list_model.h" 13 #include "ui/app_list/app_list_model.h"
13 #include "ui/app_list/app_list_switches.h" 14 #include "ui/app_list/app_list_switches.h"
14 #include "ui/app_list/test/app_list_test_view_delegate.h" 15 #include "ui/app_list/test/app_list_test_view_delegate.h"
15 #include "ui/app_list/test/test_search_result.h" 16 #include "ui/app_list/test/test_search_result.h"
16 #include "ui/app_list/views/search_result_list_view.h" 17 #include "ui/app_list/views/search_result_list_view.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_tile_item_list_view.h" 19 #include "ui/app_list/views/search_result_tile_item_list_view.h"
19 #include "ui/app_list/views/search_result_view.h" 20 #include "ui/app_list/views/search_result_view.h"
20 #include "ui/views/controls/textfield/textfield.h" 21 #include "ui/views/controls/textfield/textfield.h"
21 #include "ui/views/test/views_test_base.h" 22 #include "ui/views/test/views_test_base.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 void SetUpSearchResults(const std::vector< 55 void SetUpSearchResults(const std::vector<
55 std::pair<SearchResult::DisplayType, int>> result_types) { 56 std::pair<SearchResult::DisplayType, int>> result_types) {
56 AppListModel::SearchResults* results = GetResults(); 57 AppListModel::SearchResults* results = GetResults();
57 results->DeleteAll(); 58 results->DeleteAll();
58 double relevance = result_types.size(); 59 double relevance = result_types.size();
59 for (const auto& data : result_types) { 60 for (const auto& data : result_types) {
60 // Set the relevance of the results in each group in decreasing order (so 61 // Set the relevance of the results in each group in decreasing order (so
61 // the earlier groups have higher relevance, and therefore appear first). 62 // the earlier groups have higher relevance, and therefore appear first).
62 relevance -= 1.0; 63 relevance -= 1.0;
63 for (int i = 0; i < data.second; ++i) { 64 for (int i = 0; i < data.second; ++i) {
64 TestSearchResult* result = new TestSearchResult(); 65 std::unique_ptr<TestSearchResult> result =
66 base::MakeUnique<TestSearchResult>();
65 result->set_display_type(data.first); 67 result->set_display_type(data.first);
66 result->set_relevance(relevance); 68 result->set_relevance(relevance);
67 results->Add(result); 69 results->Add(std::move(result));
68 } 70 }
69 } 71 }
70 72
71 // Adding results will schedule Update(). 73 // Adding results will schedule Update().
72 RunPendingMessages(); 74 RunPendingMessages();
73 } 75 }
74 76
75 int GetSelectedIndex() { return view_->selected_index(); } 77 int GetSelectedIndex() { return view_->selected_index(); }
76 78
77 bool KeyPress(ui::KeyboardCode key_code) { return KeyPress(key_code, false); } 79 bool KeyPress(ui::KeyboardCode key_code) { return KeyPress(key_code, false); }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 215 }
214 216
215 TEST_F(SearchResultPageViewTest, ResultsSorted) { 217 TEST_F(SearchResultPageViewTest, ResultsSorted) {
216 AppListModel::SearchResults* results = GetResults(); 218 AppListModel::SearchResults* results = GetResults();
217 219
218 // Add 3 results and expect the tile list view to be the first result 220 // Add 3 results and expect the tile list view to be the first result
219 // container view. 221 // container view.
220 TestSearchResult* tile_result = new TestSearchResult(); 222 TestSearchResult* tile_result = new TestSearchResult();
221 tile_result->set_display_type(SearchResult::DISPLAY_TILE); 223 tile_result->set_display_type(SearchResult::DISPLAY_TILE);
222 tile_result->set_relevance(1.0); 224 tile_result->set_relevance(1.0);
223 results->Add(tile_result); 225 results->Add(base::WrapUnique(tile_result));
224 { 226 {
225 TestSearchResult* list_result = new TestSearchResult(); 227 TestSearchResult* list_result = new TestSearchResult();
226 list_result->set_display_type(SearchResult::DISPLAY_LIST); 228 list_result->set_display_type(SearchResult::DISPLAY_LIST);
227 list_result->set_relevance(0.5); 229 list_result->set_relevance(0.5);
228 results->Add(list_result); 230 results->Add(base::WrapUnique(list_result));
229 } 231 }
230 { 232 {
231 TestSearchResult* list_result = new TestSearchResult(); 233 TestSearchResult* list_result = new TestSearchResult();
232 list_result->set_display_type(SearchResult::DISPLAY_LIST); 234 list_result->set_display_type(SearchResult::DISPLAY_LIST);
233 list_result->set_relevance(0.3); 235 list_result->set_relevance(0.3);
234 results->Add(list_result); 236 results->Add(base::WrapUnique(list_result));
235 } 237 }
236 238
237 // Adding results will schedule Update(). 239 // Adding results will schedule Update().
238 RunPendingMessages(); 240 RunPendingMessages();
239 241
240 EXPECT_EQ(tile_list_view(), view()->result_container_views()[0]); 242 EXPECT_EQ(tile_list_view(), view()->result_container_views()[0]);
241 EXPECT_EQ(list_view(), view()->result_container_views()[1]); 243 EXPECT_EQ(list_view(), view()->result_container_views()[1]);
242 244
243 // Change the relevance of the tile result and expect the list results to be 245 // Change the relevance of the tile result and expect the list results to be
244 // displayed first. 246 // displayed first.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 326 }
325 327
326 // The selected container has vanished so we reset the selection to 0. 328 // The selected container has vanished so we reset the selection to 0.
327 EXPECT_EQ(0, GetSelectedIndex()); 329 EXPECT_EQ(0, GetSelectedIndex());
328 EXPECT_EQ(-1, tile_list_view()->selected_index()); 330 EXPECT_EQ(-1, tile_list_view()->selected_index());
329 EXPECT_EQ(0, list_view()->selected_index()); 331 EXPECT_EQ(0, list_view()->selected_index());
330 } 332 }
331 333
332 } // namespace test 334 } // namespace test
333 } // namespace app_list 335 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_result_list_view_unittest.cc ('k') | ui/base/models/list_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698