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 |
54 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 55 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
55 }; | 56 }; |
56 | 57 |
57 class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, | 58 class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, |
58 public aura::client::FocusChangeObserver { | 59 public aura::client::FocusChangeObserver { |
59 public: | 60 public: |
60 DeleteOnBlurDelegate() : window_(NULL) {} | 61 DeleteOnBlurDelegate() : window_(NULL) {} |
61 virtual ~DeleteOnBlurDelegate() {} | 62 virtual ~DeleteOnBlurDelegate() {} |
62 | 63 |
63 void SetWindow(aura::Window* window) { | 64 void SetWindow(aura::Window* window) { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 ++block_reason) { | 522 ++block_reason) { |
522 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 523 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
523 lock_window->Focus(); | 524 lock_window->Focus(); |
524 EXPECT_TRUE(lock_window->HasFocus()); | 525 EXPECT_TRUE(lock_window->HasFocus()); |
525 session_window->Focus(); | 526 session_window->Focus(); |
526 EXPECT_FALSE(session_window->HasFocus()); | 527 EXPECT_FALSE(session_window->HasFocus()); |
527 UnblockUserSession(); | 528 UnblockUserSession(); |
528 } | 529 } |
529 } | 530 } |
530 | 531 |
| 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 Shutdown(); |
| 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 |
531 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; | 595 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest; |
532 | 596 |
533 // Make sure that an event handler exists for entire display area. | 597 // Make sure that an event handler exists for entire display area. |
534 TEST_F(NoSessionRootWindowControllerTest, Event) { | 598 TEST_F(NoSessionRootWindowControllerTest, Event) { |
535 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 599 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
536 const gfx::Size size = root->bounds().size(); | 600 const gfx::Size size = root->bounds().size(); |
537 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); | 601 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0)); |
538 EXPECT_TRUE(event_target); | 602 EXPECT_TRUE(event_target); |
539 EXPECT_EQ(event_target, | 603 EXPECT_EQ(event_target, |
540 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); | 604 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1))); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 aura::WindowTracker tracker; | 671 aura::WindowTracker tracker; |
608 tracker.Add(keyboard_container); | 672 tracker.Add(keyboard_container); |
609 // Mock a login state change to reinitialize the keyboard. | 673 // Mock a login state change to reinitialize the keyboard. |
610 ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER); | 674 ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER); |
611 // keyboard_container should no longer be present. | 675 // keyboard_container should no longer be present. |
612 EXPECT_FALSE(tracker.Contains(keyboard_container)); | 676 EXPECT_FALSE(tracker.Contains(keyboard_container)); |
613 } | 677 } |
614 | 678 |
615 } // namespace test | 679 } // namespace test |
616 } // namespace ash | 680 } // namespace ash |
OLD | NEW |