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/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/config.h" |
9 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
10 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
11 #include "ash/session/session_state_delegate.h" | 12 #include "ash/session/session_state_delegate.h" |
12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
13 #include "ash/shell_port.h" | 14 #include "ash/shell_port.h" |
14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
15 #include "ash/wm/container_finder.h" | 16 #include "ash/wm/container_finder.h" |
16 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
17 #include "ash/wm_window.h" | 18 #include "ash/wm_window.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } // namespace | 147 } // namespace |
147 | 148 |
148 class SystemModalContainerLayoutManagerTest : public AshTestBase { | 149 class SystemModalContainerLayoutManagerTest : public AshTestBase { |
149 public: | 150 public: |
150 void SetUp() override { | 151 void SetUp() override { |
151 // Allow a virtual keyboard (and initialize it per default). | 152 // Allow a virtual keyboard (and initialize it per default). |
152 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 153 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
153 keyboard::switches::kEnableVirtualKeyboard); | 154 keyboard::switches::kEnableVirtualKeyboard); |
154 AshTestBase::SetUp(); | 155 AshTestBase::SetUp(); |
155 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. | 156 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. |
156 if (!ShellPort::Get()->IsRunningInMash()) { | 157 if (Shell::GetAshConfig() != Config::MASH) { |
157 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( | 158 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
158 keyboard::KeyboardController::GetInstance()); | 159 keyboard::KeyboardController::GetInstance()); |
159 } | 160 } |
160 } | 161 } |
161 | 162 |
162 void TearDown() override { | 163 void TearDown() override { |
163 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. | 164 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. |
164 if (!ShellPort::Get()->IsRunningInMash()) { | 165 if (Shell::GetAshConfig() != Config::MASH) { |
165 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( | 166 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
166 keyboard::KeyboardController::GetInstance()); | 167 keyboard::KeyboardController::GetInstance()); |
167 } | 168 } |
168 AshTestBase::TearDown(); | 169 AshTestBase::TearDown(); |
169 } | 170 } |
170 | 171 |
171 aura::Window* OpenToplevelTestWindow(bool modal) { | 172 aura::Window* OpenToplevelTestWindow(bool modal) { |
172 views::Widget* widget = views::Widget::CreateWindowWithContext( | 173 views::Widget* widget = views::Widget::CreateWindowWithContext( |
173 new TestWindow(modal), CurrentContext()); | 174 new TestWindow(modal), CurrentContext()); |
174 widget->Show(); | 175 widget->Show(); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 TestWindow::CloseTestWindow(modal1.release()); | 656 TestWindow::CloseTestWindow(modal1.release()); |
656 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 657 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
657 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); | 658 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); |
658 } | 659 } |
659 | 660 |
660 // Test that with the visible keyboard, an existing system modal dialog gets | 661 // Test that with the visible keyboard, an existing system modal dialog gets |
661 // positioned into the visible area. | 662 // positioned into the visible area. |
662 TEST_F(SystemModalContainerLayoutManagerTest, | 663 TEST_F(SystemModalContainerLayoutManagerTest, |
663 SystemModalDialogGetPushedFromKeyboard) { | 664 SystemModalDialogGetPushedFromKeyboard) { |
664 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. | 665 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. |
665 if (ShellPort::Get()->IsRunningInMash()) | 666 if (Shell::GetAshConfig() == Config::MASH) |
666 return; | 667 return; |
667 | 668 |
668 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); | 669 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); |
669 // Place the window at the bottom of the screen. | 670 // Place the window at the bottom of the screen. |
670 gfx::Size modal_size(100, 100); | 671 gfx::Size modal_size(100, 100); |
671 gfx::Point modal_origin = gfx::Point( | 672 gfx::Point modal_origin = gfx::Point( |
672 (container_bounds.right() - modal_size.width()) / 2, // X centered | 673 (container_bounds.right() - modal_size.width()) / 2, // X centered |
673 container_bounds.bottom() - modal_size.height()); // at bottom | 674 container_bounds.bottom() - modal_size.height()); // at bottom |
674 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 675 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
675 | 676 |
(...skipping 19 matching lines...) Expand all Loading... |
695 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); | 696 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); |
696 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 697 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
697 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 698 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
698 } | 699 } |
699 | 700 |
700 // Test that windows will not get cropped through the visible virtual keyboard - | 701 // Test that windows will not get cropped through the visible virtual keyboard - |
701 // if centered. | 702 // if centered. |
702 TEST_F(SystemModalContainerLayoutManagerTest, | 703 TEST_F(SystemModalContainerLayoutManagerTest, |
703 SystemModalDialogGetPushedButNotCroppedFromKeyboard) { | 704 SystemModalDialogGetPushedButNotCroppedFromKeyboard) { |
704 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. | 705 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. |
705 if (ShellPort::Get()->IsRunningInMash()) | 706 if (Shell::GetAshConfig() == Config::MASH) |
706 return; | 707 return; |
707 | 708 |
708 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); | 709 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); |
709 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 710 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
710 // Place the window at the bottom of the screen. | 711 // Place the window at the bottom of the screen. |
711 gfx::Size modal_size(100, screen_size.height() - 70); | 712 gfx::Size modal_size(100, screen_size.height() - 70); |
712 gfx::Point modal_origin = gfx::Point( | 713 gfx::Point modal_origin = gfx::Point( |
713 (container_bounds.right() - modal_size.width()) / 2, // X centered | 714 (container_bounds.right() - modal_size.width()) / 2, // X centered |
714 container_bounds.bottom() - modal_size.height()); // at bottom | 715 container_bounds.bottom() - modal_size.height()); // at bottom |
715 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 716 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
(...skipping 16 matching lines...) Expand all Loading... |
732 EXPECT_EQ(0, modal_window->bounds().y()); | 733 EXPECT_EQ(0, modal_window->bounds().y()); |
733 | 734 |
734 ShowKeyboard(false); | 735 ShowKeyboard(false); |
735 } | 736 } |
736 | 737 |
737 // Test that windows will not get cropped through the visible virtual keyboard - | 738 // Test that windows will not get cropped through the visible virtual keyboard - |
738 // if not centered. | 739 // if not centered. |
739 TEST_F(SystemModalContainerLayoutManagerTest, | 740 TEST_F(SystemModalContainerLayoutManagerTest, |
740 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { | 741 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { |
741 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. | 742 // TODO: mash doesn't support virtual keyboard. http://crbug.com/698892. |
742 if (ShellPort::Get()->IsRunningInMash()) | 743 if (Shell::GetAshConfig() == Config::MASH) |
743 return; | 744 return; |
744 | 745 |
745 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 746 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
746 // Place the window at the bottom of the screen. | 747 // Place the window at the bottom of the screen. |
747 gfx::Size modal_size(100, screen_size.height() - 70); | 748 gfx::Size modal_size(100, screen_size.height() - 70); |
748 gfx::Point modal_origin = gfx::Point(10, 20); | 749 gfx::Point modal_origin = gfx::Point(10, 20); |
749 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 750 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
750 | 751 |
751 // Create a modal window. | 752 // Create a modal window. |
752 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 753 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 | 923 |
923 // Make sure that events are properly blocked in multi displays environment. | 924 // Make sure that events are properly blocked in multi displays environment. |
924 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) { | 925 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) { |
925 UpdateDisplay("500x500, 500x500"); | 926 UpdateDisplay("500x500, 500x500"); |
926 InputTestDelegate delegate; | 927 InputTestDelegate delegate; |
927 delegate.RunTest(this); | 928 delegate.RunTest(this); |
928 } | 929 } |
929 | 930 |
930 } // namespace test | 931 } // namespace test |
931 } // namespace ash | 932 } // namespace ash |
OLD | NEW |