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

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

Issue 568383002: Ensure the app list search result progress bar is set in SetResult() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | ui/app_list/views/search_result_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/app_list/views/search_result_list_view.h" 5 #include "ui/app_list/views/search_result_list_view.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
11 #include "ui/app_list/search_result.h" 11 #include "ui/app_list/search_result.h"
12 #include "ui/app_list/test/app_list_test_view_delegate.h" 12 #include "ui/app_list/test/app_list_test_view_delegate.h"
13 #include "ui/app_list/views/progress_bar_view.h"
13 #include "ui/app_list/views/search_result_list_view_delegate.h" 14 #include "ui/app_list/views/search_result_list_view_delegate.h"
14 #include "ui/app_list/views/search_result_view.h" 15 #include "ui/app_list/views/search_result_view.h"
15 #include "ui/views/test/views_test_base.h" 16 #include "ui/views/test/views_test_base.h"
16 17
17 namespace app_list { 18 namespace app_list {
18 namespace test { 19 namespace test {
19 20
20 namespace { 21 namespace {
21 int kDefaultSearchItems = 5; 22 int kDefaultSearchItems = 5;
22 } // namespace 23 } // namespace
23 24
24 class SearchResultListViewTest : public views::ViewsTestBase, 25 class SearchResultListViewTest : public views::ViewsTestBase,
25 public SearchResultListViewDelegate { 26 public SearchResultListViewDelegate {
26 public: 27 public:
27 SearchResultListViewTest() {} 28 SearchResultListViewTest() {}
28 virtual ~SearchResultListViewTest() {} 29 virtual ~SearchResultListViewTest() {}
29 30
30 // Overridden from testing::Test: 31 // Overridden from testing::Test:
31 virtual void SetUp() OVERRIDE { 32 virtual void SetUp() OVERRIDE {
32 views::ViewsTestBase::SetUp(); 33 views::ViewsTestBase::SetUp();
33 view_.reset(new SearchResultListView(this, &view_delegate_)); 34 view_.reset(new SearchResultListView(this, &view_delegate_));
34 view_->SetResults(view_delegate_.GetModel()->results()); 35 view_->SetResults(view_delegate_.GetModel()->results());
35 view_->SetSelectedIndex(0); 36 view_->SetSelectedIndex(0);
36 } 37 }
37 38
38 protected: 39 protected:
39 SearchResultListView* view() { return view_.get(); } 40 SearchResultListView* view() { return view_.get(); }
40 41
42 AppListModel::SearchResults* GetResults() {
43 return view_delegate_.GetModel()->results();
44 }
45
41 void SetLongAutoLaunchTimeout() { 46 void SetLongAutoLaunchTimeout() {
42 // Sets a long timeout that lasts longer than the test run. 47 // Sets a long timeout that lasts longer than the test run.
43 view_delegate_.set_auto_launch_timeout(base::TimeDelta::FromDays(1)); 48 view_delegate_.set_auto_launch_timeout(base::TimeDelta::FromDays(1));
44 } 49 }
45 50
46 base::TimeDelta GetAutoLaunchTimeout() { 51 base::TimeDelta GetAutoLaunchTimeout() {
47 return view_delegate_.GetAutoLaunchTimeout(); 52 return view_delegate_.GetAutoLaunchTimeout();
48 } 53 }
49 54
50 void SetUpSearchResults() { 55 void SetUpSearchResults() {
51 AppListModel::SearchResults* results = view_delegate_.GetModel()->results(); 56 AppListModel::SearchResults* results = GetResults();
52 for (int i = 0; i < kDefaultSearchItems; ++i) 57 for (int i = 0; i < kDefaultSearchItems; ++i)
53 results->Add(new SearchResult()); 58 results->Add(new SearchResult());
54 59
55 // Adding results will schedule Update(). 60 // Adding results will schedule Update().
56 RunPendingMessages(); 61 RunPendingMessages();
57 } 62 }
58 63
59 int GetOpenResultCountAndReset(int ranking) { 64 int GetOpenResultCountAndReset(int ranking) {
60 int result = view_delegate_.open_search_result_counts()[ranking]; 65 int result = view_delegate_.open_search_result_counts()[ranking];
61 view_delegate_.open_search_result_counts().clear(); 66 view_delegate_.open_search_result_counts().clear();
62 return result; 67 return result;
63 } 68 }
64 69
65 int GetSearchResults() { 70 int GetResultCount() { return view_->last_visible_index_ + 1; }
66 return view_->last_visible_index_ + 1;
67 }
68 71
69 int GetSelectedIndex() { 72 int GetSelectedIndex() {
70 return view_->selected_index_; 73 return view_->selected_index_;
71 } 74 }
72 75
73 void ResetSelectedIndex() { 76 void ResetSelectedIndex() {
74 view_->SetSelectedIndex(0); 77 view_->SetSelectedIndex(0);
75 } 78 }
76 79
77 void AddTestResultAtIndex(int index) { 80 void AddTestResultAtIndex(int index) {
78 view_delegate_.GetModel()->results()->Add(new SearchResult()); 81 GetResults()->Add(new SearchResult());
79 } 82 }
80 83
81 void DeleteResultAt(int index) { 84 void DeleteResultAt(int index) { GetResults()->DeleteAt(index); }
82 view_delegate_.GetModel()->results()->DeleteAt(index);
83 }
84 85
85 bool KeyPress(ui::KeyboardCode key_code) { 86 bool KeyPress(ui::KeyboardCode key_code) {
86 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 87 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
87 return view_->OnKeyPressed(event); 88 return view_->OnKeyPressed(event);
88 } 89 }
89 90
90 bool IsAutoLaunching() { 91 bool IsAutoLaunching() {
91 return view_->auto_launch_animation_; 92 return view_->auto_launch_animation_;
92 } 93 }
93 94
94 void ForceAutoLaunch() { 95 void ForceAutoLaunch() {
95 view_->ForceAutoLaunchForTest(); 96 view_->ForceAutoLaunchForTest();
96 } 97 }
97 98
98 void ExpectConsistent() { 99 void ExpectConsistent() {
99 // Adding results will schedule Update(). 100 // Adding results will schedule Update().
100 RunPendingMessages(); 101 RunPendingMessages();
101 102
102 AppListModel::SearchResults* results = view_delegate_.GetModel()->results(); 103 AppListModel::SearchResults* results = GetResults();
103 for (size_t i = 0; i < results->item_count(); ++i) { 104 for (size_t i = 0; i < results->item_count(); ++i) {
104 EXPECT_EQ(results->GetItemAt(i), view_->GetResultViewAt(i)->result()); 105 EXPECT_EQ(results->GetItemAt(i), view_->GetResultViewAt(i)->result());
105 } 106 }
106 } 107 }
107 108
109 ProgressBarView* GetProgressBarAt(size_t index) {
110 return view()->GetResultViewAt(index)->progress_bar_;
111 }
112
108 private: 113 private:
109 virtual void OnResultInstalled(SearchResult* result) OVERRIDE {} 114 virtual void OnResultInstalled(SearchResult* result) OVERRIDE {}
110 virtual void OnResultUninstalled(SearchResult* result) OVERRIDE {} 115 virtual void OnResultUninstalled(SearchResult* result) OVERRIDE {}
111 116
112 AppListTestViewDelegate view_delegate_; 117 AppListTestViewDelegate view_delegate_;
113 scoped_ptr<SearchResultListView> view_; 118 scoped_ptr<SearchResultListView> view_;
114 119
115 DISALLOW_COPY_AND_ASSIGN(SearchResultListViewTest); 120 DISALLOW_COPY_AND_ASSIGN(SearchResultListViewTest);
116 }; 121 };
117 122
118 TEST_F(SearchResultListViewTest, Basic) { 123 TEST_F(SearchResultListViewTest, Basic) {
119 SetUpSearchResults(); 124 SetUpSearchResults();
120 125
121 const int results = GetSearchResults(); 126 const int results = GetResultCount();
122 EXPECT_EQ(kDefaultSearchItems, results); 127 EXPECT_EQ(kDefaultSearchItems, results);
123 EXPECT_EQ(0, GetSelectedIndex()); 128 EXPECT_EQ(0, GetSelectedIndex());
124 EXPECT_FALSE(IsAutoLaunching()); 129 EXPECT_FALSE(IsAutoLaunching());
125 130
126 EXPECT_TRUE(KeyPress(ui::VKEY_RETURN)); 131 EXPECT_TRUE(KeyPress(ui::VKEY_RETURN));
127 EXPECT_EQ(1, GetOpenResultCountAndReset(0)); 132 EXPECT_EQ(1, GetOpenResultCountAndReset(0));
128 133
129 for (int i = 1; i < results; ++i) { 134 for (int i = 1; i < results; ++i) {
130 EXPECT_TRUE(KeyPress(ui::VKEY_DOWN)); 135 EXPECT_TRUE(KeyPress(ui::VKEY_DOWN));
131 EXPECT_EQ(i, GetSelectedIndex()); 136 EXPECT_EQ(i, GetSelectedIndex());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 207
203 // Insert at end. 208 // Insert at end.
204 AddTestResultAtIndex(kDefaultSearchItems); 209 AddTestResultAtIndex(kDefaultSearchItems);
205 ExpectConsistent(); 210 ExpectConsistent();
206 211
207 // Delete from start. 212 // Delete from start.
208 DeleteResultAt(0); 213 DeleteResultAt(0);
209 ExpectConsistent(); 214 ExpectConsistent();
210 } 215 }
211 216
217 // Regression test for http://crbug.com/402859 to ensure ProgressBar is
218 // initialized properly in SearchResultListView::SetResult().
219 TEST_F(SearchResultListViewTest, ProgressBar) {
220 SetUpSearchResults();
221
222 GetResults()->GetItemAt(0)->SetIsInstalling(true);
223 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value());
224 GetResults()->GetItemAt(0)->SetPercentDownloaded(10);
225
226 DeleteResultAt(0);
227 RunPendingMessages();
228 EXPECT_EQ(0.0f, GetProgressBarAt(0)->current_value());
229 }
230
212 } // namespace test 231 } // namespace test
213 } // namespace app_list 232 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/views/search_result_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698