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

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

Issue 2808723004: Renames WmShell to ShellPort (Closed)
Patch Set: feedback 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 TestWindow::CloseTestWindow(modal1.release()); 655 TestWindow::CloseTestWindow(modal1.release());
656 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); 656 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds());
657 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); 657 EXPECT_TRUE(wm::IsActiveWindow(normal.get()));
658 } 658 }
659 659
660 // Test that with the visible keyboard, an existing system modal dialog gets 660 // Test that with the visible keyboard, an existing system modal dialog gets
661 // positioned into the visible area. 661 // positioned into the visible area.
662 TEST_F(SystemModalContainerLayoutManagerTest, 662 TEST_F(SystemModalContainerLayoutManagerTest,
663 SystemModalDialogGetPushedFromKeyboard) { 663 SystemModalDialogGetPushedFromKeyboard) {
664 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 664 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
665 if (WmShell::Get()->IsRunningInMash()) 665 if (ShellPort::Get()->IsRunningInMash())
666 return; 666 return;
667 667
668 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); 668 const gfx::Rect& container_bounds = GetModalContainer()->bounds();
669 // Place the window at the bottom of the screen. 669 // Place the window at the bottom of the screen.
670 gfx::Size modal_size(100, 100); 670 gfx::Size modal_size(100, 100);
671 gfx::Point modal_origin = gfx::Point( 671 gfx::Point modal_origin = gfx::Point(
672 (container_bounds.right() - modal_size.width()) / 2, // X centered 672 (container_bounds.right() - modal_size.width()) / 2, // X centered
673 container_bounds.bottom() - modal_size.height()); // at bottom 673 container_bounds.bottom() - modal_size.height()); // at bottom
674 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 674 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
675 675
(...skipping 19 matching lines...) Expand all
695 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); 695 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString());
696 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); 696 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString());
697 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); 697 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x());
698 } 698 }
699 699
700 // Test that windows will not get cropped through the visible virtual keyboard - 700 // Test that windows will not get cropped through the visible virtual keyboard -
701 // if centered. 701 // if centered.
702 TEST_F(SystemModalContainerLayoutManagerTest, 702 TEST_F(SystemModalContainerLayoutManagerTest,
703 SystemModalDialogGetPushedButNotCroppedFromKeyboard) { 703 SystemModalDialogGetPushedButNotCroppedFromKeyboard) {
704 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 704 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
705 if (WmShell::Get()->IsRunningInMash()) 705 if (ShellPort::Get()->IsRunningInMash())
706 return; 706 return;
707 707
708 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); 708 const gfx::Rect& container_bounds = GetModalContainer()->bounds();
709 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); 709 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size();
710 // Place the window at the bottom of the screen. 710 // Place the window at the bottom of the screen.
711 gfx::Size modal_size(100, screen_size.height() - 70); 711 gfx::Size modal_size(100, screen_size.height() - 70);
712 gfx::Point modal_origin = gfx::Point( 712 gfx::Point modal_origin = gfx::Point(
713 (container_bounds.right() - modal_size.width()) / 2, // X centered 713 (container_bounds.right() - modal_size.width()) / 2, // X centered
714 container_bounds.bottom() - modal_size.height()); // at bottom 714 container_bounds.bottom() - modal_size.height()); // at bottom
715 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 715 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
(...skipping 16 matching lines...) Expand all
732 EXPECT_EQ(0, modal_window->bounds().y()); 732 EXPECT_EQ(0, modal_window->bounds().y());
733 733
734 ShowKeyboard(false); 734 ShowKeyboard(false);
735 } 735 }
736 736
737 // Test that windows will not get cropped through the visible virtual keyboard - 737 // Test that windows will not get cropped through the visible virtual keyboard -
738 // if not centered. 738 // if not centered.
739 TEST_F(SystemModalContainerLayoutManagerTest, 739 TEST_F(SystemModalContainerLayoutManagerTest,
740 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { 740 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) {
741 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. 741 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892.
742 if (WmShell::Get()->IsRunningInMash()) 742 if (ShellPort::Get()->IsRunningInMash())
743 return; 743 return;
744 744
745 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); 745 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size();
746 // Place the window at the bottom of the screen. 746 // Place the window at the bottom of the screen.
747 gfx::Size modal_size(100, screen_size.height() - 70); 747 gfx::Size modal_size(100, screen_size.height() - 70);
748 gfx::Point modal_origin = gfx::Point(10, 20); 748 gfx::Point modal_origin = gfx::Point(10, 20);
749 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); 749 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size);
750 750
751 // Create a modal window. 751 // Create a modal window.
752 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); 752 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false));
(...skipping 15 matching lines...) Expand all
768 ShowKeyboard(false); 768 ShowKeyboard(false);
769 } 769 }
770 770
771 TEST_F(SystemModalContainerLayoutManagerTest, UpdateModalType) { 771 TEST_F(SystemModalContainerLayoutManagerTest, UpdateModalType) {
772 aura::Window* modal_container = Shell::GetContainer( 772 aura::Window* modal_container = Shell::GetContainer(
773 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); 773 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
774 views::Widget* widget = views::Widget::CreateWindowWithParent( 774 views::Widget* widget = views::Widget::CreateWindowWithParent(
775 new TestWindow(false), modal_container); 775 new TestWindow(false), modal_container);
776 widget->Show(); 776 widget->Show();
777 aura::Window* window = widget->GetNativeWindow(); 777 aura::Window* window = widget->GetNativeWindow();
778 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 778 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
779 779
780 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 780 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
781 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 781 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
782 782
783 // Setting twice should not cause error. 783 // Setting twice should not cause error.
784 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 784 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
785 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 785 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
786 786
787 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 787 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE);
788 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 788 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
789 789
790 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 790 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
791 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 791 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
792 792
793 widget->Close(); 793 widget->Close();
794 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 794 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
795 } 795 }
796 796
797 TEST_F(SystemModalContainerLayoutManagerTest, VisibilityChange) { 797 TEST_F(SystemModalContainerLayoutManagerTest, VisibilityChange) {
798 std::unique_ptr<aura::Window> window(OpenToplevelTestWindow(false)); 798 std::unique_ptr<aura::Window> window(OpenToplevelTestWindow(false));
799 std::unique_ptr<aura::Window> modal_window( 799 std::unique_ptr<aura::Window> modal_window(
800 views::Widget::CreateWindowWithContext(new TestWindow(true), 800 views::Widget::CreateWindowWithContext(new TestWindow(true),
801 CurrentContext()) 801 CurrentContext())
802 ->GetNativeWindow()); 802 ->GetNativeWindow());
803 SystemModalContainerLayoutManager* layout_manager = 803 SystemModalContainerLayoutManager* layout_manager =
804 WmShell::Get() 804 ShellPort::Get()
805 ->GetPrimaryRootWindowController() 805 ->GetPrimaryRootWindowController()
806 ->GetSystemModalLayoutManager(WmWindow::Get(modal_window.get())); 806 ->GetSystemModalLayoutManager(WmWindow::Get(modal_window.get()));
807 807
808 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 808 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
809 EXPECT_FALSE(layout_manager->has_window_dimmer()); 809 EXPECT_FALSE(layout_manager->has_window_dimmer());
810 810
811 modal_window->Show(); 811 modal_window->Show();
812 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 812 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
813 EXPECT_TRUE(layout_manager->has_window_dimmer()); 813 EXPECT_TRUE(layout_manager->has_window_dimmer());
814 814
815 // Make sure that a child visibility change should not cause 815 // Make sure that a child visibility change should not cause
816 // inconsistent state. 816 // inconsistent state.
817 std::unique_ptr<aura::Window> child = base::MakeUnique<aura::Window>(nullptr); 817 std::unique_ptr<aura::Window> child = base::MakeUnique<aura::Window>(nullptr);
818 child->SetType(ui::wm::WINDOW_TYPE_CONTROL); 818 child->SetType(ui::wm::WINDOW_TYPE_CONTROL);
819 child->Init(ui::LAYER_TEXTURED); 819 child->Init(ui::LAYER_TEXTURED);
820 modal_window->AddChild(child.get()); 820 modal_window->AddChild(child.get());
821 child->Show(); 821 child->Show();
822 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 822 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
823 EXPECT_TRUE(layout_manager->has_window_dimmer()); 823 EXPECT_TRUE(layout_manager->has_window_dimmer());
824 824
825 modal_window->Hide(); 825 modal_window->Hide();
826 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 826 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
827 EXPECT_FALSE(layout_manager->has_window_dimmer()); 827 EXPECT_FALSE(layout_manager->has_window_dimmer());
828 828
829 modal_window->Show(); 829 modal_window->Show();
830 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 830 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
831 EXPECT_TRUE(layout_manager->has_window_dimmer()); 831 EXPECT_TRUE(layout_manager->has_window_dimmer());
832 } 832 }
833 833
834 namespace { 834 namespace {
835 835
836 class InputTestDelegate : public aura::test::TestWindowDelegate { 836 class InputTestDelegate : public aura::test::TestWindowDelegate {
837 public: 837 public:
838 InputTestDelegate() {} 838 InputTestDelegate() {}
839 ~InputTestDelegate() override {} 839 ~InputTestDelegate() override {}
840 840
841 void RunTest(test::AshTestBase* test_base) { 841 void RunTest(test::AshTestBase* test_base) {
842 std::unique_ptr<aura::Window> window( 842 std::unique_ptr<aura::Window> window(
843 test_base->CreateTestWindowInShellWithDelegate( 843 test_base->CreateTestWindowInShellWithDelegate(
844 this, 0, gfx::Rect(0, 0, 100, 100))); 844 this, 0, gfx::Rect(0, 0, 100, 100)));
845 window->Show(); 845 window->Show();
846 846
847 GenerateEvents(window.get()); 847 GenerateEvents(window.get());
848 848
849 EXPECT_EQ(2, mouse_event_count_); 849 EXPECT_EQ(2, mouse_event_count_);
850 EXPECT_EQ(3, scroll_event_count_); 850 EXPECT_EQ(3, scroll_event_count_);
851 EXPECT_EQ(4, touch_event_count_); 851 EXPECT_EQ(4, touch_event_count_);
852 EXPECT_EQ(10, gesture_event_count_); 852 EXPECT_EQ(10, gesture_event_count_);
853 Reset(); 853 Reset();
854 854
855 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 855 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
856 new TestWindow(true), Shell::GetPrimaryRootWindow(), 856 new TestWindow(true), Shell::GetPrimaryRootWindow(),
857 gfx::Rect(200, 200, 100, 100)); 857 gfx::Rect(200, 200, 100, 100));
858 widget->Show(); 858 widget->Show();
859 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); 859 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen());
860 860
861 // Events should be blocked. 861 // Events should be blocked.
862 GenerateEvents(window.get()); 862 GenerateEvents(window.get());
863 863
864 EXPECT_EQ(0, mouse_event_count_); 864 EXPECT_EQ(0, mouse_event_count_);
865 EXPECT_EQ(0, scroll_event_count_); 865 EXPECT_EQ(0, scroll_event_count_);
866 EXPECT_EQ(0, touch_event_count_); 866 EXPECT_EQ(0, touch_event_count_);
867 EXPECT_EQ(0, gesture_event_count_); 867 EXPECT_EQ(0, gesture_event_count_);
868 Reset(); 868 Reset();
869 869
870 widget->Close(); 870 widget->Close();
871 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); 871 EXPECT_FALSE(ShellPort::Get()->IsSystemModalWindowOpen());
872 872
873 GenerateEvents(window.get()); 873 GenerateEvents(window.get());
874 874
875 EXPECT_EQ(2, mouse_event_count_); 875 EXPECT_EQ(2, mouse_event_count_);
876 EXPECT_EQ(3, scroll_event_count_); 876 EXPECT_EQ(3, scroll_event_count_);
877 EXPECT_EQ(4, touch_event_count_); 877 EXPECT_EQ(4, touch_event_count_);
878 EXPECT_EQ(10, gesture_event_count_); 878 EXPECT_EQ(10, gesture_event_count_);
879 } 879 }
880 880
881 private: 881 private:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 922
923 // Make sure that events are properly blocked in multi displays environment. 923 // Make sure that events are properly blocked in multi displays environment.
924 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) { 924 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) {
925 UpdateDisplay("500x500, 500x500"); 925 UpdateDisplay("500x500, 500x500");
926 InputTestDelegate delegate; 926 InputTestDelegate delegate;
927 delegate.RunTest(this); 927 delegate.RunTest(this);
928 } 928 }
929 929
930 } // namespace test 930 } // namespace test
931 } // namespace ash 931 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698