blob: 5bccab6bb29cdf112777eb8f415ac108d5dad2bd [file] [log] [blame]
[email protected]c39be8f2012-06-15 22:58:361// 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"
8#include "ash/wm/window_util.h"
9#include "ui/aura/client/activation_client.h"
10#include "ui/aura/client/capture_client.h"
11#include "ui/aura/focus_manager.h"
12#include "ui/aura/root_window.h"
13#include "ui/aura/test/event_generator.h"
14#include "ui/aura/window.h"
15#include "ui/base/cursor/cursor.h"
16#include "ui/views/widget/widget.h"
17#include "ui/views/widget/widget_delegate.h"
18
19namespace ash {
20namespace {
21
22views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
23 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
24 params.bounds = bounds;
25 views::Widget* widget = new views::Widget;
26 widget->Init(params);
27 return widget;
28}
29
30class ModalWidgetDelegate : public views::WidgetDelegateView {
31 public:
32 ModalWidgetDelegate() {}
33 virtual ~ModalWidgetDelegate() {}
34
35 // Overridden from views::WidgetDelegate:
36 virtual views::View* GetContentsView() OVERRIDE {
37 return this;
38 }
39 virtual ui::ModalType GetModalType() const OVERRIDE {
40 return ui::MODAL_TYPE_SYSTEM;
41 }
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
45};
46
47} // namespace
48
49class ExtendedDesktopTest : public test::AshTestBase {
50 public:
51 ExtendedDesktopTest() {}
52 virtual ~ExtendedDesktopTest() {}
53
54 virtual void SetUp() OVERRIDE {
55 internal::MonitorController::SetExtendedDesktopEnabled(true);
56 AshTestBase::SetUp();
57 }
58
59 virtual void TearDown() OVERRIDE {
60 AshTestBase::TearDown();
61 internal::MonitorController::SetExtendedDesktopEnabled(false);
62 }
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(ExtendedDesktopTest);
66};
67
68// Test conditions that root windows in extended desktop mode
69// must satisfy.
70TEST_F(ExtendedDesktopTest, Basic) {
71 UpdateMonitor("0+0-1000x600,1001+0-600x400");
72 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
73
74 // All root windows must have the root window controller.
75 ASSERT_EQ(2U, root_windows.size());
76 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
77 iter != root_windows.end(); ++iter) {
78 EXPECT_TRUE(wm::GetRootWindowController(*iter) != NULL);
79 }
80 // Make sure root windows share the same controllers.
81 EXPECT_EQ(root_windows[0]->GetFocusManager(),
82 root_windows[1]->GetFocusManager());
83 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
84 aura::client::GetActivationClient(root_windows[1]));
85 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
86 aura::client::GetCaptureClient(root_windows[1]));
87}
88
89TEST_F(ExtendedDesktopTest, Activation) {
90 UpdateMonitor("0+0-1000x600,1001+0-600x400");
91 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
92
93 // Move the active root window to the secondary.
94 Shell::GetInstance()->set_active_root_window(root_windows[1]);
95
96 views::Widget* widget_on_2nd = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
97 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
98 widget_on_2nd->Show();
99
100 // Move the active root window back to the primary.
101 Shell::GetInstance()->set_active_root_window(root_windows[0]);
102
103 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
104 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
105 widget_on_1st->Show();
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
126TEST_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));
132 widget_on_1st->Show();
133 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
134 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
135
136 // Change the active root window to 2nd.
137 Shell::GetInstance()->set_active_root_window(root_windows[1]);
138
139 // Open system modal. Make sure it's on 2nd root window and active.
140 views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
141 new ModalWidgetDelegate(), NULL);
142 modal_widget->Show();
143 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
144 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
145 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
146
147 // Clicking a widget on widget_on_1st monitor should not change activation.
148 aura::test::EventGenerator generator_1st(root_windows[0]);
149 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
150 generator_1st.ClickLeftButton();
151 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
152 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
153
154 // Close system modal and so clicking a widget should work now.
155 modal_widget->Close();
156 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
157 generator_1st.ClickLeftButton();
158 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
159 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
160}
161
162TEST_F(ExtendedDesktopTest, TestCursor) {
163 UpdateMonitor("0+0-1000x600,1001+0-600x400");
164 Shell::GetInstance()->ShowCursor(false);
165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
166 EXPECT_FALSE(root_windows[0]->cursor_shown());
167 EXPECT_FALSE(root_windows[1]->cursor_shown());
168 Shell::GetInstance()->ShowCursor(true);
169 EXPECT_TRUE(root_windows[0]->cursor_shown());
170 EXPECT_TRUE(root_windows[1]->cursor_shown());
171
172 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
173 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
174 Shell::GetInstance()->SetCursor(ui::kCursorCopy);
175 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
176 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
177}
178
179} // namespace ash