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

Unified Diff: components/exo/shell_surface_unittest.cc

Issue 2686533004: Use pixel coordinates for shadow underlay bounds (Closed)
Patch Set: remove unnecessary changes Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/exo/shell_surface_unittest.cc
diff --git a/components/exo/shell_surface_unittest.cc b/components/exo/shell_surface_unittest.cc
index 135395cc051e063517c46f47f707c4d7683e5d1d..01501f45d3d158a34f5a28f92fe49e4df73573a0 100644
--- a/components/exo/shell_surface_unittest.cc
+++ b/components/exo/shell_surface_unittest.cc
@@ -496,11 +496,15 @@ TEST_F(ShellSurfaceTest, PopupWindow) {
popup->GetWidget()->GetWindowBoundsInScreen());
}
-TEST_F(ShellSurfaceTest, Shadow) {
+TEST_F(ShellSurfaceTest, SurfaceShadow) {
+ gfx::Size buffer_size(128, 128);
+ std::unique_ptr<Buffer> buffer(
+ new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(
new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false,
ash::kShellWindowId_DefaultContainer));
+ surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
@@ -514,7 +518,6 @@ TEST_F(ShellSurfaceTest, Shadow) {
// 2) Just creating a sub surface won't create a shadow.
std::unique_ptr<Surface> child = display->CreateSurface();
- gfx::Size buffer_size(128, 128);
std::unique_ptr<Buffer> child_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
child->Attach(child_buffer.get());
@@ -525,8 +528,7 @@ TEST_F(ShellSurfaceTest, Shadow) {
EXPECT_FALSE(shadow->layer()->visible());
// 3) Create a shadow.
- shell_surface->SetRectangularShadow(true);
- shell_surface->SetRectangularShadowContentBounds(gfx::Rect(10, 10, 100, 100));
+ shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_TRUE(shadow->layer()->visible());
@@ -547,18 +549,100 @@ TEST_F(ShellSurfaceTest, Shadow) {
EXPECT_EQ(before, shadow->layer()->bounds());
// 5) This should disable shadow.
- shell_surface->SetRectangularShadow(false);
+ shell_surface->SetRectangularSurfaceShadow(gfx::Rect());
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::NONE, wm::GetShadowElevation(window));
EXPECT_FALSE(shadow->layer()->visible());
- // 6) This should enable shadow.
- shell_surface->SetRectangularShadow(true);
+ // 6) This should enable non surface shadow again.
+ shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
+
+ // For surface shadow, the underlay is placed at the bottom of shell surfaces.
+ EXPECT_EQ(surface->window(), shell_surface->shadow_underlay()->parent());
+ EXPECT_EQ(window, shell_surface->shadow_overlay()->parent());
+
+ EXPECT_EQ(*surface->window()->children().begin(),
+ shell_surface->shadow_underlay());
+}
+
+TEST_F(ShellSurfaceTest, NonSurfaceShadow) {
+ gfx::Size buffer_size(128, 128);
+ std::unique_ptr<Buffer> buffer(
+ new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
+ std::unique_ptr<Surface> surface(new Surface);
+ std::unique_ptr<ShellSurface> shell_surface(
+ new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false,
+ ash::kShellWindowId_DefaultContainer));
+ surface->Attach(buffer.get());
+ surface->Commit();
+
+ aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
+
+ // 1) Initial state, no shadow.
+ wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
+ ASSERT_TRUE(shadow);
+ EXPECT_FALSE(shadow->layer()->visible());
+
+ std::unique_ptr<Display> display(new Display);
+
+ // 2) Just creating a sub surface won't create a shadow.
+ std::unique_ptr<Surface> child = display->CreateSurface();
+ std::unique_ptr<Buffer> child_buffer(
+ new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
+ child->Attach(child_buffer.get());
+ std::unique_ptr<SubSurface> sub_surface(
+ display->CreateSubSurface(child.get(), surface.get()));
+ surface->Commit();
+
+ EXPECT_FALSE(shadow->layer()->visible());
+
+ // 3) Enable a shadow.
+ shell_surface->SetRectangularShadowEnabled(true);
+ surface->Commit();
+ EXPECT_TRUE(shadow->layer()->visible());
+
+ gfx::Rect before = shadow->layer()->bounds();
+
+ // 4) Shadow bounds is independent of the sub surface.
+ gfx::Size new_buffer_size(256, 256);
+ std::unique_ptr<Buffer> new_child_buffer(
+ new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(new_buffer_size)));
+ child->Attach(new_child_buffer.get());
+ child->Commit();
+ surface->Commit();
+
+ EXPECT_EQ(before, shadow->layer()->bounds());
+
+ // 4) Updating the widget's window bounds should change the non surface shadow
+ // bounds.
+ const gfx::Rect new_bounds(50, 50, 100, 100);
+ window->SetBounds(new_bounds);
+ EXPECT_NE(before, shadow->layer()->bounds());
+ EXPECT_NE(new_bounds, shadow->layer()->bounds());
+
+ // 5) This should disable shadow.
+ shell_surface->SetRectangularShadowEnabled(false);
+ surface->Commit();
+
+ EXPECT_EQ(wm::ShadowElevation::NONE, wm::GetShadowElevation(window));
+ EXPECT_FALSE(shadow->layer()->visible());
+
+ // 6) This should enable non surface shadow.
+ shell_surface->SetRectangularShadowEnabled(true);
+ surface->Commit();
+
+ EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
+ EXPECT_TRUE(shadow->layer()->visible());
+
+ // For no surface shadow, both of underlay and overlay should be stacked
+ // below the surface window.
+ EXPECT_EQ(window, shell_surface->shadow_underlay()->parent());
+ EXPECT_EQ(window, shell_surface->shadow_overlay()->parent());
}
TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
@@ -585,8 +669,7 @@ TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
aura::Window* window = widget->GetNativeWindow();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
- shell_surface->SetRectangularShadow(true);
- shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
@@ -603,7 +686,7 @@ TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
ASSERT_TRUE(widget->IsMaximized());
EXPECT_FALSE(shadow->layer()->visible());
- shell_surface->SetRectangularShadowContentBounds(work_area);
+ shell_surface->SetRectangularSurfaceShadow(work_area);
surface->Commit();
EXPECT_FALSE(shadow->layer()->visible());
@@ -615,7 +698,7 @@ TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
EXPECT_EQ(shadow_in_maximized, shadow->layer()->parent()->bounds());
// The bounds is updated.
- shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
surface->Commit();
EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->bounds());
}
@@ -643,8 +726,7 @@ TEST_F(ShellSurfaceTest, ShadowWithTransform) {
gfx::Transform transform;
transform.Translate(50, 50);
window->SetTransform(transform);
- shell_surface->SetRectangularShadow(true);
- shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
surface->Commit();
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->layer()->parent()->bounds());
@@ -663,8 +745,7 @@ TEST_F(ShellSurfaceTest, ShadowStartMaximized) {
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
// Sending a shadow bounds in maximized state won't create a shaodw.
- shell_surface->SetRectangularShadow(true);
- shell_surface->SetRectangularShadowContentBounds(gfx::Rect(10, 10, 100, 100));
+ shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
@@ -717,21 +798,27 @@ TEST_F(ShellSurfaceTest, ToggleFullscreen) {
}
TEST_F(ShellSurfaceTest, ImmersiveFullscreenBackground) {
- gfx::Size buffer_size(256, 256);
+ const gfx::Size display_size =
+ display::Screen::GetScreen()->GetPrimaryDisplay().size();
+ const gfx::Size buffer_size(display_size);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(
- new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false,
+ new ShellSurface(surface.get(), nullptr, gfx::Rect(100, 100), true, false,
ash::kShellWindowId_DefaultContainer));
surface->Attach(buffer.get());
gfx::Rect shadow_bounds(10, 10, 100, 100);
- shell_surface->SetRectangularShadow(true);
- shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface->SetGeometry(shadow_bounds);
+ shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
surface->Commit();
+ EXPECT_EQ(shadow_bounds,
+ shell_surface->GetWidget()->GetWindowBoundsInScreen());
ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
+ EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
+ shell_surface->surface_for_testing()->window()->bounds().size());
ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
ash::WmWindow* window =
@@ -740,12 +827,10 @@ TEST_F(ShellSurfaceTest, ImmersiveFullscreenBackground) {
// Enter immersive fullscreen mode. Shadow underlay is fullscreen.
window->GetWindowState()->OnWMEvent(&event);
- EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
- shell_surface->shadow_underlay()->bounds());
EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity());
- EXPECT_NE(shell_surface->GetWidget()->GetWindowBoundsInScreen(),
- shell_surface->shadow_underlay()->bounds());
+ EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
+ shell_surface->shadow_underlay()->bounds().size());
// Leave fullscreen mode. Shadow underlay is restored.
window->GetWindowState()->OnWMEvent(&event);
@@ -754,30 +839,35 @@ TEST_F(ShellSurfaceTest, ImmersiveFullscreenBackground) {
}
TEST_F(ShellSurfaceTest, SpokenFeedbackFullscreenBackground) {
- gfx::Size buffer_size(256, 256);
+ const gfx::Size display_size =
+ display::Screen::GetScreen()->GetPrimaryDisplay().size();
+ const gfx::Size buffer_size(display_size);
Buffer buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
Surface surface;
- ShellSurface shell_surface(&surface, nullptr, gfx::Rect(640, 480), true,
+ ShellSurface shell_surface(&surface, nullptr, gfx::Rect(100, 100), true,
false, ash::kShellWindowId_DefaultContainer);
-
surface.Attach(&buffer);
gfx::Rect shadow_bounds(10, 10, 100, 100);
- shell_surface.SetRectangularShadow(true);
- shell_surface.SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface.SetGeometry(shadow_bounds);
+ shell_surface.SetRectangularSurfaceShadow(shadow_bounds);
surface.Commit();
+ EXPECT_EQ(shadow_bounds,
+ shell_surface.GetWidget()->GetWindowBoundsInScreen());
ASSERT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
aura::Window* shell_window = shell_surface.GetWidget()->GetNativeWindow();
aura::WindowTargeter* targeter = static_cast<aura::WindowTargeter*>(
static_cast<ui::EventTarget*>(shell_window)->GetEventTargeter());
- gfx::Point pt(300, 300);
- ui::MouseEvent ev_out(ui::ET_MOUSE_PRESSED, pt, pt, ui::EventTimeForNow(),
- ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
- gfx::Point pt2(250, 250);
- ui::MouseEvent ev_in(ui::ET_MOUSE_PRESSED, pt2, pt2, ui::EventTimeForNow(),
- ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
+ gfx::Point pt_out(300, 300);
+ ui::MouseEvent ev_out(ui::ET_MOUSE_PRESSED, pt_out, pt_out,
+ ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
+ ui::EF_LEFT_MOUSE_BUTTON);
+ gfx::Point pt_in(70, 70);
+ ui::MouseEvent ev_in(ui::ET_MOUSE_PRESSED, pt_in, pt_in,
+ ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
+ ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out));
@@ -807,8 +897,7 @@ TEST_F(ShellSurfaceTest, SpokenFeedbackFullscreenBackground) {
ShellSurface shell_surface2(&surface2, nullptr, gfx::Rect(640, 480), true,
false, ash::kShellWindowId_DefaultContainer);
surface2.Attach(&buffer2);
- shell_surface2.SetRectangularShadow(true);
- shell_surface2.SetRectangularShadowContentBounds(shadow_bounds);
+ shell_surface2.SetRectangularSurfaceShadow(shadow_bounds);
surface2.Commit();
// spoken-feedback was already on, so underlay should fill screen
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698