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