OLD | NEW |
---|---|
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/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
13 #include "ui/app_list/test/app_list_test_model.h" | 13 #include "ui/app_list/test/app_list_test_model.h" |
14 #include "ui/app_list/test/app_list_test_view_delegate.h" | 14 #include "ui/app_list/test/app_list_test_view_delegate.h" |
15 #include "ui/app_list/views/app_list_folder_view.h" | |
15 #include "ui/app_list/views/app_list_main_view.h" | 16 #include "ui/app_list/views/app_list_main_view.h" |
17 #include "ui/app_list/views/apps_container_view.h" | |
18 #include "ui/app_list/views/apps_grid_view.h" | |
16 #include "ui/app_list/views/contents_view.h" | 19 #include "ui/app_list/views/contents_view.h" |
17 #include "ui/app_list/views/search_box_view.h" | 20 #include "ui/app_list/views/search_box_view.h" |
21 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | |
18 #include "ui/aura/test/aura_test_base.h" | 22 #include "ui/aura/test/aura_test_base.h" |
19 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
20 #include "ui/views/test/views_test_base.h" | 24 #include "ui/views/test/views_test_base.h" |
21 #include "ui/views/views_delegate.h" | 25 #include "ui/views/views_delegate.h" |
22 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 26 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
23 | 27 |
24 namespace app_list { | 28 namespace app_list { |
25 namespace test { | 29 namespace test { |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. | 33 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. |
30 const int kInitialItems = 34; | 34 const int kInitialItems = 34; |
31 | 35 |
32 // Allows the same tests to run with different contexts: either an Ash-style | 36 // Allows the same tests to run with different contexts: either an Ash-style |
33 // root window or a desktop window tree host. | 37 // root window or a desktop window tree host. |
34 class AppListViewTestContext { | 38 class AppListViewTestContext { |
35 public: | 39 public: |
36 AppListViewTestContext(bool is_landscape, aura::Window* parent); | 40 AppListViewTestContext(bool is_landscape, aura::Window* parent); |
37 ~AppListViewTestContext(); | 41 ~AppListViewTestContext(); |
38 | 42 |
39 // Test displaying the app list and performs a standard set of checks on its | 43 // Test displaying the app list and performs a standard set of checks on its |
40 // top level views. Then closes the window. | 44 // top level views. Then closes the window. |
41 void RunDisplayTest(); | 45 void RunDisplayTest(); |
42 | 46 |
47 // Hides and reshows the app list with a folder open, expecting the main grid | |
48 // view to be shown. | |
49 void RunReshowWithOpenFolderTest(); | |
50 | |
43 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 51 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
44 static void CheckView(views::View* subview); | 52 static void CheckView(views::View* subview); |
45 | 53 |
46 // Invoked when the Widget is closing, and the view it contains is about to | 54 // Invoked when the Widget is closing, and the view it contains is about to |
47 // be torn down. This only occurs in a run loop and will be used as a signal | 55 // be torn down. This only occurs in a run loop and will be used as a signal |
48 // to quit. | 56 // to quit. |
49 void NativeWidgetClosing() { | 57 void NativeWidgetClosing() { |
50 view_ = NULL; | 58 view_ = NULL; |
51 run_loop_->Quit(); | 59 run_loop_->Quit(); |
52 } | 60 } |
53 | 61 |
54 // Whether the experimental "landscape" app launcher UI is being tested. | 62 // Whether the experimental "landscape" app launcher UI is being tested. |
55 bool is_landscape() const { return is_landscape_; } | 63 bool is_landscape() const { return is_landscape_; } |
56 | 64 |
57 private: | 65 private: |
66 // Shows the app list and waits until a paint occurs. | |
67 void Show(); | |
68 | |
69 // Closes the app list. This sets |view_| to NULL. | |
70 void Close(); | |
71 | |
58 const bool is_landscape_; | 72 const bool is_landscape_; |
59 scoped_ptr<base::RunLoop> run_loop_; | 73 scoped_ptr<base::RunLoop> run_loop_; |
60 PaginationModel pagination_model_; | 74 PaginationModel pagination_model_; |
61 app_list::AppListView* view_; // Owned by native widget. | 75 app_list::AppListView* view_; // Owned by native widget. |
62 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; | 76 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; |
63 | 77 |
64 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 78 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
65 }; | 79 }; |
66 | 80 |
67 // Extend the regular AppListTestViewDelegate to communicate back to the test | 81 // Extend the regular AppListTestViewDelegate to communicate back to the test |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 } | 126 } |
113 | 127 |
114 // static | 128 // static |
115 void AppListViewTestContext::CheckView(views::View* subview) { | 129 void AppListViewTestContext::CheckView(views::View* subview) { |
116 ASSERT_TRUE(subview); | 130 ASSERT_TRUE(subview); |
117 EXPECT_TRUE(subview->parent()); | 131 EXPECT_TRUE(subview->parent()); |
118 EXPECT_TRUE(subview->visible()); | 132 EXPECT_TRUE(subview->visible()); |
119 EXPECT_TRUE(subview->IsDrawn()); | 133 EXPECT_TRUE(subview->IsDrawn()); |
120 } | 134 } |
121 | 135 |
136 void AppListViewTestContext::Show() { | |
137 view_->GetWidget()->Show(); | |
138 run_loop_.reset(new base::RunLoop); | |
139 view_->SetNextPaintCallback(run_loop_->QuitClosure()); | |
140 run_loop_->Run(); | |
141 | |
142 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | |
143 } | |
144 | |
145 void AppListViewTestContext::Close() { | |
146 view_->GetWidget()->Close(); | |
147 run_loop_.reset(new base::RunLoop); | |
148 run_loop_->Run(); | |
149 | |
150 // |view_| should have been deleted and set to NULL via ViewClosing(). | |
151 EXPECT_FALSE(view_); | |
152 } | |
153 | |
122 void AppListViewTestContext::RunDisplayTest() { | 154 void AppListViewTestContext::RunDisplayTest() { |
123 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 155 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
124 EXPECT_EQ(-1, pagination_model_.total_pages()); | 156 EXPECT_EQ(-1, pagination_model_.total_pages()); |
125 view_->GetWidget()->Show(); | |
126 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 157 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
127 | 158 |
128 run_loop_.reset(new base::RunLoop); | 159 Show(); |
129 view_->SetNextPaintCallback(run_loop_->QuitClosure()); | |
130 run_loop_->Run(); | |
131 | |
132 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | |
133 | |
134 if (is_landscape_) | 160 if (is_landscape_) |
135 EXPECT_EQ(2, pagination_model_.total_pages()); | 161 EXPECT_EQ(2, pagination_model_.total_pages()); |
136 else | 162 else |
137 EXPECT_EQ(3, pagination_model_.total_pages()); | 163 EXPECT_EQ(3, pagination_model_.total_pages()); |
138 EXPECT_EQ(0, pagination_model_.selected_page()); | 164 EXPECT_EQ(0, pagination_model_.selected_page()); |
139 | 165 |
140 // Checks on the main view. | 166 // Checks on the main view. |
141 AppListMainView* main_view = view_->app_list_main_view(); | 167 AppListMainView* main_view = view_->app_list_main_view(); |
142 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 168 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
143 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); | 169 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); |
144 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 170 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
145 | 171 |
146 view_->GetWidget()->Close(); | 172 Close(); |
147 run_loop_.reset(new base::RunLoop); | 173 } |
148 run_loop_->Run(); | |
149 | 174 |
150 // |view_| should have been deleted and set to NULL via ViewClosing(). | 175 void AppListViewTestContext::RunReshowWithOpenFolderTest() { |
151 EXPECT_FALSE(view_); | 176 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
177 EXPECT_EQ(-1, pagination_model_.total_pages()); | |
178 | |
179 AppListTestModel* model = delegate_->GetTestModel(); | |
180 model->PopulateApps(kInitialItems); | |
181 const std::string folder_id = | |
182 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), | |
183 model->top_level_item_list()->item_at(1)->id()); | |
184 | |
185 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); | |
186 EXPECT_TRUE(folder_item); | |
187 | |
188 Show(); | |
189 | |
190 // The main grid view should be showing initially. | |
191 AppListMainView* main_view = view_->app_list_main_view(); | |
192 AppsContainerView* container_view = | |
193 main_view->contents_view()->apps_container_view(); | |
194 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
195 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | |
196 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); | |
197 | |
198 AppsGridViewTestApi test_api(container_view->apps_grid_view()); | |
199 test_api.PressItemAt(0); | |
200 | |
201 // After pressing the folder item, the folder view should be showing. | |
202 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
203 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->app_list_folder_view())); | |
204 EXPECT_FALSE(container_view->apps_grid_view()->visible()); | |
205 | |
206 view_->GetWidget()->Hide(); | |
207 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | |
208 | |
209 Show(); | |
210 | |
211 // The main grid view should be showing after a reshow. | |
212 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
213 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | |
214 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); | |
215 | |
216 Close(); | |
152 } | 217 } |
153 | 218 |
154 class AppListViewTestAura : public views::ViewsTestBase, | 219 class AppListViewTestAura : public views::ViewsTestBase, |
155 public ::testing::WithParamInterface<bool> { | 220 public ::testing::WithParamInterface<bool> { |
156 public: | 221 public: |
157 AppListViewTestAura() {} | 222 AppListViewTestAura() {} |
158 virtual ~AppListViewTestAura() {} | 223 virtual ~AppListViewTestAura() {} |
159 | 224 |
160 // testing::Test overrides: | 225 // testing::Test overrides: |
161 virtual void SetUp() OVERRIDE { | 226 virtual void SetUp() OVERRIDE { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 TEST_P(AppListViewTestAura, Display) { | 303 TEST_P(AppListViewTestAura, Display) { |
239 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 304 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
240 } | 305 } |
241 | 306 |
242 // Tests showing the app list on the desktop. Note on ChromeOS, this will still | 307 // Tests showing the app list on the desktop. Note on ChromeOS, this will still |
243 // use the regular root window. | 308 // use the regular root window. |
244 TEST_P(AppListViewTestDesktop, Display) { | 309 TEST_P(AppListViewTestDesktop, Display) { |
245 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 310 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
246 } | 311 } |
247 | 312 |
313 // Tests that the main grid view is shown after hiding and reshowing the app | |
314 // list with a folder view open. This is a regression test for crbug.com/357058. | |
315 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) { | |
316 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | |
317 } | |
318 | |
319 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) { | |
320 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | |
321 } | |
322 | |
248 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 323 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
tapted
2014/05/22 01:21:10
You'll need lines like these for any `TEST_P` test
tapted
2014/05/22 01:27:43
oops - you're right. This TEST_P stuff is more use
| |
249 AppListViewTestAura, | 324 AppListViewTestAura, |
250 ::testing::Bool()); | 325 ::testing::Bool()); |
251 | 326 |
252 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 327 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
253 AppListViewTestDesktop, | 328 AppListViewTestDesktop, |
254 ::testing::Bool()); | 329 ::testing::Bool()); |
255 | 330 |
256 } // namespace test | 331 } // namespace test |
257 } // namespace app_list | 332 } // namespace app_list |
OLD | NEW |