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

Side by Side Diff: ash/wm/system_modal_container_layout_manager_unittest.cc

Issue 2808723004: Renames WmShell to ShellPort (Closed)
Patch Set: cleanup Created 3 years, 8 months 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
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/system_modal_container_layout_manager.h" 5 #include "ash/wm/system_modal_container_layout_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "ash/session/session_state_delegate.h" 11 #include "ash/session/session_state_delegate.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
14 #include "ash/wm/container_finder.h" 15 #include "ash/wm/container_finder.h"
15 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
16 #include "ash/wm_shell.h"
17 #include "ash/wm_window.h" 17 #include "ash/wm_window.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/run_loop.h" 21 #include "base/run_loop.h"
22 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/test/test_window_delegate.h" 23 #include "ui/aura/test/test_window_delegate.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/aura/window_event_dispatcher.h" 25 #include "ui/aura/window_event_dispatcher.h"
26 #include "ui/base/hit_test.h" 26 #include "ui/base/hit_test.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } // namespace 146 } // namespace
147 147
148 class SystemModalContainerLayoutManagerTest : public AshTestBase { 148 class SystemModalContainerLayoutManagerTest : public AshTestBase {
149 public: 149 public:
150 void SetUp() override { 150 void SetUp() override {
151 // Allow a virtual keyboard (and initialize it per default). 151 // Allow a virtual keyboard (and initialize it per default).
152 base::CommandLine::ForCurrentProcess()->AppendSwitch( 152 base::CommandLine::ForCurrentProcess()->AppendSwitch(
153 keyboard::switches::kEnableVirtualKeyboard); 153 keyboard::switches::kEnableVirtualKeyboard);
154 AshTestBase::SetUp(); 154 AshTestBase::SetUp();
155 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 155 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
156 if (!WmShell::Get()->IsRunningInMash()) { 156 if (!ShellPort::Get()->IsRunningInMash()) {
157 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( 157 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
158 keyboard::KeyboardController::GetInstance()); 158 keyboard::KeyboardController::GetInstance());
159 } 159 }
160 } 160 }
161 161
162 void TearDown() override { 162 void TearDown() override {
163 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 163 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
164 if (!WmShell::Get()->IsRunningInMash()) { 164 if (!ShellPort::Get()->IsRunningInMash()) {
165 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( 165 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
166 keyboard::KeyboardController::GetInstance()); 166 keyboard::KeyboardController::GetInstance());
167 } 167 }
168 AshTestBase::TearDown(); 168 AshTestBase::TearDown();
169 } 169 }
170 170
171 aura::Window* OpenToplevelTestWindow(bool modal) { 171 aura::Window* OpenToplevelTestWindow(bool modal) {
172 views::Widget* widget = views::Widget::CreateWindowWithContext( 172 views::Widget* widget = views::Widget::CreateWindowWithContext(
173 new TestWindow(modal), CurrentContext()); 173 new TestWindow(modal), CurrentContext());
174 widget->Show(); 174 widget->Show();
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 TestWindow::CloseTestWindow(modal1.release()); 641 TestWindow::CloseTestWindow(modal1.release());
642 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); 642 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds());
643 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); 643 EXPECT_TRUE(wm::IsActiveWindow(normal.get()));
644 } 644 }
645 645
646 // Test that with the visible keyboard, an existing system modal dialog gets 646 // Test that with the visible keyboard, an existing system modal dialog gets
647 // positioned into the visible area. 647 // positioned into the visible area.
648 TEST_F(SystemModalContainerLayoutManagerTest, 648 TEST_F(SystemModalContainerLayoutManagerTest,
649 SystemModalDialogGetPushedFromKeyboard) { 649 SystemModalDialogGetPushedFromKeyboard) {
650 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 650 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
651 if (WmShell::Get()->IsRunningInMash()) 651 if (ShellPort::Get()->IsRunningInMash())
652 return; 652 return;
653 653
654 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); 654 const gfx::Rect& container_bounds = GetModalContainer()->bounds();
655 // Place the window at the bottom of the screen. 655 // Place the window at the bottom of the screen.
656 gfx::Size modal_size(100, 100); 656 gfx::Size modal_size(100, 100);
657 gfx::Point modal_origin = gfx::Point( 657 gfx::Point modal_origin = gfx::Point(
658 (container_bounds.right() - modal_size.width()) / 2, // X centered 658 (container_bounds.right() - modal_size.width()) / 2, // X centered
659 container_bounds.bottom() - modal_size.height()); // at bottom 659 container_bounds.bottom() - modal_size.height()); // at bottom
660 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 660 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
661 661
(...skipping 19 matching lines...) Expand all
681 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); 681 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString());
682 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); 682 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString());
683 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); 683 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x());
684 } 684 }
685 685
686 // Test that windows will not get cropped through the visible virtual keyboard - 686 // Test that windows will not get cropped through the visible virtual keyboard -
687 // if centered. 687 // if centered.
688 TEST_F(SystemModalContainerLayoutManagerTest, 688 TEST_F(SystemModalContainerLayoutManagerTest,
689 SystemModalDialogGetPushedButNotCroppedFromKeyboard) { 689 SystemModalDialogGetPushedButNotCroppedFromKeyboard) {
690 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 690 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
691 if (WmShell::Get()->IsRunningInMash()) 691 if (ShellPort::Get()->IsRunningInMash())
692 return; 692 return;
693 693
694 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); 694 const gfx::Rect& container_bounds = GetModalContainer()->bounds();
695 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); 695 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size();
696 // Place the window at the bottom of the screen. 696 // Place the window at the bottom of the screen.
697 gfx::Size modal_size(100, screen_size.height() - 70); 697 gfx::Size modal_size(100, screen_size.height() - 70);
698 gfx::Point modal_origin = gfx::Point( 698 gfx::Point modal_origin = gfx::Point(
699 (container_bounds.right() - modal_size.width()) / 2, // X centered 699 (container_bounds.right() - modal_size.width()) / 2, // X centered
700 container_bounds.bottom() - modal_size.height()); // at bottom 700 container_bounds.bottom() - modal_size.height()); // at bottom
701 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 701 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
(...skipping 16 matching lines...) Expand all
718 EXPECT_EQ(0, modal_window->bounds().y()); 718 EXPECT_EQ(0, modal_window->bounds().y());
719 719
720 ShowKeyboard(false); 720 ShowKeyboard(false);
721 } 721 }
722 722
723 // Test that windows will not get cropped through the visible virtual keyboard - 723 // Test that windows will not get cropped through the visible virtual keyboard -
724 // if not centered. 724 // if not centered.
725 TEST_F(SystemModalContainerLayoutManagerTest, 725 TEST_F(SystemModalContainerLayoutManagerTest,
726 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { 726 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) {
727 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 727 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
728 if (WmShell::Get()->IsRunningInMash()) 728 if (ShellPort::Get()->IsRunningInMash())
729 return; 729 return;
730 730
731 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); 731 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size();
732 // Place the window at the bottom of the screen. 732 // Place the window at the bottom of the screen.
733 gfx::Size modal_size(100, screen_size.height() - 70); 733 gfx::Size modal_size(100, screen_size.height() - 70);
734 gfx::Point modal_origin = gfx::Point(10, 20); 734 gfx::Point modal_origin = gfx::Point(10, 20);
735 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 735 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
736 736
737 // Create a modal window. 737 // Create a modal window.
738 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); 738 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false));
(...skipping 15 matching lines...) Expand all
754 ShowKeyboard(false); 754 ShowKeyboard(false);
755 } 755 }
756 756
757 TEST_F(SystemModalContainerLayoutManagerTest, UpdateModalType) { 757 TEST_F(SystemModalContainerLayoutManagerTest, UpdateModalType) {
758 aura::Window* modal_container = Shell::GetContainer( 758 aura::Window* modal_container = Shell::GetContainer(
759 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); 759 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
760 views::Widget* widget = views::Widget::CreateWindowWithParent( 760 views::Widget* widget = views::Widget::CreateWindowWithParent(
761 new TestWindow(false), modal_container); 761 new TestWindow(false), modal_container);
762 widget->Show(); 762 widget->Show();
763 aura::Window* window = widget->GetNativeWindow(); 763 aura::Window* window = widget->GetNativeWindow();
764 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 764 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
765 765
766 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 766 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
767 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 767 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
768 768
769 // Setting twice should not cause error. 769 // Setting twice should not cause error.
770 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 770 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
771 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 771 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
772 772
773 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 773 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE);
774 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 774 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
775 775
776 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 776 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
777 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 777 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
778 778
779 widget->Close(); 779 widget->Close();
780 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 780 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
781 } 781 }
782 782
783 TEST_F(SystemModalContainerLayoutManagerTest, VisibilityChange) { 783 TEST_F(SystemModalContainerLayoutManagerTest, VisibilityChange) {
784 std::unique_ptr<aura::Window> window(OpenToplevelTestWindow(false)); 784 std::unique_ptr<aura::Window> window(OpenToplevelTestWindow(false));
785 std::unique_ptr<aura::Window> modal_window( 785 std::unique_ptr<aura::Window> modal_window(
786 views::Widget::CreateWindowWithContext(new TestWindow(true), 786 views::Widget::CreateWindowWithContext(new TestWindow(true),
787 CurrentContext()) 787 CurrentContext())
788 ->GetNativeWindow()); 788 ->GetNativeWindow());
789 SystemModalContainerLayoutManager* layout_manager = 789 SystemModalContainerLayoutManager* layout_manager =
790 WmShell::Get() 790 ShellPort::Get()
791 ->GetPrimaryRootWindowController() 791 ->GetPrimaryRootWindowController()
792 ->GetSystemModalLayoutManager(WmWindow::Get(modal_window.get())); 792 ->GetSystemModalLayoutManager(WmWindow::Get(modal_window.get()));
793 793
794 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 794 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
795 EXPECT_FALSE(layout_manager->has_window_dimmer()); 795 EXPECT_FALSE(layout_manager->has_window_dimmer());
796 796
797 modal_window->Show(); 797 modal_window->Show();
798 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 798 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
799 EXPECT_TRUE(layout_manager->has_window_dimmer()); 799 EXPECT_TRUE(layout_manager->has_window_dimmer());
800 800
801 // Make sure that a child visibility change should not cause 801 // Make sure that a child visibility change should not cause
802 // inconsistent state. 802 // inconsistent state.
803 std::unique_ptr<aura::Window> child = base::MakeUnique<aura::Window>(nullptr); 803 std::unique_ptr<aura::Window> child = base::MakeUnique<aura::Window>(nullptr);
804 child->SetType(ui::wm::WINDOW_TYPE_CONTROL); 804 child->SetType(ui::wm::WINDOW_TYPE_CONTROL);
805 child->Init(ui::LAYER_TEXTURED); 805 child->Init(ui::LAYER_TEXTURED);
806 modal_window->AddChild(child.get()); 806 modal_window->AddChild(child.get());
807 child->Show(); 807 child->Show();
808 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 808 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
809 EXPECT_TRUE(layout_manager->has_window_dimmer()); 809 EXPECT_TRUE(layout_manager->has_window_dimmer());
810 810
811 modal_window->Hide(); 811 modal_window->Hide();
812 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 812 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
813 EXPECT_FALSE(layout_manager->has_window_dimmer()); 813 EXPECT_FALSE(layout_manager->has_window_dimmer());
814 814
815 modal_window->Show(); 815 modal_window->Show();
816 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 816 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
817 EXPECT_TRUE(layout_manager->has_window_dimmer()); 817 EXPECT_TRUE(layout_manager->has_window_dimmer());
818 } 818 }
819 819
820 namespace { 820 namespace {
821 821
822 class InputTestDelegate : public aura::test::TestWindowDelegate { 822 class InputTestDelegate : public aura::test::TestWindowDelegate {
823 public: 823 public:
824 InputTestDelegate() {} 824 InputTestDelegate() {}
825 ~InputTestDelegate() override {} 825 ~InputTestDelegate() override {}
826 826
827 void RunTest(test::AshTestBase* test_base) { 827 void RunTest(test::AshTestBase* test_base) {
828 std::unique_ptr<aura::Window> window( 828 std::unique_ptr<aura::Window> window(
829 test_base->CreateTestWindowInShellWithDelegate( 829 test_base->CreateTestWindowInShellWithDelegate(
830 this, 0, gfx::Rect(0, 0, 100, 100))); 830 this, 0, gfx::Rect(0, 0, 100, 100)));
831 window->Show(); 831 window->Show();
832 832
833 GenerateEvents(window.get()); 833 GenerateEvents(window.get());
834 834
835 EXPECT_EQ(2, mouse_event_count_); 835 EXPECT_EQ(2, mouse_event_count_);
836 EXPECT_EQ(3, scroll_event_count_); 836 EXPECT_EQ(3, scroll_event_count_);
837 EXPECT_EQ(4, touch_event_count_); 837 EXPECT_EQ(4, touch_event_count_);
838 EXPECT_EQ(10, gesture_event_count_); 838 EXPECT_EQ(10, gesture_event_count_);
839 Reset(); 839 Reset();
840 840
841 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 841 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
842 new TestWindow(true), Shell::GetPrimaryRootWindow(), 842 new TestWindow(true), Shell::GetPrimaryRootWindow(),
843 gfx::Rect(200, 200, 100, 100)); 843 gfx::Rect(200, 200, 100, 100));
844 widget->Show(); 844 widget->Show();
845 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 845 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
846 846
847 // Events should be blocked. 847 // Events should be blocked.
848 GenerateEvents(window.get()); 848 GenerateEvents(window.get());
849 849
850 EXPECT_EQ(0, mouse_event_count_); 850 EXPECT_EQ(0, mouse_event_count_);
851 EXPECT_EQ(0, scroll_event_count_); 851 EXPECT_EQ(0, scroll_event_count_);
852 EXPECT_EQ(0, touch_event_count_); 852 EXPECT_EQ(0, touch_event_count_);
853 EXPECT_EQ(0, gesture_event_count_); 853 EXPECT_EQ(0, gesture_event_count_);
854 Reset(); 854 Reset();
855 855
856 widget->Close(); 856 widget->Close();
857 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 857 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
858 858
859 GenerateEvents(window.get()); 859 GenerateEvents(window.get());
860 860
861 EXPECT_EQ(2, mouse_event_count_); 861 EXPECT_EQ(2, mouse_event_count_);
862 EXPECT_EQ(3, scroll_event_count_); 862 EXPECT_EQ(3, scroll_event_count_);
863 EXPECT_EQ(4, touch_event_count_); 863 EXPECT_EQ(4, touch_event_count_);
864 EXPECT_EQ(10, gesture_event_count_); 864 EXPECT_EQ(10, gesture_event_count_);
865 } 865 }
866 866
867 private: 867 private:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 908
909 // Make sure that events are properly blocked in multi displays environment. 909 // Make sure that events are properly blocked in multi displays environment.
910 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) { 910 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) {
911 UpdateDisplay("500x500, 500x500"); 911 UpdateDisplay("500x500, 500x500");
912 InputTestDelegate delegate; 912 InputTestDelegate delegate;
913 delegate.RunTest(this); 913 delegate.RunTest(this);
914 } 914 }
915 915
916 } // namespace test 916 } // namespace test
917 } // namespace ash 917 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698