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

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

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I think the content_unittests timeout on linux_aura is flake, but try to fix it anyway. 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
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_manager.h" 5 #include "ash/wm/workspace/workspace_manager.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 47 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
48 window->Init(ui::LAYER_TEXTURED); 48 window->Init(ui::LAYER_TEXTURED);
49 return window; 49 return window;
50 } 50 }
51 51
52 aura::Window* CreateTestWindow() { 52 aura::Window* CreateTestWindow() {
53 aura::Window* window = new aura::Window(NULL); 53 aura::Window* window = new aura::Window(NULL);
54 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 54 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
55 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 55 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
56 window->Init(ui::LAYER_TEXTURED); 56 window->Init(ui::LAYER_TEXTURED);
57 window->SetParent(NULL); 57 AddToRootWindow(window);
58 return window; 58 return window;
59 } 59 }
60 60
61 aura::Window* GetViewport() { 61 aura::Window* GetViewport() {
62 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), 62 return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
63 kShellWindowId_DefaultContainer); 63 kShellWindowId_DefaultContainer);
64 } 64 }
65 65
66 const std::vector<Workspace*>& workspaces() const { 66 const std::vector<Workspace*>& workspaces() const {
67 return manager_->workspaces_; 67 return manager_->workspaces_;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // workspace. 313 // workspace.
314 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); 314 w1->SetBounds(gfx::Rect(0, 0, 200, 500));
315 EXPECT_EQ(200, w1->bounds().width()); 315 EXPECT_EQ(200, w1->bounds().width());
316 EXPECT_EQ(500, w1->bounds().height()); 316 EXPECT_EQ(500, w1->bounds().height());
317 } 317 }
318 318
319 // Verifies the bounds is not altered when showing and grid is enabled. 319 // Verifies the bounds is not altered when showing and grid is enabled.
320 TEST_F(WorkspaceManagerTest, SnapToGrid) { 320 TEST_F(WorkspaceManagerTest, SnapToGrid) {
321 scoped_ptr<Window> w1(CreateTestWindowUnparented()); 321 scoped_ptr<Window> w1(CreateTestWindowUnparented());
322 w1->SetBounds(gfx::Rect(1, 6, 25, 30)); 322 w1->SetBounds(gfx::Rect(1, 6, 25, 30));
323 w1->SetParent(NULL); 323 AddToRootWindow(w1.get());
324 // We are not aligning this anymore this way. When the window gets shown 324 // We are not aligning this anymore this way. When the window gets shown
325 // the window is expected to be handled differently, but this cannot be 325 // the window is expected to be handled differently, but this cannot be
326 // tested with this test. So the result of this test should be that the 326 // tested with this test. So the result of this test should be that the
327 // bounds are exactly as passed in. 327 // bounds are exactly as passed in.
328 EXPECT_EQ("1,6 25x30", w1->bounds().ToString()); 328 EXPECT_EQ("1,6 25x30", w1->bounds().ToString());
329 } 329 }
330 330
331 // Assertions around a fullscreen window. 331 // Assertions around a fullscreen window.
332 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) { 332 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) {
333 scoped_ptr<Window> w1(CreateTestWindow()); 333 scoped_ptr<Window> w1(CreateTestWindow());
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 829
830 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 830 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
831 ASSERT_EQ("0 M2 active=1", StateString()); 831 ASSERT_EQ("0 M2 active=1", StateString());
832 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 832 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
833 833
834 // Create another transient child of |w1|. We do this unparented, set up the 834 // Create another transient child of |w1|. We do this unparented, set up the
835 // transient parent then set parent. This is how NativeWidgetAura does things 835 // transient parent then set parent. This is how NativeWidgetAura does things
836 // too. 836 // too.
837 scoped_ptr<Window> w3(CreateTestWindowUnparented()); 837 scoped_ptr<Window> w3(CreateTestWindowUnparented());
838 w1->AddTransientChild(w3.get()); 838 w1->AddTransientChild(w3.get());
839 w3->SetParent(NULL); 839 AddToRootWindow(w3.get());
840 w3->Show(); 840 w3->Show();
841 ASSERT_EQ("0 M3 active=1", StateString()); 841 ASSERT_EQ("0 M3 active=1", StateString());
842 842
843 // Minimize the window. All the transients are hidden as a result, so it ends 843 // Minimize the window. All the transients are hidden as a result, so it ends
844 // up in pending. 844 // up in pending.
845 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 845 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
846 ASSERT_EQ("0 P=M3 active=0", StateString()); 846 ASSERT_EQ("0 P=M3 active=0", StateString());
847 847
848 // Restore and everything should go back to the first workspace. 848 // Restore and everything should go back to the first workspace.
849 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 849 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 // . minimize a maximized window. 1019 // . minimize a maximized window.
1020 // . remove the window (which happens when switching displays). 1020 // . remove the window (which happens when switching displays).
1021 // . add the window back. 1021 // . add the window back.
1022 // . show the window and during the bounds change activate it. 1022 // . show the window and during the bounds change activate it.
1023 TEST_F(WorkspaceManagerTest, DontCrashOnChangeAndActivate) { 1023 TEST_F(WorkspaceManagerTest, DontCrashOnChangeAndActivate) {
1024 // Force the shelf 1024 // Force the shelf
1025 ShelfLayoutManager* shelf = shelf_layout_manager(); 1025 ShelfLayoutManager* shelf = shelf_layout_manager();
1026 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1026 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1027 1027
1028 DontCrashOnChangeAndActivateDelegate delegate; 1028 DontCrashOnChangeAndActivateDelegate delegate;
1029 scoped_ptr<Window> w1( 1029 scoped_ptr<Window> w1(new Window(&delegate));
1030 CreateTestWindowWithDelegate(&delegate, 1000, gfx::Rect(10, 11, 250, 251), 1030 w1->set_id(1000);
sky 2012/11/21 23:35:59 Doesn't this still work (well, removing the last a
1031 NULL)); 1031 w1->SetType(aura::client::WINDOW_TYPE_NORMAL);
1032 w1->Init(ui::LAYER_TEXTURED);
1033 w1->SetBounds(gfx::Rect(10, 11, 250, 251));
1034 w1->SetProperty(aura::client::kCanMaximizeKey, true);
1035 AddToRootWindow(w1.get());
1036
1032 w1->Show(); 1037 w1->Show();
1033 wm::ActivateWindow(w1.get()); 1038 wm::ActivateWindow(w1.get());
1034 wm::MaximizeWindow(w1.get()); 1039 wm::MaximizeWindow(w1.get());
1035 wm::MinimizeWindow(w1.get()); 1040 wm::MinimizeWindow(w1.get());
1036 1041
1037 w1->parent()->RemoveChild(w1.get()); 1042 w1->parent()->RemoveChild(w1.get());
1038 1043
1039 // Do this so that when we Show() the window a resize occurs and we make the 1044 // Do this so that when we Show() the window a resize occurs and we make the
1040 // window active. 1045 // window active.
1041 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1046 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1042 1047
1043 w1->SetParent(NULL); 1048 AddToRootWindow(w1.get());
1044 delegate.set_window(w1.get()); 1049 delegate.set_window(w1.get());
1045 w1->Show(); 1050 w1->Show();
1046 } 1051 }
1047 1052
1048 // Verifies a window with a transient parent not managed by workspace works. 1053 // Verifies a window with a transient parent not managed by workspace works.
1049 TEST_F(WorkspaceManagerTest, TransientParent) { 1054 TEST_F(WorkspaceManagerTest, TransientParent) {
1050 // Normal window with no transient parent. 1055 // Normal window with no transient parent.
1051 scoped_ptr<Window> w2(CreateTestWindow()); 1056 scoped_ptr<Window> w2(CreateTestWindow());
1052 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); 1057 w2->SetBounds(gfx::Rect(10, 11, 250, 251));
1053 w2->Show(); 1058 w2->Show();
1054 wm::ActivateWindow(w2.get()); 1059 wm::ActivateWindow(w2.get());
1055 1060
1056 // Window with a transient parent. We set the transient parent to the root, 1061 // Window with a transient parent. We set the transient parent to the root,
1057 // which would never happen but is enough to exercise the bug. 1062 // which would never happen but is enough to exercise the bug.
1058 scoped_ptr<Window> w1(CreateTestWindowUnparented()); 1063 scoped_ptr<Window> w1(CreateTestWindowUnparented());
1059 Shell::GetInstance()->GetPrimaryRootWindow()->AddTransientChild(w1.get()); 1064 Shell::GetInstance()->GetPrimaryRootWindow()->AddTransientChild(w1.get());
1060 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); 1065 w1->SetBounds(gfx::Rect(10, 11, 250, 251));
1061 w1->SetParent(NULL); 1066 AddToRootWindow(w1.get());
1062 w1->Show(); 1067 w1->Show();
1063 wm::ActivateWindow(w1.get()); 1068 wm::ActivateWindow(w1.get());
1064 1069
1065 // The window with the transient parent should get added to the same parent as 1070 // The window with the transient parent should get added to the same parent as
1066 // the normal window. 1071 // the normal window.
1067 EXPECT_EQ(w2->parent(), w1->parent()); 1072 EXPECT_EQ(w2->parent(), w1->parent());
1068 } 1073 }
1069 1074
1070 // Verifies changing TrackedByWorkspace works. 1075 // Verifies changing TrackedByWorkspace works.
1071 TEST_F(WorkspaceManagerTest, TrackedByWorkspace) { 1076 TEST_F(WorkspaceManagerTest, TrackedByWorkspace) {
1072 // Create a window maximized. 1077 // Create a window maximized.
1073 scoped_ptr<Window> w1(CreateTestWindow()); 1078 scoped_ptr<Window> w1(CreateTestWindow());
1074 w1->Show(); 1079 w1->Show();
1075 wm::ActivateWindow(w1.get()); 1080 wm::ActivateWindow(w1.get());
1076 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1081 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1077 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 1082 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
1078 EXPECT_TRUE(w1->IsVisible()); 1083 EXPECT_TRUE(w1->IsVisible());
1079 1084
1080 // Create a second window maximized and mark it not tracked by workspace 1085 // Create a second window maximized and mark it not tracked by workspace
1081 // manager. 1086 // manager.
1082 scoped_ptr<Window> w2(CreateTestWindowUnparented()); 1087 scoped_ptr<Window> w2(CreateTestWindowUnparented());
1083 w2->SetBounds(gfx::Rect(1, 6, 25, 30)); 1088 w2->SetBounds(gfx::Rect(1, 6, 25, 30));
1084 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1089 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1085 w2->SetParent(NULL); 1090 AddToRootWindow(w2.get());
1086 w2->Show(); 1091 w2->Show();
1087 SetTrackedByWorkspace(w2.get(), false); 1092 SetTrackedByWorkspace(w2.get(), false);
1088 wm::ActivateWindow(w2.get()); 1093 wm::ActivateWindow(w2.get());
1089 1094
1090 // Activating |w2| should force it to have the same parent as |w1|. 1095 // Activating |w2| should force it to have the same parent as |w1|.
1091 EXPECT_EQ(w1->parent(), w2->parent()); 1096 EXPECT_EQ(w1->parent(), w2->parent());
1092 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 1097 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
1093 EXPECT_TRUE(w1->IsVisible()); 1098 EXPECT_TRUE(w1->IsVisible());
1094 EXPECT_TRUE(w2->IsVisible()); 1099 EXPECT_TRUE(w2->IsVisible());
1095 1100
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 // Activate |w1|, should result in dropping |w2| to the desktop. 1138 // Activate |w1|, should result in dropping |w2| to the desktop.
1134 wm::ActivateWindow(w1.get()); 1139 wm::ActivateWindow(w1.get());
1135 ASSERT_EQ("1 M1 active=1", StateString()); 1140 ASSERT_EQ("1 M1 active=1", StateString());
1136 } 1141 }
1137 1142
1138 // Test the basic auto placement of one and or two windows in a "simulated 1143 // Test the basic auto placement of one and or two windows in a "simulated
1139 // session" of sequential window operations. 1144 // session" of sequential window operations.
1140 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) { 1145 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) {
1141 // Test 1: In case there is no manageable window, no window should shift. 1146 // Test 1: In case there is no manageable window, no window should shift.
1142 1147
1143 scoped_ptr<aura::Window> window1( 1148 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1144 aura::test::CreateTestWindowWithId(0, NULL));
1145 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1149 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1146 gfx::Rect desktop_area = window1->parent()->bounds(); 1150 gfx::Rect desktop_area = window1->parent()->bounds();
1147 1151
1148 scoped_ptr<aura::Window> window2( 1152 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1149 aura::test::CreateTestWindowWithId(1, NULL));
1150 // Trigger the auto window placement function by making it visible. 1153 // Trigger the auto window placement function by making it visible.
1151 // Note that the bounds are getting changed while it is invisible. 1154 // Note that the bounds are getting changed while it is invisible.
1152 window2->Hide(); 1155 window2->Hide();
1153 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1156 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1154 window2->Show(); 1157 window2->Show();
1155 1158
1156 // Check the initial position of the windows is unchanged. 1159 // Check the initial position of the windows is unchanged.
1157 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); 1160 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
1158 EXPECT_EQ("32,48 256x512", window2->bounds().ToString()); 1161 EXPECT_EQ("32,48 256x512", window2->bounds().ToString());
1159 1162
1160 // Remove the second window and make sure that the first window 1163 // Remove the second window and make sure that the first window
1161 // does NOT get centered. 1164 // does NOT get centered.
1162 window2.reset(); 1165 window2.reset();
1163 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); 1166 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
1164 1167
1165 // Test 2: Set up two managed windows and check their auto positioning. 1168 // Test 2: Set up two managed windows and check their auto positioning.
1166 ash::wm::SetWindowPositionManaged(window1.get(), true); 1169 ash::wm::SetWindowPositionManaged(window1.get(), true);
1167 scoped_ptr<aura::Window> window3( 1170 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2));
1168 aura::test::CreateTestWindowWithId(2, NULL));
1169 ash::wm::SetWindowPositionManaged(window3.get(), true); 1171 ash::wm::SetWindowPositionManaged(window3.get(), true);
1170 // To avoid any auto window manager changes due to SetBounds, the window 1172 // To avoid any auto window manager changes due to SetBounds, the window
1171 // gets first hidden and then shown again. 1173 // gets first hidden and then shown again.
1172 window3->Hide(); 1174 window3->Hide();
1173 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); 1175 window3->SetBounds(gfx::Rect(32, 48, 256, 512));
1174 window3->Show(); 1176 window3->Show();
1175 // |window1| should be flush right and |window3| flush left. 1177 // |window1| should be flush right and |window3| flush left.
1176 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 1178 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
1177 EXPECT_EQ(base::IntToString( 1179 EXPECT_EQ(base::IntToString(
1178 desktop_area.width() - window3->bounds().width()) + 1180 desktop_area.width() - window3->bounds().width()) +
1179 ",48 256x512", window3->bounds().ToString()); 1181 ",48 256x512", window3->bounds().ToString());
1180 1182
1181 // After removing |window3|, |window1| should be centered again. 1183 // After removing |window3|, |window1| should be centered again.
1182 window3.reset(); 1184 window3.reset();
1183 EXPECT_EQ( 1185 EXPECT_EQ(
1184 base::IntToString( 1186 base::IntToString(
1185 (desktop_area.width() - window1->bounds().width()) / 2) + 1187 (desktop_area.width() - window1->bounds().width()) / 2) +
1186 ",32 640x320", window1->bounds().ToString()); 1188 ",32 640x320", window1->bounds().ToString());
1187 1189
1188 // Test 3: Set up a manageable and a non manageable window and check 1190 // Test 3: Set up a manageable and a non manageable window and check
1189 // positioning. 1191 // positioning.
1190 scoped_ptr<aura::Window> window4( 1192 scoped_ptr<aura::Window> window4(CreateTestWindowInShellWithId(3));
1191 aura::test::CreateTestWindowWithId(3, NULL));
1192 // To avoid any auto window manager changes due to SetBounds, the window 1193 // To avoid any auto window manager changes due to SetBounds, the window
1193 // gets first hidden and then shown again. 1194 // gets first hidden and then shown again.
1194 window1->Hide(); 1195 window1->Hide();
1195 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1196 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1196 window4->SetBounds(gfx::Rect(32, 48, 256, 512)); 1197 window4->SetBounds(gfx::Rect(32, 48, 256, 512));
1197 window1->Show(); 1198 window1->Show();
1198 // |window1| should be centered and |window4| untouched. 1199 // |window1| should be centered and |window4| untouched.
1199 EXPECT_EQ( 1200 EXPECT_EQ(
1200 base::IntToString( 1201 base::IntToString(
1201 (desktop_area.width() - window1->bounds().width()) / 2) + 1202 (desktop_area.width() - window1->bounds().width()) / 2) +
1202 ",32 640x320", window1->bounds().ToString()); 1203 ",32 640x320", window1->bounds().ToString());
1203 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); 1204 EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
1204 1205
1205 // Test4: A single manageable window should get centered. 1206 // Test4: A single manageable window should get centered.
1206 window4.reset(); 1207 window4.reset();
1207 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false); 1208 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false);
1208 // Trigger the auto window placement function by showing (and hiding) it. 1209 // Trigger the auto window placement function by showing (and hiding) it.
1209 window1->Hide(); 1210 window1->Hide();
1210 window1->Show(); 1211 window1->Show();
1211 // |window1| should be centered. 1212 // |window1| should be centered.
1212 EXPECT_EQ( 1213 EXPECT_EQ(
1213 base::IntToString( 1214 base::IntToString(
1214 (desktop_area.width() - window1->bounds().width()) / 2) + 1215 (desktop_area.width() - window1->bounds().width()) / 2) +
1215 ",32 640x320", window1->bounds().ToString()); 1216 ",32 640x320", window1->bounds().ToString());
1216 } 1217 }
1217 1218
1218 // Test the proper usage of user window movement interaction. 1219 // Test the proper usage of user window movement interaction.
1219 TEST_F(WorkspaceManagerTest, TestUserMovedWindowRepositioning) { 1220 TEST_F(WorkspaceManagerTest, TestUserMovedWindowRepositioning) {
1220 scoped_ptr<aura::Window> window1( 1221 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1221 aura::test::CreateTestWindowWithId(0, NULL));
1222 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1222 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1223 gfx::Rect desktop_area = window1->parent()->bounds(); 1223 gfx::Rect desktop_area = window1->parent()->bounds();
1224 scoped_ptr<aura::Window> window2( 1224 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1225 aura::test::CreateTestWindowWithId(1, NULL));
1226 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1225 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1227 window1->Hide(); 1226 window1->Hide();
1228 window2->Hide(); 1227 window2->Hide();
1229 ash::wm::SetWindowPositionManaged(window1.get(), true); 1228 ash::wm::SetWindowPositionManaged(window1.get(), true);
1230 ash::wm::SetWindowPositionManaged(window2.get(), true); 1229 ash::wm::SetWindowPositionManaged(window2.get(), true);
1231 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 1230 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
1232 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get())); 1231 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get()));
1233 1232
1234 // Check that the current location gets preserved if the user has 1233 // Check that the current location gets preserved if the user has
1235 // positioned it previously. 1234 // positioned it previously.
(...skipping 20 matching lines...) Expand all
1256 // Going back to one shown window should keep the state. 1255 // Going back to one shown window should keep the state.
1257 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true); 1256 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
1258 window2->Hide(); 1257 window2->Hide();
1259 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 1258 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
1260 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 1259 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
1261 } 1260 }
1262 1261
1263 // Test that user placed windows go back to their user placement after the user 1262 // Test that user placed windows go back to their user placement after the user
1264 // closes all other windows. 1263 // closes all other windows.
1265 TEST_F(WorkspaceManagerTest, TestUserHandledWindowRestore) { 1264 TEST_F(WorkspaceManagerTest, TestUserHandledWindowRestore) {
1266 scoped_ptr<aura::Window> window1( 1265 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1267 aura::test::CreateTestWindowWithId(0, NULL));
1268 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); 1266 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320);
1269 window1->SetBounds(user_pos); 1267 window1->SetBounds(user_pos);
1270 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos); 1268 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos);
1271 gfx::Rect desktop_area = window1->parent()->bounds(); 1269 gfx::Rect desktop_area = window1->parent()->bounds();
1272 1270
1273 // Create a second window to let the auto manager kick in. 1271 // Create a second window to let the auto manager kick in.
1274 scoped_ptr<aura::Window> window2( 1272 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1275 aura::test::CreateTestWindowWithId(1, NULL));
1276 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1273 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1277 window1->Hide(); 1274 window1->Hide();
1278 window2->Hide(); 1275 window2->Hide();
1279 ash::wm::SetWindowPositionManaged(window1.get(), true); 1276 ash::wm::SetWindowPositionManaged(window1.get(), true);
1280 ash::wm::SetWindowPositionManaged(window2.get(), true); 1277 ash::wm::SetWindowPositionManaged(window2.get(), true);
1281 window1->Show(); 1278 window1->Show();
1282 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 1279 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
1283 window2->Show(); 1280 window2->Show();
1284 1281
1285 // |window1| should be flush left and |window2| flush right. 1282 // |window1| should be flush left and |window2| flush right.
1286 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + 1283 EXPECT_EQ("0," + base::IntToString(user_pos.y()) +
1287 " 640x320", window1->bounds().ToString()); 1284 " 640x320", window1->bounds().ToString());
1288 EXPECT_EQ( 1285 EXPECT_EQ(
1289 base::IntToString(desktop_area.width() - window2->bounds().width()) + 1286 base::IntToString(desktop_area.width() - window2->bounds().width()) +
1290 ",48 256x512", window2->bounds().ToString()); 1287 ",48 256x512", window2->bounds().ToString());
1291 window2->Hide(); 1288 window2->Hide();
1292 1289
1293 // After the other window get hidden the window has to move back to the 1290 // After the other window get hidden the window has to move back to the
1294 // previous position and the bounds should still be set and unchanged. 1291 // previous position and the bounds should still be set and unchanged.
1295 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 1292 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
1296 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get())); 1293 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get()));
1297 EXPECT_EQ(user_pos.ToString(), 1294 EXPECT_EQ(user_pos.ToString(),
1298 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString()); 1295 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString());
1299 } 1296 }
1300 1297
1301 // Test that a window from normal to minimize will repos the remaining. 1298 // Test that a window from normal to minimize will repos the remaining.
1302 TEST_F(WorkspaceManagerTest, ToMinimizeRepositionsRemaining) { 1299 TEST_F(WorkspaceManagerTest, ToMinimizeRepositionsRemaining) {
1303 scoped_ptr<aura::Window> window1( 1300 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1304 aura::test::CreateTestWindowWithId(0, NULL));
1305 ash::wm::SetWindowPositionManaged(window1.get(), true); 1301 ash::wm::SetWindowPositionManaged(window1.get(), true);
1306 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1302 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1307 gfx::Rect desktop_area = window1->parent()->bounds(); 1303 gfx::Rect desktop_area = window1->parent()->bounds();
1308 1304
1309 scoped_ptr<aura::Window> window2( 1305 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1310 aura::test::CreateTestWindowWithId(1, NULL));
1311 ash::wm::SetWindowPositionManaged(window2.get(), true); 1306 ash::wm::SetWindowPositionManaged(window2.get(), true);
1312 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1307 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1313 1308
1314 ash::wm::MinimizeWindow(window1.get()); 1309 ash::wm::MinimizeWindow(window1.get());
1315 1310
1316 // |window2| should be centered now. 1311 // |window2| should be centered now.
1317 EXPECT_TRUE(window2->IsVisible()); 1312 EXPECT_TRUE(window2->IsVisible());
1318 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1313 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1319 EXPECT_EQ(base::IntToString( 1314 EXPECT_EQ(base::IntToString(
1320 (desktop_area.width() - window2->bounds().width()) / 2) + 1315 (desktop_area.width() - window2->bounds().width()) / 2) +
1321 ",48 256x512", window2->bounds().ToString()); 1316 ",48 256x512", window2->bounds().ToString());
1322 1317
1323 ash::wm::RestoreWindow(window1.get()); 1318 ash::wm::RestoreWindow(window1.get());
1324 // |window1| should be flush right and |window3| flush left. 1319 // |window1| should be flush right and |window3| flush left.
1325 EXPECT_EQ(base::IntToString( 1320 EXPECT_EQ(base::IntToString(
1326 desktop_area.width() - window1->bounds().width()) + 1321 desktop_area.width() - window1->bounds().width()) +
1327 ",32 640x320", window1->bounds().ToString()); 1322 ",32 640x320", window1->bounds().ToString());
1328 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1323 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1329 } 1324 }
1330 1325
1331 // Test that minimizing an initially maximized window will repos the remaining. 1326 // Test that minimizing an initially maximized window will repos the remaining.
1332 TEST_F(WorkspaceManagerTest, MaxToMinRepositionsRemaining) { 1327 TEST_F(WorkspaceManagerTest, MaxToMinRepositionsRemaining) {
1333 scoped_ptr<aura::Window> window1( 1328 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1334 aura::test::CreateTestWindowWithId(0, NULL));
1335 ash::wm::SetWindowPositionManaged(window1.get(), true); 1329 ash::wm::SetWindowPositionManaged(window1.get(), true);
1336 gfx::Rect desktop_area = window1->parent()->bounds(); 1330 gfx::Rect desktop_area = window1->parent()->bounds();
1337 1331
1338 scoped_ptr<aura::Window> window2( 1332 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1339 aura::test::CreateTestWindowWithId(1, NULL));
1340 ash::wm::SetWindowPositionManaged(window2.get(), true); 1333 ash::wm::SetWindowPositionManaged(window2.get(), true);
1341 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1334 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1342 1335
1343 ash::wm::MaximizeWindow(window1.get()); 1336 ash::wm::MaximizeWindow(window1.get());
1344 ash::wm::MinimizeWindow(window1.get()); 1337 ash::wm::MinimizeWindow(window1.get());
1345 1338
1346 // |window2| should be centered now. 1339 // |window2| should be centered now.
1347 EXPECT_TRUE(window2->IsVisible()); 1340 EXPECT_TRUE(window2->IsVisible());
1348 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1341 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1349 EXPECT_EQ(base::IntToString( 1342 EXPECT_EQ(base::IntToString(
1350 (desktop_area.width() - window2->bounds().width()) / 2) + 1343 (desktop_area.width() - window2->bounds().width()) / 2) +
1351 ",48 256x512", window2->bounds().ToString()); 1344 ",48 256x512", window2->bounds().ToString());
1352 } 1345 }
1353 1346
1354 // Test that nomral, maximize, minimizing will repos the remaining. 1347 // Test that nomral, maximize, minimizing will repos the remaining.
1355 TEST_F(WorkspaceManagerTest, NormToMaxToMinRepositionsRemaining) { 1348 TEST_F(WorkspaceManagerTest, NormToMaxToMinRepositionsRemaining) {
1356 scoped_ptr<aura::Window> window1( 1349 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1357 aura::test::CreateTestWindowWithId(0, NULL));
1358 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1350 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1359 ash::wm::SetWindowPositionManaged(window1.get(), true); 1351 ash::wm::SetWindowPositionManaged(window1.get(), true);
1360 gfx::Rect desktop_area = window1->parent()->bounds(); 1352 gfx::Rect desktop_area = window1->parent()->bounds();
1361 1353
1362 scoped_ptr<aura::Window> window2( 1354 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1363 aura::test::CreateTestWindowWithId(1, NULL));
1364 ash::wm::SetWindowPositionManaged(window2.get(), true); 1355 ash::wm::SetWindowPositionManaged(window2.get(), true);
1365 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1356 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1366 1357
1367 // Trigger the auto window placement function by showing (and hiding) it. 1358 // Trigger the auto window placement function by showing (and hiding) it.
1368 window1->Hide(); 1359 window1->Hide();
1369 window1->Show(); 1360 window1->Show();
1370 1361
1371 // |window1| should be flush right and |window3| flush left. 1362 // |window1| should be flush right and |window3| flush left.
1372 EXPECT_EQ(base::IntToString( 1363 EXPECT_EQ(base::IntToString(
1373 desktop_area.width() - window1->bounds().width()) + 1364 desktop_area.width() - window1->bounds().width()) +
1374 ",32 640x320", window1->bounds().ToString()); 1365 ",32 640x320", window1->bounds().ToString());
1375 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1366 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1376 1367
1377 ash::wm::MaximizeWindow(window1.get()); 1368 ash::wm::MaximizeWindow(window1.get());
1378 ash::wm::MinimizeWindow(window1.get()); 1369 ash::wm::MinimizeWindow(window1.get());
1379 1370
1380 // |window2| should be centered now. 1371 // |window2| should be centered now.
1381 EXPECT_TRUE(window2->IsVisible()); 1372 EXPECT_TRUE(window2->IsVisible());
1382 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1373 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1383 EXPECT_EQ(base::IntToString( 1374 EXPECT_EQ(base::IntToString(
1384 (desktop_area.width() - window2->bounds().width()) / 2) + 1375 (desktop_area.width() - window2->bounds().width()) / 2) +
1385 ",40 256x512", window2->bounds().ToString()); 1376 ",40 256x512", window2->bounds().ToString());
1386 } 1377 }
1387 1378
1388 // Test that nomral, maximize, normal will repos the remaining. 1379 // Test that nomral, maximize, normal will repos the remaining.
1389 TEST_F(WorkspaceManagerTest, NormToMaxToNormRepositionsRemaining) { 1380 TEST_F(WorkspaceManagerTest, NormToMaxToNormRepositionsRemaining) {
1390 scoped_ptr<aura::Window> window1( 1381 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1391 aura::test::CreateTestWindowWithId(0, NULL));
1392 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1382 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1393 ash::wm::SetWindowPositionManaged(window1.get(), true); 1383 ash::wm::SetWindowPositionManaged(window1.get(), true);
1394 gfx::Rect desktop_area = window1->parent()->bounds(); 1384 gfx::Rect desktop_area = window1->parent()->bounds();
1395 1385
1396 scoped_ptr<aura::Window> window2( 1386 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1397 aura::test::CreateTestWindowWithId(1, NULL));
1398 ash::wm::SetWindowPositionManaged(window2.get(), true); 1387 ash::wm::SetWindowPositionManaged(window2.get(), true);
1399 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1388 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1400 1389
1401 // Trigger the auto window placement function by showing (and hiding) it. 1390 // Trigger the auto window placement function by showing (and hiding) it.
1402 window1->Hide(); 1391 window1->Hide();
1403 window1->Show(); 1392 window1->Show();
1404 1393
1405 // |window1| should be flush right and |window3| flush left. 1394 // |window1| should be flush right and |window3| flush left.
1406 EXPECT_EQ(base::IntToString( 1395 EXPECT_EQ(base::IntToString(
1407 desktop_area.width() - window1->bounds().width()) + 1396 desktop_area.width() - window1->bounds().width()) +
1408 ",32 640x320", window1->bounds().ToString()); 1397 ",32 640x320", window1->bounds().ToString());
1409 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1398 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1410 1399
1411 ash::wm::MaximizeWindow(window1.get()); 1400 ash::wm::MaximizeWindow(window1.get());
1412 ash::wm::RestoreWindow(window1.get()); 1401 ash::wm::RestoreWindow(window1.get());
1413 1402
1414 // |window1| should be flush right and |window2| flush left. 1403 // |window1| should be flush right and |window2| flush left.
1415 EXPECT_EQ(base::IntToString( 1404 EXPECT_EQ(base::IntToString(
1416 desktop_area.width() - window1->bounds().width()) + 1405 desktop_area.width() - window1->bounds().width()) +
1417 ",32 640x320", window1->bounds().ToString()); 1406 ",32 640x320", window1->bounds().ToString());
1418 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1407 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1419 } 1408 }
1420 1409
1421 // Test that animations are triggered. 1410 // Test that animations are triggered.
1422 TEST_F(WorkspaceManagerTest, AnimatedNormToMaxToNormRepositionsRemaining) { 1411 TEST_F(WorkspaceManagerTest, AnimatedNormToMaxToNormRepositionsRemaining) {
1423 ui::LayerAnimator::set_disable_animations_for_test(false); 1412 ui::LayerAnimator::set_disable_animations_for_test(false);
1424 scoped_ptr<aura::Window> window1( 1413 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1425 aura::test::CreateTestWindowWithId(0, NULL));
1426 window1->Hide(); 1414 window1->Hide();
1427 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1415 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1428 gfx::Rect desktop_area = window1->parent()->bounds(); 1416 gfx::Rect desktop_area = window1->parent()->bounds();
1429 scoped_ptr<aura::Window> window2( 1417 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1430 aura::test::CreateTestWindowWithId(1, NULL));
1431 window2->Hide(); 1418 window2->Hide();
1432 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1419 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1433 1420
1434 ash::wm::SetWindowPositionManaged(window1.get(), true); 1421 ash::wm::SetWindowPositionManaged(window1.get(), true);
1435 ash::wm::SetWindowPositionManaged(window2.get(), true); 1422 ash::wm::SetWindowPositionManaged(window2.get(), true);
1436 // Make sure nothing is animating. 1423 // Make sure nothing is animating.
1437 window1->layer()->GetAnimator()->StopAnimating(); 1424 window1->layer()->GetAnimator()->StopAnimating();
1438 window2->layer()->GetAnimator()->StopAnimating(); 1425 window2->layer()->GetAnimator()->StopAnimating();
1439 window2->Show(); 1426 window2->Show();
1440 1427
(...skipping 10 matching lines...) Expand all
1451 window2->layer()->GetAnimator()->StopAnimating(); 1438 window2->layer()->GetAnimator()->StopAnimating();
1452 // |window1| should be flush right and |window2| flush left. 1439 // |window1| should be flush right and |window2| flush left.
1453 EXPECT_EQ(base::IntToString( 1440 EXPECT_EQ(base::IntToString(
1454 desktop_area.width() - window1->bounds().width()) + 1441 desktop_area.width() - window1->bounds().width()) +
1455 ",32 640x320", window1->bounds().ToString()); 1442 ",32 640x320", window1->bounds().ToString());
1456 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1443 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1457 } 1444 }
1458 1445
1459 } // namespace internal 1446 } // namespace internal
1460 } // namespace ash 1447 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698