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

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

Issue 11293014: Renames Workspace*2 -> Workspace*. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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/wm/workspace/workspace_layout_manager2.h"
6
7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/property_util.h"
11 #include "ash/wm/shelf_layout_manager.h"
12 #include "ash/wm/window_util.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h"
16 #include "ui/gfx/insets.h"
17
18 namespace ash {
19
20 namespace {
21
22 class WorkspaceLayoutManager2Test : public test::AshTestBase {
23 public:
24 WorkspaceLayoutManager2Test() {}
25 virtual ~WorkspaceLayoutManager2Test() {}
26
27 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
28 return aura::test::CreateTestWindowWithBounds(bounds, NULL);
29 }
30
31 private:
32 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager2Test);
33 };
34
35 // Verifies that a window containing a restore coordinate will be restored to
36 // to the size prior to minimize, keeping the restore rectangle in tact (if
37 // there is one).
38 TEST_F(WorkspaceLayoutManager2Test, RestoreFromMinimizeKeepsRestore) {
39 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
40 gfx::Rect bounds(10, 15, 25, 35);
41 window->SetBounds(bounds);
42 SetRestoreBoundsInScreen(window.get(), gfx::Rect(0, 0, 100, 100));
43 wm::MinimizeWindow(window.get());
44 wm::RestoreWindow(window.get());
45 EXPECT_EQ("0,0 100x100", GetRestoreBoundsInScreen(window.get())->ToString());
46 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString());
47 }
48
49 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver.
50 // This code mirrors what BrowserFrameAura does. In particular when this code
51 // sees the window was maximized it changes the bounds of a secondary
52 // window. The secondary window mirrors the status window.
53 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver {
54 public:
55 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {}
56
57 void set_window(aura::Window* window) { window_ = window; }
58
59 virtual void OnWindowPropertyChanged(aura::Window* window,
60 const void* key,
61 intptr_t old) {
62 if (!window_)
63 return;
64
65 if (wm::IsWindowMaximized(window)) {
66 aura::Window* w = window_;
67 window_ = NULL;
68
69 gfx::Rect shelf_bounds(
70 Shell::GetPrimaryRootWindowController()->shelf()->GetIdealBounds());
71 const gfx::Rect& window_bounds(w->bounds());
72 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1,
73 window_bounds.width(), window_bounds.height()));
74 }
75 }
76
77 private:
78 aura::Window* window_;
79
80 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver);
81 };
82
83 // Creates a window, maximized the window and from within the maximized
84 // notification sets the bounds of a window to overlap the shelf. Verifies this
85 // doesn't effect the restore bounds.
86 TEST_F(WorkspaceLayoutManager2Test, DontClobberRestoreBounds) {
87 DontClobberRestoreBoundsWindowObserver window_observer;
88 scoped_ptr<aura::Window> window(new aura::Window(NULL));
89 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
90 window->Init(ui::LAYER_TEXTURED);
91 window->SetBounds(gfx::Rect(10, 20, 30, 40));
92 // NOTE: for this test to exercise the failure the observer needs to be added
93 // before the parent set. This mimics what BrowserFrameAura does.
94 window->AddObserver(&window_observer);
95 window->SetParent(NULL);
96 window->Show();
97 ash::wm::ActivateWindow(window.get());
98
99 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(12, 20, 30, 40)));
100 window->AddTransientChild(window2.get());
101 window2->Show();
102
103 window_observer.set_window(window2.get());
104 wm::MaximizeWindow(window.get());
105 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString());
106 window->RemoveObserver(&window_observer);
107 }
108
109 // Verifies when a window is maximized all descendant windows have a size.
110 TEST_F(WorkspaceLayoutManager2Test, ChildBoundsResetOnMaximize) {
111 scoped_ptr<aura::Window> window(
112 CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
113 window->Show();
114 ash::wm::ActivateWindow(window.get());
115 scoped_ptr<aura::Window> child_window(
116 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8),
117 window.get()));
118 child_window->Show();
119 ash::wm::MaximizeWindow(window.get());
120 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString());
121 }
122
123 TEST_F(WorkspaceLayoutManager2Test, WindowShouldBeOnScreenWhenAdded) {
124 // Normal window bounds shouldn't be changed.
125 gfx::Rect window_bounds(100, 100, 200, 200);
126 scoped_ptr<aura::Window> window(CreateTestWindow(window_bounds));
127 EXPECT_EQ(window_bounds, window->bounds());
128
129 // If the window is out of the workspace, it would be moved on screen.
130 gfx::Rect root_window_bounds =
131 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds();
132 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height());
133 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds));
134 scoped_ptr<aura::Window> out_window(CreateTestWindow(window_bounds));
135 EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
136 EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds));
137 }
138
139 // Verifies the size of a window is enforced to be smaller than the work area.
140 TEST_F(WorkspaceLayoutManager2Test, SizeToWorkArea) {
141 // Normal window bounds shouldn't be changed.
142 gfx::Size work_area(
143 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size());
144 const gfx::Rect window_bounds(
145 100, 101, work_area.width() + 1, work_area.height() + 2);
146 scoped_ptr<aura::Window> window(CreateTestWindow(window_bounds));
147 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
148 window->bounds().ToString());
149
150 // Directly setting the bounds triggers a slightly different code path. Verify
151 // that too.
152 window->SetBounds(window_bounds);
153 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
154 window->bounds().ToString());
155 }
156
157 } // namespace
158 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager2.cc ('k') | ash/wm/workspace/workspace_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698