OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/focus_cycler.h" | 11 #include "ash/focus_cycler.h" |
12 #include "ash/launcher/launcher.h" | 12 #include "ash/launcher/launcher.h" |
| 13 #include "ash/launcher/launcher_view.h" |
13 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
14 #include "ash/screen_ash.h" | 15 #include "ash/screen_ash.h" |
| 16 #include "ash/shelf/shelf_widget.h" |
15 #include "ash/shell.h" | 17 #include "ash/shell.h" |
16 #include "ash/shell_delegate.h" | 18 #include "ash/shell_delegate.h" |
17 #include "ash/shell_window_ids.h" | 19 #include "ash/shell_window_ids.h" |
18 #include "ash/system/status_area_widget.h" | 20 #include "ash/system/status_area_widget.h" |
19 #include "ash/system/tray/system_tray.h" | 21 #include "ash/system/tray/system_tray.h" |
20 #include "ash/system/tray/system_tray_item.h" | 22 #include "ash/system/tray/system_tray_item.h" |
21 #include "ash/test/ash_test_base.h" | 23 #include "ash/test/ash_test_base.h" |
22 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
23 #include "base/command_line.h" | 25 #include "base/command_line.h" |
24 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
45 | 47 |
46 namespace { | 48 namespace { |
47 | 49 |
48 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { | 50 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { |
49 ui::AnimationContainerElement* element = | 51 ui::AnimationContainerElement* element = |
50 static_cast<ui::AnimationContainerElement*>( | 52 static_cast<ui::AnimationContainerElement*>( |
51 widget->GetNativeView()->layer()->GetAnimator()); | 53 widget->GetNativeView()->layer()->GetAnimator()); |
52 element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 54 element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
53 } | 55 } |
54 | 56 |
| 57 ShelfWidget* GetShelfWidget() { |
| 58 return Shell::GetPrimaryRootWindowController()->shelf(); |
| 59 } |
| 60 |
55 ShelfLayoutManager* GetShelfLayoutManager() { | 61 ShelfLayoutManager* GetShelfLayoutManager() { |
56 return Shell::GetPrimaryRootWindowController()->shelf(); | 62 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
57 } | 63 } |
58 | 64 |
59 SystemTray* GetSystemTray() { | 65 SystemTray* GetSystemTray() { |
60 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); | 66 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); |
61 } | 67 } |
62 | 68 |
63 class ShelfLayoutObserverTest : public ShelfLayoutManager::Observer { | 69 class ShelfLayoutObserverTest : public ShelfLayoutManager::Observer { |
64 public: | 70 public: |
65 ShelfLayoutObserverTest() | 71 ShelfLayoutObserverTest() |
66 : changed_auto_hide_state_(false) { | 72 : changed_auto_hide_state_(false) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 }; | 210 }; |
205 | 211 |
206 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. | 212 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. |
207 #if defined(OS_MACOSX) || defined(OS_WIN) | 213 #if defined(OS_MACOSX) || defined(OS_WIN) |
208 #define MAYBE_SetVisible DISABLED_SetVisible | 214 #define MAYBE_SetVisible DISABLED_SetVisible |
209 #else | 215 #else |
210 #define MAYBE_SetVisible SetVisible | 216 #define MAYBE_SetVisible SetVisible |
211 #endif | 217 #endif |
212 // Makes sure SetVisible updates work area and widget appropriately. | 218 // Makes sure SetVisible updates work area and widget appropriately. |
213 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { | 219 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { |
214 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 220 ShelfWidget* shelf = GetShelfWidget(); |
| 221 ShelfLayoutManager* manager = shelf->shelf_layout_manager(); |
215 // Force an initial layout. | 222 // Force an initial layout. |
216 shelf->LayoutShelf(); | 223 manager->LayoutShelf(); |
217 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 224 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state()); |
218 | 225 |
219 gfx::Rect status_bounds( | 226 gfx::Rect status_bounds( |
220 shelf->status_area_widget()->GetWindowBoundsInScreen()); | 227 shelf->status_area_widget()->GetWindowBoundsInScreen()); |
221 gfx::Rect launcher_bounds( | 228 gfx::Rect launcher_bounds( |
222 shelf->launcher_widget()->GetWindowBoundsInScreen()); | 229 shelf->GetWindowBoundsInScreen()); |
223 int shelf_height = shelf->GetIdealBounds().height(); | 230 int shelf_height = manager->GetIdealBounds().height(); |
224 | 231 |
225 const gfx::Display& display = Shell::GetInstance()->display_manager()-> | 232 const gfx::Display& display = Shell::GetInstance()->display_manager()-> |
226 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 233 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
227 ASSERT_NE(-1, display.id()); | 234 ASSERT_NE(-1, display.id()); |
228 // Bottom inset should be the max of widget heights. | 235 // Bottom inset should be the max of widget heights. |
229 EXPECT_EQ(shelf_height, | 236 EXPECT_EQ(shelf_height, |
230 display.bounds().bottom() - display.work_area().bottom()); | 237 display.bounds().bottom() - display.work_area().bottom()); |
231 | 238 |
232 // Hide the shelf. | 239 // Hide the shelf. |
233 SetState(shelf, SHELF_HIDDEN); | 240 SetState(manager, SHELF_HIDDEN); |
234 // Run the animation to completion. | 241 // Run the animation to completion. |
235 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 242 StepWidgetLayerAnimatorToEnd(shelf); |
236 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); | 243 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); |
237 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | 244 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state()); |
238 EXPECT_EQ(0, | 245 EXPECT_EQ(0, |
239 display.bounds().bottom() - display.work_area().bottom()); | 246 display.bounds().bottom() - display.work_area().bottom()); |
240 | 247 |
241 // Make sure the bounds of the two widgets changed. | 248 // Make sure the bounds of the two widgets changed. |
242 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 249 EXPECT_GE(shelf->GetNativeView()->bounds().y(), |
243 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 250 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
244 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), | 251 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), |
245 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 252 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
246 | 253 |
247 // And show it again. | 254 // And show it again. |
248 SetState(shelf, SHELF_VISIBLE); | 255 SetState(manager, SHELF_VISIBLE); |
249 // Run the animation to completion. | 256 // Run the animation to completion. |
250 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 257 StepWidgetLayerAnimatorToEnd(shelf); |
251 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); | 258 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); |
252 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 259 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state()); |
253 EXPECT_EQ(shelf_height, | 260 EXPECT_EQ(shelf_height, |
254 display.bounds().bottom() - display.work_area().bottom()); | 261 display.bounds().bottom() - display.work_area().bottom()); |
255 | 262 |
256 // Make sure the bounds of the two widgets changed. | 263 // Make sure the bounds of the two widgets changed. |
257 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); | 264 launcher_bounds = shelf->GetNativeView()->bounds(); |
258 int bottom = | 265 int bottom = |
259 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height; | 266 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height; |
260 EXPECT_EQ(launcher_bounds.y(), | 267 EXPECT_EQ(launcher_bounds.y(), |
261 bottom + (shelf->GetIdealBounds().height() - | 268 bottom + (manager->GetIdealBounds().height() - |
262 launcher_bounds.height()) / 2); | 269 launcher_bounds.height()) / 2); |
263 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds(); | 270 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds(); |
264 EXPECT_EQ(status_bounds.y(), | 271 EXPECT_EQ(status_bounds.y(), |
265 bottom + shelf_height - status_bounds.height()); | 272 bottom + shelf_height - status_bounds.height()); |
266 } | 273 } |
267 | 274 |
268 // Makes sure LayoutShelf invoked while animating cleans things up. | 275 // Makes sure LayoutShelf invoked while animating cleans things up. |
269 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { | 276 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { |
270 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 277 ShelfWidget* shelf = GetShelfWidget(); |
271 // Force an initial layout. | 278 // Force an initial layout. |
272 shelf->LayoutShelf(); | 279 shelf->shelf_layout_manager()->LayoutShelf(); |
273 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 280 EXPECT_EQ(SHELF_VISIBLE, shelf->shelf_layout_manager()->visibility_state()); |
274 | 281 |
275 const gfx::Display& display = Shell::GetInstance()->display_manager()-> | 282 const gfx::Display& display = Shell::GetInstance()->display_manager()-> |
276 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 283 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
277 | 284 |
278 // Hide the shelf. | 285 // Hide the shelf. |
279 SetState(shelf, SHELF_HIDDEN); | 286 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN); |
280 shelf->LayoutShelf(); | 287 shelf->shelf_layout_manager()->LayoutShelf(); |
281 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | 288 EXPECT_EQ(SHELF_HIDDEN, shelf->shelf_layout_manager()->visibility_state()); |
282 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); | 289 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); |
283 | 290 |
284 // Make sure the bounds of the two widgets changed. | 291 // Make sure the bounds of the two widgets changed. |
285 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 292 EXPECT_GE(shelf->GetNativeView()->bounds().y(), |
286 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 293 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
287 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), | 294 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), |
288 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 295 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
289 } | 296 } |
290 | 297 |
291 // Makes sure the launcher is initially sized correctly. | |
292 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { | |
293 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
294 ASSERT_TRUE(launcher); | |
295 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | |
296 ASSERT_TRUE(shelf_layout_manager); | |
297 ASSERT_TRUE(shelf_layout_manager->status_area_widget()); | |
298 int status_width = shelf_layout_manager->status_area_widget()-> | |
299 GetWindowBoundsInScreen().width(); | |
300 // Test only makes sense if the status is > 0, which is better be. | |
301 EXPECT_GT(status_width, 0); | |
302 EXPECT_EQ(status_width, launcher->status_size().width()); | |
303 } | |
304 | |
305 // Makes sure the launcher is sized when the status area changes size. | 298 // Makes sure the launcher is sized when the status area changes size. |
306 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { | 299 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { |
307 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 300 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
308 ASSERT_TRUE(launcher); | 301 ASSERT_TRUE(launcher); |
309 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 302 ShelfWidget* shelf_widget = GetShelfWidget(); |
310 ASSERT_TRUE(shelf_layout_manager); | 303 ASSERT_TRUE(shelf_widget); |
311 ASSERT_TRUE(shelf_layout_manager->status_area_widget()); | 304 ASSERT_TRUE(shelf_widget->status_area_widget()); |
312 shelf_layout_manager->status_area_widget()->SetBounds( | 305 shelf_widget->status_area_widget()->SetBounds( |
313 gfx::Rect(0, 0, 200, 200)); | 306 gfx::Rect(0, 0, 200, 200)); |
314 EXPECT_EQ(200, launcher->status_size().width()); | 307 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() - |
| 308 launcher->GetLauncherViewForTest()->width()); |
315 } | 309 } |
316 | 310 |
317 // Verifies when the shell is deleted with a full screen window we don't | |
318 // crash. This test is here as originally the crash was in ShelfLayoutManager. | |
319 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { | |
320 views::Widget* widget = new views::Widget; | |
321 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
322 params.bounds = gfx::Rect(0, 0, 200, 200); | |
323 params.context = CurrentContext(); | |
324 // Widget is now owned by the parent window. | |
325 widget->Init(params); | |
326 widget->SetFullscreen(true); | |
327 } | |
328 | 311 |
329 #if defined(OS_WIN) | 312 #if defined(OS_WIN) |
330 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 | 313 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 |
331 #define MAYBE_AutoHide DISABLED_AutoHide | 314 #define MAYBE_AutoHide DISABLED_AutoHide |
332 #else | 315 #else |
333 #define MAYBE_AutoHide AutoHide | 316 #define MAYBE_AutoHide AutoHide |
334 #endif | 317 #endif |
335 | 318 |
336 // Various assertions around auto-hide. | 319 // Various assertions around auto-hide. |
337 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) { | 320 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) { |
(...skipping 11 matching lines...) Expand all Loading... |
349 widget->Init(params); | 332 widget->Init(params); |
350 widget->Maximize(); | 333 widget->Maximize(); |
351 widget->Show(); | 334 widget->Show(); |
352 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 335 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
353 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 336 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
354 | 337 |
355 // LayoutShelf() forces the animation to completion, at which point the | 338 // LayoutShelf() forces the animation to completion, at which point the |
356 // launcher should go off the screen. | 339 // launcher should go off the screen. |
357 shelf->LayoutShelf(); | 340 shelf->LayoutShelf(); |
358 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 341 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
359 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 342 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
360 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 343 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
361 Shell::GetScreen()->GetDisplayNearestWindow( | 344 Shell::GetScreen()->GetDisplayNearestWindow( |
362 root).work_area().bottom()); | 345 root).work_area().bottom()); |
363 | 346 |
364 // Move the mouse to the bottom of the screen. | 347 // Move the mouse to the bottom of the screen. |
365 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 348 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
366 | 349 |
367 // Shelf should be shown again (but it shouldn't have changed the work area). | 350 // Shelf should be shown again (but it shouldn't have changed the work area). |
368 SetState(shelf, SHELF_AUTO_HIDE); | 351 SetState(shelf, SHELF_AUTO_HIDE); |
369 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 352 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
370 shelf->LayoutShelf(); | 353 shelf->LayoutShelf(); |
371 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), | 354 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), |
372 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 355 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
373 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 356 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
374 Shell::GetScreen()->GetDisplayNearestWindow( | 357 Shell::GetScreen()->GetDisplayNearestWindow( |
375 root).work_area().bottom()); | 358 root).work_area().bottom()); |
376 | 359 |
377 // Move mouse back up. | 360 // Move mouse back up. |
378 generator.MoveMouseTo(0, 0); | 361 generator.MoveMouseTo(0, 0); |
379 SetState(shelf, SHELF_AUTO_HIDE); | 362 SetState(shelf, SHELF_AUTO_HIDE); |
380 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 363 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
381 shelf->LayoutShelf(); | 364 shelf->LayoutShelf(); |
382 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 365 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
383 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 366 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
384 | 367 |
385 // Drag mouse to bottom of screen. | 368 // Drag mouse to bottom of screen. |
386 generator.PressLeftButton(); | 369 generator.PressLeftButton(); |
387 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 370 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
388 UpdateAutoHideStateNow(); | 371 UpdateAutoHideStateNow(); |
389 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 372 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
390 | 373 |
391 generator.ReleaseLeftButton(); | 374 generator.ReleaseLeftButton(); |
392 generator.MoveMouseTo(1, root->bounds().bottom() - 1); | 375 generator.MoveMouseTo(1, root->bounds().bottom() - 1); |
393 UpdateAutoHideStateNow(); | 376 UpdateAutoHideStateNow(); |
(...skipping 23 matching lines...) Expand all Loading... |
417 widget->Maximize(); | 400 widget->Maximize(); |
418 widget->Show(); | 401 widget->Show(); |
419 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 402 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
420 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 403 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
421 | 404 |
422 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 405 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
423 // LayoutShelf() forces the animation to completion, at which point the | 406 // LayoutShelf() forces the animation to completion, at which point the |
424 // launcher should go off the screen. | 407 // launcher should go off the screen. |
425 shelf->LayoutShelf(); | 408 shelf->LayoutShelf(); |
426 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 409 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
427 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 410 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
428 | 411 |
429 aura::Window* lock_container = Shell::GetContainer( | 412 aura::Window* lock_container = Shell::GetContainer( |
430 Shell::GetPrimaryRootWindow(), | 413 Shell::GetPrimaryRootWindow(), |
431 internal::kShellWindowId_LockScreenContainer); | 414 internal::kShellWindowId_LockScreenContainer); |
432 | 415 |
433 views::Widget* lock_widget = new views::Widget; | 416 views::Widget* lock_widget = new views::Widget; |
434 views::Widget::InitParams lock_params( | 417 views::Widget::InitParams lock_params( |
435 views::Widget::InitParams::TYPE_WINDOW); | 418 views::Widget::InitParams::TYPE_WINDOW); |
436 lock_params.bounds = gfx::Rect(0, 0, 200, 200); | 419 lock_params.bounds = gfx::Rect(0, 0, 200, 200); |
437 params.context = CurrentContext(); | 420 params.context = CurrentContext(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 params.context = CurrentContext(); | 495 params.context = CurrentContext(); |
513 // Widget is now owned by the parent window. | 496 // Widget is now owned by the parent window. |
514 widget->Init(params); | 497 widget->Init(params); |
515 widget->Show(); | 498 widget->Show(); |
516 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 499 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
517 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 500 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
518 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 501 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
519 | 502 |
520 // Focus the launcher. Have to go through the focus cycler as normal focus | 503 // Focus the launcher. Have to go through the focus cycler as normal focus |
521 // requests to it do nothing. | 504 // requests to it do nothing. |
522 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); | 505 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); |
523 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 506 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
524 | 507 |
525 widget->Activate(); | 508 widget->Activate(); |
526 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 509 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
527 | 510 |
528 // Trying to activate the status should fail, since we only allow activating | 511 // Trying to activate the status should fail, since we only allow activating |
529 // it when the user is using the keyboard (i.e. through FocusCycler). | 512 // it when the user is using the keyboard (i.e. through FocusCycler). |
530 shelf->status_area_widget()->Activate(); | 513 GetShelfWidget()->status_area_widget()->Activate(); |
531 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 514 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
532 | 515 |
533 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); | 516 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); |
534 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 517 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
535 } | 518 } |
536 | 519 |
537 // Makes sure shelf will be visible when app list opens as shelf is in | 520 // Makes sure shelf will be visible when app list opens as shelf is in |
538 // SHELF_VISIBLE state,and toggling app list won't change shelf | 521 // SHELF_VISIBLE state,and toggling app list won't change shelf |
539 // visibility state. | 522 // visibility state. |
540 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) { | 523 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) { |
541 Shell* shell = Shell::GetInstance(); | 524 Shell* shell = Shell::GetInstance(); |
542 internal::RootWindowController* controller = | |
543 Shell::GetPrimaryRootWindowController(); | |
544 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 525 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
545 shelf->LayoutShelf(); | 526 shelf->LayoutShelf(); |
546 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 527 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
547 | 528 |
548 // Create a normal unmaximized windowm shelf should be visible. | 529 // Create a normal unmaximized windowm shelf should be visible. |
549 aura::Window* window = CreateTestWindow(); | 530 aura::Window* window = CreateTestWindow(); |
550 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 531 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
551 window->Show(); | 532 window->Show(); |
552 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 533 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
553 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 534 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
554 | 535 |
555 // Toggle app list to show, and the shelf stays visible. | 536 // Toggle app list to show, and the shelf stays visible. |
556 shell->ToggleAppList(NULL); | 537 shell->ToggleAppList(NULL); |
557 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 538 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
558 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 539 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
559 | 540 |
560 // Toggle app list to hide, and the shelf stays visible. | 541 // Toggle app list to hide, and the shelf stays visible. |
561 shell->ToggleAppList(NULL); | 542 shell->ToggleAppList(NULL); |
562 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 543 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
563 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 544 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
564 } | 545 } |
565 | 546 |
566 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state | 547 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state |
567 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and | 548 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and |
568 // toggling app list won't change shelf visibility state. | 549 // toggling app list won't change shelf visibility state. |
569 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) { | 550 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) { |
570 Shell* shell = Shell::GetInstance(); | 551 Shell* shell = Shell::GetInstance(); |
571 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 552 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
572 internal::RootWindowController* controller = | |
573 Shell::GetPrimaryRootWindowController(); | |
574 shelf->LayoutShelf(); | 553 shelf->LayoutShelf(); |
575 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 554 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
576 | 555 |
577 // Create a window and show it in maximized state. | 556 // Create a window and show it in maximized state. |
578 aura::Window* window = CreateTestWindow(); | 557 aura::Window* window = CreateTestWindow(); |
579 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 558 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
580 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 559 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
581 window->Show(); | 560 window->Show(); |
582 wm::ActivateWindow(window); | 561 wm::ActivateWindow(window); |
583 | 562 |
584 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 563 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
585 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 564 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP). | 619 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP). |
641 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) { | 620 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) { |
642 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 621 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
643 // Force an initial layout. | 622 // Force an initial layout. |
644 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 623 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
645 shelf->LayoutShelf(); | 624 shelf->LayoutShelf(); |
646 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 625 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
647 | 626 |
648 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 627 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
649 gfx::Rect launcher_bounds( | 628 gfx::Rect launcher_bounds( |
650 shelf->launcher_widget()->GetWindowBoundsInScreen()); | 629 GetShelfWidget()->GetWindowBoundsInScreen()); |
651 const internal::DisplayManager* manager = | 630 const internal::DisplayManager* manager = |
652 Shell::GetInstance()->display_manager(); | 631 Shell::GetInstance()->display_manager(); |
653 gfx::Display display = | 632 gfx::Display display = |
654 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 633 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
655 ASSERT_NE(-1, display.id()); | 634 ASSERT_NE(-1, display.id()); |
656 EXPECT_EQ(shelf->GetIdealBounds().width(), | 635 EXPECT_EQ(shelf->GetIdealBounds().width(), |
657 display.GetWorkAreaInsets().left()); | 636 display.GetWorkAreaInsets().left()); |
658 EXPECT_GE( | 637 EXPECT_GE( |
659 launcher_bounds.width(), | 638 launcher_bounds.width(), |
660 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); | 639 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); |
661 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment()); | 640 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment()); |
662 StatusAreaWidget* status_area_widget = shelf->status_area_widget(); | 641 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget(); |
663 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen()); | 642 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen()); |
664 EXPECT_GE(status_bounds.width(), | 643 EXPECT_GE(status_bounds.width(), |
665 status_area_widget->GetContentsView()->GetPreferredSize().width()); | 644 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
666 EXPECT_EQ(shelf->GetIdealBounds().width(), | 645 EXPECT_EQ(shelf->GetIdealBounds().width(), |
667 display.GetWorkAreaInsets().left()); | 646 display.GetWorkAreaInsets().left()); |
668 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 647 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
669 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 648 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
670 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); | 649 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); |
671 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); | 650 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); |
672 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); | 651 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); |
673 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); | 652 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); |
674 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 653 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
675 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 654 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
676 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 655 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, |
677 display.GetWorkAreaInsets().left()); | 656 display.GetWorkAreaInsets().left()); |
678 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x()); | 657 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x()); |
679 | 658 |
680 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 659 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
681 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 660 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
682 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 661 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
683 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); | 662 launcher_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
684 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 663 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
685 ASSERT_NE(-1, display.id()); | 664 ASSERT_NE(-1, display.id()); |
686 EXPECT_EQ(shelf->GetIdealBounds().width(), | 665 EXPECT_EQ(shelf->GetIdealBounds().width(), |
687 display.GetWorkAreaInsets().right()); | 666 display.GetWorkAreaInsets().right()); |
688 EXPECT_GE(launcher_bounds.width(), | 667 EXPECT_GE(launcher_bounds.width(), |
689 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); | 668 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); |
690 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); | 669 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); |
691 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); | 670 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); |
692 EXPECT_GE(status_bounds.width(), | 671 EXPECT_GE(status_bounds.width(), |
693 status_area_widget->GetContentsView()->GetPreferredSize().width()); | 672 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
694 EXPECT_EQ(shelf->GetIdealBounds().width(), | 673 EXPECT_EQ(shelf->GetIdealBounds().width(), |
695 display.GetWorkAreaInsets().right()); | 674 display.GetWorkAreaInsets().right()); |
696 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 675 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
697 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 676 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
698 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 677 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
699 EXPECT_EQ(display.work_area().right(), launcher_bounds.x()); | 678 EXPECT_EQ(display.work_area().right(), launcher_bounds.x()); |
700 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); | 679 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); |
701 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); | 680 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); |
702 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 681 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
703 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 682 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
704 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 683 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, |
705 display.GetWorkAreaInsets().right()); | 684 display.GetWorkAreaInsets().right()); |
706 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 685 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, |
707 display.bounds().right() - display.work_area().right()); | 686 display.bounds().right() - display.work_area().right()); |
708 | 687 |
709 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 688 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
710 shelf->SetAlignment(SHELF_ALIGNMENT_TOP); | 689 shelf->SetAlignment(SHELF_ALIGNMENT_TOP); |
711 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 690 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
712 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); | 691 launcher_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
713 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 692 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
714 ASSERT_NE(-1, display.id()); | 693 ASSERT_NE(-1, display.id()); |
715 EXPECT_EQ(shelf->GetIdealBounds().height(), | 694 EXPECT_EQ(shelf->GetIdealBounds().height(), |
716 display.GetWorkAreaInsets().top()); | 695 display.GetWorkAreaInsets().top()); |
717 EXPECT_GE(launcher_bounds.height(), | 696 EXPECT_GE(launcher_bounds.height(), |
718 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().height()); | 697 GetShelfWidget()->GetContentsView()->GetPreferredSize().height()); |
719 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment()); | 698 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment()); |
720 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); | 699 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); |
721 EXPECT_GE(status_bounds.height(), | 700 EXPECT_GE(status_bounds.height(), |
722 status_area_widget->GetContentsView()->GetPreferredSize().height()); | 701 status_area_widget->GetContentsView()->GetPreferredSize().height()); |
723 EXPECT_EQ(shelf->GetIdealBounds().height(), | 702 EXPECT_EQ(shelf->GetIdealBounds().height(), |
724 display.GetWorkAreaInsets().top()); | 703 display.GetWorkAreaInsets().top()); |
725 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); | 704 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); |
726 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 705 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
727 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 706 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
728 EXPECT_EQ(display.work_area().y(), launcher_bounds.bottom()); | 707 EXPECT_EQ(display.work_area().y(), launcher_bounds.bottom()); |
729 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); | 708 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); |
730 EXPECT_EQ(display.bounds().width(), launcher_bounds.width()); | 709 EXPECT_EQ(display.bounds().width(), launcher_bounds.width()); |
731 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 710 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
732 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 711 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
733 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 712 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, |
734 display.GetWorkAreaInsets().top()); | 713 display.GetWorkAreaInsets().top()); |
735 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 714 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, |
736 display.work_area().y() - display.bounds().y()); | 715 display.work_area().y() - display.bounds().y()); |
737 } | 716 } |
738 | 717 |
739 #if defined(OS_WIN) | 718 #if defined(OS_WIN) |
740 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 | 719 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 |
741 #define MAYBE_GestureDrag DISABLED_GestureDrag | 720 #define MAYBE_GestureDrag DISABLED_GestureDrag |
742 #else | 721 #else |
743 #define MAYBE_GestureDrag GestureDrag | 722 #define MAYBE_GestureDrag GestureDrag |
744 #endif | 723 #endif |
745 | 724 |
746 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) { | 725 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) { |
747 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 726 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
748 internal::RootWindowController* controller = | 727 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
749 Shell::GetPrimaryRootWindowController(); | |
750 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | |
751 shelf->LayoutShelf(); | 728 shelf->LayoutShelf(); |
752 | 729 |
753 views::Widget* widget = new views::Widget; | 730 views::Widget* widget = new views::Widget; |
754 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 731 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
755 params.bounds = gfx::Rect(0, 0, 200, 200); | 732 params.bounds = gfx::Rect(0, 0, 200, 200); |
756 params.context = CurrentContext(); | 733 params.context = CurrentContext(); |
757 widget->Init(params); | 734 widget->Init(params); |
758 widget->Show(); | 735 widget->Show(); |
759 widget->Maximize(); | 736 widget->Maximize(); |
760 | 737 |
761 aura::Window* window = widget->GetNativeWindow(); | 738 aura::Window* window = widget->GetNativeWindow(); |
762 | 739 |
763 gfx::Rect shelf_shown = shelf->launcher_widget()->GetWindowBoundsInScreen(); | 740 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen(); |
764 gfx::Rect bounds_shelf = window->bounds(); | 741 gfx::Rect bounds_shelf = window->bounds(); |
765 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 742 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
766 | 743 |
767 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 744 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
768 | 745 |
769 // Swipe up on the shelf. This should not change any state. | 746 // Swipe up on the shelf. This should not change any state. |
770 gfx::Point start = | 747 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint(); |
771 shelf->launcher_widget()->GetWindowBoundsInScreen().CenterPoint(); | |
772 gfx::Point end(start.x(), start.y() + 100); | 748 gfx::Point end(start.x(), start.y() + 100); |
773 | 749 |
774 // Swipe down on the shelf to hide it. | 750 // Swipe down on the shelf to hide it. |
775 end.set_y(start.y() + 100); | 751 end.set_y(start.y() + 100); |
776 generator.GestureScrollSequence(start, end, | 752 generator.GestureScrollSequence(start, end, |
777 base::TimeDelta::FromMilliseconds(10), 1); | 753 base::TimeDelta::FromMilliseconds(10), 1); |
778 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 754 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
779 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 755 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
780 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | 756 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
781 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString()); | 757 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString()); |
782 EXPECT_NE(shelf_shown.ToString(), | 758 EXPECT_NE(shelf_shown.ToString(), |
783 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); | 759 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
784 | 760 |
785 gfx::Rect bounds_noshelf = window->bounds(); | 761 gfx::Rect bounds_noshelf = window->bounds(); |
786 gfx::Rect shelf_hidden = shelf->launcher_widget()->GetWindowBoundsInScreen(); | 762 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen(); |
787 | 763 |
788 // Swipe up to show the shelf. | 764 // Swipe up to show the shelf. |
789 generator.GestureScrollSequence(end, start, | 765 generator.GestureScrollSequence(end, start, |
790 base::TimeDelta::FromMilliseconds(10), 1); | 766 base::TimeDelta::FromMilliseconds(10), 1); |
791 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 767 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
792 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); | 768 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); |
793 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); | 769 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); |
794 EXPECT_EQ(shelf_shown.ToString(), | 770 EXPECT_EQ(shelf_shown.ToString(), |
795 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); | 771 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
796 | 772 |
797 // Swipe up again. The shelf should hide. | 773 // Swipe up again. The shelf should hide. |
798 end.set_y(start.y() - 100); | 774 end.set_y(start.y() - 100); |
799 generator.GestureScrollSequence(start, end, | 775 generator.GestureScrollSequence(start, end, |
800 base::TimeDelta::FromMilliseconds(10), 1); | 776 base::TimeDelta::FromMilliseconds(10), 1); |
801 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 777 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
802 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 778 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
803 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | 779 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
804 EXPECT_EQ(shelf_hidden.ToString(), | 780 EXPECT_EQ(shelf_hidden.ToString(), |
805 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); | 781 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
806 | 782 |
807 // Swipe up yet again to show it. | 783 // Swipe up yet again to show it. |
808 end.set_y(start.y() + 100); | 784 end.set_y(start.y() + 100); |
809 generator.GestureScrollSequence(end, start, | 785 generator.GestureScrollSequence(end, start, |
810 base::TimeDelta::FromMilliseconds(10), 1); | 786 base::TimeDelta::FromMilliseconds(10), 1); |
811 | 787 |
812 // Swipe down very little. It shouldn't change any state. | 788 // Swipe down very little. It shouldn't change any state. |
813 end.set_y(start.y() + shelf_shown.height() * 3 / 10); | 789 end.set_y(start.y() + shelf_shown.height() * 3 / 10); |
814 generator.GestureScrollSequence(start, end, | 790 generator.GestureScrollSequence(start, end, |
815 base::TimeDelta::FromMilliseconds(100), 1); | 791 base::TimeDelta::FromMilliseconds(100), 1); |
816 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 792 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
817 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); | 793 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); |
818 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); | 794 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); |
819 EXPECT_EQ(shelf_shown.ToString(), | 795 EXPECT_EQ(shelf_shown.ToString(), |
820 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); | 796 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
821 | 797 |
822 // Swipe down again to hide. | 798 // Swipe down again to hide. |
823 end.set_y(start.y() + 100); | 799 end.set_y(start.y() + 100); |
824 generator.GestureScrollSequence(start, end, | 800 generator.GestureScrollSequence(start, end, |
825 base::TimeDelta::FromMilliseconds(10), 1); | 801 base::TimeDelta::FromMilliseconds(10), 1); |
826 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 802 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
827 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 803 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
828 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | 804 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
829 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString()); | 805 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString()); |
830 EXPECT_EQ(shelf_hidden.ToString(), | 806 EXPECT_EQ(shelf_hidden.ToString(), |
831 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); | 807 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
832 | 808 |
833 // Swipe up yet again to show it. | 809 // Swipe up yet again to show it. |
834 end.set_y(start.y() + 100); | 810 end.set_y(start.y() + 100); |
835 generator.GestureScrollSequence(end, start, | 811 generator.GestureScrollSequence(end, start, |
836 base::TimeDelta::FromMilliseconds(10), 1); | 812 base::TimeDelta::FromMilliseconds(10), 1); |
837 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | 813 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
838 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); | 814 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); |
839 | 815 |
840 // Tap on the shelf itself. This should not change anything. | 816 // Tap on the shelf itself. This should not change anything. |
841 generator.GestureTapAt(start); | 817 generator.GestureTapAt(start); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 CreateTestWidget(); | 901 CreateTestWidget(); |
926 | 902 |
927 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 903 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
928 SystemTray* tray = GetSystemTray(); | 904 SystemTray* tray = GetSystemTray(); |
929 | 905 |
930 // First, make sure the shelf is visible. | 906 // First, make sure the shelf is visible. |
931 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 907 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
932 EXPECT_FALSE(tray->HasSystemBubble()); | 908 EXPECT_FALSE(tray->HasSystemBubble()); |
933 | 909 |
934 // Now, drag up on the tray to show the bubble. | 910 // Now, drag up on the tray to show the bubble. |
935 gfx::Point start = | 911 gfx::Point start = GetShelfWidget()->status_area_widget()-> |
936 shelf->status_area_widget()->GetWindowBoundsInScreen().CenterPoint(); | 912 GetWindowBoundsInScreen().CenterPoint(); |
937 gfx::Point end(start.x(), start.y() - 100); | 913 gfx::Point end(start.x(), start.y() - 100); |
938 generator.GestureScrollSequence(start, end, | 914 generator.GestureScrollSequence(start, end, |
939 base::TimeDelta::FromMilliseconds(10), 1); | 915 base::TimeDelta::FromMilliseconds(10), 1); |
940 EXPECT_TRUE(tray->HasSystemBubble()); | 916 EXPECT_TRUE(tray->HasSystemBubble()); |
941 tray->CloseBubbleForTest(); | 917 tray->CloseBubbleForTest(); |
942 RunAllPendingInMessageLoop(); | 918 RunAllPendingInMessageLoop(); |
943 EXPECT_FALSE(tray->HasSystemBubble()); | 919 EXPECT_FALSE(tray->HasSystemBubble()); |
944 | 920 |
945 // Drag again, but only a small amount, and slowly. The bubble should not be | 921 // Drag again, but only a small amount, and slowly. The bubble should not be |
946 // visible. | 922 // visible. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 // Confirm that the shelf is dimmed only when content is maximized and | 1025 // Confirm that the shelf is dimmed only when content is maximized and |
1050 // shelf is not autohidden. | 1026 // shelf is not autohidden. |
1051 TEST_F(ShelfLayoutManagerTest, Dimming) { | 1027 TEST_F(ShelfLayoutManagerTest, Dimming) { |
1052 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1028 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
1053 scoped_ptr<aura::Window> w1(CreateTestWindow()); | 1029 scoped_ptr<aura::Window> w1(CreateTestWindow()); |
1054 w1->Show(); | 1030 w1->Show(); |
1055 wm::ActivateWindow(w1.get()); | 1031 wm::ActivateWindow(w1.get()); |
1056 | 1032 |
1057 // Normal window doesn't dim shelf. | 1033 // Normal window doesn't dim shelf. |
1058 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 1034 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
1059 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 1035 ShelfWidget* shelf = GetShelfWidget(); |
1060 EXPECT_FALSE(launcher->GetDimsShelf()); | 1036 EXPECT_FALSE(shelf->GetDimsShelf()); |
1061 | 1037 |
1062 // Maximized window does. | 1038 // Maximized window does. |
1063 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1039 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
1064 EXPECT_TRUE(launcher->GetDimsShelf()); | 1040 EXPECT_TRUE(shelf->GetDimsShelf()); |
1065 | 1041 |
1066 // Change back to normal stops dimming. | 1042 // Change back to normal stops dimming. |
1067 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 1043 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
1068 EXPECT_FALSE(launcher->GetDimsShelf()); | 1044 EXPECT_FALSE(shelf->GetDimsShelf()); |
1069 | 1045 |
1070 // Changing back to maximized dims again. | 1046 // Changing back to maximized dims again. |
1071 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1047 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
1072 EXPECT_TRUE(launcher->GetDimsShelf()); | 1048 EXPECT_TRUE(shelf->GetDimsShelf()); |
1073 | 1049 |
1074 // Changing shelf to autohide stops dimming. | 1050 // Changing shelf to autohide stops dimming. |
1075 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1051 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
1076 EXPECT_FALSE(launcher->GetDimsShelf()); | 1052 EXPECT_FALSE(shelf->GetDimsShelf()); |
1077 } | 1053 } |
1078 | 1054 |
1079 // Make sure that the shelf will not hide if the mouse is between a bubble and | 1055 // Make sure that the shelf will not hide if the mouse is between a bubble and |
1080 // the shelf. | 1056 // the shelf. |
1081 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { | 1057 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { |
1082 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 1058 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
1083 StatusAreaWidget* status_area_widget = | 1059 StatusAreaWidget* status_area_widget = |
1084 Shell::GetPrimaryRootWindowController()->status_area_widget(); | 1060 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget(); |
1085 SystemTray* tray = GetSystemTray(); | 1061 SystemTray* tray = GetSystemTray(); |
1086 | 1062 |
1087 // Create a visible window so auto-hide behavior is enforced. | 1063 // Create a visible window so auto-hide behavior is enforced. |
1088 CreateTestWidget(); | 1064 CreateTestWidget(); |
1089 | 1065 |
1090 shelf->LayoutShelf(); | 1066 shelf->LayoutShelf(); |
1091 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 1067 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
1092 | 1068 |
1093 // Make two iterations - first without a message bubble which should make | 1069 // Make two iterations - first without a message bubble which should make |
1094 // the shelf disappear and then with a message bubble which should keep it | 1070 // the shelf disappear and then with a message bubble which should keep it |
(...skipping 28 matching lines...) Expand all Loading... |
1123 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); | 1099 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); |
1124 } else { | 1100 } else { |
1125 EXPECT_FALSE(shelf->IsVisible()); | 1101 EXPECT_FALSE(shelf->IsVisible()); |
1126 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); | 1102 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); |
1127 } | 1103 } |
1128 } | 1104 } |
1129 } | 1105 } |
1130 | 1106 |
1131 } // namespace internal | 1107 } // namespace internal |
1132 } // namespace ash | 1108 } // namespace ash |
OLD | NEW |