Commit 794e5a5e authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Move unit tests for ClientControlledShellSurface into separate file.

BUG=773461
TEST=None

Change-Id: I2dd813cd873e7b437606085784543b1a3d72dc95
Reviewed-on: https://chromium-review.googlesource.com/801090Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521523}
parent fa1b8298
...@@ -127,6 +127,7 @@ source_set("unit_tests") { ...@@ -127,6 +127,7 @@ source_set("unit_tests") {
sources = [ sources = [
"../../ui/events/ozone/gamepad/gamepad_event.cc", "../../ui/events/ozone/gamepad/gamepad_event.cc",
"buffer_unittest.cc", "buffer_unittest.cc",
"client_controlled_shell_surface_unittest.cc",
"data_device_unittest.cc", "data_device_unittest.cc",
"data_offer_unittest.cc", "data_offer_unittest.cc",
"data_source_unittest.cc", "data_source_unittest.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/client_controlled_shell_surface.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/interfaces/window_pin_type.mojom.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/system/tray/system_tray.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "components/exo/buffer.h"
#include "components/exo/display.h"
#include "components/exo/pointer.h"
#include "components/exo/sub_surface.h"
#include "components/exo/surface.h"
#include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_helper.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/shadow.h"
#include "ui/wm/core/shadow_controller.h"
#include "ui/wm/core/shadow_types.h"
namespace exo {
namespace {
using ClientControlledShellSurfaceTest = test::ExoTestBase;
bool IsWidgetPinned(views::Widget* widget) {
ash::mojom::WindowPinType type =
widget->GetNativeWindow()->GetProperty(ash::kWindowPinTypeKey);
return type == ash::mojom::WindowPinType::PINNED ||
type == ash::mojom::WindowPinType::TRUSTED_PINNED;
}
wm::ShadowElevation GetShadowElevation(aura::Window* window) {
return window->GetProperty(wm::kShadowElevationKey);
}
} // namespace
TEST_F(ClientControlledShellSurfaceTest, SetPinned) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
shell_surface->SetPinned(ash::mojom::WindowPinType::TRUSTED_PINNED);
EXPECT_TRUE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::NONE);
EXPECT_FALSE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::PINNED);
EXPECT_TRUE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::NONE);
EXPECT_FALSE(IsWidgetPinned(shell_surface->GetWidget()));
}
TEST_F(ClientControlledShellSurfaceTest, SetSystemUiVisibility) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
shell_surface->SetSystemUiVisibility(true);
EXPECT_TRUE(
ash::wm::GetWindowState(shell_surface->GetWidget()->GetNativeWindow())
->autohide_shelf_when_maximized_or_fullscreen());
shell_surface->SetSystemUiVisibility(false);
EXPECT_FALSE(
ash::wm::GetWindowState(shell_surface->GetWidget()->GetNativeWindow())
->autohide_shelf_when_maximized_or_fullscreen());
}
TEST_F(ClientControlledShellSurfaceTest, SetTopInset) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
ASSERT_TRUE(window);
EXPECT_EQ(0, window->GetProperty(aura::client::kTopViewInset));
int top_inset_height = 20;
shell_surface->SetTopInset(top_inset_height);
surface->Commit();
EXPECT_EQ(top_inset_height, window->GetProperty(aura::client::kTopViewInset));
}
TEST_F(ClientControlledShellSurfaceTest, ModalWindowDefaultActive) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get(),
/*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(gfx::Rect(10, 10, 100, 100));
ASSERT_FALSE(shell_surface->GetWidget());
shell_surface->SetSystemModal(true);
surface->Commit();
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
}
TEST_F(ClientControlledShellSurfaceTest, UpdateModalWindow) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(cc::Region());
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Creating a surface without input region should not make it modal.
std::unique_ptr<Display> display(new Display);
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());
std::unique_ptr<SubSurface> sub_surface(
display->CreateSubSurface(child.get(), surface.get()));
surface->SetSubSurfacePosition(child.get(), gfx::Point(10, 10));
child->Commit();
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Making the surface opaque shouldn't make it modal either.
child->SetBlendMode(SkBlendMode::kSrc);
child->Commit();
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Setting input regions won't make it modal either.
surface->SetInputRegion(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Only SetSystemModal changes modality.
shell_surface->SetSystemModal(true);
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// If the non modal system window was active,
shell_surface->GetWidget()->Activate();
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(true);
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
}
TEST_F(ClientControlledShellSurfaceTest,
ModalWindowSetSystemModalBeforeCommit) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(cc::Region());
// Set SetSystemModal before any commit happens. Widget is not created at
// this time.
EXPECT_FALSE(shell_surface->GetWidget());
shell_surface->SetSystemModal(true);
surface->Commit();
// It is expected that modal window is shown.
EXPECT_TRUE(shell_surface->GetWidget());
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
// Now widget is created and setting modal state should be applied
// immediately.
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
}
TEST_F(ClientControlledShellSurfaceTest, 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);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
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) Create a shadow.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
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 not change the shadow bounds.
// TODO(oshima): The following scenario only worked with Xdg/ShellSurface,
// which never uses SetShadowBounds. This is broken with correct scenario, and
// will be fixed when the bounds control is delegated to the client.
//
// window->SetBounds(gfx::Rect(10, 10, 100, 100));
// EXPECT_EQ(before, shadow->layer()->bounds());
// 5) This should disable shadow.
shell_surface->SetShadowBounds(gfx::Rect());
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::NONE, GetShadowElevation(window));
EXPECT_FALSE(shadow->layer()->visible());
// 6) This should enable non surface shadow again.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
}
TEST_F(ClientControlledShellSurfaceTest, ShadowWithStateChange) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
shell_surface->SetGeometry(original_bounds);
surface->Attach(buffer.get());
surface->Commit();
// Placing a shadow at screen origin will make the shadow's origin (-10, -10).
const gfx::Rect shadow_bounds(content_size);
// Expected shadow position/bounds in parent coordinates.
const gfx::Point expected_shadow_origin(-10, -10);
const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size);
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
// Origin must be in sync.
EXPECT_EQ(expected_shadow_origin, shadow->content_bounds().origin());
const gfx::Rect work_area =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
// Maximizing window hides the shadow.
widget->Maximize();
ASSERT_TRUE(widget->IsMaximized());
EXPECT_FALSE(shadow->layer()->visible());
shell_surface->SetShadowBounds(work_area);
surface->Commit();
EXPECT_FALSE(shadow->layer()->visible());
// Restoring bounds will re-enable shadow. It's content size is set to work
// area,/ thus not visible until new bounds is committed.
widget->Restore();
EXPECT_TRUE(shadow->layer()->visible());
const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size());
EXPECT_EQ(shadow_in_maximized, shadow->content_bounds());
// The bounds is updated.
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_EQ(expected_shadow_bounds, shadow->content_bounds());
}
TEST_F(ClientControlledShellSurfaceTest, ShadowWithTransform) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
shell_surface->SetGeometry(original_bounds);
surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
// Placing a shadow at screen origin will make the shadow's origin (-10, -10).
const gfx::Rect shadow_bounds(content_size);
// Shadow bounds relative to its parent should not be affected by a transform.
gfx::Transform transform;
transform.Translate(50, 50);
window->SetTransform(transform);
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->content_bounds());
}
TEST_F(ClientControlledShellSurfaceTest, ShadowStartMaximized) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
shell_surface->Maximize();
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
// There is no shadow when started in maximized state.
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
// Sending a shadow bounds in maximized state won't create a shaodw.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
// Restore the window and make sure the shadow is created, visible and
// has the latest bounds.
widget->Restore();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
ASSERT_TRUE(shadow);
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(gfx::Rect(10, 10, 100, 100), shadow->content_bounds());
}
TEST_F(ClientControlledShellSurfaceTest, CompositorLockInRotation) {
UpdateDisplay("800x600");
const gfx::Size buffer_size(800, 600);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
ash::Shell* shell = ash::Shell::Get();
shell->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// Start in maximized.
shell_surface->Maximize();
surface->Attach(buffer.get());
surface->Commit();
gfx::Rect maximum_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
shell_surface->SetGeometry(maximum_bounds);
shell_surface->SetOrientation(Orientation::LANDSCAPE);
surface->Commit();
ui::Compositor* compositor =
shell_surface->GetWidget()->GetNativeWindow()->layer()->GetCompositor();
EXPECT_FALSE(compositor->IsLocked());
UpdateDisplay("800x600/r");
EXPECT_TRUE(compositor->IsLocked());
shell_surface->SetOrientation(Orientation::PORTRAIT);
surface->Commit();
EXPECT_FALSE(compositor->IsLocked());
}
// If system tray is shown by click. It should be activated if user presses tab
// key while shell surface is active.
TEST_F(ClientControlledShellSurfaceTest, KeyboardNavigationWithSystemTray) {
const gfx::Size buffer_size(800, 600);
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 =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
// Show system tray by perfoming a gesture tap at tray.
ash::SystemTray* system_tray = GetPrimarySystemTray();
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
system_tray->PerformAction(tap);
ASSERT_TRUE(system_tray->GetWidget());
// Confirm that system tray is not active at this time.
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
EXPECT_FALSE(
system_tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive());
// Send tab key event.
ui::test::EventGenerator& event_generator = GetEventGenerator();
event_generator.PressKey(ui::VKEY_TAB, ui::EF_NONE);
event_generator.ReleaseKey(ui::VKEY_TAB, ui::EF_NONE);
// Confirm that system tray is activated.
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
EXPECT_TRUE(
system_tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive());
}
} // namespace exo
...@@ -6,13 +6,9 @@ ...@@ -6,13 +6,9 @@
#include "ash/accessibility/accessibility_delegate.h" #include "ash/accessibility/accessibility_delegate.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/interfaces/window_pin_type.mojom.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_port.h" #include "ash/shell_port.h"
#include "ash/shell_test_api.h" #include "ash/shell_test_api.h"
#include "ash/system/tray/system_tray.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h" #include "ash/wm/wm_event.h"
#include "ash/wm/workspace/workspace_window_resizer.h" #include "ash/wm/workspace/workspace_window_resizer.h"
...@@ -29,7 +25,6 @@ ...@@ -29,7 +25,6 @@
#include "components/exo/test/exo_test_helper.h" #include "components/exo/test/exo_test_helper.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
...@@ -37,7 +32,6 @@ ...@@ -37,7 +32,6 @@
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/shadow.h" #include "ui/wm/core/shadow.h"
#include "ui/wm/core/shadow_controller.h" #include "ui/wm/core/shadow_controller.h"
...@@ -59,17 +53,6 @@ uint32_t ConfigureFullscreen(uint32_t serial, ...@@ -59,17 +53,6 @@ uint32_t ConfigureFullscreen(uint32_t serial,
return serial; return serial;
} }
wm::ShadowElevation GetShadowElevation(aura::Window* window) {
return window->GetProperty(wm::kShadowElevationKey);
}
bool IsWidgetPinned(views::Widget* widget) {
ash::mojom::WindowPinType type =
widget->GetNativeWindow()->GetProperty(ash::kWindowPinTypeKey);
return type == ash::mojom::WindowPinType::PINNED ||
type == ash::mojom::WindowPinType::TRUSTED_PINNED;
}
class ShellSurfaceBoundsModeTest class ShellSurfaceBoundsModeTest
: public ShellSurfaceTest, : public ShellSurfaceTest,
public testing::WithParamInterface<ShellSurface::BoundsMode> { public testing::WithParamInterface<ShellSurface::BoundsMode> {
...@@ -273,48 +256,6 @@ TEST_P(ShellSurfaceBoundsModeTest, SetFullscreen) { ...@@ -273,48 +256,6 @@ TEST_P(ShellSurfaceBoundsModeTest, SetFullscreen) {
shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString());
} }
TEST_F(ShellSurfaceTest, SetPinned) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
shell_surface->SetPinned(ash::mojom::WindowPinType::TRUSTED_PINNED);
EXPECT_TRUE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::NONE);
EXPECT_FALSE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::PINNED);
EXPECT_TRUE(IsWidgetPinned(shell_surface->GetWidget()));
shell_surface->SetPinned(ash::mojom::WindowPinType::NONE);
EXPECT_FALSE(IsWidgetPinned(shell_surface->GetWidget()));
}
TEST_F(ShellSurfaceTest, SetSystemUiVisibility) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
shell_surface->SetSystemUiVisibility(true);
EXPECT_TRUE(
ash::wm::GetWindowState(shell_surface->GetWidget()->GetNativeWindow())
->autohide_shelf_when_maximized_or_fullscreen());
shell_surface->SetSystemUiVisibility(false);
EXPECT_FALSE(
ash::wm::GetWindowState(shell_surface->GetWidget()->GetNativeWindow())
->autohide_shelf_when_maximized_or_fullscreen());
}
TEST_F(ShellSurfaceTest, SetTitle) { TEST_F(ShellSurfaceTest, SetTitle) {
std::unique_ptr<Surface> surface(new Surface); std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
...@@ -487,26 +428,6 @@ TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorFromDisplayManager) { ...@@ -487,26 +428,6 @@ TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorFromDisplayManager) {
shell_surface->host_window()->layer()->GetTargetTransform().ToString()); shell_surface->host_window()->layer()->GetTargetTransform().ToString());
} }
TEST_F(ShellSurfaceTest, SetTopInset) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
ASSERT_TRUE(window);
EXPECT_EQ(0, window->GetProperty(aura::client::kTopViewInset));
int top_inset_height = 20;
shell_surface->SetTopInset(top_inset_height);
surface->Commit();
EXPECT_EQ(top_inset_height, window->GetProperty(aura::client::kTopViewInset));
}
void Close(int* close_call_count) { void Close(int* close_call_count) {
(*close_call_count)++; (*close_call_count)++;
} }
...@@ -615,372 +536,6 @@ TEST_F(ShellSurfaceTest, ConfigureCallback) { ...@@ -615,372 +536,6 @@ TEST_F(ShellSurfaceTest, ConfigureCallback) {
EXPECT_TRUE(is_resizing); EXPECT_TRUE(is_resizing);
} }
TEST_F(ShellSurfaceTest, ModalWindowDefaultActive) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get(),
/*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(gfx::Rect(10, 10, 100, 100));
ASSERT_FALSE(shell_surface->GetWidget());
shell_surface->SetSystemModal(true);
surface->Commit();
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
}
TEST_F(ShellSurfaceTest, UpdateModalWindow) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(cc::Region());
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Creating a surface without input region should not make it modal.
std::unique_ptr<Display> display(new Display);
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());
std::unique_ptr<SubSurface> sub_surface(
display->CreateSubSurface(child.get(), surface.get()));
surface->SetSubSurfacePosition(child.get(), gfx::Point(10, 10));
child->Commit();
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Making the surface opaque shouldn't make it modal either.
child->SetBlendMode(SkBlendMode::kSrc);
child->Commit();
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Setting input regions won't make it modal either.
surface->SetInputRegion(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// Only SetSystemModal changes modality.
shell_surface->SetSystemModal(true);
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
// If the non modal system window was active,
shell_surface->GetWidget()->Activate();
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(true);
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
}
TEST_F(ShellSurfaceTest, ModalWindowSetSystemModalBeforeCommit) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
surface->Attach(desktop_buffer.get());
surface->SetInputRegion(cc::Region());
// Set SetSystemModal before any commit happens. Widget is not created at
// this time.
EXPECT_FALSE(shell_surface->GetWidget());
shell_surface->SetSystemModal(true);
surface->Commit();
// It is expected that modal window is shown.
EXPECT_TRUE(shell_surface->GetWidget());
EXPECT_TRUE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
// Now widget is created and setting modal state should be applied
// immediately.
shell_surface->SetSystemModal(false);
EXPECT_FALSE(ash::ShellPort::Get()->IsSystemModalWindowOpen());
}
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);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
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) Create a shadow.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
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 not change the shadow bounds.
// TODO(oshima): The following scenario only worked with Xdg/ShellSurface,
// which never uses SetShadowBounds. This is broken with correct scenario, and
// will be fixed when the bounds control is delegated to the client.
//
// window->SetBounds(gfx::Rect(10, 10, 100, 100));
// EXPECT_EQ(before, shadow->layer()->bounds());
// 5) This should disable shadow.
shell_surface->SetShadowBounds(gfx::Rect());
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::NONE, GetShadowElevation(window));
EXPECT_FALSE(shadow->layer()->visible());
// 6) This should enable non surface shadow again.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
}
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(), ShellSurface::BoundsMode::SHELL, gfx::Point(), 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->OnSetFrame(SurfaceFrameType::SHADOW);
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.
surface->SetFrame(SurfaceFrameType::NONE);
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::NONE, GetShadowElevation(window));
EXPECT_FALSE(shadow->layer()->visible());
// 6) This should enable non surface shadow.
surface->SetFrame(SurfaceFrameType::SHADOW);
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
}
TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
shell_surface->SetGeometry(original_bounds);
surface->Attach(buffer.get());
surface->Commit();
// Placing a shadow at screen origin will make the shadow's origin (-10, -10).
const gfx::Rect shadow_bounds(content_size);
// Expected shadow position/bounds in parent coordinates.
const gfx::Point expected_shadow_origin(-10, -10);
const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size);
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window));
EXPECT_TRUE(shadow->layer()->visible());
// Origin must be in sync.
EXPECT_EQ(expected_shadow_origin, shadow->content_bounds().origin());
const gfx::Rect work_area =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
// Maximizing window hides the shadow.
widget->Maximize();
ASSERT_TRUE(widget->IsMaximized());
EXPECT_FALSE(shadow->layer()->visible());
shell_surface->SetShadowBounds(work_area);
surface->Commit();
EXPECT_FALSE(shadow->layer()->visible());
// Restoring bounds will re-enable shadow. It's content size is set to work
// area,/ thus not visible until new bounds is committed.
widget->Restore();
EXPECT_TRUE(shadow->layer()->visible());
const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size());
EXPECT_EQ(shadow_in_maximized, shadow->content_bounds());
// The bounds is updated.
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_EQ(expected_shadow_bounds, shadow->content_bounds());
}
TEST_F(ShellSurfaceTest, ShadowWithTransform) {
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
shell_surface->SetGeometry(original_bounds);
surface->Attach(buffer.get());
surface->Commit();
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
// Placing a shadow at screen origin will make the shadow's origin (-10, -10).
const gfx::Rect shadow_bounds(content_size);
// Shadow bounds relative to its parent should not be affected by a transform.
gfx::Transform transform;
transform.Translate(50, 50);
window->SetTransform(transform);
shell_surface->SetShadowBounds(shadow_bounds);
surface->Commit();
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->content_bounds());
}
TEST_F(ShellSurfaceTest, ShadowStartMaximized) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
shell_surface->Maximize();
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
// There is no shadow when started in maximized state.
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
// Sending a shadow bounds in maximized state won't create a shaodw.
shell_surface->SetShadowBounds(gfx::Rect(10, 10, 100, 100));
surface->Commit();
EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
// Restore the window and make sure the shadow is created, visible and
// has the latest bounds.
widget->Restore();
wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
ASSERT_TRUE(shadow);
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(gfx::Rect(10, 10, 100, 100), shadow->content_bounds());
}
TEST_P(ShellSurfaceBoundsModeTest, ToggleFullscreen) { TEST_P(ShellSurfaceBoundsModeTest, ToggleFullscreen) {
gfx::Size buffer_size(256, 256); gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer( std::unique_ptr<Buffer> buffer(
...@@ -1028,80 +583,5 @@ TEST_P(ShellSurfaceBoundsModeTest, ToggleFullscreen) { ...@@ -1028,80 +583,5 @@ TEST_P(ShellSurfaceBoundsModeTest, ToggleFullscreen) {
} }
} }
TEST_F(ShellSurfaceTest, CompositorLockInRotation) {
UpdateDisplay("800x600");
const gfx::Size buffer_size(800, 600);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
ash::Shell* shell = ash::Shell::Get();
shell->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// Start in maximized.
shell_surface->Maximize();
surface->Attach(buffer.get());
surface->Commit();
gfx::Rect maximum_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
shell_surface->SetGeometry(maximum_bounds);
shell_surface->SetOrientation(Orientation::LANDSCAPE);
surface->Commit();
ui::Compositor* compositor =
shell_surface->GetWidget()->GetNativeWindow()->layer()->GetCompositor();
EXPECT_FALSE(compositor->IsLocked());
UpdateDisplay("800x600/r");
EXPECT_TRUE(compositor->IsLocked());
shell_surface->SetOrientation(Orientation::PORTRAIT);
surface->Commit();
EXPECT_FALSE(compositor->IsLocked());
}
// If system tray is shown by click. It should be activated if user presses tab
// key while shell surface is active.
TEST_F(ShellSurfaceTest, KeyboardNavigationWithSystemTray) {
const gfx::Size buffer_size(800, 600);
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 =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
// Show system tray by perfoming a gesture tap at tray.
ash::SystemTray* system_tray = GetPrimarySystemTray();
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
system_tray->PerformAction(tap);
ASSERT_TRUE(system_tray->GetWidget());
// Confirm that system tray is not active at this time.
EXPECT_TRUE(shell_surface->GetWidget()->IsActive());
EXPECT_FALSE(
system_tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive());
// Send tab key event.
ui::test::EventGenerator& event_generator = GetEventGenerator();
event_generator.PressKey(ui::VKEY_TAB, ui::EF_NONE);
event_generator.ReleaseKey(ui::VKEY_TAB, ui::EF_NONE);
// Confirm that system tray is activated.
EXPECT_FALSE(shell_surface->GetWidget()->IsActive());
EXPECT_TRUE(
system_tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive());
}
} // namespace } // namespace
} // namespace exo } // namespace exo
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment