| 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
|
|
|