[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/monitor/monitor_controller.h" |
| 6 | #include "ash/shell.h" |
| 7 | #include "ash/test/ash_test_base.h" |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame^] | 8 | #include "ash/wm/window_cycle_controller.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 9 | #include "ash/wm/window_util.h" |
| 10 | #include "ui/aura/client/activation_client.h" |
| 11 | #include "ui/aura/client/capture_client.h" |
| 12 | #include "ui/aura/focus_manager.h" |
| 13 | #include "ui/aura/root_window.h" |
| 14 | #include "ui/aura/test/event_generator.h" |
| 15 | #include "ui/aura/window.h" |
| 16 | #include "ui/base/cursor/cursor.h" |
| 17 | #include "ui/views/widget/widget.h" |
| 18 | #include "ui/views/widget/widget_delegate.h" |
| 19 | |
| 20 | namespace ash { |
| 21 | namespace { |
| 22 | |
| 23 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 24 | views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 25 | params.bounds = bounds; |
| 26 | views::Widget* widget = new views::Widget; |
| 27 | widget->Init(params); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame^] | 28 | widget->Show(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 29 | return widget; |
| 30 | } |
| 31 | |
| 32 | class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 33 | public: |
| 34 | ModalWidgetDelegate() {} |
| 35 | virtual ~ModalWidgetDelegate() {} |
| 36 | |
| 37 | // Overridden from views::WidgetDelegate: |
| 38 | virtual views::View* GetContentsView() OVERRIDE { |
| 39 | return this; |
| 40 | } |
| 41 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 42 | return ui::MODAL_TYPE_SYSTEM; |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
| 47 | }; |
| 48 | |
| 49 | } // namespace |
| 50 | |
| 51 | class ExtendedDesktopTest : public test::AshTestBase { |
| 52 | public: |
| 53 | ExtendedDesktopTest() {} |
| 54 | virtual ~ExtendedDesktopTest() {} |
| 55 | |
| 56 | virtual void SetUp() OVERRIDE { |
| 57 | internal::MonitorController::SetExtendedDesktopEnabled(true); |
| 58 | AshTestBase::SetUp(); |
| 59 | } |
| 60 | |
| 61 | virtual void TearDown() OVERRIDE { |
| 62 | AshTestBase::TearDown(); |
| 63 | internal::MonitorController::SetExtendedDesktopEnabled(false); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | DISALLOW_COPY_AND_ASSIGN(ExtendedDesktopTest); |
| 68 | }; |
| 69 | |
| 70 | // Test conditions that root windows in extended desktop mode |
| 71 | // must satisfy. |
| 72 | TEST_F(ExtendedDesktopTest, Basic) { |
| 73 | UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 74 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 75 | |
| 76 | // All root windows must have the root window controller. |
| 77 | ASSERT_EQ(2U, root_windows.size()); |
| 78 | for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| 79 | iter != root_windows.end(); ++iter) { |
| 80 | EXPECT_TRUE(wm::GetRootWindowController(*iter) != NULL); |
| 81 | } |
| 82 | // Make sure root windows share the same controllers. |
| 83 | EXPECT_EQ(root_windows[0]->GetFocusManager(), |
| 84 | root_windows[1]->GetFocusManager()); |
| 85 | EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), |
| 86 | aura::client::GetActivationClient(root_windows[1])); |
| 87 | EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
| 88 | aura::client::GetCaptureClient(root_windows[1])); |
| 89 | } |
| 90 | |
| 91 | TEST_F(ExtendedDesktopTest, Activation) { |
| 92 | UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 93 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 94 | |
| 95 | // Move the active root window to the secondary. |
| 96 | Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 97 | |
| 98 | views::Widget* widget_on_2nd = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 99 | EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 100 | |
| 101 | // Move the active root window back to the primary. |
| 102 | Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 103 | |
| 104 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 105 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 106 | |
| 107 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 108 | aura::test::EventGenerator generator_2nd(root_windows[1]); |
| 109 | |
| 110 | // Clicking a window changes the active window and active root window. |
| 111 | generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
| 112 | generator_2nd.ClickLeftButton(); |
| 113 | |
| 114 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
| 115 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 116 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
| 117 | |
| 118 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 119 | generator_1st.ClickLeftButton(); |
| 120 | |
| 121 | EXPECT_EQ(widget_on_1st->GetNativeView(), |
| 122 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 123 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 124 | } |
| 125 | |
| 126 | TEST_F(ExtendedDesktopTest, SystemModal) { |
| 127 | UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 128 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 129 | Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 130 | |
| 131 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 132 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 133 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 134 | |
| 135 | // Change the active root window to 2nd. |
| 136 | Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 137 | |
| 138 | // Open system modal. Make sure it's on 2nd root window and active. |
| 139 | views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 140 | new ModalWidgetDelegate(), NULL); |
| 141 | modal_widget->Show(); |
| 142 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 143 | EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
| 144 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 145 | |
| 146 | // Clicking a widget on widget_on_1st monitor should not change activation. |
| 147 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 148 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 149 | generator_1st.ClickLeftButton(); |
| 150 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 151 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 152 | |
| 153 | // Close system modal and so clicking a widget should work now. |
| 154 | modal_widget->Close(); |
| 155 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 156 | generator_1st.ClickLeftButton(); |
| 157 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 158 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 159 | } |
| 160 | |
| 161 | TEST_F(ExtendedDesktopTest, TestCursor) { |
| 162 | UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 163 | Shell::GetInstance()->ShowCursor(false); |
| 164 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 165 | EXPECT_FALSE(root_windows[0]->cursor_shown()); |
| 166 | EXPECT_FALSE(root_windows[1]->cursor_shown()); |
| 167 | Shell::GetInstance()->ShowCursor(true); |
| 168 | EXPECT_TRUE(root_windows[0]->cursor_shown()); |
| 169 | EXPECT_TRUE(root_windows[1]->cursor_shown()); |
| 170 | |
| 171 | EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); |
| 172 | EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); |
| 173 | Shell::GetInstance()->SetCursor(ui::kCursorCopy); |
| 174 | EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); |
| 175 | EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); |
| 176 | } |
| 177 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame^] | 178 | TEST_F(ExtendedDesktopTest, CycleWindows) { |
| 179 | UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 180 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 181 | WindowCycleController* controller = |
| 182 | Shell::GetInstance()->window_cycle_controller(); |
| 183 | |
| 184 | // Switch active windows between root windows. |
| 185 | Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 186 | views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 187 | EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); |
| 188 | |
| 189 | Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 190 | views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 191 | EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); |
| 192 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 193 | |
| 194 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 195 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 196 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 197 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 198 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 199 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 200 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 201 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 202 | |
| 203 | // Cycle through all windows across root windows. |
| 204 | Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 205 | views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(100, 100, 100, 100)); |
| 206 | EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow()); |
| 207 | |
| 208 | Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 209 | views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(100, 100, 100, 100)); |
| 210 | EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow()); |
| 211 | |
| 212 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 213 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 214 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 215 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 216 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 217 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 218 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 219 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
| 220 | |
| 221 | // Backwards |
| 222 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 223 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 224 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 225 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 226 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 227 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 228 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 229 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
| 230 | } |
| 231 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 232 | } // namespace ash |