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." |
tapted
2014/04/01 06:28:27
make sure you rebase to avoid my derp :p
calamity
2014/04/01 08:08:46
Done.
| |
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 const char* TestName() { | 36 const char* TestName() { |
33 return ::testing::UnitTest::GetInstance()->current_test_info()->name(); | 37 return ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
34 } | 38 } |
35 | 39 |
36 // Allows the same tests to run with different contexts: either an Ash-style | 40 // Allows the same tests to run with different contexts: either an Ash-style |
37 // root window or a desktop window tree host. | 41 // root window or a desktop window tree host. |
38 class AppListViewTestContext { | 42 class AppListViewTestContext { |
39 public: | 43 public: |
40 AppListViewTestContext(aura::Window* parent); | 44 AppListViewTestContext(aura::Window* parent); |
41 ~AppListViewTestContext(); | 45 ~AppListViewTestContext(); |
42 | 46 |
43 // Test displaying the app list and performs a standard set of checks on its | 47 // Test displaying the app list and performs a standard set of checks on its |
44 // top level views. Then closes the window. | 48 // top level views. Then closes the window. |
45 void RunDisplayTest(); | 49 void RunDisplayTest(); |
46 | 50 |
51 // Hides and reshows the app list with a folder open, expecting the main grid | |
52 // view to be shown. | |
53 void RunReshowWithOpenFolderTest(); | |
54 | |
47 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 55 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
48 static void CheckView(views::View* subview); | 56 static void CheckView(views::View* subview); |
49 | 57 |
50 // Invoked when the Widget is closing, and the view it contains is about to | 58 // Invoked when the Widget is closing, and the view it contains is about to |
51 // be torn down. This only occurs in a run loop and will be used as a signal | 59 // be torn down. This only occurs in a run loop and will be used as a signal |
52 // to quit. | 60 // to quit. |
53 void NativeWidgetClosing() { | 61 void NativeWidgetClosing() { |
54 view_ = NULL; | 62 view_ = NULL; |
55 run_loop_->Quit(); | 63 run_loop_->Quit(); |
56 } | 64 } |
57 | 65 |
58 // Whether the experimental "landscape" app launcher UI is being tested. | 66 // Whether the experimental "landscape" app launcher UI is being tested. |
59 bool is_landscape() const { return is_landscape_; } | 67 bool is_landscape() const { return is_landscape_; } |
60 | 68 |
61 private: | 69 private: |
70 // Shows the app list and waits until a paint occurs. | |
71 void Show(); | |
72 | |
73 // Closes the app list. This sets |view_| to NULL. | |
74 void Close(); | |
75 | |
62 const bool is_landscape_; | 76 const bool is_landscape_; |
63 scoped_ptr<base::RunLoop> run_loop_; | 77 scoped_ptr<base::RunLoop> run_loop_; |
64 PaginationModel pagination_model_; | 78 PaginationModel pagination_model_; |
65 app_list::AppListView* view_; // Owned by native widget. | 79 app_list::AppListView* view_; // Owned by native widget. |
66 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; | 80 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; |
67 | 81 |
68 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 82 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
69 }; | 83 }; |
70 | 84 |
71 // Extend the regular AppListTestViewDelegate to communicate back to the test | 85 // Extend the regular AppListTestViewDelegate to communicate back to the test |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 124 } |
111 | 125 |
112 // static | 126 // static |
113 void AppListViewTestContext::CheckView(views::View* subview) { | 127 void AppListViewTestContext::CheckView(views::View* subview) { |
114 ASSERT_TRUE(subview); | 128 ASSERT_TRUE(subview); |
115 EXPECT_TRUE(subview->parent()); | 129 EXPECT_TRUE(subview->parent()); |
116 EXPECT_TRUE(subview->visible()); | 130 EXPECT_TRUE(subview->visible()); |
117 EXPECT_TRUE(subview->IsDrawn()); | 131 EXPECT_TRUE(subview->IsDrawn()); |
118 } | 132 } |
119 | 133 |
134 void AppListViewTestContext::Show() { | |
135 view_->GetWidget()->Show(); | |
136 run_loop_.reset(new base::RunLoop); | |
137 AppListView::SetNextPaintCallback(run_loop_->QuitClosure()); | |
138 run_loop_->Run(); | |
139 | |
140 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | |
141 } | |
142 | |
143 void AppListViewTestContext::Close() { | |
144 view_->GetWidget()->Close(); | |
145 run_loop_.reset(new base::RunLoop); | |
146 run_loop_->Run(); | |
147 | |
148 // |view_| should have been deleted and set to NULL via ViewClosing(). | |
149 EXPECT_FALSE(view_); | |
150 } | |
151 | |
120 void AppListViewTestContext::RunDisplayTest() { | 152 void AppListViewTestContext::RunDisplayTest() { |
121 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 153 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
122 EXPECT_EQ(-1, pagination_model_.total_pages()); | 154 EXPECT_EQ(-1, pagination_model_.total_pages()); |
123 view_->GetWidget()->Show(); | |
124 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 155 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
125 | 156 |
126 run_loop_.reset(new base::RunLoop); | 157 Show(); |
127 AppListView::SetNextPaintCallback(run_loop_->QuitClosure()); | |
128 run_loop_->Run(); | |
129 | |
130 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | |
131 | 158 |
132 if (is_landscape_) | 159 if (is_landscape_) |
133 EXPECT_EQ(2, pagination_model_.total_pages()); | 160 EXPECT_EQ(2, pagination_model_.total_pages()); |
134 else | 161 else |
135 EXPECT_EQ(3, pagination_model_.total_pages()); | 162 EXPECT_EQ(3, pagination_model_.total_pages()); |
136 EXPECT_EQ(0, pagination_model_.selected_page()); | 163 EXPECT_EQ(0, pagination_model_.selected_page()); |
137 | 164 |
138 // Checks on the main view. | 165 // Checks on the main view. |
139 AppListMainView* main_view = view_->app_list_main_view(); | 166 AppListMainView* main_view = view_->app_list_main_view(); |
140 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 167 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
141 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); | 168 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); |
142 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 169 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
143 | 170 |
144 view_->GetWidget()->Close(); | 171 Close(); |
145 run_loop_.reset(new base::RunLoop); | 172 } |
146 run_loop_->Run(); | |
147 | 173 |
148 // |view_| should have been deleted and set to NULL via ViewClosing(). | 174 void AppListViewTestContext::RunReshowWithOpenFolderTest() { |
149 EXPECT_FALSE(view_); | 175 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
176 EXPECT_EQ(-1, pagination_model_.total_pages()); | |
177 | |
178 AppListTestModel* model = delegate_->GetTestModel(); | |
179 model->PopulateApps(kInitialItems); | |
180 const std::string folder_id = | |
181 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), | |
182 model->top_level_item_list()->item_at(1)->id()); | |
183 | |
184 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); | |
185 EXPECT_TRUE(folder_item); | |
186 | |
187 Show(); | |
188 | |
189 // The main grid view should be showing initially. | |
190 AppListMainView* main_view = view_->app_list_main_view(); | |
191 AppsContainerView* container_view = | |
192 main_view->contents_view()->apps_container_view(); | |
193 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
194 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | |
195 | |
tapted
2014/04/01 06:28:27
Can you
EXPECT_FALSE(container_view->app_list_fo
calamity
2014/04/01 08:08:46
Done.
| |
196 AppsGridViewTestApi test_api(container_view->apps_grid_view()); | |
197 test_api.PressItemAt(0); | |
198 | |
199 // After pressing the folder item, the folder view should be showing. | |
200 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
201 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->app_list_folder_view())); | |
202 | |
tapted
2014/04/01 06:28:27
and
EXPECT_FALSE(container_view->apps_grid_view()
calamity
2014/04/01 08:08:46
Done.
| |
203 view_->GetWidget()->Hide(); | |
204 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | |
205 | |
206 Show(); | |
207 | |
208 // The main grid view should be showing after a reshow. | |
209 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | |
210 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | |
tapted
2014/04/01 06:28:27
EXPECT_FALSE(container_view->app_list_folder_view(
calamity
2014/04/01 08:08:46
Done.
| |
211 | |
212 Close(); | |
150 } | 213 } |
151 | 214 |
152 class AppListViewTestAura : public views::ViewsTestBase { | 215 class AppListViewTestAura : public views::ViewsTestBase { |
153 public: | 216 public: |
154 AppListViewTestAura() {} | 217 AppListViewTestAura() {} |
155 virtual ~AppListViewTestAura() {} | 218 virtual ~AppListViewTestAura() {} |
156 | 219 |
157 // testing::Test overrides: | 220 // testing::Test overrides: |
158 virtual void SetUp() OVERRIDE { | 221 virtual void SetUp() OVERRIDE { |
159 views::ViewsTestBase::SetUp(); | 222 views::ViewsTestBase::SetUp(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 EXPECT_TRUE(test_context_->is_landscape()); | 313 EXPECT_TRUE(test_context_->is_landscape()); |
251 host()->Show(); | 314 host()->Show(); |
252 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 315 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
253 } | 316 } |
254 | 317 |
255 TEST_F(AppListViewTestDesktop, DisplayLandscape) { | 318 TEST_F(AppListViewTestDesktop, DisplayLandscape) { |
256 EXPECT_TRUE(test_context_->is_landscape()); | 319 EXPECT_TRUE(test_context_->is_landscape()); |
257 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 320 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
258 } | 321 } |
259 | 322 |
323 // Tests that the main grid view is shown after hiding and reshowing the app | |
324 // list with a folder view open. This is a regression test for crbug.com/357058. | |
325 TEST_F(AppListViewTestAura, ReshowWithOpenFolder) { | |
326 EXPECT_FALSE(test_context_->is_landscape()); | |
327 host()->Show(); | |
328 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | |
329 } | |
330 | |
331 TEST_F(AppListViewTestDesktop, ReshowWithOpenFolder) { | |
332 EXPECT_FALSE(test_context_->is_landscape()); | |
333 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | |
334 } | |
335 | |
260 } // namespace test | 336 } // namespace test |
261 } // namespace app_list | 337 } // namespace app_list |
OLD | NEW |