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

Side by Side Diff: chrome/browser/ui/app_list/search/mixer_unittest.cc

Issue 369693004: Make app list search result mixer more resilient to reordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // Only three results with unique id are kept. 194 // Only three results with unique id are kept.
195 EXPECT_EQ("dup0,dup1,dup2", GetResults()); 195 EXPECT_EQ("dup0,dup1,dup2", GetResults());
196 } 196 }
197 197
198 TEST_F(MixerTest, Publish) { 198 TEST_F(MixerTest, Publish) {
199 scoped_ptr<ChromeSearchResult> result1(new TestSearchResult("app1", 0)); 199 scoped_ptr<ChromeSearchResult> result1(new TestSearchResult("app1", 0));
200 scoped_ptr<ChromeSearchResult> result2(new TestSearchResult("app2", 0)); 200 scoped_ptr<ChromeSearchResult> result2(new TestSearchResult("app2", 0));
201 scoped_ptr<ChromeSearchResult> result3(new TestSearchResult("app3", 0)); 201 scoped_ptr<ChromeSearchResult> result3(new TestSearchResult("app3", 0));
202 scoped_ptr<ChromeSearchResult> result3_copy = result3->Duplicate(); 202 scoped_ptr<ChromeSearchResult> result3_copy = result3->Duplicate();
203 scoped_ptr<ChromeSearchResult> result4(new TestSearchResult("app4", 0)); 203 scoped_ptr<ChromeSearchResult> result4(new TestSearchResult("app4", 0));
204 scoped_ptr<ChromeSearchResult> result5(new TestSearchResult("app5", 0));
204 205
205 AppListModel::SearchResults ui_results; 206 AppListModel::SearchResults ui_results;
206 207
207 // Publish the first three results to |ui_results|. 208 // Publish the first three results to |ui_results|.
208 Mixer::SortedResults new_results; 209 Mixer::SortedResults new_results;
209 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); 210 new_results.push_back(Mixer::SortData(result1.get(), 1.0f));
210 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); 211 new_results.push_back(Mixer::SortData(result2.get(), 1.0f));
211 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); 212 new_results.push_back(Mixer::SortData(result3.get(), 1.0f));
212 213
213 Mixer::Publish(new_results, &ui_results); 214 Mixer::Publish(new_results, &ui_results);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 // The second result will still use the original object, but have a different 251 // The second result will still use the original object, but have a different
251 // title, since the ID did not change. 252 // title, since the ID did not change.
252 EXPECT_EQ(old_ui_result_ids[1], 253 EXPECT_EQ(old_ui_result_ids[1],
253 TestSearchResult::GetInstanceId(ui_results.GetItemAt(1))); 254 TestSearchResult::GetInstanceId(ui_results.GetItemAt(1)));
254 EXPECT_EQ(kNewAppTitle, ui_results.GetItemAt(1)->title()); 255 EXPECT_EQ(kNewAppTitle, ui_results.GetItemAt(1)->title());
255 256
256 // The third result will use the original object as the ID did not change. 257 // The third result will use the original object as the ID did not change.
257 EXPECT_EQ(old_ui_result_ids[2], 258 EXPECT_EQ(old_ui_result_ids[2],
258 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); 259 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2)));
260
261 // Save the current |ui_results| order which should is app4, app2, app3.
262 old_ui_result_ids.clear();
263 for (size_t i = 0; i < ui_results.item_count(); ++i) {
264 old_ui_result_ids.push_back(
265 TestSearchResult::GetInstanceId(ui_results.GetItemAt(i)));
266 }
267
268 // Reorder the existing results and add a new one in the second place.
269 new_results[0] = Mixer::SortData(result2.get(), 1.0f);
270 new_results[1] = Mixer::SortData(result5.get(), 1.0f);
271 new_results[2] = Mixer::SortData(result3.get(), 1.0f);
272 new_results.push_back(Mixer::SortData(result4.get(), 1.0f));
273
274 Mixer::Publish(new_results, &ui_results);
275 EXPECT_EQ(4u, ui_results.item_count());
276
277 // The reordered results should use the original objects.
278 EXPECT_EQ(old_ui_result_ids[0],
279 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3)));
280 EXPECT_EQ(old_ui_result_ids[1],
281 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0)));
282 EXPECT_EQ(old_ui_result_ids[2],
283 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2)));
259 } 284 }
260 285
261 } // namespace test 286 } // namespace test
262 } // namespace app_list 287 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/mixer.cc ('k') | ui/app_list/views/search_result_list_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698