OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/common/shelf/shelf_widget.h" | 5 #include "ash/common/shelf/shelf_widget.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/shelf/shelf.h" | |
9 #include "ash/common/shelf/shelf_delegate.h" | 8 #include "ash/common/shelf/shelf_delegate.h" |
10 #include "ash/common/shelf/shelf_layout_manager.h" | 9 #include "ash/common/shelf/shelf_layout_manager.h" |
11 #include "ash/common/shelf/shelf_view.h" | 10 #include "ash/common/shelf/shelf_view.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" |
12 #include "ash/common/system/status_area_widget.h" | 12 #include "ash/common/system/status_area_widget.h" |
| 13 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
14 #include "ash/common/wm_window.h" | 15 #include "ash/common/wm_window.h" |
15 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
17 #include "ash/test/ash_md_test_base.h" | 18 #include "ash/test/ash_md_test_base.h" |
18 #include "ash/test/ash_test_helper.h" | 19 #include "ash/test/ash_test_helper.h" |
19 #include "ash/test/shelf_test_api.h" | 20 #include "ash/test/shelf_test_api.h" |
20 #include "ash/test/shelf_view_test_api.h" | 21 #include "ash/test/shelf_view_test_api.h" |
21 #include "ash/test/test_shell_delegate.h" | 22 #include "ash/test/test_shell_delegate.h" |
22 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/display/display.h" | 25 #include "ui/display/display.h" |
25 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
28 | 29 |
29 namespace ash { | 30 namespace ash { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 ShelfWidget* GetShelfWidget() { | 34 ShelfWidget* GetShelfWidget() { |
34 return Shelf::ForPrimaryDisplay()->shelf_widget(); | 35 return test::AshTestBase::GetPrimaryShelf()->GetShelfWidgetForTesting(); |
35 } | 36 } |
36 | 37 |
37 ShelfLayoutManager* GetShelfLayoutManager() { | 38 ShelfLayoutManager* GetShelfLayoutManager() { |
38 return GetShelfWidget()->shelf_layout_manager(); | 39 return GetShelfWidget()->shelf_layout_manager(); |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 using ShelfWidgetTest = test::AshMDTestBase; | 44 using ShelfWidgetTest = test::AshMDTestBase; |
44 | 45 |
45 INSTANTIATE_TEST_CASE_P( | 46 INSTANTIATE_TEST_CASE_P( |
46 /* prefix intentionally left blank due to only one parameterization */, | 47 /* prefix intentionally left blank due to only one parameterization */, |
47 ShelfWidgetTest, | 48 ShelfWidgetTest, |
48 testing::Values(MaterialDesignController::NON_MATERIAL, | 49 testing::Values(MaterialDesignController::NON_MATERIAL, |
49 MaterialDesignController::MATERIAL_NORMAL, | 50 MaterialDesignController::MATERIAL_NORMAL, |
50 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | 51 MaterialDesignController::MATERIAL_EXPERIMENTAL)); |
51 | 52 |
52 void TestLauncherAlignment(WmWindow* root, | 53 void TestLauncherAlignment(WmWindow* root, |
53 ShelfAlignment alignment, | 54 ShelfAlignment alignment, |
54 const gfx::Rect& expected) { | 55 const gfx::Rect& expected) { |
55 Shelf::ForWindow(root)->SetAlignment(alignment); | 56 root->GetRootWindowController()->GetShelf()->SetAlignment(alignment); |
56 EXPECT_EQ(expected.ToString(), | 57 EXPECT_EQ(expected.ToString(), |
57 root->GetDisplayNearestWindow().work_area().ToString()); | 58 root->GetDisplayNearestWindow().work_area().ToString()); |
58 } | 59 } |
59 | 60 |
60 TEST_P(ShelfWidgetTest, TestAlignment) { | 61 TEST_P(ShelfWidgetTest, TestAlignment) { |
61 if (!SupportsHostWindowResize()) | 62 if (!SupportsHostWindowResize()) |
62 return; | 63 return; |
63 | 64 |
64 // Note that for a left- and right-aligned shelf, this offset must be | 65 // Note that for a left- and right-aligned shelf, this offset must be |
65 // applied to a maximized window's width rather than its height. | 66 // applied to a maximized window's width rather than its height. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 { | 141 { |
141 SCOPED_TRACE("Secondary Left"); | 142 SCOPED_TRACE("Secondary Left"); |
142 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_LEFT, | 143 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_LEFT, |
143 gfx::Rect(300 + kShelfSize, 0, 453 + offset, 500)); | 144 gfx::Rect(300 + kShelfSize, 0, 453 + offset, 500)); |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 // Makes sure the shelf is initially sized correctly. | 148 // Makes sure the shelf is initially sized correctly. |
148 TEST_P(ShelfWidgetTest, LauncherInitiallySized) { | 149 TEST_P(ShelfWidgetTest, LauncherInitiallySized) { |
149 ShelfWidget* shelf_widget = GetShelfWidget(); | 150 ShelfWidget* shelf_widget = GetShelfWidget(); |
150 Shelf* shelf = shelf_widget->shelf(); | |
151 ASSERT_TRUE(shelf); | |
152 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 151 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); |
153 ASSERT_TRUE(shelf_layout_manager); | 152 ASSERT_TRUE(shelf_layout_manager); |
154 ASSERT_TRUE(shelf_widget->status_area_widget()); | 153 ASSERT_TRUE(shelf_widget->status_area_widget()); |
155 int status_width = | 154 int status_width = |
156 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); | 155 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); |
157 // Test only makes sense if the status is > 0, which it better be. | 156 // Test only makes sense if the status is > 0, which it better be. |
158 EXPECT_GT(status_width, 0); | 157 EXPECT_GT(status_width, 0); |
159 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - | 158 EXPECT_EQ(status_width, |
160 test::ShelfTestAPI(shelf).shelf_view()->width()); | 159 shelf_widget->GetContentsView()->width() - |
| 160 GetPrimaryShelf()->GetShelfViewForTesting()->width()); |
161 } | 161 } |
162 | 162 |
163 // Verifies when the shell is deleted with a full screen window we don't crash. | 163 // Verifies when the shell is deleted with a full screen window we don't crash. |
164 TEST_P(ShelfWidgetTest, DontReferenceShelfAfterDeletion) { | 164 TEST_P(ShelfWidgetTest, DontReferenceShelfAfterDeletion) { |
165 views::Widget* widget = new views::Widget; | 165 views::Widget* widget = new views::Widget; |
166 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 166 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
167 params.bounds = gfx::Rect(0, 0, 200, 200); | 167 params.bounds = gfx::Rect(0, 0, 200, 200); |
168 params.context = CurrentContext(); | 168 params.context = CurrentContext(); |
169 // Widget is now owned by the parent window. | 169 // Widget is now owned by the parent window. |
170 widget->Init(params); | 170 widget->Init(params); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // window-targeter should find |widget| as the target (instead of the | 246 // window-targeter should find |widget| as the target (instead of the |
247 // shelf). | 247 // shelf). |
248 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); | 248 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); |
249 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 249 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
250 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 250 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
251 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 251 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
252 EXPECT_EQ(widget->GetNativeWindow(), target); | 252 EXPECT_EQ(widget->GetNativeWindow(), target); |
253 } | 253 } |
254 | 254 |
255 // Change shelf alignment to verify that the targeter insets are updated. | 255 // Change shelf alignment to verify that the targeter insets are updated. |
256 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 256 WmShelf* shelf = GetPrimaryShelf(); |
257 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 257 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
258 shelf_layout_manager->LayoutShelf(); | 258 shelf_layout_manager->LayoutShelf(); |
259 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 259 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
260 { | 260 { |
261 // Create a mouse-event targeting the right edge of the shelf widget. The | 261 // Create a mouse-event targeting the right edge of the shelf widget. The |
262 // window-targeter should find |widget| as the target (instead of the | 262 // window-targeter should find |widget| as the target (instead of the |
263 // shelf). | 263 // shelf). |
264 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); | 264 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); |
265 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 265 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
266 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 266 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
(...skipping 23 matching lines...) Expand all Loading... |
290 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 290 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
291 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 291 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
292 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 292 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
293 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); | 293 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 // Tests that the shelf has a slightly larger hit-region for touch-events when | 297 // Tests that the shelf has a slightly larger hit-region for touch-events when |
298 // it's in the auto-hidden state. | 298 // it's in the auto-hidden state. |
299 TEST_P(ShelfWidgetTest, HiddenShelfHitTestTouch) { | 299 TEST_P(ShelfWidgetTest, HiddenShelfHitTestTouch) { |
300 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 300 WmShelf* shelf = GetPrimaryShelf(); |
301 ShelfWidget* shelf_widget = GetShelfWidget(); | 301 ShelfWidget* shelf_widget = GetShelfWidget(); |
302 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 302 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
303 EXPECT_TRUE(!shelf_bounds.IsEmpty()); | 303 EXPECT_TRUE(!shelf_bounds.IsEmpty()); |
304 ShelfLayoutManager* shelf_layout_manager = | 304 ShelfLayoutManager* shelf_layout_manager = |
305 shelf_widget->shelf_layout_manager(); | 305 shelf_widget->shelf_layout_manager(); |
306 ASSERT_TRUE(shelf_layout_manager); | 306 ASSERT_TRUE(shelf_layout_manager); |
307 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); | 307 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); |
308 | 308 |
309 // Create a widget to make sure that the shelf does auto-hide. | 309 // Create a widget to make sure that the shelf does auto-hide. |
310 views::Widget* widget = new views::Widget; | 310 views::Widget* widget = new views::Widget; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 class TestShelfDelegate : public ShelfDelegate { | 353 class TestShelfDelegate : public ShelfDelegate { |
354 public: | 354 public: |
355 TestShelfDelegate(ShelfAlignment initial_alignment, | 355 TestShelfDelegate(ShelfAlignment initial_alignment, |
356 ShelfAutoHideBehavior initial_auto_hide_behavior) | 356 ShelfAutoHideBehavior initial_auto_hide_behavior) |
357 : initial_alignment_(initial_alignment), | 357 : initial_alignment_(initial_alignment), |
358 initial_auto_hide_behavior_(initial_auto_hide_behavior) {} | 358 initial_auto_hide_behavior_(initial_auto_hide_behavior) {} |
359 ~TestShelfDelegate() override {} | 359 ~TestShelfDelegate() override {} |
360 | 360 |
361 // ShelfDelegate implementation. | 361 // ShelfDelegate implementation. |
362 void OnShelfCreated(Shelf* shelf) override { | 362 void OnShelfCreated(Shelf* shelf) override { |
363 shelf->SetAlignment(initial_alignment_); | 363 shelf->wm_shelf()->SetAlignment(initial_alignment_); |
364 shelf->SetAutoHideBehavior(initial_auto_hide_behavior_); | 364 shelf->wm_shelf()->SetAutoHideBehavior(initial_auto_hide_behavior_); |
365 } | 365 } |
366 void OnShelfDestroyed(Shelf* shelf) override {} | 366 void OnShelfDestroyed(Shelf* shelf) override {} |
367 void OnShelfAlignmentChanged(Shelf* shelf) override {} | 367 void OnShelfAlignmentChanged(Shelf* shelf) override {} |
368 void OnShelfAutoHideBehaviorChanged(Shelf* shelf) override {} | 368 void OnShelfAutoHideBehaviorChanged(Shelf* shelf) override {} |
369 void OnShelfAutoHideStateChanged(Shelf* shelf) override {} | 369 void OnShelfAutoHideStateChanged(Shelf* shelf) override {} |
370 void OnShelfVisibilityStateChanged(Shelf* shelf) override {} | 370 void OnShelfVisibilityStateChanged(Shelf* shelf) override {} |
371 ShelfID GetShelfIDForAppID(const std::string& app_id) override { return 0; } | 371 ShelfID GetShelfIDForAppID(const std::string& app_id) override { return 0; } |
372 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return false; } | 372 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return false; } |
373 const std::string& GetAppIDForShelfID(ShelfID id) override { | 373 const std::string& GetAppIDForShelfID(ShelfID id) override { |
374 return base::EmptyString(); | 374 return base::EmptyString(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 ShelfVisibilityState expected_shelf_visibility_state, | 430 ShelfVisibilityState expected_shelf_visibility_state, |
431 ShelfAutoHideState expected_shelf_auto_hide_state) { | 431 ShelfAutoHideState expected_shelf_auto_hide_state) { |
432 shelf_widget_test_shell_delegate_->set_initial_alignment(initial_alignment); | 432 shelf_widget_test_shell_delegate_->set_initial_alignment(initial_alignment); |
433 shelf_widget_test_shell_delegate_->set_initial_auto_hide_behavior( | 433 shelf_widget_test_shell_delegate_->set_initial_auto_hide_behavior( |
434 initial_auto_hide_behavior); | 434 initial_auto_hide_behavior); |
435 SetUserLoggedIn(true); | 435 SetUserLoggedIn(true); |
436 SetSessionStarted(true); | 436 SetSessionStarted(true); |
437 | 437 |
438 ShelfWidget* shelf_widget = GetShelfWidget(); | 438 ShelfWidget* shelf_widget = GetShelfWidget(); |
439 ASSERT_NE(nullptr, shelf_widget); | 439 ASSERT_NE(nullptr, shelf_widget); |
440 Shelf* shelf = shelf_widget->shelf(); | 440 WmShelf* shelf = GetPrimaryShelf(); |
441 ASSERT_NE(nullptr, shelf); | 441 ASSERT_NE(nullptr, shelf); |
442 ShelfLayoutManager* shelf_layout_manager = | 442 ShelfLayoutManager* shelf_layout_manager = |
443 shelf_widget->shelf_layout_manager(); | 443 shelf_widget->shelf_layout_manager(); |
444 ASSERT_NE(nullptr, shelf_layout_manager); | 444 ASSERT_NE(nullptr, shelf_layout_manager); |
445 | 445 |
446 EXPECT_EQ(initial_alignment, shelf->alignment()); | 446 EXPECT_EQ(initial_alignment, shelf->alignment()); |
447 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); | 447 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); |
448 EXPECT_EQ(expected_shelf_visibility_state, | 448 EXPECT_EQ(expected_shelf_visibility_state, |
449 shelf_layout_manager->visibility_state()); | 449 shelf_layout_manager->visibility_state()); |
450 EXPECT_EQ(expected_shelf_auto_hide_state, | 450 EXPECT_EQ(expected_shelf_auto_hide_state, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 487 } |
488 | 488 |
489 TEST_P(ShelfWidgetTestWithDelegate, CreateLockedShelf) { | 489 TEST_P(ShelfWidgetTestWithDelegate, CreateLockedShelf) { |
490 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 490 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. |
491 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, | 491 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, |
492 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | 492 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, |
493 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | 493 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); |
494 } | 494 } |
495 | 495 |
496 } // namespace ash | 496 } // namespace ash |
OLD | NEW |