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

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

Issue 372843003: Add unit test for Mixer::Publish. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // This gives "dup0". 175 // This gives "dup0".
176 webstore_provider()->set_prefix(dup); 176 webstore_provider()->set_prefix(dup);
177 webstore_provider()->set_count(1); 177 webstore_provider()->set_count(1);
178 178
179 RunQuery(); 179 RunQuery();
180 180
181 // Only three results with unique id are kept. 181 // Only three results with unique id are kept.
182 EXPECT_EQ("dup0,dup1,dup2", GetResults()); 182 EXPECT_EQ("dup0,dup1,dup2", GetResults());
183 } 183 }
184 184
185 TEST_F(MixerTest, PublishReusesExisting) {
Matt Giuca 2014/07/08 01:48:23 I think should just call this "Publish" (as it is
calamity 2014/07/08 04:23:00 Done.
186 ScopedVector<TestSearchResult> test_results;
Matt Giuca 2014/07/08 01:48:24 I don't think you should use a vector here. It imp
calamity 2014/07/08 04:23:00 Done.
187 test_results.push_back(new TestSearchResult("app1", 0));
188 test_results.push_back(new TestSearchResult("app2", 0));
189 test_results.push_back(new TestSearchResult("app3", 0));
190 test_results.push_back(new TestSearchResult("app4", 0));
191
192 AppListModel::SearchResults ui_results;
Matt Giuca 2014/07/08 01:48:23 // Publish the first three results to |ui_results|
calamity 2014/07/08 04:23:01 Done.
193 std::vector<Mixer::SortData> new_results;
194
195 new_results.push_back(Mixer::SortData(test_results[0], 1.0f));
196 new_results.push_back(Mixer::SortData(test_results[1], 1.0f));
197 new_results.push_back(Mixer::SortData(test_results[2], 1.0f));
198
199 Mixer::Publish(new_results, &ui_results);
200 EXPECT_EQ(3u, ui_results.item_count());
Matt Giuca 2014/07/08 01:48:23 EXPECT_EQ(new_results[0], ui_results.GetItemAt(0))
calamity 2014/07/08 04:23:00 As discussed, this isn't true since new copies get
201
202 // Ensure old results are reused if the ID is the same.
Matt Giuca 2014/07/08 01:48:23 Save the "ensures" for the EXPECT section. Here ju
calamity 2014/07/08 04:23:00 Done.
203 std::vector<const SearchResult*> old_ui_results;
204 for (size_t i = 0; i < ui_results.item_count(); ++i)
205 old_ui_results.push_back(ui_results.GetItemAt(i));
206
207 // The first result will be different as the ID has changed.
Matt Giuca 2014/07/08 01:48:23 // Change the first result to a totally new object
calamity 2014/07/08 04:23:00 Done.
208 new_results[0] = Mixer::SortData(test_results[3], 1.0f);
Matt Giuca 2014/07/08 01:48:23 Shouldn't you have: new_results[1] = Mixer::SortDa
calamity 2014/07/08 04:23:00 As discussed, copies are always made because the i
Matt Giuca 2014/07/08 05:31:45 As discussed, do the duplication on 2, not 3 (to t
209
210 // The second result will have a different title but still use the original
211 // object.
Matt Giuca 2014/07/08 01:48:23 This is VERY CONFUSING since without reading TestS
calamity 2014/07/08 04:23:00 Done.
212 const base::string16 kApp2AltName = base::UTF8ToUTF16("app2altname");
213 new_results[1].result->set_title(kApp2AltName);
214
215 Mixer::Publish(new_results, &ui_results);
216 EXPECT_EQ(3u, ui_results.item_count());
217
218 EXPECT_NE(old_ui_results[0], ui_results.GetItemAt(0));
Matt Giuca 2014/07/08 01:48:23 // The first result will be a new object, as the I
calamity 2014/07/08 04:23:00 Done. Second check does not apply.
219 EXPECT_EQ(old_ui_results[1], ui_results.GetItemAt(1));
Matt Giuca 2014/07/08 01:48:23 // The second result will still use the original o
calamity 2014/07/08 04:23:00 Done.
220 EXPECT_EQ(kApp2AltName, new_results[1].result->title());
Matt Giuca 2014/07/08 01:48:23 This isn't testing anything. Should be: EXPECT_EQ(
calamity 2014/07/08 04:23:00 Done.
221 EXPECT_EQ(old_ui_results[2], ui_results.GetItemAt(2));
222 }
223
185 } // namespace test 224 } // namespace test
186 } // namespace app_list 225 } // namespace app_list
OLDNEW
« chrome/browser/ui/app_list/search/mixer.h ('K') | « chrome/browser/ui/app_list/search/mixer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698