| // Copyright 2015 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/shell_surface.h" |
| |
| #include "ash/accessibility_delegate.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_port.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/wm_event.h" |
| #include "ash/wm/workspace/workspace_window_resizer.h" |
| #include "ash/wm/workspace_controller_test_api.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "components/exo/buffer.h" |
| #include "components/exo/display.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 "testing/gtest/include/gtest/gtest.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/window.h" |
| #include "ui/base/hit_test.h" |
| #include "ui/compositor/compositor.h" |
| #include "ui/compositor/layer.h" |
| #include "ui/display/display.h" |
| #include "ui/display/manager/display_manager.h" |
| #include "ui/display/screen.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" |
| #include "ui/wm/core/window_util.h" |
| |
| namespace exo { |
| namespace { |
| |
| using ShellSurfaceTest = test::ExoTestBase; |
| |
| uint32_t ConfigureFullscreen(uint32_t serial, |
| const gfx::Size& size, |
| ash::wm::WindowStateType state_type, |
| bool resizing, |
| bool activated, |
| const gfx::Vector2d& origin_offset) { |
| EXPECT_EQ(ash::wm::WINDOW_STATE_TYPE_FULLSCREEN, state_type); |
| 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 |
| : public ShellSurfaceTest, |
| public testing::WithParamInterface<ShellSurface::BoundsMode> { |
| public: |
| ShellSurfaceBoundsModeTest() {} |
| ~ShellSurfaceBoundsModeTest() override {} |
| |
| bool IsClientBoundsMode() const { |
| return GetParam() == ShellSurface::BoundsMode::CLIENT; |
| } |
| |
| bool HasBackdrop() { |
| ash::WorkspaceController* wc = |
| ash::ShellTestApi(ash::Shell::Get()).workspace_controller(); |
| return !!ash::WorkspaceControllerTestApi(wc).GetBackdropWindow(); |
| } |
| |
| std::unique_ptr<ShellSurface> CreateDefaultShellSurface(Surface* surface) { |
| if (IsClientBoundsMode()) { |
| return Display().CreateRemoteShellSurface( |
| surface, ash::kShellWindowId_DefaultContainer, |
| true /* scale_by_default_scale_factor */); |
| } else { |
| return Display().CreateShellSurface(surface); |
| } |
| } |
| |
| private: |
| DISALLOW_COPY_AND_ASSIGN(ShellSurfaceBoundsModeTest); |
| }; |
| |
| INSTANTIATE_TEST_CASE_P(, |
| ShellSurfaceBoundsModeTest, |
| testing::Values(ShellSurface::BoundsMode::CLIENT, |
| ShellSurface::BoundsMode::SHELL)); |
| |
| TEST_F(ShellSurfaceTest, AcknowledgeConfigure) { |
| gfx::Size buffer_size(32, 32); |
| 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())); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| |
| gfx::Point origin(100, 100); |
| shell_surface->GetWidget()->SetBounds(gfx::Rect(origin, buffer_size)); |
| EXPECT_EQ(origin.ToString(), |
| surface->window()->GetBoundsInRootWindow().origin().ToString()); |
| |
| const uint32_t kSerial = 1; |
| shell_surface->set_configure_callback( |
| base::Bind(&ConfigureFullscreen, kSerial)); |
| shell_surface->SetFullscreen(true); |
| |
| // Surface origin should not change until configure request is acknowledged. |
| EXPECT_EQ(origin.ToString(), |
| surface->window()->GetBoundsInRootWindow().origin().ToString()); |
| |
| shell_surface->AcknowledgeConfigure(kSerial); |
| std::unique_ptr<Buffer> fullscreen_buffer( |
| new Buffer(exo_test_helper()->CreateGpuMemoryBuffer( |
| CurrentContext()->bounds().size()))); |
| surface->Attach(fullscreen_buffer.get()); |
| surface->Commit(); |
| |
| EXPECT_EQ(gfx::Point().ToString(), |
| surface->window()->GetBoundsInRootWindow().origin().ToString()); |
| } |
| |
| TEST_F(ShellSurfaceTest, SetParent) { |
| gfx::Size buffer_size(256, 256); |
| std::unique_ptr<Buffer> parent_buffer( |
| new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| std::unique_ptr<Surface> parent_surface(new Surface); |
| std::unique_ptr<ShellSurface> parent_shell_surface( |
| new ShellSurface(parent_surface.get())); |
| |
| parent_surface->Attach(parent_buffer.get()); |
| parent_surface->Commit(); |
| |
| 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())); |
| shell_surface->SetParent(parent_shell_surface.get()); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_EQ( |
| parent_shell_surface->GetWidget()->GetNativeWindow(), |
| wm::GetTransientParent(shell_surface->GetWidget()->GetNativeWindow())); |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, Maximize) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_FALSE(HasBackdrop()); |
| shell_surface->Maximize(); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| surface->Commit(); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(CurrentContext()->bounds().width(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); |
| } |
| EXPECT_TRUE(shell_surface->GetWidget()->IsMaximized()); |
| |
| // Toggle maximize. |
| ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); |
| |
| ash::wm::GetWindowState(window)->OnWMEvent(&maximize_event); |
| EXPECT_FALSE(shell_surface->GetWidget()->IsMaximized()); |
| EXPECT_FALSE(HasBackdrop()); |
| |
| ash::wm::GetWindowState(window)->OnWMEvent(&maximize_event); |
| EXPECT_TRUE(shell_surface->GetWidget()->IsMaximized()); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| } |
| |
| TEST_F(ShellSurfaceTest, Minimize) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| // Minimizing can be performed before the surface is committed. |
| shell_surface->Minimize(); |
| EXPECT_TRUE(shell_surface->GetWidget()->IsMinimized()); |
| |
| // Confirm that attaching and commiting doesn't reset the state. |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_TRUE(shell_surface->GetWidget()->IsMinimized()); |
| |
| shell_surface->Restore(); |
| EXPECT_FALSE(shell_surface->GetWidget()->IsMinimized()); |
| |
| shell_surface->Minimize(); |
| EXPECT_TRUE(shell_surface->GetWidget()->IsMinimized()); |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, Restore) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_FALSE(HasBackdrop()); |
| // Note: Remove contents to avoid issues with maximize animations in tests. |
| shell_surface->Maximize(); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| shell_surface->Restore(); |
| EXPECT_FALSE(HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(buffer_size.ToString(), shell_surface->GetWidget() |
| ->GetWindowBoundsInScreen() |
| .size() |
| .ToString()); |
| } |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, SetFullscreen) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| |
| shell_surface->SetFullscreen(true); |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(CurrentContext()->bounds().ToString(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); |
| } |
| |
| shell_surface->SetFullscreen(false); |
| surface->Commit(); |
| EXPECT_FALSE(HasBackdrop()); |
| EXPECT_NE(CurrentContext()->bounds().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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(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) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test"))); |
| surface->Commit(); |
| } |
| |
| TEST_F(ShellSurfaceTest, SetApplicationId) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| EXPECT_FALSE(shell_surface->GetWidget()); |
| shell_surface->SetApplicationId("pre-widget-id"); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); |
| EXPECT_EQ("pre-widget-id", *ShellSurface::GetApplicationId(window)); |
| shell_surface->SetApplicationId("test"); |
| EXPECT_EQ("test", *ShellSurface::GetApplicationId(window)); |
| } |
| |
| TEST_F(ShellSurfaceTest, Move) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| // Map shell surface. |
| surface->Commit(); |
| |
| // The interactive move should end when surface is destroyed. |
| shell_surface->Move(); |
| |
| // Test that destroying the shell surface before move ends is OK. |
| shell_surface.reset(); |
| } |
| |
| TEST_F(ShellSurfaceTest, Resize) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| // Map shell surface. |
| surface->Commit(); |
| |
| // The interactive resize should end when surface is destroyed. |
| shell_surface->Resize(HTBOTTOMRIGHT); |
| |
| // Test that destroying the surface before resize ends is OK. |
| surface.reset(); |
| } |
| |
| TEST_F(ShellSurfaceTest, SetGeometry) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| gfx::Rect geometry(16, 16, 32, 32); |
| shell_surface->SetGeometry(geometry); |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_EQ( |
| geometry.size().ToString(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString()); |
| EXPECT_EQ(gfx::Rect(gfx::Point() - geometry.OffsetFromOrigin(), buffer_size) |
| .ToString(), |
| shell_surface->host_window()->bounds().ToString()); |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorForcedScaleFactor) { |
| double scale = 1.5; |
| display::Display::SetForceDeviceScaleFactor(scale); |
| |
| int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| display::Display::SetInternalDisplayId(display_id); |
| |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| gfx::Transform transform; |
| if (IsClientBoundsMode()) |
| transform.Scale(1.0 / scale, 1.0 / scale); |
| |
| EXPECT_EQ( |
| transform.ToString(), |
| shell_surface->host_window()->layer()->GetTargetTransform().ToString()); |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorFromDisplayManager) { |
| int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| display::Display::SetInternalDisplayId(display_id); |
| gfx::Size size(1920, 1080); |
| |
| display::DisplayManager* display_manager = |
| ash::Shell::Get()->display_manager(); |
| |
| double scale = 1.25; |
| scoped_refptr<display::ManagedDisplayMode> mode( |
| new display::ManagedDisplayMode(size, 60.f, false /* overscan */, |
| true /*native*/, 1.0, scale)); |
| mode->set_is_default(true); |
| |
| display::ManagedDisplayInfo::ManagedDisplayModeList mode_list; |
| mode_list.push_back(mode); |
| |
| display::ManagedDisplayInfo native_display_info(display_id, "test", false); |
| native_display_info.SetManagedDisplayModes(mode_list); |
| |
| native_display_info.SetBounds(gfx::Rect(size)); |
| native_display_info.set_device_scale_factor(scale); |
| |
| std::vector<display::ManagedDisplayInfo> display_info_list; |
| display_info_list.push_back(native_display_info); |
| |
| display_manager->OnNativeDisplaysChanged(display_info_list); |
| display_manager->UpdateInternalManagedDisplayModeListForTest(); |
| |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| |
| gfx::Transform transform; |
| if (IsClientBoundsMode()) |
| transform.Scale(1.0 / scale, 1.0 / scale); |
| |
| EXPECT_EQ( |
| transform.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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(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) { |
| (*close_call_count)++; |
| } |
| |
| TEST_F(ShellSurfaceTest, CloseCallback) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| int close_call_count = 0; |
| shell_surface->set_close_callback( |
| base::Bind(&Close, base::Unretained(&close_call_count))); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| |
| EXPECT_EQ(0, close_call_count); |
| shell_surface->GetWidget()->Close(); |
| EXPECT_EQ(1, close_call_count); |
| } |
| |
| void DestroyShellSurface(std::unique_ptr<ShellSurface>* shell_surface) { |
| shell_surface->reset(); |
| } |
| |
| TEST_F(ShellSurfaceTest, SurfaceDestroyedCallback) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| shell_surface->set_surface_destroyed_callback( |
| base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface))); |
| |
| surface->Commit(); |
| |
| EXPECT_TRUE(shell_surface.get()); |
| surface.reset(); |
| EXPECT_FALSE(shell_surface.get()); |
| } |
| |
| uint32_t Configure(gfx::Size* suggested_size, |
| ash::wm::WindowStateType* has_state_type, |
| bool* is_resizing, |
| bool* is_active, |
| const gfx::Size& size, |
| ash::wm::WindowStateType state_type, |
| bool resizing, |
| bool activated, |
| const gfx::Vector2d& origin_offset) { |
| *suggested_size = size; |
| *has_state_type = state_type; |
| *is_resizing = resizing; |
| *is_active = activated; |
| return 0; |
| } |
| |
| TEST_F(ShellSurfaceTest, ConfigureCallback) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| |
| gfx::Size suggested_size; |
| ash::wm::WindowStateType has_state_type = ash::wm::WINDOW_STATE_TYPE_NORMAL; |
| bool is_resizing = false; |
| bool is_active = false; |
| shell_surface->set_configure_callback( |
| base::Bind(&Configure, base::Unretained(&suggested_size), |
| base::Unretained(&has_state_type), |
| base::Unretained(&is_resizing), base::Unretained(&is_active))); |
| shell_surface->Maximize(); |
| shell_surface->AcknowledgeConfigure(0); |
| EXPECT_EQ(CurrentContext()->bounds().width(), suggested_size.width()); |
| EXPECT_EQ(ash::wm::WINDOW_STATE_TYPE_MAXIMIZED, has_state_type); |
| shell_surface->Restore(); |
| shell_surface->AcknowledgeConfigure(0); |
| |
| shell_surface->SetFullscreen(true); |
| shell_surface->AcknowledgeConfigure(0); |
| EXPECT_EQ(CurrentContext()->bounds().size().ToString(), |
| suggested_size.ToString()); |
| EXPECT_EQ(ash::wm::WINDOW_STATE_TYPE_FULLSCREEN, has_state_type); |
| shell_surface->SetFullscreen(false); |
| shell_surface->AcknowledgeConfigure(0); |
| |
| gfx::Size buffer_size(64, 64); |
| std::unique_ptr<Buffer> buffer( |
| new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| shell_surface->GetWidget()->Activate(); |
| shell_surface->AcknowledgeConfigure(0); |
| EXPECT_TRUE(is_active); |
| shell_surface->GetWidget()->Deactivate(); |
| shell_surface->AcknowledgeConfigure(0); |
| EXPECT_FALSE(is_active); |
| |
| EXPECT_FALSE(is_resizing); |
| shell_surface->Resize(HTBOTTOMRIGHT); |
| shell_surface->AcknowledgeConfigure(0); |
| EXPECT_TRUE(is_resizing); |
| } |
| |
| TEST_F(ShellSurfaceTest, ModalWindowDefaultActive) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(), |
| true, false, ash::kShellWindowId_SystemModalContainer)); |
| 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( |
| SkRegion(gfx::RectToSkIRect(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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(), |
| true, false, ash::kShellWindowId_SystemModalContainer)); |
| 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(SkRegion()); |
| 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( |
| SkRegion(gfx::RectToSkIRect(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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(), |
| true, false, ash::kShellWindowId_SystemModalContainer)); |
| 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(SkRegion()); |
| |
| // 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, PopupWindow) { |
| Surface parent_surface; |
| ShellSurface parent(&parent_surface); |
| const gfx::Rect parent_bounds(100, 100, 300, 300); |
| |
| Buffer parent_buffer( |
| exo_test_helper()->CreateGpuMemoryBuffer(parent_bounds.size())); |
| parent_surface.Attach(&parent_buffer); |
| parent_surface.Commit(); |
| |
| parent.GetWidget()->SetBounds(parent_bounds); |
| |
| Display display; |
| Surface popup_surface; |
| const gfx::Rect popup_bounds(10, 10, 100, 100); |
| std::unique_ptr<ShellSurface> popup = display.CreatePopupShellSurface( |
| &popup_surface, &parent, popup_bounds.origin()); |
| |
| Buffer popup_buffer( |
| exo_test_helper()->CreateGpuMemoryBuffer(popup_bounds.size())); |
| popup_surface.Attach(&popup_buffer); |
| popup_surface.Commit(); |
| |
| // Popup bounds are relative to parent. |
| EXPECT_EQ(gfx::Rect(parent_bounds.origin() + popup_bounds.OffsetFromOrigin(), |
| popup_bounds.size()), |
| popup->GetWidget()->GetWindowBoundsInScreen()); |
| |
| const gfx::Rect geometry(5, 5, 90, 90); |
| popup->SetGeometry(geometry); |
| popup_surface.Commit(); |
| |
| // Popup position is fixed, and geometry is relative to it. |
| EXPECT_EQ(gfx::Rect(parent_bounds.origin() + |
| popup_bounds.OffsetFromOrigin() + |
| geometry.OffsetFromOrigin(), |
| geometry.size()), |
| popup->GetWidget()->GetWindowBoundsInScreen()); |
| } |
| |
| 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, 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) Create a shadow. |
| shell_surface->SetRectangularSurfaceShadow(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. |
| window->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| EXPECT_EQ(before, shadow->layer()->bounds()); |
| |
| // 5) This should disable shadow. |
| shell_surface->SetRectangularSurfaceShadow(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->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100)); |
| surface->Commit(); |
| |
| EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window)); |
| EXPECT_TRUE(shadow->layer()->visible()); |
| |
| // For surface shadow, the underlay is placed at the bottom of shell surfaces. |
| EXPECT_EQ(window, shell_surface->shadow_underlay()->parent()); |
| EXPECT_EQ(window, shell_surface->shadow_overlay()->parent()); |
| |
| auto child_it = window->children().begin(); |
| EXPECT_EQ(*child_it++, shell_surface->shadow_underlay()); |
| EXPECT_EQ(*child_it++, shell_surface->shadow_overlay()); |
| EXPECT_EQ(*child_it++, shell_surface->host_window()); |
| EXPECT_EQ(child_it, window->children().end()); |
| |
| // Set the shadow background to 0, and the shadow_underlay should be |
| // destroyed. |
| shell_surface->SetRectangularShadowBackgroundOpacity(0.f); |
| surface->Commit(); |
| |
| EXPECT_FALSE(shell_surface->shadow_underlay()); |
| EXPECT_EQ(window, shell_surface->shadow_overlay()->parent()); |
| |
| child_it = window->children().begin(); |
| EXPECT_EQ(*child_it++, shell_surface->shadow_overlay()); |
| EXPECT_EQ(*child_it++, shell_surface->host_window()); |
| EXPECT_EQ(child_it, window->children().end()); |
| |
| // Set the shadow background to 1, and the shadow_underlay should be |
| // recreated. |
| shell_surface->SetRectangularShadowBackgroundOpacity(1.f); |
| surface->Commit(); |
| |
| EXPECT_TRUE(shell_surface->shadow_underlay()); |
| EXPECT_EQ(window, shell_surface->shadow_underlay()->parent()); |
| EXPECT_EQ(window, shell_surface->shadow_overlay()->parent()); |
| |
| child_it = window->children().begin(); |
| EXPECT_EQ(*child_it++, shell_surface->shadow_underlay()); |
| EXPECT_EQ(*child_it++, shell_surface->shadow_overlay()); |
| EXPECT_EQ(*child_it++, shell_surface->host_window()); |
| EXPECT_EQ(child_it, window->children().end()); |
| } |
| |
| 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, 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()); |
| |
| // 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()); |
| |
| // Shadow overlay should be stacked just above the shadow underlay. |
| auto underlay_it = |
| std::find(window->children().begin(), window->children().end(), |
| shell_surface->shadow_underlay()); |
| ASSERT_NE(underlay_it, window->children().end()); |
| ASSERT_NE(std::next(underlay_it), window->children().end()); |
| EXPECT_EQ(*std::next(underlay_it), shell_surface->shadow_overlay()); |
| } |
| |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| |
| // 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->SetRectangularSurfaceShadow(shadow_bounds); |
| surface->Commit(); |
| EXPECT_EQ(wm::ShadowElevation::DEFAULT, GetShadowElevation(window)); |
| |
| // Shadow overlay bounds. |
| EXPECT_TRUE(shadow->layer()->visible()); |
| // Origin must be in sync. |
| EXPECT_EQ(expected_shadow_origin, |
| shadow->layer()->parent()->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->SetRectangularSurfaceShadow(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->layer()->parent()->bounds()); |
| |
| // The bounds is updated. |
| shell_surface->SetRectangularSurfaceShadow(shadow_bounds); |
| surface->Commit(); |
| EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| |
| // 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->SetRectangularSurfaceShadow(shadow_bounds); |
| surface->Commit(); |
| EXPECT_TRUE(shadow->layer()->visible()); |
| EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->layer()->parent()->bounds()); |
| } |
| |
| TEST_F(ShellSurfaceTest, ShadowStartMaximized) { |
| std::unique_ptr<Surface> surface(new Surface); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| 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->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100)); |
| surface->Commit(); |
| |
| EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window)); |
| // Underlay should be created even without shadow. |
| ASSERT_TRUE(shell_surface->shadow_underlay()); |
| EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); |
| shell_surface->SetRectangularSurfaceShadow(gfx::Rect(0, 0, 0, 0)); |
| // Underlay should be created even without shadow. |
| ASSERT_TRUE(shell_surface->shadow_underlay()); |
| EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); |
| surface->SetFrame(SurfaceFrameType::NONE); |
| surface->Commit(); |
| // No underlay if there is no shadow. |
| EXPECT_FALSE(shell_surface->shadow_underlay()); |
| |
| surface->SetFrame(SurfaceFrameType::SHADOW); |
| shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100)); |
| surface->Commit(); |
| |
| // 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->layer()->parent()->bounds()); |
| } |
| |
| TEST_P(ShellSurfaceBoundsModeTest, ToggleFullscreen) { |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface( |
| CreateDefaultShellSurface(surface.get())); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| EXPECT_FALSE(HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(buffer_size.ToString(), shell_surface->GetWidget() |
| ->GetWindowBoundsInScreen() |
| .size() |
| .ToString()); |
| } |
| shell_surface->Maximize(); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(CurrentContext()->bounds().width(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); |
| } |
| |
| ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); |
| |
| // Enter fullscreen mode. |
| ash::wm::GetWindowState(window)->OnWMEvent(&event); |
| |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(CurrentContext()->bounds().ToString(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); |
| } |
| |
| // Leave fullscreen mode. |
| ash::wm::GetWindowState(window)->OnWMEvent(&event); |
| EXPECT_EQ(IsClientBoundsMode(), HasBackdrop()); |
| |
| // Check that shell surface is maximized. |
| if (!IsClientBoundsMode()) { |
| EXPECT_EQ(CurrentContext()->bounds().width(), |
| shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); |
| } |
| } |
| |
| // Make sure that a surface shell started in maximize creates deprecated |
| // shadow correctly. |
| TEST_F(ShellSurfaceTest, |
| StartMaximizedThenMinimizeWithSetRectangularShadow_DEPRECATED) { |
| 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, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| |
| // Start in maximized. |
| shell_surface->Maximize(); |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| |
| gfx::Rect shadow_bounds = |
| display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| shell_surface->SetGeometry(shadow_bounds); |
| shell_surface->SetRectangularShadow_DEPRECATED(shadow_bounds); |
| surface->Commit(); |
| EXPECT_EQ(shadow_bounds, |
| shell_surface->GetWidget()->GetWindowBoundsInScreen()); |
| ASSERT_EQ(shadow_bounds, |
| shell_surface->shadow_underlay()->GetBoundsInScreen()); |
| EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(), |
| shell_surface->surface_for_testing()->window()->bounds().size()); |
| |
| ash::wm::WMEvent minimize_event(ash::wm::WM_EVENT_MINIMIZE); |
| aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); |
| ash::wm::GetWindowState(window)->OnWMEvent(&minimize_event); |
| } |
| |
| 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); |
| std::unique_ptr<ShellSurface> shell_surface(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| 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()); |
| } |
| |
| // System tray 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(new ShellSurface( |
| surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(), |
| true, false, ash::kShellWindowId_DefaultContainer)); |
| |
| surface->Attach(buffer.get()); |
| surface->Commit(); |
| |
| EXPECT_TRUE(shell_surface->GetWidget()->IsActive()); |
| |
| // Show system tray. |
| ash::SystemTray* system_tray = GetPrimarySystemTray(); |
| system_tray->ShowDefaultView(ash::BUBBLE_CREATE_NEW); |
| 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 exo |