| 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/launcher/launcher.h" | 5 #include "ash/launcher/launcher.h" |
| 6 #include "ash/launcher/launcher_button.h" | 6 #include "ash/launcher/launcher_button.h" |
| 7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
| 8 #include "ash/launcher/launcher_view.h" | 8 #include "ash/launcher/launcher_view.h" |
| 9 | 9 |
| 10 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/launcher_view_test_api.h" | 13 #include "ash/test/launcher_view_test_api.h" |
| 13 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 15 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 16 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 17 #include "ui/views/corewm/corewm_switches.h" | 18 #include "ui/views/corewm/corewm_switches.h" |
| 18 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 | 21 |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 25 typedef ash::test::AshTestBase LauncherTest; | 26 typedef ash::test::AshTestBase LauncherTest; |
| 26 using ash::internal::LauncherView; | 27 using ash::internal::LauncherView; |
| 27 using ash::internal::LauncherButton; | 28 using ash::internal::LauncherButton; |
| 28 | 29 |
| 29 namespace ash { | 30 namespace ash { |
| 30 | 31 |
| 31 // Makes sure invoking SetStatusSize on the launcher changes the size of the | |
| 32 // LauncherView. | |
| 33 TEST_F(LauncherTest, SetStatusSize) { | |
| 34 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 35 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | |
| 36 | |
| 37 gfx::Size launcher_size = | |
| 38 launcher->widget()->GetWindowBoundsInScreen().size(); | |
| 39 int total_width = launcher_size.width(); | |
| 40 ASSERT_GT(total_width, 0); | |
| 41 launcher->SetStatusSize(gfx::Size(total_width / 2, launcher_size.height())); | |
| 42 EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); | |
| 43 } | |
| 44 | |
| 45 // Tests that the dimmer widget resizes itself as appropriate. | |
| 46 TEST_F(LauncherTest, DimmerSize) { | |
| 47 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 48 launcher->SetDimsShelf(true); | |
| 49 | |
| 50 gfx::Size launcher_size = | |
| 51 launcher->widget()->GetWindowBoundsInScreen().size(); | |
| 52 EXPECT_EQ( | |
| 53 launcher->widget()->GetWindowBoundsInScreen().ToString(), | |
| 54 launcher->GetDimmerWidgetForTest()->GetWindowBoundsInScreen().ToString()); | |
| 55 | |
| 56 launcher->widget()->SetSize( | |
| 57 gfx::Size(launcher_size.width() / 2, launcher_size.height() + 10)); | |
| 58 EXPECT_EQ( | |
| 59 launcher->widget()->GetWindowBoundsInScreen().ToString(), | |
| 60 launcher->GetDimmerWidgetForTest()->GetWindowBoundsInScreen().ToString()); | |
| 61 } | |
| 62 | |
| 63 // Confirm that launching a browser gets the appropriate state reflected in | 32 // Confirm that launching a browser gets the appropriate state reflected in |
| 64 // its button. | 33 // its button. |
| 65 TEST_F(LauncherTest, OpenBrowser) { | 34 TEST_F(LauncherTest, OpenBrowser) { |
| 66 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 35 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| 67 ASSERT_TRUE(launcher); | 36 ASSERT_TRUE(launcher); |
| 68 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | 37 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
| 69 test::LauncherViewTestAPI test(launcher_view); | 38 test::LauncherViewTestAPI test(launcher_view); |
| 70 LauncherModel* model = launcher_view->model(); | 39 LauncherModel* model = launcher_view->model(); |
| 71 | 40 |
| 72 // Initially we have the app list and chrome icon. | 41 // Initially we have the app list and chrome icon. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); | 82 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); |
| 114 | 83 |
| 115 // Removes the first item in main launcher view. | 84 // Removes the first item in main launcher view. |
| 116 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); | 85 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); |
| 117 | 86 |
| 118 // Waits for all transitions to finish and there should be no crash. | 87 // Waits for all transitions to finish and there should be no crash. |
| 119 test.RunMessageLoopUntilAnimationsDone(); | 88 test.RunMessageLoopUntilAnimationsDone(); |
| 120 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); | 89 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); |
| 121 } | 90 } |
| 122 | 91 |
| 123 // Launcher can't be activated on mouse click, but it is activable from | |
| 124 // the focus cycler or as fallback. | |
| 125 TEST_F(LauncherTest, ActivateAsFallback) { | |
| 126 // TODO(mtomasz): make this test work with the FocusController. | |
| 127 if (views::corewm::UseFocusController()) | |
| 128 return; | |
| 129 | |
| 130 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 131 views::Widget* launcher_widget = launcher->widget(); | |
| 132 EXPECT_FALSE(launcher_widget->CanActivate()); | |
| 133 | |
| 134 launcher->WillActivateAsFallback(); | |
| 135 EXPECT_TRUE(launcher_widget->CanActivate()); | |
| 136 | |
| 137 wm::ActivateWindow(launcher_widget->GetNativeWindow()); | |
| 138 EXPECT_FALSE(launcher_widget->CanActivate()); | |
| 139 } | |
| 140 | |
| 141 void TestLauncherAlignment(aura::RootWindow* root, | |
| 142 ShelfAlignment alignment, | |
| 143 const std::string& expected) { | |
| 144 Shell::GetInstance()->SetShelfAlignment(alignment, root); | |
| 145 gfx::Screen* screen = gfx::Screen::GetScreenFor(root); | |
| 146 EXPECT_EQ(expected, | |
| 147 screen->GetDisplayNearestWindow(root).work_area().ToString()); | |
| 148 } | |
| 149 | |
| 150 TEST_F(LauncherTest, TestAlignment) { | |
| 151 Launcher* launcher = Launcher::ForPrimaryDisplay(); | |
| 152 UpdateDisplay("400x400"); | |
| 153 ASSERT_TRUE(launcher); | |
| 154 { | |
| 155 SCOPED_TRACE("Single Bottom"); | |
| 156 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 157 SHELF_ALIGNMENT_BOTTOM, | |
| 158 "0,0 400x352"); | |
| 159 } | |
| 160 { | |
| 161 SCOPED_TRACE("Single Right"); | |
| 162 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 163 SHELF_ALIGNMENT_RIGHT, | |
| 164 "0,0 348x400"); | |
| 165 } | |
| 166 { | |
| 167 SCOPED_TRACE("Single Left"); | |
| 168 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | |
| 169 SHELF_ALIGNMENT_LEFT, | |
| 170 "52,0 348x400"); | |
| 171 } | |
| 172 UpdateDisplay("300x300,500x500"); | |
| 173 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 174 { | |
| 175 SCOPED_TRACE("Primary Bottom"); | |
| 176 TestLauncherAlignment(root_windows[0], | |
| 177 SHELF_ALIGNMENT_BOTTOM, | |
| 178 "0,0 300x252"); | |
| 179 } | |
| 180 { | |
| 181 SCOPED_TRACE("Primary Right"); | |
| 182 TestLauncherAlignment(root_windows[0], | |
| 183 SHELF_ALIGNMENT_RIGHT, | |
| 184 "0,0 248x300"); | |
| 185 } | |
| 186 { | |
| 187 SCOPED_TRACE("Primary Left"); | |
| 188 TestLauncherAlignment(root_windows[0], | |
| 189 SHELF_ALIGNMENT_LEFT, | |
| 190 "52,0 248x300"); | |
| 191 } | |
| 192 if (Shell::IsLauncherPerDisplayEnabled()) { | |
| 193 { | |
| 194 SCOPED_TRACE("Secondary Bottom"); | |
| 195 TestLauncherAlignment(root_windows[1], | |
| 196 SHELF_ALIGNMENT_BOTTOM, | |
| 197 "300,0 500x452"); | |
| 198 } | |
| 199 { | |
| 200 SCOPED_TRACE("Secondary Right"); | |
| 201 TestLauncherAlignment(root_windows[1], | |
| 202 SHELF_ALIGNMENT_RIGHT, | |
| 203 "300,0 448x500"); | |
| 204 } | |
| 205 { | |
| 206 SCOPED_TRACE("Secondary Left"); | |
| 207 TestLauncherAlignment(root_windows[1], | |
| 208 SHELF_ALIGNMENT_LEFT, | |
| 209 "352,0 448x500"); | |
| 210 } | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 } // namespace ash | 92 } // namespace ash |
| OLD | NEW |