blob: c6cce9a27f430c820e0741185bc37b38af782995 [file] [log] [blame]
[email protected]f1853122012-06-27 16:21:261// 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
[email protected]8674b312012-10-12 19:02:445#include "ash/root_window_controller.h"
6
[email protected]fcb123d2013-04-17 15:58:497#include "ash/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:588#include "ash/shelf/shelf_layout_manager.h"
[email protected]f1853122012-06-27 16:21:269#include "ash/shell.h"
10#include "ash/shell_window_ids.h"
[email protected]8674b312012-10-12 19:02:4411#include "ash/system/tray/system_tray_delegate.h"
[email protected]f1853122012-06-27 16:21:2612#include "ash/test/ash_test_base.h"
[email protected]8674b312012-10-12 19:02:4413#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]2ee2f5d2013-01-10 23:37:1614#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3415#include "ash/wm/window_state.h"
[email protected]f1853122012-06-27 16:21:2616#include "ash/wm/window_util.h"
[email protected]eff4c7f2013-08-13 01:45:5017#include "base/command_line.h"
[email protected]792b9b12012-12-11 03:53:2718#include "ui/aura/client/focus_change_observer.h"
[email protected]8cfb6722012-11-28 03:28:4619#include "ui/aura/client/focus_client.h"
[email protected]e3225e02013-10-23 20:44:3720#include "ui/aura/client/window_tree_client.h"
[email protected]f1853122012-06-27 16:21:2621#include "ui/aura/env.h"
[email protected]f1853122012-06-27 16:21:2622#include "ui/aura/test/event_generator.h"
[email protected]dbf835d82012-09-11 18:23:0923#include "ui/aura/test/test_window_delegate.h"
24#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2625#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2626#include "ui/aura/window_event_dispatcher.h"
[email protected]dbf835d82012-09-11 18:23:0927#include "ui/aura/window_tracker.h"
[email protected]cd9f71d2014-03-20 21:54:2128#include "ui/events/test/test_event_handler.h"
[email protected]647b4842013-12-12 14:24:2429#include "ui/keyboard/keyboard_controller_proxy.h"
[email protected]eff4c7f2013-08-13 01:45:5030#include "ui/keyboard/keyboard_switches.h"
[email protected]39e95212014-04-23 20:00:0131#include "ui/keyboard/keyboard_util.h"
[email protected]f1853122012-06-27 16:21:2632#include "ui/views/controls/menu/menu_controller.h"
33#include "ui/views/widget/widget.h"
34#include "ui/views/widget/widget_delegate.h"
35
[email protected]2ee2f5d2013-01-10 23:37:1636using aura::Window;
37using views::Widget;
38
[email protected]f1853122012-06-27 16:21:2639namespace ash {
40namespace {
41
42class TestDelegate : public views::WidgetDelegateView {
43 public:
44 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
45 virtual ~TestDelegate() {}
46
47 // Overridden from views::WidgetDelegate:
48 virtual views::View* GetContentsView() OVERRIDE {
49 return this;
50 }
51
52 virtual ui::ModalType GetModalType() const OVERRIDE {
53 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
54 }
55
56 private:
57 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3358
[email protected]f1853122012-06-27 16:21:2659 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
60};
61
[email protected]792b9b12012-12-11 03:53:2762class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
63 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0964 public:
65 DeleteOnBlurDelegate() : window_(NULL) {}
66 virtual ~DeleteOnBlurDelegate() {}
67
[email protected]792b9b12012-12-11 03:53:2768 void SetWindow(aura::Window* window) {
69 window_ = window;
70 aura::client::SetFocusChangeObserver(window_, this);
71 }
[email protected]dbf835d82012-09-11 18:23:0972
[email protected]869f6352012-12-06 20:47:1773 private:
[email protected]dbf835d82012-09-11 18:23:0974 // aura::test::TestWindowDelegate overrides:
75 virtual bool CanFocus() OVERRIDE {
76 return true;
77 }
[email protected]dbf835d82012-09-11 18:23:0978
[email protected]792b9b12012-12-11 03:53:2779 // aura::client::FocusChangeObserver implementation:
80 virtual void OnWindowFocused(aura::Window* gained_focus,
81 aura::Window* lost_focus) OVERRIDE {
82 if (window_ == lost_focus)
83 delete window_;
[email protected]869f6352012-12-06 20:47:1784 }
85
[email protected]dbf835d82012-09-11 18:23:0986 aura::Window* window_;
87
88 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
89};
90
[email protected]f1853122012-06-27 16:21:2691} // namespace
92
93namespace test {
[email protected]f1853122012-06-27 16:21:2694
[email protected]a2e6af12013-01-07 21:40:3595class RootWindowControllerTest : public test::AshTestBase {
96 public:
97 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
98 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
99 NULL, CurrentContext(), bounds);
100 widget->Show();
101 return widget;
102 }
103
104 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
105 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
106 new TestDelegate(true), CurrentContext(), bounds);
107 widget->Show();
108 return widget;
109 }
110
111 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
112 gfx::NativeWindow parent) {
113 views::Widget* widget =
114 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
115 parent,
116 bounds);
117 widget->Show();
118 return widget;
119 }
120
[email protected]c9390bd2013-11-08 20:33:13121 aura::Window* GetModalContainer(aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28122 return Shell::GetContainer(root_window,
123 ash::kShellWindowId_SystemModalContainer);
[email protected]a2e6af12013-01-07 21:40:35124 }
125};
[email protected]f1853122012-06-27 16:21:26126
[email protected]e75642a2013-06-12 17:21:18127TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
128 if (!SupportsMultipleDisplays())
129 return;
[email protected]2816c2462013-12-17 02:22:25130 // Windows origin should be doubled when moved to the 1st display.
131 UpdateDisplay("600x600,300x300");
[email protected]c9390bd2013-11-08 20:33:13132 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]093b8d642014-04-03 20:59:28133 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
134 ShelfLayoutManager* shelf_layout_manager =
[email protected]478c6c32013-03-09 02:50:58135 controller->GetShelfLayoutManager();
136 shelf_layout_manager->SetAutoHideBehavior(
137 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26138
139 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
140 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04141 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06142 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04143 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26144
145 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
146 maximized->Maximize();
147 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25148 EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString());
149 EXPECT_EQ("0,0 300x253",
[email protected]8c0ec432013-05-10 04:33:39150 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26151
152 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
153 minimized->Minimize();
154 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06155 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04156 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26157
[email protected]2816c2462013-12-17 02:22:25158 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100));
[email protected]f1853122012-06-27 16:21:26159 fullscreen->SetFullscreen(true);
160 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59161
[email protected]2816c2462013-12-17 02:22:25162 EXPECT_EQ("600,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04163 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25164 EXPECT_EQ("0,0 300x300",
[email protected]e2f64d102012-07-19 19:17:04165 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26166
[email protected]8f2f151412013-01-26 03:58:37167 views::Widget* unparented_control = new Widget;
168 Widget::InitParams params;
169 params.bounds = gfx::Rect(650, 10, 100, 100);
170 params.context = CurrentContext();
171 params.type = Widget::InitParams::TYPE_CONTROL;
172 unparented_control->Init(params);
173 EXPECT_EQ(root_windows[1],
174 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28175 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37176 unparented_control->GetNativeView()->parent()->id());
177
[email protected]95db9c12013-01-31 11:47:44178 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
[email protected]5b251f12013-12-19 01:50:05179 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
[email protected]95db9c12013-01-31 11:47:44180 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28181 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]95db9c12013-01-31 11:47:44182
[email protected]dbf835d82012-09-11 18:23:09183 // Make sure a window that will delete itself when losing focus
184 // will not crash.
185 aura::WindowTracker tracker;
186 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03187 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
188 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27189 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44190 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09191 tracker.Add(d2);
192
[email protected]f634dd32012-07-23 22:49:07193 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26194
[email protected]dbf835d82012-09-11 18:23:09195 // d2 must have been deleted.
196 EXPECT_FALSE(tracker.Contains(d2));
197
[email protected]f1853122012-06-27 16:21:26198 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25199 EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString());
200 EXPECT_EQ("100,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04201 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26202
[email protected]eefd51b22012-09-25 20:26:24203 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26204 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54205
206 // First clear fullscreen status, since both fullscreen and maximized windows
207 // share the same desktop workspace, which cancels the shelf status.
208 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26209 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20210 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04211 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20212 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04213 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26214
[email protected]2a64b0a2013-07-23 23:15:54215 // Set fullscreen to true. In that case the 3px inset becomes invisible so
216 // the maximized window can also use the area fully.
217 fullscreen->SetFullscreen(true);
218 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
219 EXPECT_EQ("0,0 600x600",
220 maximized->GetWindowBoundsInScreen().ToString());
221 EXPECT_EQ("0,0 600x600",
222 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
223
[email protected]f1853122012-06-27 16:21:26224 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]2816c2462013-12-17 02:22:25225 EXPECT_EQ("400,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04226 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26227
228 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
229 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06230 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04231 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06232 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04233 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06234
235 // Test if the restore bounds are correctly updated.
[email protected]a41b4e12013-09-20 04:36:34236 wm::GetWindowState(maximized->GetNativeView())->Restore();
[email protected]2816c2462013-12-17 02:22:25237 EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString());
238 EXPECT_EQ("200,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04239 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06240
241 fullscreen->SetFullscreen(false);
[email protected]2816c2462013-12-17 02:22:25242 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04243 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]2816c2462013-12-17 02:22:25244 EXPECT_EQ("500,20 100x100",
[email protected]e2f64d102012-07-19 19:17:04245 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8f2f151412013-01-26 03:58:37246
247 // Test if the unparented widget has moved.
248 EXPECT_EQ(root_windows[0],
249 unparented_control->GetNativeView()->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28250 EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
[email protected]8f2f151412013-01-26 03:58:37251 unparented_control->GetNativeView()->parent()->id());
[email protected]95db9c12013-01-31 11:47:44252
253 // Test if the panel has moved.
254 EXPECT_EQ(root_windows[0], panel->GetRootWindow());
[email protected]093b8d642014-04-03 20:59:28255 EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]f1853122012-06-27 16:21:26256}
257
[email protected]e75642a2013-06-12 17:21:18258TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
259 if (!SupportsMultipleDisplays())
260 return;
[email protected]1c3f7002013-01-21 18:46:05261
[email protected]f634dd32012-07-23 22:49:07262 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26263
[email protected]c9390bd2013-11-08 20:33:13264 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:26265 // Emulate virtual screen coordinate system.
266 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
267 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
268
269 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
270 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
271 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
272
273 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
274 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
275 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
276 modal->GetNativeView()));
277 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
278
279 aura::test::EventGenerator generator_1st(root_windows[0]);
280 generator_1st.ClickLeftButton();
281 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
282
[email protected]f634dd32012-07-23 22:49:07283 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26284 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
285 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
286 generator_1st.ClickLeftButton();
287 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
288}
289
[email protected]8674b312012-10-12 19:02:44290TEST_F(RootWindowControllerTest, ModalContainer) {
291 UpdateDisplay("600x600");
292 Shell* shell = Shell::GetInstance();
[email protected]093b8d642014-04-03 20:59:28293 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]8674b312012-10-12 19:02:44294 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29295 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45296 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28297 ->layout_manager(),
298 controller->GetSystemModalLayoutManager(NULL));
[email protected]8674b312012-10-12 19:02:44299
[email protected]3b162e12012-11-09 11:52:35300 views::Widget* session_modal_widget =
301 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45302 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28303 ->layout_manager(),
304 controller->GetSystemModalLayoutManager(
305 session_modal_widget->GetNativeView()));
[email protected]3b162e12012-11-09 11:52:35306
[email protected]fcb123d2013-04-17 15:58:49307 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44308 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29309 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]f5c9dbc2014-04-11 08:13:45310 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28311 ->layout_manager(),
312 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35313
[email protected]f5c9dbc2014-04-11 08:13:45314 aura::Window* lock_container =
315 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]3b162e12012-11-09 11:52:35316 views::Widget* lock_modal_widget =
317 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45318 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28319 ->layout_manager(),
320 controller->GetSystemModalLayoutManager(
321 lock_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45322 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28323 ->layout_manager(),
[email protected]3b162e12012-11-09 11:52:35324 controller->GetSystemModalLayoutManager(
325 session_modal_widget->GetNativeView()));
326
[email protected]fcb123d2013-04-17 15:58:49327 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44328}
329
[email protected]1b219922012-11-13 21:16:43330TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
331 UpdateDisplay("600x600");
332 Shell* shell = Shell::GetInstance();
333
334 // Configure login screen environment.
335 SetUserLoggedIn(false);
336 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29337 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41338 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49339 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43340
[email protected]093b8d642014-04-03 20:59:28341 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45342 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28343 ->layout_manager(),
344 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43345
[email protected]f5c9dbc2014-04-11 08:13:45346 aura::Window* lock_container =
347 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]1b219922012-11-13 21:16:43348 views::Widget* login_modal_widget =
349 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45350 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28351 ->layout_manager(),
352 controller->GetSystemModalLayoutManager(
353 login_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43354 login_modal_widget->Close();
355
356 // Configure user session environment.
357 SetUserLoggedIn(true);
358 SetSessionStarted(true);
359 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29360 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41361 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49362 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]f5c9dbc2014-04-11 08:13:45363 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28364 ->layout_manager(),
365 controller->GetSystemModalLayoutManager(NULL));
[email protected]1b219922012-11-13 21:16:43366
367 views::Widget* session_modal_widget =
368 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45369 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28370 ->layout_manager(),
371 controller->GetSystemModalLayoutManager(
372 session_modal_widget->GetNativeView()));
[email protected]1b219922012-11-13 21:16:43373}
374
[email protected]a44afbbd2013-07-24 21:49:35375TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
376 UpdateDisplay("600x600");
377 Shell* shell = Shell::GetInstance();
[email protected]093b8d642014-04-03 20:59:28378 RootWindowController* controller = shell->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45379 aura::Window* lock_container =
380 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]a44afbbd2013-07-24 21:49:35381 for (int block_reason = FIRST_BLOCK_REASON;
382 block_reason < NUMBER_OF_BLOCK_REASONS;
383 ++block_reason) {
384 views::Widget* session_modal_widget =
385 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45386 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28387 ->layout_manager(),
388 controller->GetSystemModalLayoutManager(
389 session_modal_widget->GetNativeView()));
[email protected]f5c9dbc2014-04-11 08:13:45390 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28391 ->layout_manager(),
392 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35393 session_modal_widget->Close();
394
395 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
396
[email protected]f5c9dbc2014-04-11 08:13:45397 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28398 ->layout_manager(),
399 controller->GetSystemModalLayoutManager(NULL));
[email protected]a44afbbd2013-07-24 21:49:35400
401 views::Widget* lock_modal_widget =
402 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
403 lock_container);
[email protected]f5c9dbc2014-04-11 08:13:45404 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28405 ->layout_manager(),
[email protected]a44afbbd2013-07-24 21:49:35406 controller->GetSystemModalLayoutManager(
407 lock_modal_widget->GetNativeView()));
408
409 session_modal_widget =
410 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
[email protected]f5c9dbc2014-04-11 08:13:45411 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer)
[email protected]093b8d642014-04-03 20:59:28412 ->layout_manager(),
413 controller->GetSystemModalLayoutManager(
414 session_modal_widget->GetNativeView()));
[email protected]a44afbbd2013-07-24 21:49:35415 session_modal_widget->Close();
416
417 lock_modal_widget->Close();
418 UnblockUserSession();
419 }
420}
421
[email protected]2c9171d22013-12-10 21:55:10422TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) {
[email protected]2ee2f5d2013-01-10 23:37:16423 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28424 RootWindowController* controller =
[email protected]2ee2f5d2013-01-10 23:37:16425 Shell::GetInstance()->GetPrimaryRootWindowController();
426
[email protected]700849f2013-04-30 17:49:20427 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16428 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20429 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
430 w2->SetFullscreen(true);
431 // |w3| is a transient child of |w2|.
432 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
433 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16434
[email protected]2c9171d22013-12-10 21:55:10435 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
[email protected]e3bc88e2013-09-06 06:22:06436 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20437 w3->Activate();
[email protected]2c9171d22013-12-10 21:55:10438 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16439
[email protected]2c9171d22013-12-10 21:55:10440 // If the topmost window is not fullscreen, it returns NULL.
[email protected]700849f2013-04-30 17:49:20441 w1->Activate();
[email protected]2c9171d22013-12-10 21:55:10442 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
443 w1->Close();
444 w3->Close();
[email protected]e3bc88e2013-09-06 06:22:06445
[email protected]2c9171d22013-12-10 21:55:10446 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
447 // NULL.
[email protected]e3bc88e2013-09-06 06:22:06448 w2->Activate();
[email protected]2c9171d22013-12-10 21:55:10449 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
450 w2->Minimize();
451 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16452}
453
[email protected]2c5db9e2014-02-27 13:58:14454TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) {
455 if (!SupportsMultipleDisplays())
456 return;
457
458 UpdateDisplay("600x600,600x600");
459 Shell::RootWindowControllerList controllers =
460 Shell::GetInstance()->GetAllRootWindowControllers();
461
462 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
463 w1->Maximize();
464 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
465 w2->SetFullscreen(true);
466 Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
467
468 EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45469 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14470 EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45471 controllers[0]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14472 EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(),
[email protected]f5c9dbc2014-04-11 08:13:45473 controllers[1]->GetRootWindow());
[email protected]2c5db9e2014-02-27 13:58:14474
475 w1->Activate();
476 EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode());
477 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
478
479 w2->Activate();
480 EXPECT_EQ(w2->GetNativeWindow(),
481 controllers[0]->GetWindowForFullscreenMode());
482 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
483
484 // Verify that the first root window controller remains in fullscreen mode
485 // when a window on the other display is activated.
486 w3->Activate();
487 EXPECT_EQ(w2->GetNativeWindow(),
488 controllers[0]->GetWindowForFullscreenMode());
489 EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
490}
491
[email protected]82ced2352013-07-19 20:49:06492// Test that user session window can't be focused if user session blocked by
493// some overlapping UI.
494TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
495 UpdateDisplay("600x600");
[email protected]093b8d642014-04-03 20:59:28496 RootWindowController* controller =
[email protected]82ced2352013-07-19 20:49:06497 Shell::GetInstance()->GetPrimaryRootWindowController();
[email protected]f5c9dbc2014-04-11 08:13:45498 aura::Window* lock_container =
499 controller->GetContainer(kShellWindowId_LockScreenContainer);
[email protected]82ced2352013-07-19 20:49:06500 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
501 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
502 lock_window->Show();
503 aura::Window* session_window =
504 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
505 session_window->Show();
506
[email protected]a44afbbd2013-07-24 21:49:35507 for (int block_reason = FIRST_BLOCK_REASON;
508 block_reason < NUMBER_OF_BLOCK_REASONS;
509 ++block_reason) {
510 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
511 lock_window->Focus();
512 EXPECT_TRUE(lock_window->HasFocus());
513 session_window->Focus();
514 EXPECT_FALSE(session_window->HasFocus());
515 UnblockUserSession();
516 }
[email protected]82ced2352013-07-19 20:49:06517}
518
[email protected]0fbfa972013-10-02 19:23:33519// Tracks whether OnWindowDestroying() has been invoked.
520class DestroyedWindowObserver : public aura::WindowObserver {
521 public:
522 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
523 virtual ~DestroyedWindowObserver() {
524 Shutdown();
525 }
526
527 void SetWindow(Window* window) {
528 window_ = window;
529 window->AddObserver(this);
530 }
531
532 bool destroyed() const { return destroyed_; }
533
534 // WindowObserver overrides:
535 virtual void OnWindowDestroying(Window* window) OVERRIDE {
536 destroyed_ = true;
537 Shutdown();
538 }
539
540 private:
541 void Shutdown() {
542 if (!window_)
543 return;
544 window_->RemoveObserver(this);
545 window_ = NULL;
546 }
547
548 bool destroyed_;
549 Window* window_;
550
551 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
552};
553
554// Verifies shutdown doesn't delete windows that are not owned by the parent.
555TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
556 DestroyedWindowObserver observer1;
557 aura::test::TestWindowDelegate delegate1;
558 aura::Window* window1 = new aura::Window(&delegate1);
[email protected]5b251f12013-12-19 01:50:05559 window1->SetType(ui::wm::WINDOW_TYPE_CONTROL);
[email protected]0fbfa972013-10-02 19:23:33560 window1->set_owned_by_parent(false);
561 observer1.SetWindow(window1);
[email protected]52b02a72014-01-08 21:41:50562 window1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]e3225e02013-10-23 20:44:37563 aura::client::ParentWindowWithContext(
564 window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
[email protected]0fbfa972013-10-02 19:23:33565
566 DestroyedWindowObserver observer2;
567 aura::Window* window2 = new aura::Window(NULL);
568 window2->set_owned_by_parent(false);
569 observer2.SetWindow(window2);
[email protected]52b02a72014-01-08 21:41:50570 window2->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]0fbfa972013-10-02 19:23:33571 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
572
573 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
574
575 ASSERT_FALSE(observer1.destroyed());
576 delete window1;
577
578 ASSERT_FALSE(observer2.destroyed());
579 delete window2;
580}
581
[email protected]cf6fea22013-08-07 14:24:01582typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
583
584// Make sure that an event handler exists for entire display area.
585TEST_F(NoSessionRootWindowControllerTest, Event) {
[email protected]bf9cdb362013-10-25 19:22:45586 aura::Window* root = Shell::GetPrimaryRootWindow();
[email protected]cf6fea22013-08-07 14:24:01587 const gfx::Size size = root->bounds().size();
588 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0));
589 EXPECT_TRUE(event_target);
590 EXPECT_EQ(event_target,
591 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
592 EXPECT_EQ(event_target,
593 root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
594 EXPECT_EQ(event_target,
595 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
596 EXPECT_EQ(event_target,
597 root->GetEventHandlerForPoint(
598 gfx::Point(size.width() - 1, size.height() - 1)));
599}
600
[email protected]602022b2014-03-31 17:07:31601class VirtualKeyboardRootWindowControllerTest : public RootWindowControllerTest
602{
[email protected]eff4c7f2013-08-13 01:45:50603 public:
604 VirtualKeyboardRootWindowControllerTest() {};
605 virtual ~VirtualKeyboardRootWindowControllerTest() {};
606
607 virtual void SetUp() OVERRIDE {
608 CommandLine::ForCurrentProcess()->AppendSwitch(
609 keyboard::switches::kEnableVirtualKeyboard);
610 test::AshTestBase::SetUp();
[email protected]24ca45d2013-10-25 03:37:44611 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
[email protected]a0b3fb882014-04-07 19:26:03612 keyboard::KeyboardController::GetInstance());
[email protected]eff4c7f2013-08-13 01:45:50613 }
614
615 private:
616 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
617};
618
[email protected]b6ba05d902013-10-04 21:38:45619// Test for http://crbug.com/297858. Virtual keyboard container should only show
620// on primary root window.
621TEST_F(VirtualKeyboardRootWindowControllerTest,
622 VirtualKeyboardOnPrimaryRootWindowOnly) {
623 if (!SupportsMultipleDisplays())
624 return;
625
626 UpdateDisplay("500x500,500x500");
627
[email protected]c9390bd2013-11-08 20:33:13628 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]bf9cdb362013-10-25 19:22:45629 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
630 aura::Window* secondary_root_window =
[email protected]b6ba05d902013-10-04 21:38:45631 root_windows[0] == primary_root_window ?
632 root_windows[1] : root_windows[0];
633
[email protected]093b8d642014-04-03 20:59:28634 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
635 kShellWindowId_VirtualKeyboardContainer));
636 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
637 kShellWindowId_VirtualKeyboardContainer));
[email protected]b6ba05d902013-10-04 21:38:45638}
639
[email protected]eff4c7f2013-08-13 01:45:50640// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
641// events at blocked user session.
642TEST_F(VirtualKeyboardRootWindowControllerTest,
643 ClickVirtualKeyboardInBlockedWindow) {
[email protected]bf9cdb362013-10-25 19:22:45644 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28645 aura::Window* keyboard_container =
646 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]eff4c7f2013-08-13 01:45:50647 ASSERT_TRUE(keyboard_container);
648 keyboard_container->Show();
649
[email protected]a0b3fb882014-04-07 19:26:03650 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]647b4842013-12-12 14:24:24651 proxy()->GetKeyboardWindow();
652 keyboard_container->AddChild(keyboard_window);
[email protected]183e28d2014-01-20 18:18:02653 keyboard_window->set_owned_by_parent(false);
[email protected]647b4842013-12-12 14:24:24654 keyboard_window->SetBounds(gfx::Rect());
[email protected]eff4c7f2013-08-13 01:45:50655 keyboard_window->Show();
[email protected]647b4842013-12-12 14:24:24656
[email protected]cd9f71d2014-03-20 21:54:21657 ui::test::TestEventHandler* handler = new ui::test::TestEventHandler;
[email protected]647b4842013-12-12 14:24:24658 root_window->SetEventFilter(handler);
659
660 aura::test::EventGenerator event_generator(root_window, keyboard_window);
[email protected]eff4c7f2013-08-13 01:45:50661 event_generator.ClickLeftButton();
662 int expected_mouse_presses = 1;
[email protected]647b4842013-12-12 14:24:24663 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50664
665 for (int block_reason = FIRST_BLOCK_REASON;
666 block_reason < NUMBER_OF_BLOCK_REASONS;
667 ++block_reason) {
668 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
669 event_generator.ClickLeftButton();
670 expected_mouse_presses++;
[email protected]647b4842013-12-12 14:24:24671 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50672 UnblockUserSession();
673 }
674}
675
[email protected]45c66672013-10-01 22:48:56676// Test for http://crbug.com/299787. RootWindowController should delete
677// the old container since the keyboard controller creates a new window in
678// GetWindowContainer().
679TEST_F(VirtualKeyboardRootWindowControllerTest,
680 DeleteOldContainerOnVirtualKeyboardInit) {
[email protected]1025937e2014-02-13 01:25:50681 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28682 aura::Window* keyboard_container =
683 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]45c66672013-10-01 22:48:56684 ASSERT_TRUE(keyboard_container);
685 // Track the keyboard container window.
686 aura::WindowTracker tracker;
687 tracker.Add(keyboard_container);
[email protected]51f438112013-11-18 19:32:50688 // Mock a login user profile change to reinitialize the keyboard.
689 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
[email protected]45c66672013-10-01 22:48:56690 // keyboard_container should no longer be present.
691 EXPECT_FALSE(tracker.Contains(keyboard_container));
692}
693
[email protected]1025937e2014-02-13 01:25:50694// Test for crbug.com/342524. After user login, the work space should restore to
695// full screen.
696TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
697 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28698 aura::Window* keyboard_container =
699 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]1025937e2014-02-13 01:25:50700 keyboard_container->Show();
701 keyboard::KeyboardController* controller =
[email protected]a0b3fb882014-04-07 19:26:03702 keyboard::KeyboardController::GetInstance();
[email protected]1025937e2014-02-13 01:25:50703 aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow();
704 keyboard_container->AddChild(keyboard_window);
705 keyboard_window->set_owned_by_parent(false);
[email protected]39e95212014-04-23 20:00:01706 keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
707 keyboard_container->bounds(), 100));
[email protected]1025937e2014-02-13 01:25:50708 keyboard_window->Show();
709
710 gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
711
712 // Notify keyboard bounds changing.
713 controller->NotifyKeyboardBoundsChanging(
714 controller->proxy()->GetKeyboardWindow()->bounds());
715
716 gfx::Rect after = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
717 EXPECT_LT(after, before);
718
719 // Mock a login user profile change to reinitialize the keyboard.
720 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
721 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before);
722}
723
[email protected]602022b2014-03-31 17:07:31724// Ensure that system modal dialogs do not block events targeted at the virtual
725// keyboard.
726TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
727 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]093b8d642014-04-03 20:59:28728 aura::Window* keyboard_container =
729 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
[email protected]602022b2014-03-31 17:07:31730 ASSERT_TRUE(keyboard_container);
731 keyboard_container->Show();
732
[email protected]a0b3fb882014-04-07 19:26:03733 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()->
[email protected]602022b2014-03-31 17:07:31734 proxy()->GetKeyboardWindow();
735 keyboard_container->AddChild(keyboard_window);
736 keyboard_window->set_owned_by_parent(false);
[email protected]39e95212014-04-23 20:00:01737 keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
738 keyboard_container->bounds(), 100));
[email protected]602022b2014-03-31 17:07:31739 ui::test::TestEventHandler* handler = new ui::test::TestEventHandler;
740 root_window->SetEventFilter(handler);
741 aura::test::EventGenerator root_window_event_generator(root_window);
742 aura::test::EventGenerator keyboard_event_generator(root_window,
743 keyboard_window);
744
745 views::Widget* modal_widget =
746 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
747
748 // Verify that mouse events to the root window are block with a visble modal
749 // dialog.
750 root_window_event_generator.ClickLeftButton();
751 EXPECT_EQ(0, handler->num_mouse_events());
752
753 // Verify that event dispatch to the virtual keyboard is unblocked.
754 keyboard_event_generator.ClickLeftButton();
755 EXPECT_EQ(1, handler->num_mouse_events() / 2);
756
757 modal_widget->Close();
758
759 // Verify that mouse events are now unblocked to the root window.
760 root_window_event_generator.ClickLeftButton();
761 EXPECT_EQ(2, handler->num_mouse_events() / 2);
762}
763
[email protected]f1853122012-06-27 16:21:26764} // namespace test
765} // namespace ash