Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } | 121 } |
| 122 | 122 |
| 123 const std::vector<Workspace*>& workspaces() const { | 123 const std::vector<Workspace*>& workspaces() const { |
| 124 return manager_->workspaces_; | 124 return manager_->workspaces_; |
| 125 } | 125 } |
| 126 | 126 |
| 127 gfx::Rect GetFullscreenBounds(aura::Window* window) { | 127 gfx::Rect GetFullscreenBounds(aura::Window* window) { |
| 128 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds(); | 128 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 Workspace* active_workspace() { | |
| 132 return manager_->active_workspace_; | |
| 133 } | |
| 134 | |
| 135 ShelfWidget* shelf_widget() { | 131 ShelfWidget* shelf_widget() { |
| 136 return Shell::GetPrimaryRootWindowController()->shelf(); | 132 return Shell::GetPrimaryRootWindowController()->shelf(); |
| 137 } | 133 } |
| 138 | 134 |
| 139 ShelfLayoutManager* shelf_layout_manager() { | 135 ShelfLayoutManager* shelf_layout_manager() { |
| 140 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 136 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
| 141 } | 137 } |
| 142 | 138 |
| 143 bool GetWindowOverlapsShelf() { | 139 bool GetWindowOverlapsShelf() { |
| 144 return shelf_layout_manager()->window_overlaps_shelf(); | 140 return shelf_layout_manager()->window_overlaps_shelf(); |
| 145 } | 141 } |
| 146 | 142 |
| 147 Workspace* FindBy(aura::Window* window) const { | 143 Workspace* FindBy(aura::Window* window) const { |
| 148 return manager_->FindBy(window); | 144 return manager_->FindBy(window); |
| 149 } | 145 } |
| 150 | 146 |
| 151 std::string WorkspaceStateString(Workspace* workspace) { | 147 Workspace* CreateWorkspace() { |
| 152 return (workspace->is_fullscreen() ? "F" : "") + | 148 return manager_->CreateWorkspaceForTest(); |
| 153 base::IntToString(static_cast<int>( | |
| 154 workspace->window()->children().size())); | |
| 155 } | |
| 156 | |
| 157 int active_index() { | |
| 158 return static_cast<int>( | |
| 159 manager_->FindWorkspace(manager_->active_workspace_) - | |
| 160 manager_->workspaces_.begin()); | |
| 161 } | |
| 162 | |
| 163 // Returns a string description of the current state. The string has the | |
| 164 // following format: | |
| 165 // W* P=W* active=N | |
| 166 // Each W corresponds to a workspace. Each workspace is prefixed with an 'F' | |
| 167 // if the workspace is fullscreen and is followed by the number of windows in | |
| 168 // the workspace. | |
| 169 // 'P=' is used for the pending workspaces (see | |
| 170 // WorkspaceManager::pending_workspaces_ for details on pending workspaces). | |
| 171 // N is the index of the active workspace (index into | |
| 172 // WorkspaceManager::workspaces_). | |
| 173 // For example, '2 F1 P=F1 active=1' means the first workspace (the desktop) | |
| 174 // has 2 windows, the second workspace is a maximized workspace with 1 window, | |
| 175 // there is a pending maximized workspace with 1 window and the second | |
| 176 // workspace is active. | |
| 177 std::string StateString() { | |
| 178 std::string result; | |
| 179 for (size_t i = 0; i < manager_->workspaces_.size(); ++i) { | |
| 180 if (i > 0) | |
| 181 result += " "; | |
| 182 result += WorkspaceStateString(manager_->workspaces_[i]); | |
| 183 } | |
| 184 | |
| 185 if (!manager_->pending_workspaces_.empty()) { | |
| 186 result += " P="; | |
| 187 for (std::set<Workspace*>::const_iterator i = | |
| 188 manager_->pending_workspaces_.begin(); | |
| 189 i != manager_->pending_workspaces_.end(); ++i) { | |
| 190 if (i != manager_->pending_workspaces_.begin()) | |
| 191 result += " "; | |
| 192 result += WorkspaceStateString(*i); | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 result += " active=" + base::IntToString(active_index()); | |
| 197 return result; | |
| 198 } | 149 } |
| 199 | 150 |
| 200 // Overridden from AshTestBase: | 151 // Overridden from AshTestBase: |
| 201 virtual void SetUp() OVERRIDE { | 152 virtual void SetUp() OVERRIDE { |
| 202 test::AshTestBase::SetUp(); | 153 test::AshTestBase::SetUp(); |
| 203 WorkspaceControllerTestHelper workspace_helper( | 154 WorkspaceControllerTestHelper workspace_helper( |
| 204 test::ShellTestApi(Shell::GetInstance()).workspace_controller()); | 155 test::ShellTestApi(Shell::GetInstance()).workspace_controller()); |
| 205 manager_ = workspace_helper.workspace_manager(); | 156 manager_ = workspace_helper.workspace_manager(); |
| 206 } | 157 } |
| 207 | 158 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 228 | 179 |
| 229 w1->Show(); | 180 w1->Show(); |
| 230 | 181 |
| 231 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL); | 182 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL); |
| 232 | 183 |
| 233 ASSERT_TRUE(w1->layer() != NULL); | 184 ASSERT_TRUE(w1->layer() != NULL); |
| 234 EXPECT_TRUE(w1->layer()->visible()); | 185 EXPECT_TRUE(w1->layer()->visible()); |
| 235 | 186 |
| 236 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 187 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 237 | 188 |
| 238 // Should be 1 workspace for the desktop, not maximized. | |
| 239 ASSERT_EQ("1 active=0", StateString()); | |
| 240 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 189 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 241 } | 190 } |
| 242 | 191 |
| 243 // Assertions around maximizing/unmaximizing. | 192 // Assertions around maximizing/unmaximizing. |
| 244 TEST_F(WorkspaceManagerTest, SingleMaximizeWindow) { | 193 TEST_F(WorkspaceManagerTest, SingleMaximizeWindow) { |
| 245 scoped_ptr<Window> w1(CreateTestWindow()); | 194 scoped_ptr<Window> w1(CreateTestWindow()); |
| 246 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 195 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 247 | 196 |
| 248 w1->Show(); | 197 w1->Show(); |
| 249 wm::ActivateWindow(w1.get()); | 198 wm::ActivateWindow(w1.get()); |
| 250 | 199 |
| 251 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 200 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 252 | 201 |
| 253 ASSERT_TRUE(w1->layer() != NULL); | 202 ASSERT_TRUE(w1->layer() != NULL); |
| 254 EXPECT_TRUE(w1->layer()->visible()); | 203 EXPECT_TRUE(w1->layer()->visible()); |
| 255 | 204 |
| 256 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 205 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 257 | 206 |
| 258 // Maximize the window. | 207 // Maximize the window. |
| 259 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 208 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 260 | 209 |
| 261 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 210 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 262 | 211 |
| 263 // Should be 1 workspace, maximized window doesn't create its own workspace. | |
| 264 ASSERT_EQ("1 active=0", StateString()); | |
| 265 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 212 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 266 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).width(), | 213 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).width(), |
| 267 w1->bounds().width()); | 214 w1->bounds().width()); |
| 268 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).height(), | 215 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).height(), |
| 269 w1->bounds().height()); | 216 w1->bounds().height()); |
| 270 | 217 |
| 271 // Restore the window. | 218 // Restore the window. |
| 272 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 219 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 273 | 220 |
| 274 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 221 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 275 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 222 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 276 } | 223 } |
| 277 | 224 |
| 278 // Assertions around closing the last window in a workspace. | |
| 279 TEST_F(WorkspaceManagerTest, CloseLastWindowInWorkspace) { | |
| 280 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 281 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 282 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 283 w1->Show(); | |
| 284 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 285 w2->Show(); | |
| 286 wm::ActivateWindow(w1.get()); | |
| 287 | |
| 288 // Should be 1 workspace and 1 pending, !fullscreen and fullsceen. The second | |
| 289 // workspace is pending since the window wasn't active. | |
| 290 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 291 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | |
| 292 | |
| 293 // Close w2. | |
| 294 w2.reset(); | |
| 295 | |
| 296 // Should have one workspace. | |
| 297 ASSERT_EQ("1 active=0", StateString()); | |
| 298 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | |
| 299 EXPECT_TRUE(w1->IsVisible()); | |
| 300 } | |
| 301 | |
| 302 // Assertions around adding a fullscreen window when empty. | |
| 303 TEST_F(WorkspaceManagerTest, AddFullscreenWindowWhenEmpty) { | |
| 304 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 305 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 306 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 307 w1->Show(); | |
| 308 wm::ActivateWindow(w1.get()); | |
| 309 | |
| 310 ASSERT_TRUE(w1->layer() != NULL); | |
| 311 EXPECT_TRUE(w1->layer()->visible()); | |
| 312 gfx::Rect work_area( | |
| 313 ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get())); | |
| 314 EXPECT_EQ(work_area.width(), w1->bounds().width()); | |
| 315 EXPECT_EQ(work_area.height(), w1->bounds().height()); | |
| 316 | |
| 317 // Should be 2 workspaces (since we always keep the desktop). | |
| 318 ASSERT_EQ("0 F1 active=1", StateString()); | |
| 319 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 320 } | |
| 321 | |
| 322 // Assertions around two windows and toggling one to be fullscreen. | 225 // Assertions around two windows and toggling one to be fullscreen. |
| 323 TEST_F(WorkspaceManagerTest, FullscreenWithNormalWindow) { | 226 TEST_F(WorkspaceManagerTest, FullscreenWithNormalWindow) { |
| 324 scoped_ptr<Window> w1(CreateTestWindow()); | 227 scoped_ptr<Window> w1(CreateTestWindow()); |
| 325 scoped_ptr<Window> w2(CreateTestWindow()); | 228 scoped_ptr<Window> w2(CreateTestWindow()); |
| 326 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 229 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 327 w1->Show(); | 230 w1->Show(); |
| 328 | 231 |
| 329 ASSERT_TRUE(w1->layer() != NULL); | 232 ASSERT_TRUE(w1->layer() != NULL); |
| 330 EXPECT_TRUE(w1->layer()->visible()); | 233 EXPECT_TRUE(w1->layer()->visible()); |
| 331 | 234 |
| 332 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); | 235 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); |
| 333 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 236 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 334 w2->Show(); | 237 w2->Show(); |
| 335 wm::ActivateWindow(w2.get()); | 238 wm::ActivateWindow(w2.get()); |
| 336 | 239 |
| 337 // Should now be two workspaces. | 240 // Both windows should be in the same workspace. |
| 338 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 339 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 241 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 340 EXPECT_EQ(w2.get(), workspaces()[1]->window()->children()[0]); | 242 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[1]); |
| 341 | 243 |
| 342 gfx::Rect work_area( | 244 gfx::Rect work_area( |
| 343 ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get())); | 245 ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get())); |
| 344 EXPECT_EQ(work_area.width(), w2->bounds().width()); | 246 EXPECT_EQ(work_area.width(), w2->bounds().width()); |
| 345 EXPECT_EQ(work_area.height(), w2->bounds().height()); | 247 EXPECT_EQ(work_area.height(), w2->bounds().height()); |
| 346 | 248 |
| 347 // Restore w2, which should then go back to one workspace. | 249 // Restore w2, which should then go back to one workspace. |
| 348 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 250 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 349 ASSERT_EQ("2 active=0", StateString()); | |
| 350 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | |
| 351 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[1]); | |
| 352 EXPECT_EQ(50, w2->bounds().width()); | 251 EXPECT_EQ(50, w2->bounds().width()); |
| 353 EXPECT_EQ(51, w2->bounds().height()); | 252 EXPECT_EQ(51, w2->bounds().height()); |
| 354 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 253 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 355 } | 254 } |
| 356 | 255 |
| 357 // Assertions around two fullscreen windows. | |
| 358 TEST_F(WorkspaceManagerTest, TwoFullscreen) { | |
| 359 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 360 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 361 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 362 w1->Show(); | |
| 363 wm::ActivateWindow(w1.get()); | |
| 364 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 365 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 366 | |
| 367 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); | |
| 368 w2->Show(); | |
| 369 wm::ActivateWindow(w2.get()); | |
| 370 ASSERT_EQ("1 F1 active=0", StateString()); | |
| 371 | |
| 372 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 373 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 374 ASSERT_EQ("0 F1 F1 active=2", StateString()); | |
| 375 | |
| 376 // The last stacked window (|w2|) should be last since it was fullscreen last. | |
| 377 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 378 EXPECT_EQ(w2.get(), workspaces()[2]->window()->children()[0]); | |
| 379 } | |
| 380 | |
| 381 // Get the index of the layer inside its parent. This index can be used to | |
| 382 // determine the z-order / draw-order of objects in the render tree. | |
| 383 size_t IndexOfLayerInParent(ui::Layer* layer) { | |
| 384 ui::Layer* parent = layer->parent(); | |
| 385 for (size_t i = 0; i < parent->children().size(); i++) { | |
| 386 if (layer == parent->children()[i]) | |
| 387 return i; | |
| 388 } | |
| 389 // This should never be reached. | |
| 390 NOTREACHED(); | |
| 391 return 0; | |
| 392 } | |
| 393 | |
| 394 // Make sure that the layer z-order is correct for the time of the animation | |
| 395 // when in a workspace with a normal and a fullscreen window the normal window | |
| 396 // gets fullscreen. See crbug.com/232399. | |
| 397 TEST_F(WorkspaceManagerTest, FullscreenSecondInWorkspace) { | |
| 398 // Create a fullscreen window. | |
| 399 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 400 ASSERT_EQ(1U, w1->layer()->parent()->children().size()); | |
| 401 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 402 w1->Show(); | |
| 403 wm::ActivateWindow(w1.get()); | |
| 404 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 405 wm::ActivateWindow(w1.get()); | |
| 406 // There are two workspaces: A normal and a fullscreen one. | |
| 407 ASSERT_EQ("0 F1 active=1", StateString()); | |
| 408 | |
| 409 // Create a second window and make it part of the fullscreen workspace. | |
| 410 scoped_ptr<Window> w2(CreateAppTestWindow(w1->parent())); | |
| 411 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); | |
| 412 w2->Show(); | |
| 413 wm::ActivateWindow(w2.get()); | |
| 414 // There are still two workspaces and two windows in the (fullscreen) | |
| 415 // workspace. | |
| 416 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 417 ASSERT_EQ(w1->layer()->parent()->children()[0], w1->layer()); | |
| 418 ASSERT_EQ(w1->layer()->parent()->children()[1], w2->layer()); | |
| 419 | |
| 420 // Now we need to enable all animations since the incorrect layer ordering we | |
| 421 // want to test against happens only while the animation is going on. | |
| 422 scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration( | |
| 423 new ui::ScopedAnimationDurationScaleMode( | |
| 424 ui::ScopedAnimationDurationScaleMode::FAST_DURATION)); | |
| 425 | |
| 426 ui::Layer* old_w2_layer = w2->layer(); | |
| 427 | |
| 428 // Maximize the second window and make sure that the workspace changes. | |
| 429 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 430 | |
| 431 // Check the correct window hierarchy - (|w2|) should be last since it got | |
| 432 // fullscreen last. | |
| 433 ASSERT_EQ("0 F1 F1 active=2", StateString()); | |
| 434 EXPECT_EQ(3U, workspaces().size()); | |
| 435 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 436 EXPECT_EQ(w2.get(), workspaces()[2]->window()->children()[0]); | |
| 437 | |
| 438 // Check the workspace layer visibility. | |
| 439 EXPECT_EQ(1, workspaces()[1]->window()->layer()->opacity()); | |
| 440 EXPECT_EQ(1, workspaces()[2]->window()->layer()->opacity()); | |
| 441 | |
| 442 // Check that |w2| got a new layer and that the old layer is still visible, | |
| 443 // while the new one is not. Further and foremost the old layer should be a | |
| 444 // member of the workspace's window and it should be the second last of the | |
| 445 // list to be properly stacked while the animation is going on. | |
| 446 EXPECT_NE(w2->layer(), old_w2_layer); | |
| 447 EXPECT_EQ(0, w2->layer()->opacity()); | |
| 448 EXPECT_EQ(1, old_w2_layer->opacity()); | |
| 449 | |
| 450 // For the animation to look right we need the following ordering: | |
| 451 // workspace_1_layer_index < old_layer_index < workspace_2_layer_index. | |
| 452 ASSERT_EQ(workspaces()[1]->window()->parent()->layer(), | |
| 453 old_w2_layer->parent()); | |
| 454 const size_t workspace_1_layer_index = IndexOfLayerInParent( | |
| 455 workspaces()[1]->window()->layer()); | |
| 456 const size_t workspace_2_layer_index = IndexOfLayerInParent( | |
| 457 workspaces()[2]->window()->layer()); | |
| 458 const size_t old_layer_index = IndexOfLayerInParent(old_w2_layer); | |
| 459 EXPECT_LT(workspace_1_layer_index, old_layer_index); | |
| 460 EXPECT_LT(old_layer_index, workspace_2_layer_index); | |
| 461 } | |
| 462 | |
| 463 // Makes sure requests to change the bounds of a normal window go through. | 256 // Makes sure requests to change the bounds of a normal window go through. |
| 464 TEST_F(WorkspaceManagerTest, ChangeBoundsOfNormalWindow) { | 257 TEST_F(WorkspaceManagerTest, ChangeBoundsOfNormalWindow) { |
| 465 scoped_ptr<Window> w1(CreateTestWindow()); | 258 scoped_ptr<Window> w1(CreateTestWindow()); |
| 466 w1->Show(); | 259 w1->Show(); |
| 467 | 260 |
| 468 // Setting the bounds should go through since the window is in the normal | 261 // Setting the bounds should go through since the window is in the normal |
| 469 // workspace. | 262 // workspace. |
| 470 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); | 263 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); |
| 471 EXPECT_EQ(200, w1->bounds().width()); | 264 EXPECT_EQ(200, w1->bounds().width()); |
| 472 EXPECT_EQ(500, w1->bounds().height()); | 265 EXPECT_EQ(500, w1->bounds().height()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 486 | 279 |
| 487 // Assertions around a fullscreen window. | 280 // Assertions around a fullscreen window. |
| 488 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) { | 281 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) { |
| 489 scoped_ptr<Window> w1(CreateTestWindow()); | 282 scoped_ptr<Window> w1(CreateTestWindow()); |
| 490 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 283 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 491 // Make the window fullscreen. | 284 // Make the window fullscreen. |
| 492 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 285 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 493 w1->Show(); | 286 w1->Show(); |
| 494 wm::ActivateWindow(w1.get()); | 287 wm::ActivateWindow(w1.get()); |
| 495 | 288 |
| 496 // Should be 2 workspaces, normal and fullscreen. | 289 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 497 ASSERT_EQ("0 F1 active=1", StateString()); | |
| 498 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 499 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); | 290 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); |
| 500 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); | 291 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); |
| 501 | 292 |
| 502 // Restore the window. Use SHOW_STATE_DEFAULT as that is what we'll end up | 293 // Restore the window. Use SHOW_STATE_DEFAULT as that is what we'll end up |
| 503 // with when using views::Widget. | 294 // with when using views::Widget. |
| 504 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT); | 295 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT); |
| 505 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 296 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 506 | 297 |
| 507 // Should be 1 workspace for the desktop. | |
| 508 ASSERT_EQ("1 active=0", StateString()); | |
| 509 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 298 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 510 EXPECT_EQ(250, w1->bounds().width()); | 299 EXPECT_EQ(250, w1->bounds().width()); |
| 511 EXPECT_EQ(251, w1->bounds().height()); | 300 EXPECT_EQ(251, w1->bounds().height()); |
| 512 | 301 |
| 513 // Back to fullscreen. | 302 // Back to fullscreen. |
| 514 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 303 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 515 ASSERT_EQ("0 F1 active=1", StateString()); | 304 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 516 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 517 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); | 305 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); |
| 518 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); | 306 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); |
| 519 ASSERT_TRUE(GetRestoreBoundsInScreen(w1.get())); | 307 ASSERT_TRUE(GetRestoreBoundsInScreen(w1.get())); |
| 520 EXPECT_EQ("0,0 250x251", GetRestoreBoundsInScreen(w1.get())->ToString()); | 308 EXPECT_EQ("0,0 250x251", GetRestoreBoundsInScreen(w1.get())->ToString()); |
| 521 } | 309 } |
| 522 | 310 |
| 523 // Makes sure switching workspaces doesn't show transient windows. | |
| 524 TEST_F(WorkspaceManagerTest, DontShowTransientsOnSwitch) { | |
| 525 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 526 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 527 | |
| 528 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 529 w2->SetBounds(gfx::Rect(0, 0, 250, 251)); | |
| 530 w1->AddTransientChild(w2.get()); | |
| 531 | |
| 532 w1->Show(); | |
| 533 | |
| 534 scoped_ptr<Window> w3(CreateTestWindow()); | |
| 535 w3->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 536 w3->Show(); | |
| 537 wm::ActivateWindow(w3.get()); | |
| 538 | |
| 539 EXPECT_FALSE(w1->layer()->IsDrawn()); | |
| 540 EXPECT_FALSE(w2->layer()->IsDrawn()); | |
| 541 EXPECT_TRUE(w3->layer()->IsDrawn()); | |
| 542 | |
| 543 wm::ActivateWindow(w1.get()); | |
| 544 EXPECT_TRUE(w1->layer()->IsDrawn()); | |
| 545 EXPECT_FALSE(w2->layer()->IsDrawn()); | |
| 546 EXPECT_FALSE(w3->layer()->IsDrawn()); | |
| 547 } | |
| 548 | |
| 549 // Persists-across-all-workspace flag should not cause a transient child | |
| 550 // to be activated at desktop workspace. | |
| 551 TEST_F(WorkspaceManagerTest, PersistsTransientChildStayInSameWorkspace) { | |
| 552 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 553 SetPersistsAcrossAllWorkspaces( | |
| 554 w1.get(), | |
| 555 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 556 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 557 w1->Show(); | |
| 558 wm::ActivateWindow(w1.get()); | |
| 559 ASSERT_EQ("0 F1 active=1", StateString()); | |
| 560 | |
| 561 scoped_ptr<Window> w2(CreateTestWindowUnparented()); | |
| 562 w1->AddTransientChild(w2.get()); | |
| 563 SetPersistsAcrossAllWorkspaces( | |
| 564 w2.get(), | |
| 565 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 566 SetDefaultParentByPrimaryRootWindow(w2.get()); | |
| 567 w2->Show(); | |
| 568 wm::ActivateWindow(w2.get()); | |
| 569 | |
| 570 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 571 } | |
| 572 | |
| 573 // Assertions around minimizing a single window. | 311 // Assertions around minimizing a single window. |
| 574 TEST_F(WorkspaceManagerTest, MinimizeSingleWindow) { | 312 TEST_F(WorkspaceManagerTest, MinimizeSingleWindow) { |
| 575 scoped_ptr<Window> w1(CreateTestWindow()); | 313 scoped_ptr<Window> w1(CreateTestWindow()); |
| 576 | 314 |
| 577 w1->Show(); | 315 w1->Show(); |
| 578 ASSERT_EQ("1 active=0", StateString()); | |
| 579 | 316 |
| 580 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 317 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 581 ASSERT_EQ("1 active=0", StateString()); | |
| 582 EXPECT_FALSE(w1->layer()->IsDrawn()); | 318 EXPECT_FALSE(w1->layer()->IsDrawn()); |
| 583 | 319 |
| 584 // Show the window. | 320 // Show the window. |
| 585 w1->Show(); | 321 w1->Show(); |
| 586 EXPECT_TRUE(wm::IsWindowNormal(w1.get())); | 322 EXPECT_TRUE(wm::IsWindowNormal(w1.get())); |
| 587 ASSERT_EQ("1 active=0", StateString()); | |
| 588 EXPECT_TRUE(w1->layer()->IsDrawn()); | 323 EXPECT_TRUE(w1->layer()->IsDrawn()); |
| 589 } | 324 } |
| 590 | 325 |
| 591 // Assertions around minimizing a fullscreen window. | 326 // Assertions around minimizing a fullscreen window. |
| 592 TEST_F(WorkspaceManagerTest, MinimizeFullscreenWindow) { | 327 TEST_F(WorkspaceManagerTest, MinimizeFullscreenWindow) { |
| 593 // Two windows, w1 normal, w2 fullscreen. | 328 // Two windows, w1 normal, w2 fullscreen. |
| 594 scoped_ptr<Window> w1(CreateTestWindow()); | 329 scoped_ptr<Window> w1(CreateTestWindow()); |
| 595 scoped_ptr<Window> w2(CreateTestWindow()); | 330 scoped_ptr<Window> w2(CreateTestWindow()); |
| 596 w1->Show(); | 331 w1->Show(); |
| 597 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 332 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 598 w2->Show(); | 333 w2->Show(); |
| 599 wm::ActivateWindow(w2.get()); | 334 wm::ActivateWindow(w2.get()); |
| 600 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 601 | 335 |
| 602 // Minimize w2. | 336 // Minimize w2. |
| 603 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 337 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 604 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 605 EXPECT_TRUE(w1->layer()->IsDrawn()); | 338 EXPECT_TRUE(w1->layer()->IsDrawn()); |
| 606 EXPECT_FALSE(w2->layer()->IsDrawn()); | 339 EXPECT_FALSE(w2->layer()->IsDrawn()); |
| 607 | 340 |
| 608 // Show the window, which should trigger unminimizing. | 341 // Show the window, which should trigger unminimizing. |
| 609 w2->Show(); | 342 w2->Show(); |
| 610 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 611 | |
| 612 wm::ActivateWindow(w2.get()); | 343 wm::ActivateWindow(w2.get()); |
| 613 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 614 | 344 |
| 615 EXPECT_TRUE(wm::IsWindowFullscreen(w2.get())); | 345 EXPECT_TRUE(wm::IsWindowFullscreen(w2.get())); |
| 616 EXPECT_FALSE(w1->layer()->IsDrawn()); | 346 EXPECT_TRUE(w1->layer()->IsDrawn()); |
| 617 EXPECT_TRUE(w2->layer()->IsDrawn()); | 347 EXPECT_TRUE(w2->layer()->IsDrawn()); |
| 618 | 348 |
| 619 // Minimize the window, which should hide the window and activate another. | 349 // Minimize the window, which should hide the window. |
| 620 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 350 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 621 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 351 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 622 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | 352 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
| 623 EXPECT_FALSE(w2->layer()->IsDrawn()); | 353 EXPECT_FALSE(w2->layer()->IsDrawn()); |
| 624 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 354 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 625 | 355 |
| 626 // Make the window normal. | 356 // Make the window normal. |
| 627 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 357 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 628 ASSERT_EQ("2 active=0", StateString()); | |
| 629 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | 358 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); |
| 630 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[1]); | 359 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[1]); |
| 631 EXPECT_TRUE(w2->layer()->IsDrawn()); | 360 EXPECT_TRUE(w2->layer()->IsDrawn()); |
| 632 } | 361 } |
| 633 | 362 |
| 363 // Verifies the basic behavior of multiple workspaces. | |
| 364 TEST_F(WorkspaceManagerTest, MultiWorkspaces) { | |
|
James Cook
2013/07/23 16:53:48
Thanks for adding a test for this.
| |
| 365 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 366 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); | |
| 367 w1->Show(); | |
| 368 wm::ActivateWindow(w1.get()); | |
| 369 EXPECT_TRUE(w1->layer()->IsDrawn()); | |
| 370 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | |
| 371 | |
| 372 // Creates a secondary workspace and a window in it. | |
| 373 Workspace* secondary_workspace = CreateWorkspace(); | |
| 374 scoped_ptr<Window> w2(CreateTestWindowUnparented()); | |
| 375 w2->SetBounds(gfx::Rect(8, 9, 150, 151)); | |
| 376 secondary_workspace->window()->AddChild(w2.get()); | |
| 377 w2->Show(); | |
| 378 wm::ActivateWindow(w2.get()); | |
| 379 EXPECT_FALSE(w1->layer()->IsDrawn()); | |
| 380 EXPECT_TRUE(w2->layer()->IsDrawn()); | |
| 381 // As the result of activation, |secondary_workspace| has been added to | |
| 382 // the list of workspaces managed by |workspace_manager|. | |
| 383 ASSERT_EQ(2u, workspaces().size()); | |
| 384 EXPECT_EQ(secondary_workspace, workspaces()[1]); | |
| 385 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[0]); | |
| 386 EXPECT_EQ(w2.get(), workspaces()[1]->window()->children()[0]); | |
| 387 | |
| 388 // Activates w1 again, w2 should be hidden. | |
| 389 wm::ActivateWindow(w1.get()); | |
| 390 EXPECT_TRUE(w1->layer()->IsDrawn()); | |
| 391 EXPECT_FALSE(w2->layer()->IsDrawn()); | |
| 392 | |
| 393 // Activates and then removes the w2. |secondary_workspace| remains and | |
| 394 // active. | |
| 395 wm::ActivateWindow(w2.get()); | |
| 396 w2.reset(); | |
| 397 EXPECT_FALSE(w1->layer()->IsDrawn()); | |
| 398 EXPECT_EQ(2u, workspaces().size()); | |
| 399 } | |
| 400 | |
| 634 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly | 401 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly |
| 635 // updated. | 402 // updated. |
| 636 TEST_F(WorkspaceManagerTest, ShelfStateUpdated) { | 403 TEST_F(WorkspaceManagerTest, ShelfStateUpdated) { |
| 637 // Since ShelfLayoutManager queries for mouse location, move the mouse so | 404 // Since ShelfLayoutManager queries for mouse location, move the mouse so |
| 638 // it isn't over the shelf. | 405 // it isn't over the shelf. |
| 639 aura::test::EventGenerator generator( | 406 aura::test::EventGenerator generator( |
| 640 Shell::GetPrimaryRootWindow(), gfx::Point()); | 407 Shell::GetPrimaryRootWindow(), gfx::Point()); |
| 641 generator.MoveMouseTo(0, 0); | 408 generator.MoveMouseTo(0, 0); |
| 642 | 409 |
| 643 scoped_ptr<Window> w1(CreateTestWindow()); | 410 scoped_ptr<Window> w1(CreateTestWindow()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 485 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 719 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 486 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 720 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 487 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
| 721 | 488 |
| 722 // Create another window, maximized. | 489 // Create another window, maximized. |
| 723 scoped_ptr<Window> w2(CreateTestWindow()); | 490 scoped_ptr<Window> w2(CreateTestWindow()); |
| 724 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 491 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
| 725 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 492 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 726 w2->Show(); | 493 w2->Show(); |
| 727 wm::ActivateWindow(w2.get()); | 494 wm::ActivateWindow(w2.get()); |
| 728 EXPECT_EQ(0, active_index()); | |
| 729 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 495 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 730 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 496 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 731 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 497 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
| 732 | 498 |
| 733 // Switch to w1. | 499 // Switch to w1. |
| 734 wm::ActivateWindow(w1.get()); | 500 wm::ActivateWindow(w1.get()); |
| 735 EXPECT_EQ(0, active_index()); | |
| 736 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 501 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 737 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 502 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
| 738 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent( | 503 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent( |
| 739 w2->parent()).ToString(), | 504 w2->parent()).ToString(), |
| 740 w2->bounds().ToString()); | 505 w2->bounds().ToString()); |
| 741 | 506 |
| 742 // Switch to w2. | 507 // Switch to w2. |
| 743 wm::ActivateWindow(w2.get()); | 508 wm::ActivateWindow(w2.get()); |
| 744 EXPECT_EQ(0, active_index()); | |
| 745 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 509 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 746 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 510 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 747 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 511 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
| 748 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w2.get()).ToString(), | 512 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w2.get()).ToString(), |
| 749 w2->bounds().ToString()); | 513 w2->bounds().ToString()); |
| 750 | 514 |
| 751 // Turn off auto-hide, switch back to w2 (maximized) and verify overlap. | 515 // Turn off auto-hide, switch back to w2 (maximized) and verify overlap. |
| 752 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 516 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 753 wm::ActivateWindow(w2.get()); | 517 wm::ActivateWindow(w2.get()); |
| 754 EXPECT_FALSE(GetWindowOverlapsShelf()); | 518 EXPECT_FALSE(GetWindowOverlapsShelf()); |
| 755 | 519 |
| 756 // Move w1 to overlap shelf, it shouldn't change window overlaps shelf since | 520 // Move w1 to overlap shelf, it shouldn't change window overlaps shelf since |
| 757 // the window isn't in the visible workspace. | 521 // the window isn't in the visible workspace. |
| 758 w1->SetBounds(touches_shelf_bounds); | 522 w1->SetBounds(touches_shelf_bounds); |
| 759 EXPECT_FALSE(GetWindowOverlapsShelf()); | 523 EXPECT_FALSE(GetWindowOverlapsShelf()); |
| 760 | 524 |
| 761 // Activate w1. Although w1 is visible, the overlap state is still false since | 525 // Activate w1. Although w1 is visible, the overlap state is still false since |
| 762 // w2 is maximized. | 526 // w2 is maximized. |
| 763 wm::ActivateWindow(w1.get()); | 527 wm::ActivateWindow(w1.get()); |
| 764 EXPECT_FALSE(GetWindowOverlapsShelf()); | 528 EXPECT_FALSE(GetWindowOverlapsShelf()); |
| 765 | 529 |
| 766 // Restore w2. | 530 // Restore w2. |
| 767 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 531 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 768 EXPECT_TRUE(GetWindowOverlapsShelf()); | 532 EXPECT_TRUE(GetWindowOverlapsShelf()); |
| 769 } | 533 } |
| 770 | 534 |
| 771 // Verifies persist across all workspaces. | |
| 772 TEST_F(WorkspaceManagerTest, PersistAcrossAllWorkspaces) { | |
|
James Cook
2013/07/23 16:53:48
Is the idea of "persist across all workspaces" rem
Jun Mukai
2013/07/23 18:04:19
The idea is removed although a bit of code remains
| |
| 773 // Create a fullscreen window. | |
| 774 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 775 w1->Show(); | |
| 776 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 777 wm::ActivateWindow(w1.get()); | |
| 778 ASSERT_EQ("0 F1 active=1", StateString()); | |
| 779 | |
| 780 // Create a window that persists across all workspaces. It should be placed in | |
| 781 // the current fullscreen workspace. | |
| 782 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 783 SetPersistsAcrossAllWorkspaces( | |
| 784 w2.get(), | |
| 785 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 786 w2->Show(); | |
| 787 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 788 | |
| 789 // Activate w2, which should move it to the 2nd workspace. | |
| 790 wm::ActivateWindow(w2.get()); | |
| 791 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 792 | |
| 793 // Restoring w2 should drop the persists window back to the desktop, and drop | |
| 794 // it to the bottom of the stack. | |
| 795 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 796 ASSERT_EQ("2 active=0", StateString()); | |
| 797 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[0]); | |
| 798 EXPECT_EQ(w1.get(), workspaces()[0]->window()->children()[1]); | |
| 799 | |
| 800 // Repeat, but this time minimize. The minimized window should end up in | |
| 801 // pending. | |
| 802 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 803 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 804 w2.reset(CreateTestWindow()); | |
| 805 SetPersistsAcrossAllWorkspaces( | |
| 806 w2.get(), | |
| 807 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 808 w2->Show(); | |
| 809 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 810 wm::ActivateWindow(w2.get()); | |
| 811 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 812 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
| 813 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 814 EXPECT_EQ(w2.get(), workspaces()[0]->window()->children()[0]); | |
| 815 } | |
| 816 | |
| 817 // Verifies that when a window persists across all workpaces is activated that | |
| 818 // it moves to the current workspace. | |
| 819 TEST_F(WorkspaceManagerTest, ActivatePersistAcrossAllWorkspacesWhenNotActive) { | |
| 820 // Create a window that persists across all workspaces. | |
| 821 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 822 SetPersistsAcrossAllWorkspaces( | |
| 823 w2.get(), | |
| 824 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 825 w2->Show(); | |
| 826 ASSERT_EQ("1 active=0", StateString()); | |
| 827 | |
| 828 // Create a maximized window. | |
| 829 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 830 w1->Show(); | |
| 831 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 832 wm::ActivateWindow(w1.get()); | |
| 833 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 834 | |
| 835 // Activate the persists across all workspace window. It should move to the | |
| 836 // current workspace. | |
| 837 wm::ActivateWindow(w2.get()); | |
| 838 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 839 // The window that persists across all workspaces should be moved to the top | |
| 840 // of the stacking order. | |
| 841 EXPECT_EQ(w1.get(), workspaces()[1]->window()->children()[0]); | |
| 842 EXPECT_EQ(w2.get(), workspaces()[1]->window()->children()[1]); | |
| 843 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 844 } | |
| 845 | |
| 846 // Verifies Show()ing a minimized window that persists across all workspaces | |
| 847 // unminimizes the window. | |
| 848 TEST_F(WorkspaceManagerTest, ShowMinimizedPersistWindow) { | |
|
James Cook
2013/07/23 16:53:48
Should we keep this test?
Jun Mukai
2013/07/23 18:04:19
since I've removed PERSIST_ACROSS_ALL_WORKSPACES,
| |
| 849 // Create a window that persists across all workspaces. | |
| 850 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 851 SetPersistsAcrossAllWorkspaces( | |
| 852 w1.get(), | |
| 853 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 854 w1->Show(); | |
| 855 wm::ActivateWindow(w1.get()); | |
| 856 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
| 857 EXPECT_FALSE(w1->IsVisible()); | |
| 858 w1->Show(); | |
| 859 EXPECT_TRUE(w1->IsVisible()); | |
| 860 } | |
| 861 | |
| 862 // Test that a persistent window across all workspaces which got fullscreen | 535 // Test that a persistent window across all workspaces which got fullscreen |
| 863 // first, then got minimized and finally got restored does not crash the | 536 // first, then got minimized and finally got restored does not crash the |
| 864 // system (see http://crbug.com/151698) and restores its fullscreen workspace | 537 // system (see http://crbug.com/151698) and restores its fullscreen workspace |
| 865 // instead. | 538 // instead. |
| 866 TEST_F(WorkspaceManagerTest, MaximizeMinimizeRestoreDoesNotCrash) { | 539 TEST_F(WorkspaceManagerTest, MaximizeMinimizeRestoreDoesNotCrash) { |
| 867 // We need to create a regular window first so there's an active workspace. | 540 // We need to create a regular window first so there's an active workspace. |
| 868 scoped_ptr<Window> w1(CreateTestWindow()); | 541 scoped_ptr<Window> w1(CreateTestWindow()); |
| 869 w1->Show(); | 542 w1->Show(); |
| 870 | 543 |
| 871 // Create a window that persists across all workspaces. | 544 // Create a window that persists across all workspaces. |
| 872 scoped_ptr<Window> w2(CreateTestWindow()); | 545 scoped_ptr<Window> w2(CreateTestWindow()); |
| 873 SetPersistsAcrossAllWorkspaces( | 546 SetPersistsAcrossAllWorkspaces( |
| 874 w2.get(), | 547 w2.get(), |
| 875 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | 548 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); |
| 876 w2->Show(); | 549 w2->Show(); |
| 877 wm::ActivateWindow(w2.get()); | 550 wm::ActivateWindow(w2.get()); |
| 878 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 551 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 879 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 552 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 880 EXPECT_FALSE(w2->IsVisible()); | 553 EXPECT_FALSE(w2->IsVisible()); |
| 881 // This is the critical call which should switch to the fullscreen workspace | 554 // This is the critical call which should switch to the fullscreen workspace |
| 882 // of that window instead of reparenting it to the other workspace (and | 555 // of that window instead of reparenting it to the other workspace (and |
| 883 // crashing while trying to do so). | 556 // crashing while trying to do so). |
| 884 wm::ActivateWindow(w2.get()); | 557 wm::ActivateWindow(w2.get()); |
| 885 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, | 558 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, |
| 886 w2->GetProperty(aura::client::kShowStateKey)); | 559 w2->GetProperty(aura::client::kShowStateKey)); |
| 887 EXPECT_TRUE(w2->IsVisible()); | 560 EXPECT_TRUE(w2->IsVisible()); |
| 888 } | 561 } |
| 889 | 562 |
| 890 // Test that we report we're in the fullscreen state even if the fullscreen | |
| 891 // window isn't being managed by us (http://crbug.com/123931). | |
| 892 TEST_F(WorkspaceManagerTest, GetWindowStateWithUnmanagedFullscreenWindow) { | |
| 893 ShelfLayoutManager* shelf = shelf_layout_manager(); | |
| 894 | |
| 895 // We need to create a regular window first so there's an active workspace. | |
| 896 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 897 w1->Show(); | |
| 898 | |
| 899 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 900 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 901 SetPersistsAcrossAllWorkspaces( | |
| 902 w2.get(), | |
| 903 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 904 w2->Show(); | |
| 905 wm::ActivateWindow(w2.get()); | |
| 906 | |
| 907 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 908 | |
| 909 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | |
| 910 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN, manager_->GetWindowState()); | |
| 911 | |
| 912 w2->Hide(); | |
| 913 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 914 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
| 915 | |
| 916 w2->Show(); | |
| 917 ASSERT_EQ("1 P=F1 active=0", StateString()); | |
| 918 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
| 919 EXPECT_EQ(WORKSPACE_WINDOW_STATE_DEFAULT, manager_->GetWindowState()); | |
| 920 | |
| 921 wm::ActivateWindow(w2.get()); | |
| 922 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 923 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | |
| 924 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN, manager_->GetWindowState()); | |
| 925 | |
| 926 w2.reset(); | |
| 927 ASSERT_EQ("1 active=0", StateString()); | |
| 928 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
| 929 EXPECT_EQ(WORKSPACE_WINDOW_STATE_DEFAULT, manager_->GetWindowState()); | |
| 930 } | |
| 931 | |
| 932 // Variant of GetWindowStateWithUnmanagedFullscreenWindow that uses a maximized | |
| 933 // window rather than a normal window. It should be same as the normal window. | |
| 934 TEST_F(WorkspaceManagerTest, | |
| 935 GetWindowStateWithUnmanagedFullscreenWindowWithMaximized) { | |
| 936 ShelfLayoutManager* shelf = shelf_layout_manager(); | |
| 937 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | |
| 938 | |
| 939 // Make the first window maximized. | |
| 940 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 941 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 942 w1->Show(); | |
| 943 | |
| 944 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 945 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 946 SetPersistsAcrossAllWorkspaces( | |
| 947 w2.get(), | |
| 948 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 949 w2->Show(); | |
| 950 wm::ActivateWindow(w2.get()); | |
| 951 | |
| 952 // Even though auto-hide behavior is NEVER full-screen windows cause the shelf | |
| 953 // to hide. | |
| 954 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | |
| 955 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN, | |
| 956 manager_->GetWindowState()); | |
| 957 | |
| 958 w2->Hide(); | |
| 959 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
| 960 | |
| 961 w2->Show(); | |
| 962 wm::ActivateWindow(w2.get()); | |
| 963 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | |
| 964 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN, | |
| 965 manager_->GetWindowState()); | |
| 966 | |
| 967 w2.reset(); | |
| 968 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
| 969 } | |
| 970 | |
| 971 // Verifies a window marked as persisting across all workspaces ends up in its | |
| 972 // own workspace when got fullscreen. | |
| 973 TEST_F(WorkspaceManagerTest, FullscreenDontPersistEndsUpInOwnWorkspace) { | |
| 974 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 975 | |
| 976 SetPersistsAcrossAllWorkspaces( | |
| 977 w1.get(), | |
| 978 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 979 w1->Show(); | |
| 980 | |
| 981 ASSERT_EQ("1 active=0", StateString()); | |
| 982 | |
| 983 // Maximize should trigger containing the window. | |
| 984 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 985 ASSERT_EQ("0 P=F1 active=0", StateString()); | |
| 986 | |
| 987 // And resetting to normal should remove it. | |
| 988 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 989 ASSERT_EQ("1 active=0", StateString()); | |
| 990 } | |
| 991 | |
| 992 // Verifies going from maximized to minimized sets the right state for painting | 563 // Verifies going from maximized to minimized sets the right state for painting |
| 993 // the background of the launcher. | 564 // the background of the launcher. |
| 994 TEST_F(WorkspaceManagerTest, MinimizeResetsVisibility) { | 565 TEST_F(WorkspaceManagerTest, MinimizeResetsVisibility) { |
| 995 scoped_ptr<Window> w1(CreateTestWindow()); | 566 scoped_ptr<Window> w1(CreateTestWindow()); |
| 996 w1->Show(); | 567 w1->Show(); |
| 997 wm::ActivateWindow(w1.get()); | 568 wm::ActivateWindow(w1.get()); |
| 998 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 569 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 999 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, shelf_widget()->GetBackgroundType()); | 570 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, shelf_widget()->GetBackgroundType()); |
| 1000 | 571 |
| 1001 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 572 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 1002 EXPECT_EQ(SHELF_VISIBLE, | 573 EXPECT_EQ(SHELF_VISIBLE, |
| 1003 shelf_layout_manager()->visibility_state()); | 574 shelf_layout_manager()->visibility_state()); |
| 1004 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, shelf_widget()->GetBackgroundType()); | 575 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, shelf_widget()->GetBackgroundType()); |
| 1005 } | 576 } |
| 1006 | 577 |
| 1007 // Verifies transients are moved when fullscreen. | |
| 1008 TEST_F(WorkspaceManagerTest, MoveTransientOnFullscreen) { | |
| 1009 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 1010 w1->Show(); | |
| 1011 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 1012 w1->AddTransientChild(w2.get()); | |
| 1013 w2->Show(); | |
| 1014 wm::ActivateWindow(w1.get()); | |
| 1015 ASSERT_EQ("2 active=0", StateString()); | |
| 1016 | |
| 1017 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 1018 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 1019 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 1020 | |
| 1021 // Create another transient child of |w1|. We do this unparented, set up the | |
| 1022 // transient parent then set parent. This is how NativeWidgetAura does things | |
| 1023 // too. | |
| 1024 scoped_ptr<Window> w3(CreateTestWindowUnparented()); | |
| 1025 w1->AddTransientChild(w3.get()); | |
| 1026 SetDefaultParentByPrimaryRootWindow(w3.get()); | |
| 1027 w3->Show(); | |
| 1028 ASSERT_EQ("0 F3 active=1", StateString()); | |
| 1029 | |
| 1030 // Minimize the window. All the transients are hidden as a result, so it ends | |
| 1031 // up in pending. | |
| 1032 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
| 1033 ASSERT_EQ("0 P=F3 active=0", StateString()); | |
| 1034 | |
| 1035 // Restore and everything should go back to the first workspace. | |
| 1036 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 1037 ASSERT_EQ("3 active=0", StateString()); | |
| 1038 } | |
| 1039 | |
| 1040 // Verifies window visibility during various workspace changes. | 578 // Verifies window visibility during various workspace changes. |
| 1041 TEST_F(WorkspaceManagerTest, VisibilityTests) { | 579 TEST_F(WorkspaceManagerTest, VisibilityTests) { |
| 1042 scoped_ptr<Window> w1(CreateTestWindow()); | 580 scoped_ptr<Window> w1(CreateTestWindow()); |
| 1043 w1->Show(); | 581 w1->Show(); |
| 1044 EXPECT_TRUE(w1->IsVisible()); | 582 EXPECT_TRUE(w1->IsVisible()); |
| 1045 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 583 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
| 1046 | 584 |
| 1047 // Create another window, activate it and make it fullscreen. | 585 // Create another window, activate it and make it fullscreen. |
| 1048 scoped_ptr<Window> w2(CreateTestWindow()); | 586 scoped_ptr<Window> w2(CreateTestWindow()); |
| 1049 w2->Show(); | 587 w2->Show(); |
| 1050 wm::ActivateWindow(w2.get()); | 588 wm::ActivateWindow(w2.get()); |
| 1051 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 589 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 1052 EXPECT_TRUE(w2->IsVisible()); | 590 EXPECT_TRUE(w2->IsVisible()); |
| 1053 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); | 591 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); |
| 1054 EXPECT_FALSE(w1->IsVisible()); | 592 EXPECT_TRUE(w1->IsVisible()); |
| 1055 | 593 |
| 1056 // Switch to w1. |w1| should be visible and |w2| hidden. | 594 // Switch to w1. |w1| should be visible and |w2| hidden. |
|
James Cook
2013/07/23 16:53:48
comment is wrong
Jun Mukai
2013/07/23 18:04:19
Done.
| |
| 1057 wm::ActivateWindow(w1.get()); | 595 wm::ActivateWindow(w1.get()); |
| 1058 EXPECT_TRUE(w1->IsVisible()); | 596 EXPECT_TRUE(w1->IsVisible()); |
| 1059 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 597 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
| 1060 EXPECT_FALSE(w2->IsVisible()); | 598 EXPECT_TRUE(w2->IsVisible()); |
| 1061 | 599 |
| 1062 // Switch back to |w2|. | 600 // Switch back to |w2|. |
| 1063 wm::ActivateWindow(w2.get()); | 601 wm::ActivateWindow(w2.get()); |
| 1064 EXPECT_TRUE(w2->IsVisible()); | 602 EXPECT_TRUE(w2->IsVisible()); |
| 1065 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); | 603 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); |
| 1066 EXPECT_FALSE(w1->IsVisible()); | 604 EXPECT_TRUE(w1->IsVisible()); |
| 1067 | 605 |
| 1068 // Restore |w2|, both windows should be visible. | 606 // Restore |w2|, both windows should be visible. |
| 1069 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 607 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 1070 EXPECT_TRUE(w1->IsVisible()); | 608 EXPECT_TRUE(w1->IsVisible()); |
| 1071 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 609 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
| 1072 EXPECT_TRUE(w2->IsVisible()); | 610 EXPECT_TRUE(w2->IsVisible()); |
| 1073 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); | 611 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); |
| 1074 | 612 |
| 1075 // Make |w2| fullscreen again, then close it. | 613 // Make |w2| fullscreen again, then close it. |
| 1076 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 614 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 gfx::Insets insets = | 687 gfx::Insets insets = |
| 1150 Shell::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); | 688 Shell::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); |
| 1151 insets.Set(0, 0, insets.bottom() + 30, 0); | 689 insets.Set(0, 0, insets.bottom() + 30, 0); |
| 1152 Shell::GetInstance()->SetDisplayWorkAreaInsets(w1.get(), insets); | 690 Shell::GetInstance()->SetDisplayWorkAreaInsets(w1.get(), insets); |
| 1153 | 691 |
| 1154 // Switch to w1. The window should have moved. | 692 // Switch to w1. The window should have moved. |
| 1155 wm::ActivateWindow(w1.get()); | 693 wm::ActivateWindow(w1.get()); |
| 1156 EXPECT_NE(w1_bounds.ToString(), w1->bounds().ToString()); | 694 EXPECT_NE(w1_bounds.ToString(), w1->bounds().ToString()); |
| 1157 } | 695 } |
| 1158 | 696 |
| 1159 // Verifies Focus() works in a window that isn't in the active workspace. | |
| 1160 TEST_F(WorkspaceManagerTest, FocusOnFullscreenInSeparateWorkspace) { | |
| 1161 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 1162 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); | |
| 1163 w1->Show(); | |
| 1164 wm::ActivateWindow(w1.get()); | |
| 1165 | |
| 1166 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 1167 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | |
| 1168 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 1169 w2->Show(); | |
| 1170 EXPECT_FALSE(w2->IsVisible()); | |
| 1171 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | |
| 1172 | |
| 1173 w2->Focus(); | |
| 1174 EXPECT_TRUE(w2->IsVisible()); | |
| 1175 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 1176 EXPECT_FALSE(w1->IsVisible()); | |
| 1177 } | |
| 1178 | |
| 1179 namespace { | 697 namespace { |
| 1180 | 698 |
| 1181 // WindowDelegate used by DontCrashOnChangeAndActivate. | 699 // WindowDelegate used by DontCrashOnChangeAndActivate. |
| 1182 class DontCrashOnChangeAndActivateDelegate | 700 class DontCrashOnChangeAndActivateDelegate |
| 1183 : public aura::test::TestWindowDelegate { | 701 : public aura::test::TestWindowDelegate { |
| 1184 public: | 702 public: |
| 1185 DontCrashOnChangeAndActivateDelegate() : window_(NULL) {} | 703 DontCrashOnChangeAndActivateDelegate() : window_(NULL) {} |
| 1186 | 704 |
| 1187 void set_window(aura::Window* window) { window_ = window; } | 705 void set_window(aura::Window* window) { window_ = window; } |
| 1188 | 706 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 798 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 1281 EXPECT_TRUE(w1->IsVisible()); | 799 EXPECT_TRUE(w1->IsVisible()); |
| 1282 EXPECT_TRUE(w2->IsVisible()); | 800 EXPECT_TRUE(w2->IsVisible()); |
| 1283 | 801 |
| 1284 // Because |w2| isn't tracked we should be able to set the bounds of it. | 802 // Because |w2| isn't tracked we should be able to set the bounds of it. |
| 1285 gfx::Rect bounds(w2->bounds()); | 803 gfx::Rect bounds(w2->bounds()); |
| 1286 bounds.Offset(4, 5); | 804 bounds.Offset(4, 5); |
| 1287 w2->SetBounds(bounds); | 805 w2->SetBounds(bounds); |
| 1288 EXPECT_EQ(bounds.ToString(), w2->bounds().ToString()); | 806 EXPECT_EQ(bounds.ToString(), w2->bounds().ToString()); |
| 1289 | 807 |
| 1290 // Transition it to tracked by worskpace. It should end up in its own | 808 // Transition it to tracked by worskpace. It should end up in its own |
|
James Cook
2013/07/23 16:53:48
comment is wrong
Jun Mukai
2013/07/23 18:04:19
Done.
| |
| 1291 // workspace. | 809 // workspace. |
| 1292 SetTrackedByWorkspace(w2.get(), true); | 810 SetTrackedByWorkspace(w2.get(), true); |
| 1293 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 811 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 1294 EXPECT_FALSE(w1->IsVisible()); | 812 EXPECT_TRUE(w1->IsVisible()); |
| 1295 EXPECT_TRUE(w2->IsVisible()); | 813 EXPECT_TRUE(w2->IsVisible()); |
| 1296 EXPECT_NE(w1->parent(), w2->parent()); | |
| 1297 } | |
| 1298 | |
| 1299 // Verifies a window marked as persisting across all workspaces ends up in its | |
| 1300 // own workspace when get fullscreen. | |
| 1301 TEST_F(WorkspaceManagerTest, DeactivateDropsToDesktop) { | |
| 1302 // Create a fullscreen window. | |
| 1303 scoped_ptr<Window> w1(CreateTestWindow()); | |
| 1304 w1->Show(); | |
| 1305 wm::ActivateWindow(w1.get()); | |
| 1306 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 1307 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 1308 EXPECT_TRUE(w1->IsVisible()); | |
| 1309 | |
| 1310 // Create another window that persists across all workspaces. It should end | |
| 1311 // up with the same parent as |w1|. | |
| 1312 scoped_ptr<Window> w2(CreateTestWindow()); | |
| 1313 SetPersistsAcrossAllWorkspaces( | |
| 1314 w2.get(), | |
| 1315 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); | |
| 1316 w2->Show(); | |
| 1317 wm::ActivateWindow(w2.get()); | |
| 1318 EXPECT_EQ(w1->parent(), w2->parent()); | 814 EXPECT_EQ(w1->parent(), w2->parent()); |
| 1319 ASSERT_EQ("0 F2 active=1", StateString()); | |
| 1320 | |
| 1321 // Activate |w1|, should result in dropping |w2| to the desktop. | |
| 1322 wm::ActivateWindow(w1.get()); | |
| 1323 ASSERT_EQ("1 F1 active=1", StateString()); | |
| 1324 } | 815 } |
| 1325 | 816 |
| 1326 // Test the basic auto placement of one and or two windows in a "simulated | 817 // Test the basic auto placement of one and or two windows in a "simulated |
| 1327 // session" of sequential window operations. | 818 // session" of sequential window operations. |
| 1328 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) { | 819 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) { |
| 1329 // Test 1: In case there is no manageable window, no window should shift. | 820 // Test 1: In case there is no manageable window, no window should shift. |
| 1330 | 821 |
| 1331 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 822 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1332 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 823 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1333 gfx::Rect desktop_area = window1->parent()->bounds(); | 824 gfx::Rect desktop_area = window1->parent()->bounds(); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1752 gfx::Rect(5, 6, 7, 8), | 1243 gfx::Rect(5, 6, 7, 8), |
| 1753 NULL)); | 1244 NULL)); |
| 1754 SetDefaultParentByPrimaryRootWindow(w1.get()); | 1245 SetDefaultParentByPrimaryRootWindow(w1.get()); |
| 1755 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 1246 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 1756 w1->Show(); | 1247 w1->Show(); |
| 1757 wm::ActivateWindow(w1.get()); | 1248 wm::ActivateWindow(w1.get()); |
| 1758 DragMaximizedNonTrackedWindowObserver observer; | 1249 DragMaximizedNonTrackedWindowObserver observer; |
| 1759 w1->parent()->parent()->AddObserver(&observer); | 1250 w1->parent()->parent()->AddObserver(&observer); |
| 1760 const gfx::Rect max_bounds(w1->bounds()); | 1251 const gfx::Rect max_bounds(w1->bounds()); |
| 1761 | 1252 |
| 1762 // There should be two workspace, one for the desktop and one for the | |
| 1763 // maximized window with the maximized active. | |
| 1764 EXPECT_EQ("0 F1 active=1", StateString()); | |
| 1765 | |
| 1766 generator.PressLeftButton(); | 1253 generator.PressLeftButton(); |
| 1767 generator.MoveMouseTo(100, 100); | 1254 generator.MoveMouseTo(100, 100); |
| 1768 // The bounds shouldn't change (drag should result in nothing happening | 1255 // The bounds shouldn't change (drag should result in nothing happening |
| 1769 // now. | 1256 // now. |
| 1770 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1257 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
| 1771 EXPECT_EQ("0 F1 active=1", StateString()); | |
| 1772 | 1258 |
| 1773 generator.ReleaseLeftButton(); | 1259 generator.ReleaseLeftButton(); |
| 1774 EXPECT_EQ(0, observer.change_count()); | 1260 EXPECT_EQ(0, observer.change_count()); |
| 1775 | 1261 |
| 1776 // Set tracked to false and repeat, now the window should move. | 1262 // Set tracked to false and repeat, now the window should move. |
| 1777 SetTrackedByWorkspace(w1.get(), false); | 1263 SetTrackedByWorkspace(w1.get(), false); |
| 1778 generator.MoveMouseTo(5, 5); | 1264 generator.MoveMouseTo(5, 5); |
| 1779 generator.PressLeftButton(); | 1265 generator.PressLeftButton(); |
| 1780 generator.MoveMouseBy(100, 100); | 1266 generator.MoveMouseBy(100, 100); |
| 1781 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, | 1267 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, |
| 1782 max_bounds.width(), max_bounds.height()).ToString(), | 1268 max_bounds.width(), max_bounds.height()).ToString(), |
| 1783 w1->bounds().ToString()); | 1269 w1->bounds().ToString()); |
| 1784 EXPECT_EQ("0 F1 active=1", StateString()); | |
| 1785 | 1270 |
| 1786 generator.ReleaseLeftButton(); | 1271 generator.ReleaseLeftButton(); |
| 1787 SetTrackedByWorkspace(w1.get(), true); | 1272 SetTrackedByWorkspace(w1.get(), true); |
| 1788 // Marking the window tracked again should snap back to origin. | 1273 // Marking the window tracked again should snap back to origin. |
| 1789 EXPECT_EQ("0 F1 active=1", StateString()); | |
| 1790 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1274 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
| 1791 EXPECT_EQ(0, observer.change_count()); | 1275 EXPECT_EQ(0, observer.change_count()); |
| 1792 | 1276 |
| 1793 w1->parent()->parent()->RemoveObserver(&observer); | 1277 w1->parent()->parent()->RemoveObserver(&observer); |
| 1794 } | 1278 } |
| 1795 | 1279 |
| 1796 // Verifies setting tracked by workspace to false and then dragging a maximized | 1280 // Verifies setting tracked by workspace to false and then dragging a maximized |
| 1797 // window can change the bound. | 1281 // window can change the bound. |
| 1798 TEST_F(WorkspaceManagerTest, DragMaximizedNonTrackedWindow) { | 1282 TEST_F(WorkspaceManagerTest, DragMaximizedNonTrackedWindow) { |
| 1799 aura::test::EventGenerator generator( | 1283 aura::test::EventGenerator generator( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1856 scoped_ptr<Window> maximized_window(CreateTestWindow()); | 1340 scoped_ptr<Window> maximized_window(CreateTestWindow()); |
| 1857 maximized_window->SetProperty( | 1341 maximized_window->SetProperty( |
| 1858 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1342 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 1859 maximized_window->Show(); | 1343 maximized_window->Show(); |
| 1860 wm::ActivateWindow(maximized_window.get()); | 1344 wm::ActivateWindow(maximized_window.get()); |
| 1861 EXPECT_TRUE(maximized_window->IsVisible()); | 1345 EXPECT_TRUE(maximized_window->IsVisible()); |
| 1862 } | 1346 } |
| 1863 | 1347 |
| 1864 } // namespace internal | 1348 } // namespace internal |
| 1865 } // namespace ash | 1349 } // namespace ash |
| OLD | NEW |