Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: ash/wm/workspace/workspace_layout_manager_unittest.cc

Issue 22394003: Maximize window in the display to be restored. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check null Created 7 years, 4 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
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/property_util.h" 13 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
15 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/test/test_windows.h" 17 #include "ui/aura/test/test_windows.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/gfx/insets.h" 19 #include "ui/gfx/insets.h"
20 #include "ui/views/widget/widget.h"
21 #include "ui/views/widget/widget_delegate.h"
20 22
21 namespace ash { 23 namespace ash {
24 namespace {
22 25
23 namespace { 26 class MaximizeDelegateView : public views::WidgetDelegateView {
27 public:
28 MaximizeDelegateView(const gfx::Rect& initial_bounds)
29 : initial_bounds_(initial_bounds) {
30 }
31 virtual ~MaximizeDelegateView() {}
32
33 virtual bool GetSavedWindowPlacement(
34 gfx::Rect* bounds,
35 ui::WindowShowState* show_state) const OVERRIDE {
36 *bounds = initial_bounds_;
37 *show_state = ui::SHOW_STATE_MAXIMIZED;
38 return true;
39 }
40
41 private:
42 const gfx::Rect initial_bounds_;
43
44 DISALLOW_COPY_AND_ASSIGN(MaximizeDelegateView);
45 };
46
47 } // namespace
24 48
25 typedef test::AshTestBase WorkspaceLayoutManagerTest; 49 typedef test::AshTestBase WorkspaceLayoutManagerTest;
26 50
27 // Verifies that a window containing a restore coordinate will be restored to 51 // Verifies that a window containing a restore coordinate will be restored to
28 // to the size prior to minimize, keeping the restore rectangle in tact (if 52 // to the size prior to minimize, keeping the restore rectangle in tact (if
29 // there is one). 53 // there is one).
30 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { 54 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) {
31 scoped_ptr<aura::Window> window( 55 scoped_ptr<aura::Window> window(
32 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 56 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
33 gfx::Rect bounds(10, 15, 25, 35); 57 gfx::Rect bounds(10, 15, 25, 35);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 ASSERT_EQ("0,0 30x40", window->bounds().ToString()); 115 ASSERT_EQ("0,0 30x40", window->bounds().ToString());
92 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 116 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
93 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); 117 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds());
94 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40)); 118 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40));
95 wm::RestoreWindow(window.get()); 119 wm::RestoreWindow(window.get());
96 EXPECT_TRUE( 120 EXPECT_TRUE(
97 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); 121 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
98 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); 122 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString());
99 } 123 }
100 124
125 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {
126 if (!SupportsMultipleDisplays())
127 return;
128 UpdateDisplay("300x400,400x500");
129
130 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
131
132 scoped_ptr<aura::Window> window(
133 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
134 EXPECT_EQ(root_windows[0], window->GetRootWindow());
135
136 SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40));
137 // Maximize the window in 2nd display as the restore bounds
138 // is inside 2nd display.
139 wm::MaximizeWindow(window.get());
140 EXPECT_EQ(root_windows[1], window->GetRootWindow());
141 EXPECT_EQ("300,0 400x452", window->GetBoundsInScreen().ToString());
142
143 wm::RestoreWindow(window.get());
144 EXPECT_EQ(root_windows[1], window->GetRootWindow());
145 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
146
147 // If the restore bounds intersects with the current display,
148 // don't move.
149 SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40));
150 wm::MaximizeWindow(window.get());
151 EXPECT_EQ(root_windows[1], window->GetRootWindow());
152 EXPECT_EQ("300,0 400x452", window->GetBoundsInScreen().ToString());
153
154 wm::RestoreWindow(window.get());
155 EXPECT_EQ(root_windows[1], window->GetRootWindow());
156 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString());
157
158 // Restoring widget state.
159 scoped_ptr<views::Widget> w1(new views::Widget);
160 views::Widget::InitParams params;
161 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
162 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
163 params.context = root_windows[0];
164 w1->Init(params);
165 w1->Show();
166 EXPECT_TRUE(w1->IsMaximized());
167 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
168 EXPECT_EQ("300,0 400x452", w1->GetWindowBoundsInScreen().ToString());
169 w1->Restore();
170 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
171 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString());
172 }
173
174 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) {
175 if (!SupportsMultipleDisplays())
176 return;
177 UpdateDisplay("300x400,400x500");
178
179 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
180
181 scoped_ptr<aura::Window> window(
182 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
183 EXPECT_EQ(root_windows[0], window->GetRootWindow());
184
185 SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40));
186 // Maximize the window in 2nd display as the restore bounds
187 // is inside 2nd display.
188 window->SetProperty(aura::client::kShowStateKey,
189 ui::SHOW_STATE_FULLSCREEN);
190 EXPECT_EQ(root_windows[1], window->GetRootWindow());
191 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
192
193 wm::RestoreWindow(window.get());
194 EXPECT_EQ(root_windows[1], window->GetRootWindow());
195 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
196
197 // If the restore bounds intersects with the current display,
198 // don't move.
199 SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40));
200 window->SetProperty(aura::client::kShowStateKey,
201 ui::SHOW_STATE_FULLSCREEN);
202 EXPECT_EQ(root_windows[1], window->GetRootWindow());
203 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
204
205 wm::RestoreWindow(window.get());
206 EXPECT_EQ(root_windows[1], window->GetRootWindow());
207 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString());
208 }
209
101 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. 210 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver.
102 // This code mirrors what BrowserFrameAura does. In particular when this code 211 // This code mirrors what BrowserFrameAura does. In particular when this code
103 // sees the window was maximized it changes the bounds of a secondary 212 // sees the window was maximized it changes the bounds of a secondary
104 // window. The secondary window mirrors the status window. 213 // window. The secondary window mirrors the status window.
105 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { 214 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver {
106 public: 215 public:
107 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {} 216 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {}
108 217
109 void set_window(aura::Window* window) { window_ = window; } 218 void set_window(aura::Window* window) { window_ = window; }
110 219
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), 352 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
244 window->bounds().ToString()); 353 window->bounds().ToString());
245 354
246 // Directly setting the bounds triggers a slightly different code path. Verify 355 // Directly setting the bounds triggers a slightly different code path. Verify
247 // that too. 356 // that too.
248 window->SetBounds(window_bounds); 357 window->SetBounds(window_bounds);
249 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), 358 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
250 window->bounds().ToString()); 359 window->bounds().ToString());
251 } 360 }
252 361
253 } // namespace
254 } // namespace ash 362 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698