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

Side by Side Diff: ui/app_list/views/search_result_tile_item_list_view_unittest.cc

Issue 2972243002: Fix app list item indexing bug. (Closed)
Patch Set: Correct the wrong year number. Created 3 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
« no previous file with comments | « ui/app_list/views/search_result_tile_item_list_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/app_list/views/search_result_tile_item_list_view.h"
6
7 #include <map>
oshima 2017/07/14 00:54:56 do you need this?
Jiaquan He 2017/07/17 16:57:33 No. Thanks for the catch.
8 #include <memory>
9 #include <utility>
10
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/scoped_feature_list.h"
16 #include "ui/app_list/app_list_features.h"
17 #include "ui/app_list/app_list_model.h"
18 #include "ui/app_list/test/app_list_test_view_delegate.h"
19 #include "ui/app_list/test/test_search_result.h"
20 #include "ui/app_list/views/search_result_list_view_delegate.h"
21 #include "ui/app_list/views/search_result_view.h"
22 #include "ui/views/controls/textfield/textfield.h"
23 #include "ui/views/test/views_test_base.h"
24
25 namespace app_list {
26 namespace test {
oshima 2017/07/14 00:54:57 I'd suggest to remove test namespace. It's best us
Jiaquan He 2017/07/17 16:57:33 Thanks for this information!
27
28 namespace {
29 const int kMaxNumSearchResultTiles = 6;
oshima 2017/07/14 00:54:57 constexpr
Jiaquan He 2017/07/17 16:57:34 Done.
30 const int kInstalledApps = 4;
31 const int kPlayStoreApps = 2;
32 } // namespace
33
34 class SearchResultTileItemListViewTest : public views::ViewsTestBase {
35 public:
36 SearchResultTileItemListViewTest() {}
37 ~SearchResultTileItemListViewTest() override {}
38
39 // Overridden from testing::Test:
40 void SetUp() override { views::ViewsTestBase::SetUp(); }
oshima 2017/07/14 00:54:57 you don't need this
Jiaquan He 2017/07/17 16:57:33 Done.
41
42 protected:
43 void CreateSearchResultTileItemListView() {
44 textfield_.reset(new views::Textfield());
oshima 2017/07/14 00:54:57 MakeUnique
Jiaquan He 2017/07/17 16:57:33 Done.
45 view_.reset(
46 new SearchResultTileItemListView(textfield_.get(), &view_delegate_));
oshima 2017/07/14 00:54:57 ditto
Jiaquan He 2017/07/17 16:57:34 Done.
47 view_->SetResults(view_delegate_.GetModel()->results());
48 }
49
50 void EnablePlayStoreAppSearch() {
51 scoped_feature_list_.InitAndEnableFeature(
52 app_list::features::kEnablePlayStoreAppSearch);
53 }
54
55 SearchResultTileItemListView* view() { return view_.get(); }
56
57 AppListModel::SearchResults* GetResults() {
58 return view_delegate_.GetModel()->results();
59 }
60
61 void SetUpSearchResults() {
62 AppListModel::SearchResults* results = GetResults();
63
64 // Populate results for installed applications.
65 for (int i = 0; i < kInstalledApps; ++i) {
66 std::unique_ptr<TestSearchResult> result =
67 base::MakeUnique<TestSearchResult>();
68 result->set_display_type(SearchResult::DISPLAY_TILE);
69 result->set_result_type(SearchResult::RESULT_INSTALLED_APP);
70 result->set_title(
71 base::UTF8ToUTF16(base::StringPrintf("InstalledApp %d", i)));
72 results->Add(std::move(result));
73 }
74
75 // Populate results for Play Store search applications.
76 if (app_list::features::IsPlayStoreAppSearchEnabled()) {
77 for (int i = 0; i < kPlayStoreApps; ++i) {
78 std::unique_ptr<TestSearchResult> result =
79 base::MakeUnique<TestSearchResult>();
80 result->set_display_type(SearchResult::DISPLAY_TILE);
81 result->set_result_type(SearchResult::RESULT_PLAYSTORE_APP);
82 result->set_title(
83 base::UTF8ToUTF16(base::StringPrintf("PlayStoreApp %d", i)));
84 results->Add(std::move(result));
85 }
86 }
87
88 // Adding results will schedule Update().
89 RunPendingMessages();
oshima 2017/07/14 00:54:56 it's not clear why you need this. can you clarify?
Jiaquan He 2017/07/17 16:57:34 Done.
90 view_->OnContainerSelected(false, false);
91 }
92
93 int GetOpenResultCount(int ranking) {
oshima 2017/07/14 00:54:56 const
Jiaquan He 2017/07/17 16:57:34 Done.
94 int result = view_delegate_.open_search_result_counts()[ranking];
95 return result;
96 }
97
98 void ResetOpenResultCount() {
99 view_delegate_.open_search_result_counts().clear();
100 }
101
102 int GetResultCount() { return view_->num_results(); }
oshima 2017/07/14 00:54:57 const?
Jiaquan He 2017/07/17 16:57:33 Done.
103
104 int GetSelectedIndex() { return view_->selected_index(); }
oshima 2017/07/14 00:54:57 ditto
Jiaquan He 2017/07/17 16:57:33 Done.
105
106 void ResetSelectedIndex() { view_->SetSelectedIndex(0); }
oshima 2017/07/14 00:54:56 ditto
Jiaquan He 2017/07/17 16:57:33 Done.
107
108 bool KeyPress(ui::KeyboardCode key_code) {
109 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
110 return view_->OnKeyPressed(event);
111 }
112
113 private:
114 AppListTestViewDelegate view_delegate_;
115 std::unique_ptr<SearchResultTileItemListView> view_;
116 std::unique_ptr<views::Textfield> textfield_;
117 base::test::ScopedFeatureList scoped_feature_list_;
118
119 DISALLOW_COPY_AND_ASSIGN(SearchResultTileItemListViewTest);
120 };
121
122 TEST_F(SearchResultTileItemListViewTest, Basic) {
123 EnablePlayStoreAppSearch();
124 CreateSearchResultTileItemListView();
125 SetUpSearchResults();
126
127 const int results = GetResultCount();
128 EXPECT_EQ(kInstalledApps + kPlayStoreApps, results);
129 // For each results, we added a separator for result type grouping.
130 EXPECT_EQ(kMaxNumSearchResultTiles * 2, view()->child_count());
131
132 // Tests item indexing.
133 for (int i = 1; i < results; ++i) {
134 EXPECT_TRUE(KeyPress(ui::VKEY_TAB));
135 EXPECT_EQ(i, GetSelectedIndex());
136 }
oshima 2017/07/14 00:54:56 can you also test what happens if you tab extra ti
Jiaquan He 2017/07/17 16:57:33 Done.
137
138 // Tests app opening.
139 ResetSelectedIndex();
140 ResetOpenResultCount();
141 for (int i = 1; i < results; ++i) {
142 EXPECT_TRUE(KeyPress(ui::VKEY_TAB));
143 EXPECT_EQ(i, GetSelectedIndex());
144 for (int j = 0; j < i; j++) {
145 EXPECT_TRUE(KeyPress(ui::VKEY_RETURN));
146 }
147 }
oshima 2017/07/14 00:54:56 new line
Jiaquan He 2017/07/17 16:57:33 Done. I've merged the for below into the one above
148 for (int i = 0; i < results; ++i) {
149 EXPECT_EQ(i, GetOpenResultCount(i));
150 }
oshima 2017/07/14 00:54:57 nuke {}
Jiaquan He 2017/07/17 16:57:33 Done.
151 }
152
153 } // namespace test
154 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_result_tile_item_list_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698