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

Side by Side Diff: components/exo/shell_surface_unittest.cc

Issue 2890733005: Refactor backdrop that is currently used in the maximized mode. (Closed)
Patch Set: fix memory issue in AshTouchExplorationManager Created 3 years, 7 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
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wm_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include "ash/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/public/cpp/shell_window_ids.h" 8 #include "ash/public/cpp/shell_window_ids.h"
9 #include "ash/public/cpp/window_properties.h" 9 #include "ash/public/cpp/window_properties.h"
10 #include "ash/public/interfaces/window_pin_type.mojom.h" 10 #include "ash/public/interfaces/window_pin_type.mojom.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_port.h" 12 #include "ash/shell_port.h"
13 #include "ash/test/shell_test_api.h"
14 #include "ash/test/workspace_controller_test_api.h"
13 #include "ash/wm/window_state.h" 15 #include "ash/wm/window_state.h"
14 #include "ash/wm/window_state_aura.h" 16 #include "ash/wm/window_state_aura.h"
15 #include "ash/wm/wm_event.h" 17 #include "ash/wm/wm_event.h"
18 #include "ash/wm/workspace/workspace_window_resizer.h"
16 #include "ash/wm_window.h" 19 #include "ash/wm_window.h"
17 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
18 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
19 #include "components/exo/buffer.h" 22 #include "components/exo/buffer.h"
20 #include "components/exo/display.h" 23 #include "components/exo/display.h"
21 #include "components/exo/sub_surface.h" 24 #include "components/exo/sub_surface.h"
22 #include "components/exo/surface.h" 25 #include "components/exo/surface.h"
23 #include "components/exo/test/exo_test_base.h" 26 #include "components/exo/test/exo_test_base.h"
24 #include "components/exo/test/exo_test_helper.h" 27 #include "components/exo/test/exo_test_helper.h"
25 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/aura/client/aura_constants.h" 29 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/window.h" 30 #include "ui/aura/window.h"
28 #include "ui/aura/window_targeter.h"
29 #include "ui/base/hit_test.h" 31 #include "ui/base/hit_test.h"
30 #include "ui/display/display.h" 32 #include "ui/display/display.h"
31 #include "ui/display/screen.h" 33 #include "ui/display/screen.h"
32 #include "ui/events/base_event_utils.h"
33 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
34 #include "ui/wm/core/shadow.h" 35 #include "ui/wm/core/shadow.h"
35 #include "ui/wm/core/shadow_controller.h" 36 #include "ui/wm/core/shadow_controller.h"
36 #include "ui/wm/core/shadow_types.h" 37 #include "ui/wm/core/shadow_types.h"
37 #include "ui/wm/core/window_util.h" 38 #include "ui/wm/core/window_util.h"
38 39
39 namespace exo { 40 namespace exo {
40 namespace { 41 namespace {
41 42
42 using ShellSurfaceTest = test::ExoTestBase; 43 using ShellSurfaceTest = test::ExoTestBase;
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // Underlay should be created even without shadow. 832 // Underlay should be created even without shadow.
832 ASSERT_TRUE(shell_surface->shadow_underlay()); 833 ASSERT_TRUE(shell_surface->shadow_underlay());
833 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 834 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
834 835
835 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(0, 0, 0, 0)); 836 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(0, 0, 0, 0));
836 // Underlay should be created even without shadow. 837 // Underlay should be created even without shadow.
837 ASSERT_TRUE(shell_surface->shadow_underlay()); 838 ASSERT_TRUE(shell_surface->shadow_underlay());
838 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 839 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
839 shell_surface->SetRectangularShadowEnabled(false); 840 shell_surface->SetRectangularShadowEnabled(false);
840 surface->Commit(); 841 surface->Commit();
841 // Underlay should be created even without shadow. 842 // No underlay if there is no shadow.
842 ASSERT_TRUE(shell_surface->shadow_underlay()); 843 EXPECT_FALSE(shell_surface->shadow_underlay());
843 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
844 844
845 shell_surface->SetRectangularShadowEnabled(true); 845 shell_surface->SetRectangularShadowEnabled(true);
846 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100)); 846 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
847 surface->Commit(); 847 surface->Commit();
848 848
849 // Restore the window and make sure the shadow is created, visible and 849 // Restore the window and make sure the shadow is created, visible and
850 // has the latest bounds. 850 // has the latest bounds.
851 widget->Restore(); 851 widget->Restore();
852 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 852 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
853 ASSERT_TRUE(shadow); 853 ASSERT_TRUE(shadow);
(...skipping 29 matching lines...) Expand all
883 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); 883 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString());
884 884
885 // Leave fullscreen mode. 885 // Leave fullscreen mode.
886 window->GetWindowState()->OnWMEvent(&event); 886 window->GetWindowState()->OnWMEvent(&event);
887 887
888 // Check that shell surface is maximized. 888 // Check that shell surface is maximized.
889 EXPECT_EQ(CurrentContext()->bounds().width(), 889 EXPECT_EQ(CurrentContext()->bounds().width(),
890 shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); 890 shell_surface->GetWidget()->GetWindowBoundsInScreen().width());
891 } 891 }
892 892
893 TEST_F(ShellSurfaceTest, MaximizedAndImmersiveFullscreenBackground) { 893 TEST_F(ShellSurfaceTest, MaximizedAndImmersiveFullscreenBackdrop) {
894 ash::WorkspaceController* wc =
895 ash::test::ShellTestApi(ash::Shell::Get()).workspace_controller();
896 ash::test::WorkspaceControllerTestApi test_helper(wc);
897
894 const gfx::Size display_size = 898 const gfx::Size display_size =
895 display::Screen::GetScreen()->GetPrimaryDisplay().size(); 899 display::Screen::GetScreen()->GetPrimaryDisplay().size();
896 const gfx::Size buffer_size(display_size); 900 const gfx::Size buffer_size(display_size);
897 std::unique_ptr<Buffer> buffer( 901 std::unique_ptr<Buffer> buffer(
898 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 902 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
899 std::unique_ptr<Surface> surface(new Surface); 903 std::unique_ptr<Surface> surface(new Surface);
900 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( 904 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
901 surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), 905 surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
902 true, false, ash::kShellWindowId_DefaultContainer)); 906 true, false, ash::kShellWindowId_DefaultContainer));
903 907
904 surface->Attach(buffer.get()); 908 surface->Attach(buffer.get());
905 909
906 gfx::Rect shadow_bounds(10, 10, 100, 100); 910 gfx::Rect shadow_bounds(10, 10, 100, 100);
907 shell_surface->SetGeometry(shadow_bounds); 911 shell_surface->SetGeometry(shadow_bounds);
908 shell_surface->SetRectangularSurfaceShadow(shadow_bounds); 912 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
909 surface->Commit(); 913 surface->Commit();
910 EXPECT_EQ(shadow_bounds, 914 EXPECT_EQ(shadow_bounds,
911 shell_surface->GetWidget()->GetWindowBoundsInScreen()); 915 shell_surface->GetWidget()->GetWindowBoundsInScreen());
912 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds()); 916 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
913 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(), 917 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
914 shell_surface->surface_for_testing()->window()->bounds().size()); 918 shell_surface->surface_for_testing()->window()->bounds().size());
915 919
920 EXPECT_FALSE(test_helper.GetBackdropWindow());
921
916 ash::wm::WMEvent fullscreen_event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); 922 ash::wm::WMEvent fullscreen_event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
917 ash::WmWindow* window = 923 ash::WmWindow* window =
918 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow()); 924 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow());
919 925
920 // Enter immersive fullscreen mode. Shadow underlay is fullscreen. 926 // Enter immersive fullscreen mode. Shadow underlay is fullscreen.
921 window->GetWindowState()->OnWMEvent(&fullscreen_event); 927 window->GetWindowState()->OnWMEvent(&fullscreen_event);
922 928
923 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 929 EXPECT_TRUE(test_helper.GetBackdropWindow());
924 EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity());
925 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
926 shell_surface->shadow_underlay()->bounds().size());
927 930
928 // Leave fullscreen mode. Shadow underlay is restored. 931 // Leave fullscreen mode. Shadow underlay is restored.
929 window->GetWindowState()->OnWMEvent(&fullscreen_event); 932 window->GetWindowState()->OnWMEvent(&fullscreen_event);
930 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 933 EXPECT_FALSE(test_helper.GetBackdropWindow());
931 EXPECT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
932 934
933 ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE); 935 ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE);
934 936
935 // Enter maximized mode. Shadow underlay is fullscreen. 937 // Enter maximized mode.
936 window->GetWindowState()->OnWMEvent(&maximize_event); 938 window->GetWindowState()->OnWMEvent(&maximize_event);
937 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 939 EXPECT_TRUE(test_helper.GetBackdropWindow());
938 EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity());
939 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
940 shell_surface->shadow_underlay()->bounds().size());
941 940
942 // Leave maximized mode. Shadow underlay is fullscreen. 941 // Leave maximized mode.
943 window->GetWindowState()->OnWMEvent(&maximize_event); 942 window->GetWindowState()->OnWMEvent(&maximize_event);
944 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 943 EXPECT_FALSE(test_helper.GetBackdropWindow());
945 EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity());
946 EXPECT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
947 }
948
949 TEST_F(ShellSurfaceTest, SpokenFeedbackFullscreenBackground) {
950 const gfx::Size display_size =
951 display::Screen::GetScreen()->GetPrimaryDisplay().size();
952 const gfx::Size buffer_size(display_size);
953 Buffer buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
954 Surface surface;
955 ShellSurface shell_surface(&surface, nullptr,
956 ShellSurface::BoundsMode::CLIENT, gfx::Point(),
957 true, false, ash::kShellWindowId_DefaultContainer);
958 surface.Attach(&buffer);
959
960 gfx::Rect shadow_bounds(10, 10, 100, 100);
961 shell_surface.SetGeometry(shadow_bounds);
962 shell_surface.SetRectangularSurfaceShadow(shadow_bounds);
963 surface.Commit();
964 EXPECT_EQ(shadow_bounds,
965 shell_surface.GetWidget()->GetWindowBoundsInScreen());
966 ASSERT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
967
968 aura::Window* shell_window = shell_surface.GetWidget()->GetNativeWindow();
969 aura::WindowTargeter* targeter = static_cast<aura::WindowTargeter*>(
970 static_cast<ui::EventTarget*>(shell_window)->GetEventTargeter());
971
972 gfx::Point pt_out(300, 300);
973 ui::MouseEvent ev_out(ui::ET_MOUSE_PRESSED, pt_out, pt_out,
974 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
975 ui::EF_LEFT_MOUSE_BUTTON);
976 gfx::Point pt_in(70, 70);
977 ui::MouseEvent ev_in(ui::ET_MOUSE_PRESSED, pt_in, pt_in,
978 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
979 ui::EF_LEFT_MOUSE_BUTTON);
980
981 EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out));
982
983 // Enable spoken feedback.
984 ash::Shell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
985 ash::A11Y_NOTIFICATION_NONE);
986 shell_surface.OnAccessibilityModeChanged();
987
988 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
989 shell_surface.shadow_underlay()->bounds());
990 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
991 EXPECT_NE(shell_surface.GetWidget()->GetWindowBoundsInScreen(),
992 shell_surface.shadow_underlay()->bounds());
993
994 // Test event capture
995 EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out));
996 EXPECT_EQ(shell_surface.shadow_underlay(),
997 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent(
998 shell_window, &ev_out));
999 EXPECT_NE(shell_surface.shadow_underlay(),
1000 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent(
1001 shell_window, &ev_in));
1002
1003 // Create a new surface
1004 Buffer buffer2(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
1005 Surface surface2;
1006 ShellSurface shell_surface2(
1007 &surface2, nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), true,
1008 false, ash::kShellWindowId_DefaultContainer);
1009 surface2.Attach(&buffer2);
1010 shell_surface2.SetRectangularSurfaceShadow(shadow_bounds);
1011 surface2.Commit();
1012
1013 // spoken-feedback was already on, so underlay should fill screen
1014 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
1015 shell_surface2.shadow_underlay()->bounds());
1016
1017 // De-activated shell-surface should NOT have fullscreen underlay
1018 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
1019
1020 // Disable spoken feedback. Shadow underlay is restored.
1021 ash::Shell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
1022 ash::A11Y_NOTIFICATION_NONE);
1023 shell_surface.OnAccessibilityModeChanged();
1024 shell_surface2.OnAccessibilityModeChanged();
1025
1026 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
1027 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
1028 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds());
1029 } 944 }
1030 945
1031 // Make sure that a surface shell started in maximize creates deprecated 946 // Make sure that a surface shell started in maximize creates deprecated
1032 // shadow correctly. 947 // shadow correctly.
1033 TEST_F(ShellSurfaceTest, 948 TEST_F(ShellSurfaceTest,
1034 StartMaximizedThenMinimizeWithSetRectangularShadow_DEPRECATED) { 949 StartMaximizedThenMinimizeWithSetRectangularShadow_DEPRECATED) {
1035 const gfx::Size display_size = 950 const gfx::Size display_size =
1036 display::Screen::GetScreen()->GetPrimaryDisplay().size(); 951 display::Screen::GetScreen()->GetPrimaryDisplay().size();
1037 const gfx::Size buffer_size(display_size); 952 const gfx::Size buffer_size(display_size);
1038 std::unique_ptr<Buffer> buffer( 953 std::unique_ptr<Buffer> buffer(
(...skipping 20 matching lines...) Expand all
1059 shell_surface->surface_for_testing()->window()->bounds().size()); 974 shell_surface->surface_for_testing()->window()->bounds().size());
1060 975
1061 ash::wm::WMEvent minimize_event(ash::wm::WM_EVENT_MINIMIZE); 976 ash::wm::WMEvent minimize_event(ash::wm::WM_EVENT_MINIMIZE);
1062 ash::WmWindow* window = 977 ash::WmWindow* window =
1063 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow()); 978 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow());
1064 window->GetWindowState()->OnWMEvent(&minimize_event); 979 window->GetWindowState()->OnWMEvent(&minimize_event);
1065 } 980 }
1066 981
1067 } // namespace 982 } // namespace
1068 } // namespace exo 983 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wm_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698