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

Unified 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: use testing macros for friendliness 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/search/mixer_unittest.cc
diff --git a/chrome/browser/ui/app_list/search/mixer_unittest.cc b/chrome/browser/ui/app_list/search/mixer_unittest.cc
index ddcf3a9f31cd40eac20ee2e79bc78c5d4f1173b3..ef9a0d2a92afefea3b562be7daca83b4076e21c3 100644
--- a/chrome/browser/ui/app_list/search/mixer_unittest.cc
+++ b/chrome/browser/ui/app_list/search/mixer_unittest.cc
@@ -27,7 +27,6 @@ class TestSearchResult : public ChromeSearchResult {
}
virtual ~TestSearchResult() {}
- private:
// ChromeSearchResult overides:
virtual void Open(int event_flags) OVERRIDE {}
virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {}
@@ -39,6 +38,7 @@ class TestSearchResult : public ChromeSearchResult {
return SEARCH_RESULT_TYPE_BOUNDARY;
}
+ private:
DISALLOW_COPY_AND_ASSIGN(TestSearchResult);
};
@@ -182,5 +182,60 @@ TEST_F(MixerTest, RemoveDuplicates) {
EXPECT_EQ("dup0,dup1,dup2", GetResults());
}
+TEST_F(MixerTest, Publish) {
+ scoped_ptr<ChromeSearchResult> result1(new TestSearchResult("app1", 0));
+ scoped_ptr<ChromeSearchResult> result2(new TestSearchResult("app2", 0));
+ scoped_ptr<ChromeSearchResult> result3(new TestSearchResult("app3", 0));
+ scoped_ptr<ChromeSearchResult> result3_copy = result3->Duplicate();
+ scoped_ptr<ChromeSearchResult> result4(new TestSearchResult("app4", 0));
+
+ AppListModel::SearchResults ui_results;
+
+ // Publish the first three results to |ui_results|.
+ Mixer::SortedResults new_results;
+ new_results.push_back(Mixer::SortData(result1.get(), 1.0f));
+ new_results.push_back(Mixer::SortData(result2.get(), 1.0f));
+ new_results.push_back(Mixer::SortData(result3.get(), 1.0f));
+
+ mixer()->Publish(new_results, &ui_results);
+ EXPECT_EQ(3u, ui_results.item_count());
+ // The objects in |ui_results| should be new copies because the input results
+ // are owned and |ui_results| needs to own its results as well.
+ EXPECT_NE(new_results[0].result, ui_results.GetItemAt(0));
+ EXPECT_NE(new_results[1].result, ui_results.GetItemAt(1));
+ EXPECT_NE(new_results[2].result, ui_results.GetItemAt(2));
+
+ // Save the current |ui_results| for comparison later.
+ std::vector<const SearchResult*> old_ui_results;
+ for (size_t i = 0; i < ui_results.item_count(); ++i)
+ old_ui_results.push_back(ui_results.GetItemAt(i));
+
+ // Change the first result to a totally new object (with a new ID).
+ new_results[0] = Mixer::SortData(result4.get(), 1.0f);
+
+ // Change the second result's title, but keep the same id. (The result will
+ // keep the id "app2" but change its title to "New App 2 Title".)
+ const base::string16 kNewAppTitle = base::UTF8ToUTF16("New App 2 Title");
+ new_results[1].result->set_title(kNewAppTitle);
+
+ // Change the third result's object address (it points to an object with the
+ // same data).
+ new_results[2] = Mixer::SortData(result3_copy.get(), 1.0f);
+
+ mixer()->Publish(new_results, &ui_results);
+ EXPECT_EQ(3u, ui_results.item_count());
+
+ // The first result will be a new object, as the ID has changed.
+ EXPECT_NE(old_ui_results[0], ui_results.GetItemAt(0));
+
+ // The second result will still use the original object, but have a different
+ // title, since the ID did not change.
+ EXPECT_EQ(old_ui_results[1], ui_results.GetItemAt(1));
+ EXPECT_EQ(kNewAppTitle, ui_results.GetItemAt(1)->title());
+
+ // The third result will use the original object as the ID did not change.
+ EXPECT_EQ(old_ui_results[2], ui_results.GetItemAt(2));
+}
+
} // namespace test
} // namespace app_list
« 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