Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: ash/root_window_controller_unittest.cc

Issue 10659006: move windows when disconnecting secondary monitors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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/monitor/multi_monitor_manager.h"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_util.h"
11 #include "ui/aura/env.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/views/widget/widget.h"
16 #include "ui/views/widget/widget_delegate.h"
17
18 namespace ash {
19 namespace {
20
21 class ModalWindow : public views::WidgetDelegateView {
22 public:
23 ModalWindow() {}
24 virtual ~ModalWindow() {}
25
26 // Overridden from views::WidgetDelegate:
27 virtual views::View* GetContentsView() OVERRIDE {
28 return this;
29 }
30 virtual ui::ModalType GetModalType() const OVERRIDE {
31 return ui::MODAL_TYPE_SYSTEM;
32 }
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(ModalWindow);
36 };
37
38 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
39 views::Widget* widget = views::Widget::CreateWindowWithBounds(NULL, bounds);
40 widget->Show();
41 return widget;
42 }
43
44 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
45 views::Widget* widget =
46 views::Widget::CreateWindowWithBounds(new ModalWindow(), bounds);
47 widget->Show();
48 return widget;
49 }
50
51 aura::Window* GetModalContainer(aura::RootWindow* root_window) {
52 return Shell::GetContainer(
53 root_window,
54 ash::internal::kShellWindowId_SystemModalContainer);
55 }
56
57 } // namespace
58
59 namespace test {
60 class RootWindowControllerTest : public test::AshTestBase {
61 public:
62 RootWindowControllerTest() {}
63 virtual ~RootWindowControllerTest() {}
64
65 virtual void SetUp() OVERRIDE {
66 internal::MonitorController::SetExtendedDesktopEnabled(true);
67 internal::MonitorController::SetVirtualScreenCoordinatesEnabled(true);
68 AshTestBase::SetUp();
69 }
70
71 virtual void TearDown() OVERRIDE {
72 AshTestBase::TearDown();
73 internal::MonitorController::SetExtendedDesktopEnabled(false);
74 internal::MonitorController::SetVirtualScreenCoordinatesEnabled(false);
75 }
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(RootWindowControllerTest);
79 };
80
81 TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
82 UpdateMonitor("0+0-600x600,600+0-500x500");
83 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
84 // Emulate virtual screen coordinate system.
85 root_windows[0]->SetBounds(gfx::Rect(0, 0, 600, 600));
86 root_windows[1]->SetBounds(gfx::Rect(600, 0, 500, 500));
87
88 // TODO(oshima): Creating minimized window here and move causes
89 // maximized window to report 500x500 after move. It looks working
90 // when tested using ash (the window is maximzied on the primary
91 // display), so it could be just returning false value. Investigate
92 // why.
oshima 2012/06/25 21:34:09 Scott, do you have any clue what's causing this? I
sky 2012/06/25 22:05:14 I don't know exactly what the bug is. The code sho
oshima 2012/06/25 22:42:28 Never miond. I rewrite the test and it seems to be
93
94 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
95 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
96 EXPECT_EQ("100x100", normal->GetWindowScreenBounds().size().ToString());
97
98 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
99 maximized->Maximize();
100 EXPECT_EQ("500x500", maximized->GetWindowScreenBounds().size().ToString());
101 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
102
103 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
104 fullscreen->SetFullscreen(true);
105 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
106 EXPECT_EQ("500x500", fullscreen->GetWindowScreenBounds().size().ToString());
107
108 UpdateMonitor("0+0-600x600");
109
110 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
111 EXPECT_EQ("100x100", normal->GetWindowScreenBounds().size().ToString());
112
113 // Maximized area on primary monitor has 2px (given as
114 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
115 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
116 EXPECT_EQ("600x598", maximized->GetWindowScreenBounds().size().ToString());
117
118 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
119 EXPECT_TRUE(fullscreen->IsFullscreen());
120 EXPECT_EQ("600x600", fullscreen->GetWindowScreenBounds().size().ToString());
121 }
122
123 TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
124 UpdateMonitor("0+0-500x500,500+0-500x500");
125
126 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
127 // Emulate virtual screen coordinate system.
128 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
129 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
130
131 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
132 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
133 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
134
135 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
136 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
137 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
138 modal->GetNativeView()));
139 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
140
141 aura::test::EventGenerator generator_1st(root_windows[0]);
142 generator_1st.ClickLeftButton();
143 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
144
145 UpdateMonitor("0+0-500x500");
146 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
147 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
148 generator_1st.ClickLeftButton();
149 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
150 }
151
152 } // namespace test
153 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698