Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/shelf/shelf_widget.h" | |
| 6 | |
| 7 #include "ash/launcher/launcher.h" | |
| 8 #include "ash/launcher/launcher_button.h" | |
| 9 #include "ash/launcher/launcher_model.h" | |
| 10 #include "ash/launcher/launcher_view.h" | |
| 11 #include "ash/shelf/shelf_layout_manager.h" | |
| 12 #include "ash/shell.h" | |
| 13 #include "ash/test/ash_test_base.h" | |
| 14 #include "ash/test/launcher_view_test_api.h" | |
| 15 #include "ash/wm/window_util.h" | |
| 16 #include "ui/aura/root_window.h" | |
| 17 #include "ui/gfx/display.h" | |
| 18 #include "ui/gfx/screen.h" | |
| 19 #include "ui/views/corewm/corewm_switches.h" | |
| 20 #include "ui/views/view.h" | |
| 21 #include "ui/views/widget/widget.h" | |
| 22 | |
| 23 namespace ash { | |
| 24 | |
| 25 namespace { | |
| 26 ShelfWidget* GetShelfWidget() { | |
| 27 return Launcher::ForPrimaryDisplay()->shelf_widget(); | |
| 28 } | |
| 29 | |
| 30 internal::ShelfLayoutManager* GetShelfLayoutManager() { | |
| 31 return GetShelfWidget()->shelf_layout_manager(); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 typedef test::AshTestBase ShelfWidgetTest; | |
| 37 | |
| 38 // Launcher can't be activated on mouse click, but it is activable from | |
| 39 // the focus cycler or as fallback. | |
| 40 TEST_F(ShelfWidgetTest, ActivateAsFallback) { | |
| 41 // TODO(mtomasz): make this test work with the FocusController. | |
| 42 if (views::corewm::UseFocusController()) | |
| 43 return; | |
| 44 | |
| 45 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 46 ShelfWidget* shelf_widget = launcher->shelf_widget(); | |
| 47 EXPECT_FALSE(shelf_widget->CanActivate()); | |
| 48 | |
| 49 shelf_widget->WillActivateAsFallback(); | |
| 50 EXPECT_TRUE(shelf_widget->CanActivate()); | |
| 51 | |
| 52 wm::ActivateWindow(shelf_widget->GetNativeWindow()); | |
| 53 EXPECT_FALSE(shelf_widget->CanActivate()); | |
| 54 } | |
| 55 | |
| 56 void TestLauncherAlignment(aura::RootWindow* root, | |
| 57 ShelfAlignment alignment, | |
| 58 const std::string& expected) { | |
| 59 Shell::GetInstance()->SetShelfAlignment(alignment, root); | |
| 60 gfx::Screen* screen = gfx::Screen::GetScreenFor(root); | |
| 61 EXPECT_EQ(expected, | |
| 62 screen->GetDisplayNearestWindow(root).work_area().ToString()); | |
| 63 } | |
| 64 | |
| 65 TEST_F(ShelfWidgetTest, TestAlignment) { | |
| 66 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 67 UpdateDisplay("400x400"); | |
| 68 ASSERT_TRUE(launcher); | |
| 69 { | |
| 70 SCOPED_TRACE("Single Bottom"); | |
| 71 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 72 SHELF_ALIGNMENT_BOTTOM, | |
| 73 "0,0 400x352"); | |
| 74 } | |
| 75 { | |
| 76 SCOPED_TRACE("Single Right"); | |
| 77 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 78 SHELF_ALIGNMENT_RIGHT, | |
| 79 "0,0 348x400"); | |
| 80 } | |
| 81 { | |
| 82 SCOPED_TRACE("Single Left"); | |
| 83 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 84 SHELF_ALIGNMENT_LEFT, | |
| 85 "52,0 348x400"); | |
| 86 } | |
| 87 UpdateDisplay("300x300,500x500"); | |
| 88 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 89 { | |
| 90 SCOPED_TRACE("Primary Bottom"); | |
| 91 TestLauncherAlignment(root_windows[0], | |
| 92 SHELF_ALIGNMENT_BOTTOM, | |
| 93 "0,0 300x252"); | |
| 94 } | |
| 95 { | |
| 96 SCOPED_TRACE("Primary Right"); | |
| 97 TestLauncherAlignment(root_windows[0], | |
| 98 SHELF_ALIGNMENT_RIGHT, | |
| 99 "0,0 248x300"); | |
| 100 } | |
| 101 { | |
| 102 SCOPED_TRACE("Primary Left"); | |
| 103 TestLauncherAlignment(root_windows[0], | |
| 104 SHELF_ALIGNMENT_LEFT, | |
| 105 "52,0 248x300"); | |
| 106 } | |
| 107 if (Shell::IsLauncherPerDisplayEnabled()) { | |
| 108 { | |
| 109 SCOPED_TRACE("Secondary Bottom"); | |
| 110 TestLauncherAlignment(root_windows[1], | |
| 111 SHELF_ALIGNMENT_BOTTOM, | |
| 112 "300,0 500x452"); | |
| 113 } | |
| 114 { | |
| 115 SCOPED_TRACE("Secondary Right"); | |
| 116 TestLauncherAlignment(root_windows[1], | |
| 117 SHELF_ALIGNMENT_RIGHT, | |
| 118 "300,0 448x500"); | |
| 119 } | |
| 120 { | |
| 121 SCOPED_TRACE("Secondary Left"); | |
| 122 TestLauncherAlignment(root_windows[1], | |
| 123 SHELF_ALIGNMENT_LEFT, | |
| 124 "352,0 448x500"); | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 // Makes sure the launcher is initially sized correctly. | |
| 130 TEST_F(ShelfWidgetTest, LauncherInitiallySized) { | |
| 131 ShelfWidget* shelf_widget = GetShelfWidget(); | |
| 132 Launcher* launcher = shelf_widget->launcher(); | |
| 133 ASSERT_TRUE(launcher); | |
| 134 internal::ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | |
| 135 ASSERT_TRUE(shelf_layout_manager); | |
| 136 ASSERT_TRUE(shelf_widget->status_area_widget()); | |
| 137 int status_width = shelf_widget->status_area_widget()-> | |
| 138 GetWindowBoundsInScreen().width(); | |
| 139 // Test only makes sense if the status is > 0, which is better be. | |
|
James Cook
2013/03/05 20:30:38
"it better be"
Harry McCleave
2013/03/06 01:59:49
Done.
| |
| 140 EXPECT_GT(status_width, 0); | |
| 141 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - | |
| 142 launcher->GetLauncherViewForTest()->width()); | |
| 143 } | |
| 144 | |
| 145 // Verifies when the shell is deleted with a full screen window we don't crash. | |
| 146 TEST_F(ShelfWidgetTest, DontReferenceLauncherAfterDeletion) { | |
| 147 views::Widget* widget = new views::Widget; | |
| 148 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
| 149 params.bounds = gfx::Rect(0, 0, 200, 200); | |
| 150 params.context = CurrentContext(); | |
| 151 // Widget is now owned by the parent window. | |
| 152 widget->Init(params); | |
| 153 widget->SetFullscreen(true); | |
| 154 } | |
| 155 | |
| 156 } // namespace ash | |
| OLD | NEW |