| 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf.h" |
| 8 #include "ash/shelf/shelf_constants.h" | 9 #include "ash/shelf/shelf_constants.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" | 11 #include "ash/shelf/shelf_view.h" |
| 11 #include "ash/shelf/wm_shelf.h" | |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_port.h" | 13 #include "ash/shell_port.h" |
| 14 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/ash_test_helper.h" | 16 #include "ash/test/ash_test_helper.h" |
| 17 #include "ash/test/shelf_view_test_api.h" | 17 #include "ash/test/shelf_view_test_api.h" |
| 18 #include "ash/test/test_shell_delegate.h" | 18 #include "ash/test/test_shell_delegate.h" |
| 19 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 20 #include "ash/wm_window.h" | 20 #include "ash/wm_window.h" |
| 21 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Verifies shelf is created with correct size after user login and when its | 146 // Verifies shelf is created with correct size after user login and when its |
| 147 // container and status widget has finished sizing. | 147 // container and status widget has finished sizing. |
| 148 // See http://crbug.com/252533 | 148 // See http://crbug.com/252533 |
| 149 TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) { | 149 TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) { |
| 150 SetUserLoggedIn(false); | 150 SetUserLoggedIn(false); |
| 151 UpdateDisplay("300x200,400x300"); | 151 UpdateDisplay("300x200,400x300"); |
| 152 | 152 |
| 153 // Both displays have a shelf controller. | 153 // Both displays have a shelf controller. |
| 154 aura::Window::Windows roots = Shell::GetAllRootWindows(); | 154 aura::Window::Windows roots = Shell::GetAllRootWindows(); |
| 155 WmShelf* shelf1 = WmShelf::ForWindow(roots[0]); | 155 Shelf* shelf1 = Shelf::ForWindow(roots[0]); |
| 156 WmShelf* shelf2 = WmShelf::ForWindow(roots[1]); | 156 Shelf* shelf2 = Shelf::ForWindow(roots[1]); |
| 157 ASSERT_TRUE(shelf1); | 157 ASSERT_TRUE(shelf1); |
| 158 ASSERT_TRUE(shelf2); | 158 ASSERT_TRUE(shelf2); |
| 159 | 159 |
| 160 // Both shelf controllers have a shelf widget. | 160 // Both shelf controllers have a shelf widget. |
| 161 ShelfWidget* shelf_widget1 = shelf1->shelf_widget(); | 161 ShelfWidget* shelf_widget1 = shelf1->shelf_widget(); |
| 162 ShelfWidget* shelf_widget2 = shelf2->shelf_widget(); | 162 ShelfWidget* shelf_widget2 = shelf2->shelf_widget(); |
| 163 ASSERT_TRUE(shelf_widget1); | 163 ASSERT_TRUE(shelf_widget1); |
| 164 ASSERT_TRUE(shelf_widget2); | 164 ASSERT_TRUE(shelf_widget2); |
| 165 | 165 |
| 166 // Simulate login. | 166 // Simulate login. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // window-targeter should find |widget| as the target (instead of the | 219 // window-targeter should find |widget| as the target (instead of the |
| 220 // shelf). | 220 // shelf). |
| 221 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); | 221 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); |
| 222 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 222 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 223 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 223 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 224 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 224 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
| 225 EXPECT_EQ(widget->GetNativeWindow(), target); | 225 EXPECT_EQ(widget->GetNativeWindow(), target); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Change shelf alignment to verify that the targeter insets are updated. | 228 // Change shelf alignment to verify that the targeter insets are updated. |
| 229 WmShelf* shelf = GetPrimaryShelf(); | 229 Shelf* shelf = GetPrimaryShelf(); |
| 230 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 230 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 231 shelf_layout_manager->LayoutShelf(); | 231 shelf_layout_manager->LayoutShelf(); |
| 232 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 232 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
| 233 { | 233 { |
| 234 // Create a mouse-event targeting the right edge of the shelf widget. The | 234 // Create a mouse-event targeting the right edge of the shelf widget. The |
| 235 // window-targeter should find |widget| as the target (instead of the | 235 // window-targeter should find |widget| as the target (instead of the |
| 236 // shelf). | 236 // shelf). |
| 237 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); | 237 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); |
| 238 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 238 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 239 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 239 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 263 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 263 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 264 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 264 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 265 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 265 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
| 266 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); | 266 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Tests that the shelf has a slightly larger hit-region for touch-events when | 270 // Tests that the shelf has a slightly larger hit-region for touch-events when |
| 271 // it's in the auto-hidden state. | 271 // it's in the auto-hidden state. |
| 272 TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) { | 272 TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) { |
| 273 WmShelf* shelf = GetPrimaryShelf(); | 273 Shelf* shelf = GetPrimaryShelf(); |
| 274 ShelfWidget* shelf_widget = GetShelfWidget(); | 274 ShelfWidget* shelf_widget = GetShelfWidget(); |
| 275 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 275 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
| 276 EXPECT_TRUE(!shelf_bounds.IsEmpty()); | 276 EXPECT_TRUE(!shelf_bounds.IsEmpty()); |
| 277 ShelfLayoutManager* shelf_layout_manager = | 277 ShelfLayoutManager* shelf_layout_manager = |
| 278 shelf_widget->shelf_layout_manager(); | 278 shelf_widget->shelf_layout_manager(); |
| 279 ASSERT_TRUE(shelf_layout_manager); | 279 ASSERT_TRUE(shelf_layout_manager); |
| 280 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); | 280 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); |
| 281 | 281 |
| 282 // Create a widget to make sure that the shelf does auto-hide. | 282 // Create a widget to make sure that the shelf does auto-hide. |
| 283 views::Widget* widget = new views::Widget; | 283 views::Widget* widget = new views::Widget; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 void TestShelf(ShelfAlignment alignment, | 330 void TestShelf(ShelfAlignment alignment, |
| 331 ShelfAutoHideBehavior auto_hide_behavior, | 331 ShelfAutoHideBehavior auto_hide_behavior, |
| 332 ShelfVisibilityState expected_shelf_visibility_state, | 332 ShelfVisibilityState expected_shelf_visibility_state, |
| 333 ShelfAutoHideState expected_shelf_auto_hide_state) { | 333 ShelfAutoHideState expected_shelf_auto_hide_state) { |
| 334 // Simulate login. | 334 // Simulate login. |
| 335 SetUserLoggedIn(true); | 335 SetUserLoggedIn(true); |
| 336 SetSessionStarted(true); | 336 SetSessionStarted(true); |
| 337 | 337 |
| 338 // Simulate shelf settings being applied from profile prefs. | 338 // Simulate shelf settings being applied from profile prefs. |
| 339 WmShelf* shelf = GetPrimaryShelf(); | 339 Shelf* shelf = GetPrimaryShelf(); |
| 340 ASSERT_NE(nullptr, shelf); | 340 ASSERT_NE(nullptr, shelf); |
| 341 shelf->SetAlignment(alignment); | 341 shelf->SetAlignment(alignment); |
| 342 shelf->SetAutoHideBehavior(auto_hide_behavior); | 342 shelf->SetAutoHideBehavior(auto_hide_behavior); |
| 343 shelf->UpdateVisibilityState(); | 343 shelf->UpdateVisibilityState(); |
| 344 | 344 |
| 345 // Ensure settings are applied correctly. | 345 // Ensure settings are applied correctly. |
| 346 EXPECT_EQ(alignment, shelf->alignment()); | 346 EXPECT_EQ(alignment, shelf->alignment()); |
| 347 EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior()); | 347 EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior()); |
| 348 EXPECT_EQ(expected_shelf_visibility_state, shelf->GetVisibilityState()); | 348 EXPECT_EQ(expected_shelf_visibility_state, shelf->GetVisibilityState()); |
| 349 EXPECT_EQ(expected_shelf_auto_hide_state, shelf->GetAutoHideState()); | 349 EXPECT_EQ(expected_shelf_auto_hide_state, shelf->GetAutoHideState()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 private: | 352 private: |
| 353 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetAfterLoginTest); | 353 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetAfterLoginTest); |
| 354 }; | 354 }; |
| 355 | 355 |
| 356 TEST_F(ShelfWidgetAfterLoginTest, InitialValues) { | 356 TEST_F(ShelfWidgetAfterLoginTest, InitialValues) { |
| 357 // Ensure shelf components are created. | 357 // Ensure shelf components are created. |
| 358 WmShelf* shelf = GetPrimaryShelf(); | 358 Shelf* shelf = GetPrimaryShelf(); |
| 359 ASSERT_NE(nullptr, shelf); | 359 ASSERT_NE(nullptr, shelf); |
| 360 ShelfWidget* shelf_widget = GetShelfWidget(); | 360 ShelfWidget* shelf_widget = GetShelfWidget(); |
| 361 ASSERT_NE(nullptr, shelf_widget); | 361 ASSERT_NE(nullptr, shelf_widget); |
| 362 ASSERT_NE(nullptr, shelf_widget->shelf_view_for_testing()); | 362 ASSERT_NE(nullptr, shelf_widget->shelf_view_for_testing()); |
| 363 ASSERT_NE(nullptr, shelf_widget->shelf_layout_manager()); | 363 ASSERT_NE(nullptr, shelf_widget->shelf_layout_manager()); |
| 364 | 364 |
| 365 // Ensure settings are correct before login. | 365 // Ensure settings are correct before login. |
| 366 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 366 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 367 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM_LOCKED, shelf->alignment()); | 367 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM_LOCKED, shelf->alignment()); |
| 368 EXPECT_EQ(SHELF_AUTO_HIDE_ALWAYS_HIDDEN, shelf->auto_hide_behavior()); | 368 EXPECT_EQ(SHELF_AUTO_HIDE_ALWAYS_HIDDEN, shelf->auto_hide_behavior()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) { | 401 TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) { |
| 402 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 402 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. |
| 403 TestShelf(SHELF_ALIGNMENT_BOTTOM_LOCKED, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | 403 TestShelf(SHELF_ALIGNMENT_BOTTOM_LOCKED, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, |
| 404 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | 404 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); |
| 405 } | 405 } |
| 406 | 406 |
| 407 } // namespace | 407 } // namespace |
| 408 } // namespace ash | 408 } // namespace ash |
| OLD | NEW |