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

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

Issue 2887103002: Revert of Refactor backdrop (Closed)
Patch Set: 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"
15 #include "ash/wm/window_state.h" 13 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_state_aura.h" 14 #include "ash/wm/window_state_aura.h"
17 #include "ash/wm/wm_event.h" 15 #include "ash/wm/wm_event.h"
18 #include "ash/wm/workspace/workspace_window_resizer.h"
19 #include "ash/wm_window.h" 16 #include "ash/wm_window.h"
20 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
21 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
22 #include "components/exo/buffer.h" 19 #include "components/exo/buffer.h"
23 #include "components/exo/display.h" 20 #include "components/exo/display.h"
24 #include "components/exo/sub_surface.h" 21 #include "components/exo/sub_surface.h"
25 #include "components/exo/surface.h" 22 #include "components/exo/surface.h"
26 #include "components/exo/test/exo_test_base.h" 23 #include "components/exo/test/exo_test_base.h"
27 #include "components/exo/test/exo_test_helper.h" 24 #include "components/exo/test/exo_test_helper.h"
28 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/aura/client/aura_constants.h" 26 #include "ui/aura/client/aura_constants.h"
30 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
28 #include "ui/aura/window_targeter.h"
31 #include "ui/base/hit_test.h" 29 #include "ui/base/hit_test.h"
32 #include "ui/display/display.h" 30 #include "ui/display/display.h"
33 #include "ui/display/screen.h" 31 #include "ui/display/screen.h"
32 #include "ui/events/base_event_utils.h"
34 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
35 #include "ui/wm/core/shadow.h" 34 #include "ui/wm/core/shadow.h"
36 #include "ui/wm/core/shadow_controller.h" 35 #include "ui/wm/core/shadow_controller.h"
37 #include "ui/wm/core/shadow_types.h" 36 #include "ui/wm/core/shadow_types.h"
38 #include "ui/wm/core/window_util.h" 37 #include "ui/wm/core/window_util.h"
39 38
40 namespace exo { 39 namespace exo {
41 namespace { 40 namespace {
42 41
43 using ShellSurfaceTest = test::ExoTestBase; 42 using ShellSurfaceTest = test::ExoTestBase;
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // Underlay should be created even without shadow. 831 // Underlay should be created even without shadow.
833 ASSERT_TRUE(shell_surface->shadow_underlay()); 832 ASSERT_TRUE(shell_surface->shadow_underlay());
834 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 833 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
835 834
836 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(0, 0, 0, 0)); 835 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(0, 0, 0, 0));
837 // Underlay should be created even without shadow. 836 // Underlay should be created even without shadow.
838 ASSERT_TRUE(shell_surface->shadow_underlay()); 837 ASSERT_TRUE(shell_surface->shadow_underlay());
839 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 838 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
840 shell_surface->SetRectangularShadowEnabled(false); 839 shell_surface->SetRectangularShadowEnabled(false);
841 surface->Commit(); 840 surface->Commit();
842 // No underlay if there is no shadow. 841 // Underlay should be created even without shadow.
843 EXPECT_FALSE(shell_surface->shadow_underlay()); 842 ASSERT_TRUE(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, MaximizedAndImmersiveFullscreenBackdrop) { 893 TEST_F(ShellSurfaceTest, MaximizedAndImmersiveFullscreenBackground) {
894 ash::WorkspaceController* wc =
895 ash::test::ShellTestApi(ash::Shell::Get()).workspace_controller();
896 ash::test::WorkspaceControllerTestApi test_helper(wc);
897
898 const gfx::Size display_size = 894 const gfx::Size display_size =
899 display::Screen::GetScreen()->GetPrimaryDisplay().size(); 895 display::Screen::GetScreen()->GetPrimaryDisplay().size();
900 const gfx::Size buffer_size(display_size); 896 const gfx::Size buffer_size(display_size);
901 std::unique_ptr<Buffer> buffer( 897 std::unique_ptr<Buffer> buffer(
902 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 898 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
903 std::unique_ptr<Surface> surface(new Surface); 899 std::unique_ptr<Surface> surface(new Surface);
904 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( 900 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
905 surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), 901 surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
906 true, false, ash::kShellWindowId_DefaultContainer)); 902 true, false, ash::kShellWindowId_DefaultContainer));
907 903
908 surface->Attach(buffer.get()); 904 surface->Attach(buffer.get());
909 905
910 gfx::Rect shadow_bounds(10, 10, 100, 100); 906 gfx::Rect shadow_bounds(10, 10, 100, 100);
911 shell_surface->SetGeometry(shadow_bounds); 907 shell_surface->SetGeometry(shadow_bounds);
912 shell_surface->SetRectangularSurfaceShadow(shadow_bounds); 908 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
913 surface->Commit(); 909 surface->Commit();
914 EXPECT_EQ(shadow_bounds, 910 EXPECT_EQ(shadow_bounds,
915 shell_surface->GetWidget()->GetWindowBoundsInScreen()); 911 shell_surface->GetWidget()->GetWindowBoundsInScreen());
916 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds()); 912 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
917 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(), 913 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
918 shell_surface->surface_for_testing()->window()->bounds().size()); 914 shell_surface->surface_for_testing()->window()->bounds().size());
919 915
920 EXPECT_FALSE(test_helper.GetBackdropWindow());
921
922 ash::wm::WMEvent fullscreen_event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); 916 ash::wm::WMEvent fullscreen_event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
923 ash::WmWindow* window = 917 ash::WmWindow* window =
924 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow()); 918 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow());
925 919
926 // Enter immersive fullscreen mode. Shadow underlay is fullscreen. 920 // Enter immersive fullscreen mode. Shadow underlay is fullscreen.
927 window->GetWindowState()->OnWMEvent(&fullscreen_event); 921 window->GetWindowState()->OnWMEvent(&fullscreen_event);
928 922
929 EXPECT_TRUE(test_helper.GetBackdropWindow()); 923 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
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());
930 927
931 // Leave fullscreen mode. Shadow underlay is restored. 928 // Leave fullscreen mode. Shadow underlay is restored.
932 window->GetWindowState()->OnWMEvent(&fullscreen_event); 929 window->GetWindowState()->OnWMEvent(&fullscreen_event);
933 EXPECT_FALSE(test_helper.GetBackdropWindow()); 930 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
931 EXPECT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
934 932
935 ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE); 933 ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE);
936 934
937 // Enter maximized mode. 935 // Enter maximized mode. Shadow underlay is fullscreen.
938 window->GetWindowState()->OnWMEvent(&maximize_event); 936 window->GetWindowState()->OnWMEvent(&maximize_event);
939 EXPECT_TRUE(test_helper.GetBackdropWindow()); 937 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
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());
940 941
941 // Leave maximized mode. 942 // Leave maximized mode. Shadow underlay is fullscreen.
942 window->GetWindowState()->OnWMEvent(&maximize_event); 943 window->GetWindowState()->OnWMEvent(&maximize_event);
943 EXPECT_FALSE(test_helper.GetBackdropWindow()); 944 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
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());
944 } 1029 }
945 1030
946 // Make sure that a surface shell started in maximize creates deprecated 1031 // Make sure that a surface shell started in maximize creates deprecated
947 // shadow correctly. 1032 // shadow correctly.
948 TEST_F(ShellSurfaceTest, 1033 TEST_F(ShellSurfaceTest,
949 StartMaximizedThenMinimizeWithSetRectangularShadow_DEPRECATED) { 1034 StartMaximizedThenMinimizeWithSetRectangularShadow_DEPRECATED) {
950 const gfx::Size display_size = 1035 const gfx::Size display_size =
951 display::Screen::GetScreen()->GetPrimaryDisplay().size(); 1036 display::Screen::GetScreen()->GetPrimaryDisplay().size();
952 const gfx::Size buffer_size(display_size); 1037 const gfx::Size buffer_size(display_size);
953 std::unique_ptr<Buffer> buffer( 1038 std::unique_ptr<Buffer> buffer(
(...skipping 20 matching lines...) Expand all
974 shell_surface->surface_for_testing()->window()->bounds().size()); 1059 shell_surface->surface_for_testing()->window()->bounds().size());
975 1060
976 ash::wm::WMEvent minimize_event(ash::wm::WM_EVENT_MINIMIZE); 1061 ash::wm::WMEvent minimize_event(ash::wm::WM_EVENT_MINIMIZE);
977 ash::WmWindow* window = 1062 ash::WmWindow* window =
978 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow()); 1063 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow());
979 window->GetWindowState()->OnWMEvent(&minimize_event); 1064 window->GetWindowState()->OnWMEvent(&minimize_event);
980 } 1065 }
981 1066
982 } // namespace 1067 } // namespace
983 } // namespace exo 1068 } // 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