| 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 | 6 |
| 7 #include "ash/session_state_delegate.h" | 7 #include "ash/session_state_delegate.h" |
| 8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual views::View* GetContentsView() OVERRIDE { | 44 virtual views::View* GetContentsView() OVERRIDE { |
| 45 return this; | 45 return this; |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual ui::ModalType GetModalType() const OVERRIDE { | 48 virtual ui::ModalType GetModalType() const OVERRIDE { |
| 49 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; | 49 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 bool system_modal_; | 53 bool system_modal_; |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 54 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, | 57 class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
| 59 public aura::client::FocusChangeObserver { | 58 public aura::client::FocusChangeObserver { |
| 60 public: | 59 public: |
| 61 DeleteOnBlurDelegate() : window_(NULL) {} | 60 DeleteOnBlurDelegate() : window_(NULL) {} |
| 62 virtual ~DeleteOnBlurDelegate() {} | 61 virtual ~DeleteOnBlurDelegate() {} |
| 63 | 62 |
| 64 void SetWindow(aura::Window* window) { | 63 void SetWindow(aura::Window* window) { |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 ++block_reason) { | 521 ++block_reason) { |
| 523 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 522 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 524 lock_window->Focus(); | 523 lock_window->Focus(); |
| 525 EXPECT_TRUE(lock_window->HasFocus()); | 524 EXPECT_TRUE(lock_window->HasFocus()); |
| 526 session_window->Focus(); | 525 session_window->Focus(); |
| 527 EXPECT_FALSE(session_window->HasFocus()); | 526 EXPECT_FALSE(session_window->HasFocus()); |
| 528 UnblockUserSession(); | 527 UnblockUserSession(); |
| 529 } | 528 } |
| 530 } | 529 } |
| 531 | 530 |
| 532 // Tracks whether OnWindowDestroying() has been invoked. | |
| 533 class DestroyedWindowObserver : public aura::WindowObserver { | |
| 534 public: | |
| 535 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {} | |
| 536 virtual ~DestroyedWindowObserver() { | |
| 537 Shutdown(); | |
| 538 } | |
| 539 | |
| 540 void SetWindow(Window* window) { | |
| 541 window_ = window; | |
| 542 window->AddObserver(this); | |
| 543 } | |
| 544 | |
| 545 bool destroyed() const { return destroyed_; } | |
| 546 | |
| 547 // WindowObserver overrides: | |
| 548 virtual void OnWindowDestroying(Window* window) OVERRIDE { | |
| 549 destroyed_ = true; | |
| 550 window->RemoveObserver(this); | |
| 551 } | |
| 552 | |
| 553 private: | |
| 554 void Shutdown() { | |
| 555 if (!window_) | |
| 556 return; | |
| 557 window_->RemoveObserver(this); | |
| 558 window_ = NULL; | |
| 559 } | |
| 560 | |
| 561 bool destroyed_; | |
| 562 Window* window_; | |
| 563 | |
| 564 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver); | |
| 565 }; | |
| 566 | |
| 567 // Verifies shutdown doesn't delete windows that are not owned by the parent. | |
| 568 TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) { | |
| 569 DestroyedWindowObserver observer1; | |
| 570 aura::test::TestWindowDelegate delegate1; | |
| 571 aura::Window* window1 = new aura::Window(&delegate1); | |
| 572 window1->SetType(aura::client::WINDOW_TYPE_CONTROL); | |
| 573 window1->set_owned_by_parent(false); | |
| 574 observer1.SetWindow(window1); | |
| 575 window1->Init(ui::LAYER_NOT_DRAWN); | |
| 576 window1->SetDefaultParentByRootWindow( | |
| 577 Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect()); | |
| 578 | |
| 579 DestroyedWindowObserver observer2; | |
| 580 aura::Window* window2 = new aura::Window(NULL); | |
| 581 window2->set_owned_by_parent(false); | |
| 582 observer2.SetWindow(window2); | |
| 583 window2->Init(ui::LAYER_NOT_DRAWN); | |
| 584 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2); | |
| 585 | |
| 586 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows(); | |
| 587 | |
| 588 ASSERT_FALSE(observer1.destroyed()); | |
| 589 delete window1; | |
| 590 | |
| 591 ASSERT_FALSE(observer2.destroyed()); | |
| 592 delete window2; | |
| 593 } | |
| 594 | |
| 595 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; | 531 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; |
| 596 | 532 |
| 597 // Make sure that an event handler exists for entire display area. | 533 // Make sure that an event handler exists for entire display area. |
| 598 TEST_F(NoSessionRootWindowControllerTest, Event) { | 534 TEST_F(NoSessionRootWindowControllerTest, Event) { |
| 599 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 535 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 600 const gfx::Size size = root->bounds().size(); | 536 const gfx::Size size = root->bounds().size(); |
| 601 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); | 537 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); |
| 602 EXPECT_TRUE(event_target); | 538 EXPECT_TRUE(event_target); |
| 603 EXPECT_EQ(event_target, | 539 EXPECT_EQ(event_target, |
| 604 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); | 540 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 aura::WindowTracker tracker; | 607 aura::WindowTracker tracker; |
| 672 tracker.Add(keyboard_container); | 608 tracker.Add(keyboard_container); |
| 673 // Mock a login state change to reinitialize the keyboard. | 609 // Mock a login state change to reinitialize the keyboard. |
| 674 ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER); | 610 ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER); |
| 675 // keyboard_container should no longer be present. | 611 // keyboard_container should no longer be present. |
| 676 EXPECT_FALSE(tracker.Contains(keyboard_container)); | 612 EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 677 } | 613 } |
| 678 | 614 |
| 679 } // namespace test | 615 } // namespace test |
| 680 } // namespace ash | 616 } // namespace ash |
| OLD | NEW |