chromeos: convert remaining AshTest usage to AshTestBase
And remove the now unused test related classes.
BUG=707057
TEST=test only changes
[email protected]
Review-Url: https://codereview.chromium.org/2847283002
Cr-Commit-Position: refs/heads/master@{#468352}
diff --git a/ash/BUILD.gn b/ash/BUILD.gn
index 20e933d..5001ced 100644
--- a/ash/BUILD.gn
+++ b/ash/BUILD.gn
@@ -1253,7 +1253,6 @@
"wm/workspace_controller_test_helper.cc",
"wm/workspace_controller_test_helper.h",
"wm/workspace_controller_unittest.cc",
- "wm_window_unittest.cc",
]
deps = [
"//ash",
diff --git a/ash/mus/BUILD.gn b/ash/mus/BUILD.gn
index 605d8dd..01d59b8 100644
--- a/ash/mus/BUILD.gn
+++ b/ash/mus/BUILD.gn
@@ -191,12 +191,6 @@
"bridge/shell_port_mash_test_api.h",
"non_client_frame_controller_unittest.cc",
"screen_mus_unittest.cc",
- "test/ash_test_impl_mus.cc",
- "test/ash_test_impl_mus.h",
- "test/wm_test_base.cc",
- "test/wm_test_base.h",
- "test/wm_test_helper.cc",
- "test/wm_test_helper.h",
"top_level_window_factory_unittest.cc",
"window_manager_unittest.cc",
]
diff --git a/ash/mus/test/ash_test_impl_mus.cc b/ash/mus/test/ash_test_impl_mus.cc
deleted file mode 100644
index b9e5f50f..0000000
--- a/ash/mus/test/ash_test_impl_mus.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2016 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 "ash/mus/test/ash_test_impl_mus.h"
-
-#include "ash/test/ash_test.h"
-#include "ash/wm_window.h"
-#include "base/command_line.h"
-#include "base/memory/ptr_util.h"
-#include "services/ui/public/cpp/property_type_converters.h"
-#include "services/ui/public/interfaces/window_manager.mojom.h"
-#include "ui/aura/window.h"
-#include "ui/display/display_switches.h"
-#include "ui/wm/core/window_util.h"
-
-namespace ash {
-namespace mus {
-namespace {
-
-// WmTestBase is abstract as TestBody() is pure virtual (the various TEST
-// macros have the implementation). In order to create WmTestBase we have to
-// subclass with an empty implementation of TestBody(). That's ok as the class
-// isn't used as a normal test here.
-class WmTestBaseImpl : public WmTestBase {
- public:
- WmTestBaseImpl() {}
- ~WmTestBaseImpl() override {}
-
- // WmTestBase:
- void TestBody() override {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WmTestBaseImpl);
-};
-
-} // namespace
-
-AshTestImplMus::AshTestImplMus()
- : wm_test_base_(base::MakeUnique<WmTestBaseImpl>()) {}
-
-AshTestImplMus::~AshTestImplMus() {}
-
-void AshTestImplMus::SetUp() {
- // This matches what AshTestBase does.
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- if (!command_line->HasSwitch(::switches::kHostWindowBounds)) {
- command_line->AppendSwitchASCII(::switches::kHostWindowBounds,
- "1+1-800x600");
- }
-
- wm_test_base_->SetUp();
-}
-
-void AshTestImplMus::TearDown() {
- wm_test_base_->TearDown();
-}
-
-void AshTestImplMus::UpdateDisplay(const std::string& display_spec) {
- wm_test_base_->UpdateDisplay(display_spec);
-}
-
-std::unique_ptr<WindowOwner> AshTestImplMus::CreateTestWindow(
- const gfx::Rect& bounds_in_screen,
- ui::wm::WindowType type,
- int shell_window_id) {
- aura::Window* window =
- wm_test_base_->CreateTestWindow(bounds_in_screen, type);
- window->set_id(shell_window_id);
- return base::MakeUnique<WindowOwner>(WmWindow::Get(window));
-}
-
-std::unique_ptr<WindowOwner> AshTestImplMus::CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) {
- // For mus CreateTestWindow() creates top level windows (assuming
- // WINDOW_TYPE_NORMAL).
- return CreateTestWindow(bounds_in_screen, ui::wm::WINDOW_TYPE_NORMAL,
- shell_window_id);
-}
-
-display::Display AshTestImplMus::GetSecondaryDisplay() {
- return wm_test_base_->GetSecondaryDisplay();
-}
-
-bool AshTestImplMus::SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) {
- NOTIMPLEMENTED();
- return false;
-}
-
-void AshTestImplMus::ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) {
- init_params->context = WmWindow::GetAuraWindow(window);
- init_params
- ->mus_properties[ui::mojom::WindowManager::kDisplayId_InitProperty] =
- mojo::ConvertTo<std::vector<uint8_t>>(
- window->GetDisplayNearestWindow().id());
-}
-
-void AshTestImplMus::AddTransientChild(WmWindow* parent, WmWindow* window) {
- // TODO(sky): remove this as both classes can share same implementation now.
- ::wm::AddTransientChild(WmWindow::GetAuraWindow(parent),
- WmWindow::GetAuraWindow(window));
-}
-
-} // namespace mus
-} // namespace ash
diff --git a/ash/mus/test/ash_test_impl_mus.h b/ash/mus/test/ash_test_impl_mus.h
deleted file mode 100644
index 5e900aa..0000000
--- a/ash/mus/test/ash_test_impl_mus.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_MUS_TEST_ASH_TEST_IMPL_MUS_H_
-#define ASH_MUS_TEST_ASH_TEST_IMPL_MUS_H_
-
-#include "ash/mus/test/wm_test_base.h"
-#include "ash/test/ash_test_impl.h"
-#include "base/macros.h"
-
-namespace ash {
-namespace mus {
-
-class WmTestBase;
-
-// Implementation of AshTestImpl for mus.
-class AshTestImplMus : public AshTestImpl {
- public:
- AshTestImplMus();
- ~AshTestImplMus() override;
-
- // AshTestImpl:
- void SetUp() override;
- void TearDown() override;
- void UpdateDisplay(const std::string& display_spec) override;
- std::unique_ptr<WindowOwner> CreateTestWindow(
- const gfx::Rect& bounds_in_screen,
- ui::wm::WindowType type,
- int shell_window_id) override;
- std::unique_ptr<WindowOwner> CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) override;
- display::Display GetSecondaryDisplay() override;
- bool SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) override;
- void ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) override;
- void AddTransientChild(WmWindow* parent, WmWindow* window) override;
-
- private:
- // TODO(sky): fold WmTestBase directly into this class when no more subclasses
- // of WmTestBase.
- std::unique_ptr<WmTestBase> wm_test_base_;
-
- DISALLOW_COPY_AND_ASSIGN(AshTestImplMus);
-};
-
-} // namespace mus
-} // namespace ash
-
-#endif // ASH_MUS_TEST_ASH_TEST_IMPL_MUS_H_
diff --git a/ash/mus/test/wm_test_base.cc b/ash/mus/test/wm_test_base.cc
deleted file mode 100644
index eb0979f..0000000
--- a/ash/mus/test/wm_test_base.cc
+++ /dev/null
@@ -1,201 +0,0 @@
-// Copyright 2016 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 "ash/mus/test/wm_test_base.h"
-
-#include <algorithm>
-#include <vector>
-
-#include "ash/display/window_tree_host_manager.h"
-#include "ash/mus/test/wm_test_helper.h"
-#include "ash/mus/top_level_window_factory.h"
-#include "ash/mus/window_manager.h"
-#include "ash/mus/window_manager_application.h"
-#include "ash/public/cpp/config.h"
-#include "ash/public/cpp/session_types.h"
-#include "ash/public/interfaces/session_controller.mojom.h"
-#include "ash/session/session_controller.h"
-#include "ash/shell.h"
-#include "ash/test/wm_window_test_api.h"
-#include "base/memory/ptr_util.h"
-#include "services/ui/public/cpp/property_type_converters.h"
-#include "ui/aura/mus/property_converter.h"
-#include "ui/aura/mus/window_tree_client.h"
-#include "ui/aura/window.h"
-#include "ui/compositor/scoped_animation_duration_scale_mode.h"
-#include "ui/display/display.h"
-#include "ui/display/manager/display_manager.h"
-
-namespace ash {
-namespace mus {
-namespace {
-
-ui::mojom::WindowType MusWindowTypeFromWmWindowType(
- ui::wm::WindowType wm_window_type) {
- switch (wm_window_type) {
- case ui::wm::WINDOW_TYPE_UNKNOWN:
- break;
-
- case ui::wm::WINDOW_TYPE_NORMAL:
- return ui::mojom::WindowType::WINDOW;
-
- case ui::wm::WINDOW_TYPE_POPUP:
- return ui::mojom::WindowType::POPUP;
-
- case ui::wm::WINDOW_TYPE_CONTROL:
- return ui::mojom::WindowType::CONTROL;
-
- case ui::wm::WINDOW_TYPE_PANEL:
- return ui::mojom::WindowType::PANEL;
-
- case ui::wm::WINDOW_TYPE_MENU:
- return ui::mojom::WindowType::MENU;
-
- case ui::wm::WINDOW_TYPE_TOOLTIP:
- return ui::mojom::WindowType::TOOLTIP;
- }
-
- NOTREACHED();
- return ui::mojom::WindowType::CONTROL;
-}
-
-} // namespace
-
-WmTestBase::WmTestBase() {}
-
-WmTestBase::~WmTestBase() {
- CHECK(setup_called_)
- << "You have overridden SetUp but never called WmTestBase::SetUp";
- CHECK(teardown_called_)
- << "You have overridden TearDown but never called WmTestBase::TearDown";
-}
-
-void WmTestBase::UpdateDisplay(const std::string& display_spec) {
- test_helper_->UpdateDisplay(display_spec);
-}
-
-aura::Window* WmTestBase::GetPrimaryRootWindow() {
- return Shell::Get()->GetPrimaryRootWindow();
-}
-
-aura::Window* WmTestBase::GetSecondaryRootWindow() {
- if (Shell::GetAshConfig() == Config::MUS) {
- return Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId(
- GetSecondaryDisplay().id());
- }
-
- std::vector<RootWindowController*> roots =
- test_helper_->GetRootsOrderedByDisplayId();
- return roots.size() < 2 ? nullptr : roots[1]->GetRootWindow();
-}
-
-display::Display WmTestBase::GetPrimaryDisplay() {
- if (Shell::GetAshConfig() == Config::MUS) {
- return display::Screen::GetScreen()->GetDisplayNearestWindow(
- Shell::Get()->GetPrimaryRootWindow());
- }
-
- std::vector<RootWindowController*> roots =
- test_helper_->GetRootsOrderedByDisplayId();
- DCHECK(!roots.empty());
- return roots[0]->GetWindow()->GetDisplayNearestWindow();
-}
-
-display::Display WmTestBase::GetSecondaryDisplay() {
- if (Shell::GetAshConfig() == Config::MUS)
- return Shell::Get()->display_manager()->GetSecondaryDisplay();
-
- std::vector<RootWindowController*> roots =
- test_helper_->GetRootsOrderedByDisplayId();
- return roots.size() < 2 ? display::Display()
- : roots[1]->GetWindow()->GetDisplayNearestWindow();
-}
-
-aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) {
- return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL);
-}
-
-aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds,
- ui::wm::WindowType window_type) {
- std::map<std::string, std::vector<uint8_t>> properties;
- if (!bounds.IsEmpty()) {
- properties[ui::mojom::WindowManager::kBounds_InitProperty] =
- mojo::ConvertTo<std::vector<uint8_t>>(bounds);
- }
-
- properties[ui::mojom::WindowManager::kResizeBehavior_Property] =
- mojo::ConvertTo<std::vector<uint8_t>>(
- static_cast<aura::PropertyConverter::PrimitiveType>(
- ui::mojom::kResizeBehaviorCanResize |
- ui::mojom::kResizeBehaviorCanMaximize |
- ui::mojom::kResizeBehaviorCanMinimize));
-
- const ui::mojom::WindowType mus_window_type =
- MusWindowTypeFromWmWindowType(window_type);
- WindowManager* window_manager =
- test_helper_->window_manager_app()->window_manager();
- aura::Window* window = CreateAndParentTopLevelWindow(
- window_manager, mus_window_type, &properties);
- window->Show();
- return window;
-}
-
-aura::Window* WmTestBase::CreateChildTestWindow(aura::Window* parent,
- const gfx::Rect& bounds) {
- std::map<std::string, std::vector<uint8_t>> properties;
- aura::Window* window = new aura::Window(nullptr);
- window->Init(ui::LAYER_TEXTURED);
- window->SetBounds(bounds);
- window->Show();
- parent->AddChild(window);
- return window;
-}
-
-void WmTestBase::SetUp() {
- setup_called_ = true;
- // Disable animations during tests.
- zero_duration_mode_ = base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
- ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
- // Most tests expect a minimum size of 0x0.
- minimum_size_lock_ =
- base::MakeUnique<WmWindowTestApi::GlobalMinimumSizeLock>();
- test_helper_.reset(new WmTestHelper);
- test_helper_->Init();
-
- // Most tests assume the user is logged in (and hence the shelf is created).
- SimulateUserLogin();
-}
-
-void WmTestBase::TearDown() {
- teardown_called_ = true;
- test_helper_.reset();
- minimum_size_lock_.reset();
- zero_duration_mode_.reset();
-}
-
-void WmTestBase::SimulateUserLogin() {
- SessionController* session_controller = Shell::Get()->session_controller();
-
- // Simulate the first user logging in.
- mojom::UserSessionPtr session = mojom::UserSession::New();
- session->session_id = 1;
- session->type = user_manager::USER_TYPE_REGULAR;
- const std::string email("[email protected]");
- session->account_id = AccountId::FromUserEmail(email);
- session->display_name = "Ash User";
- session->display_email = email;
- session_controller->UpdateUserSession(std::move(session));
-
- // Simulate the user session becoming active.
- mojom::SessionInfoPtr info = mojom::SessionInfo::New();
- info->can_lock_screen = true;
- info->should_lock_screen_automatically = false;
- info->add_user_session_policy = AddUserSessionPolicy::ALLOWED;
- info->state = session_manager::SessionState::ACTIVE;
- session_controller->SetSessionInfo(std::move(info));
-}
-
-
-} // namespace mus
-} // namespace ash
diff --git a/ash/mus/test/wm_test_base.h b/ash/mus/test/wm_test_base.h
deleted file mode 100644
index 57d10d05..0000000
--- a/ash/mus/test/wm_test_base.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_MUS_TEST_WM_TEST_BASE_H_
-#define ASH_MUS_TEST_WM_TEST_BASE_H_
-
-#include <memory>
-#include <string>
-
-#include "ash/test/wm_window_test_api.h"
-#include "base/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/display/display.h"
-#include "ui/wm/public/window_types.h"
-
-namespace aura {
-class Window;
-}
-
-namespace display {
-class Display;
-}
-
-namespace gfx {
-class Rect;
-}
-
-namespace ui {
-class ScopedAnimationDurationScaleMode;
-}
-
-namespace ash {
-namespace mus {
-
-class AshTestImplMus;
-class WmTestHelper;
-
-// Base class for window manager tests that want to configure
-// WindowTreeClient without a client to mus.
-// TODO(sky): nuke this.
-class WmTestBase : public testing::Test {
- public:
- WmTestBase();
- ~WmTestBase() override;
-
- // Update the display configuration as given in |display_spec|.
- // See test::DisplayManagerTestApi::UpdateDisplay for more details.
- void UpdateDisplay(const std::string& display_spec);
-
- aura::Window* GetPrimaryRootWindow();
- aura::Window* GetSecondaryRootWindow();
-
- display::Display GetPrimaryDisplay();
- display::Display GetSecondaryDisplay();
-
- // Creates a top level window visible window in the appropriate container.
- // NOTE: you can explicitly destroy the returned value if necessary, but it
- // will also be automatically destroyed when the WindowTreeClient is
- // destroyed.
- aura::Window* CreateTestWindow(const gfx::Rect& bounds);
- aura::Window* CreateTestWindow(const gfx::Rect& bounds,
- ui::wm::WindowType window_type);
-
- // Creates a window parented to |parent|. The returned window is visible.
- aura::Window* CreateChildTestWindow(aura::Window* parent,
- const gfx::Rect& bounds);
-
- protected:
- // testing::Test:
- void SetUp() override;
- void TearDown() override;
-
- private:
- friend class AshTestImplMus;
-
- // Simulates the first user logging in and the session becoming active.
- // Classic ash handles this via AshTestHelper and TestSessionStateDelegate.
- void SimulateUserLogin();
-
- bool setup_called_ = false;
- bool teardown_called_ = false;
- std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
- std::unique_ptr<WmWindowTestApi::GlobalMinimumSizeLock> minimum_size_lock_;
- std::unique_ptr<WmTestHelper> test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(WmTestBase);
-};
-
-} // namespace mus
-} // namespace ash
-
-#endif // ASH_MUS_TEST_WM_TEST_BASE_H_
diff --git a/ash/mus/test/wm_test_helper.cc b/ash/mus/test/wm_test_helper.cc
deleted file mode 100644
index 26bb271..0000000
--- a/ash/mus/test/wm_test_helper.cc
+++ /dev/null
@@ -1,224 +0,0 @@
-// Copyright 2016 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 "ash/mus/test/wm_test_helper.h"
-
-#include "ash/mus/screen_mus.h"
-#include "ash/mus/window_manager.h"
-#include "ash/mus/window_manager_application.h"
-#include "ash/public/cpp/config.h"
-#include "ash/shell.h"
-#include "ash/test/test_shell_delegate.h"
-#include "ash/wm_window.h"
-#include "base/memory/ptr_util.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/test/sequenced_worker_pool_owner.h"
-#include "services/ui/public/cpp/input_devices/input_device_client.h"
-#include "services/ui/public/cpp/property_type_converters.h"
-#include "ui/aura/mus/window_tree_client.h"
-#include "ui/aura/test/env_test_helper.h"
-#include "ui/aura/test/mus/window_tree_client_private.h"
-#include "ui/aura/window.h"
-#include "ui/base/material_design/material_design_controller.h"
-#include "ui/base/test/material_design_controller_test_api.h"
-#include "ui/display/display.h"
-#include "ui/display/display_list.h"
-#include "ui/display/screen_base.h"
-#include "ui/display/test/display_manager_test_api.h"
-#include "ui/views/test/test_views_delegate.h"
-
-namespace ash {
-namespace mus {
-namespace {
-
-bool CompareByDisplayId(RootWindowController* root1,
- RootWindowController* root2) {
- return root1->GetWindow()->GetDisplayNearestWindow().id() <
- root2->GetWindow()->GetDisplayNearestWindow().id();
-}
-
-// TODO(sky): at some point this needs to support everything in DisplayInfo,
-// for now just the bare minimum, which is [x+y-]wxh.
-gfx::Rect ParseDisplayBounds(const std::string& spec) {
- gfx::Rect bounds;
- const std::vector<std::string> parts =
- base::SplitString(spec, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- std::string size_spec;
- if (parts.size() == 2u) {
- size_spec = parts[1];
- const std::vector<std::string> origin_parts = base::SplitString(
- parts[0], "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- CHECK_EQ(2u, origin_parts.size());
- int x, y;
- CHECK(base::StringToInt(origin_parts[0], &x));
- CHECK(base::StringToInt(origin_parts[1], &y));
- bounds.set_origin(gfx::Point(x, y));
- } else {
- CHECK_EQ(1u, parts.size());
- size_spec = spec;
- }
- const std::vector<std::string> size_parts = base::SplitString(
- size_spec, "x", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- CHECK_EQ(2u, size_parts.size());
- int w = 0, h = 0;
- CHECK(base::StringToInt(size_parts[0], &w));
- CHECK(base::StringToInt(size_parts[1], &h));
- bounds.set_size(gfx::Size(w, h));
- return bounds;
-}
-
-} // namespace
-
-WmTestHelper::WmTestHelper() {}
-
-WmTestHelper::~WmTestHelper() {
- // Flush the message loop so that any pending tasks are run. This ensures
- // any delayed tasks, such as deleting RootWindowControllers, are processed
- // before continuing.
- base::RunLoop().RunUntilIdle();
-
- // Needs to be destroyed before material design.
- window_manager_app_.reset();
-
- base::RunLoop().RunUntilIdle();
- blocking_pool_owner_.reset();
- base::RunLoop().RunUntilIdle();
-
- ui::test::MaterialDesignControllerTestAPI::Uninitialize();
-
- input_device_client_.reset();
-}
-
-void WmTestHelper::Init() {
- const Config config = base::CommandLine::ForCurrentProcess()->HasSwitch("mus")
- ? Config::MUS
- : Config::MASH;
- if (config == Config::MUS)
- input_device_client_ = base::MakeUnique<ui::InputDeviceClient>();
-
- // MaterialDesignController may have already been initialized. To cover that
- // case explicitly uninitialize before initializing.
- ui::test::MaterialDesignControllerTestAPI::Uninitialize();
- ui::MaterialDesignController::Initialize();
-
- views_delegate_ = base::MakeUnique<views::TestViewsDelegate>();
-
- const bool show_primary_host_on_connect = false;
- window_manager_app_ = base::MakeUnique<WindowManagerApplication>(
- show_primary_host_on_connect, config);
-
- message_loop_.reset(new base::MessageLoopForUI());
-
- const size_t kMaxNumberThreads = 3u; // Matches that of content.
- const char kThreadNamePrefix[] = "MashBlockingForTesting";
- blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>(
- kMaxNumberThreads, kThreadNamePrefix);
-
- window_manager_app_->window_manager_ = base::MakeUnique<WindowManager>(
- nullptr, config, show_primary_host_on_connect);
- window_manager_app_->window_manager()->shell_delegate_ =
- base::MakeUnique<test::TestShellDelegate>();
-
- window_tree_client_setup_.InitForWindowManager(
- window_manager_app_->window_manager_.get(),
- window_manager_app_->window_manager_.get());
- aura::test::EnvTestHelper().SetWindowTreeClient(
- window_tree_client_setup_.window_tree_client());
- // See comment in AshTestHelper for details on why NetworkHandler is not
- // initialized.
- const bool init_network_handler = false;
- window_manager_app_->InitWindowManager(
- window_tree_client_setup_.OwnWindowTreeClient(),
- blocking_pool_owner_->pool(), init_network_handler);
-
- aura::WindowTreeClient* window_tree_client =
- window_manager_app_->window_manager()->window_tree_client();
- window_tree_client_private_ =
- base::MakeUnique<aura::WindowTreeClientPrivate>(window_tree_client);
- if (config == Config::MUS) {
- window_tree_client_private_->CallOnConnect();
- } else {
- int next_x = 0;
- CreateRootWindowController("800x600", &next_x);
- }
-}
-
-std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() {
- std::set<RootWindowController*> roots =
- window_manager_app_->window_manager()->GetRootWindowControllers();
- std::vector<RootWindowController*> ordered_roots;
- ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
- std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
- return ordered_roots;
-}
-
-void WmTestHelper::UpdateDisplay(const std::string& display_spec) {
- if (Shell::GetAshConfig() == Config::MUS) {
- display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
- .UpdateDisplay(display_spec);
- return;
- }
- const std::vector<std::string> parts = base::SplitString(
- display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- std::vector<RootWindowController*> root_window_controllers =
- GetRootsOrderedByDisplayId();
- int next_x = 0;
- for (size_t i = 0,
- end = std::min(parts.size(), root_window_controllers.size());
- i < end; ++i) {
- UpdateDisplay(root_window_controllers[i], parts[i], &next_x);
- }
- for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) {
- root_window_controllers.push_back(
- CreateRootWindowController(parts[i], &next_x));
- }
- const bool in_shutdown = false;
- while (root_window_controllers.size() > parts.size()) {
- window_manager_app_->window_manager()->DestroyRootWindowController(
- root_window_controllers.back(), in_shutdown);
- root_window_controllers.pop_back();
- }
-}
-
-RootWindowController* WmTestHelper::CreateRootWindowController(
- const std::string& display_spec,
- int* next_x) {
- gfx::Rect bounds = ParseDisplayBounds(display_spec);
- bounds.set_x(*next_x);
- *next_x += bounds.size().width();
- display::Display display(next_display_id_++, bounds);
- gfx::Rect work_area(display.bounds());
- // Offset the height slightly to give a different work area. -20 is arbitrary,
- // it could be anything.
- work_area.set_height(std::max(0, work_area.height() - 20));
- display.set_work_area(work_area);
- window_tree_client_private_->CallWmNewDisplayAdded(display);
- return GetRootsOrderedByDisplayId().back();
-}
-
-void WmTestHelper::UpdateDisplay(RootWindowController* root_window_controller,
- const std::string& display_spec,
- int* next_x) {
- gfx::Rect bounds = ParseDisplayBounds(display_spec);
- bounds.set_x(*next_x);
- *next_x += bounds.size().width();
- display::Display updated_display =
- root_window_controller->GetWindow()->GetDisplayNearestWindow();
- gfx::Insets work_area_insets = updated_display.GetWorkAreaInsets();
- updated_display.set_bounds(bounds);
- updated_display.UpdateWorkAreaFromInsets(work_area_insets);
- root_window_controller->GetWindow()->SetBounds(gfx::Rect(bounds.size()));
- ScreenMus* screen = window_manager_app_->window_manager()->screen_.get();
- const bool is_primary =
- screen->display_list().FindDisplayById(updated_display.id()) ==
- screen->display_list().GetPrimaryDisplayIterator();
- screen->display_list().UpdateDisplay(
- updated_display, is_primary ? display::DisplayList::Type::PRIMARY
- : display::DisplayList::Type::NOT_PRIMARY);
-}
-
-} // namespace mus
-} // namespace ash
diff --git a/ash/mus/test/wm_test_helper.h b/ash/mus/test/wm_test_helper.h
deleted file mode 100644
index f28c7582f..0000000
--- a/ash/mus/test/wm_test_helper.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_MUS_TEST_WM_TEST_HELPER_H_
-#define ASH_MUS_TEST_WM_TEST_HELPER_H_
-
-#include <memory>
-
-#include "ash/mus/window_manager_application.h"
-#include "base/macros.h"
-#include "ui/aura/test/mus/test_window_tree_client_setup.h"
-
-namespace aura {
-class WindowTreeClientPrivate;
-}
-
-namespace base {
-class MessageLoop;
-class SequencedWorkerPoolOwner;
-}
-
-namespace ui {
-class InputDeviceClient;
-}
-
-namespace views {
-class ViewsDelegate;
-}
-
-namespace ash {
-
-class RootWindowController;
-
-namespace mus {
-
-// WMTestHelper is responsible for configuring a WindowTreeClient that
-// does not talk to mus.
-class WmTestHelper {
- public:
- WmTestHelper();
- ~WmTestHelper();
-
- void Init();
-
- WindowManagerApplication* window_manager_app() {
- return window_manager_app_.get();
- }
-
- // Returns the RootWindowControllers ordered by display id (which we assume
- // correlates with creation order).
- std::vector<RootWindowController*> GetRootsOrderedByDisplayId();
-
- void UpdateDisplay(const std::string& display_spec);
-
- private:
- // Creates a new RootWindowController given |display_spec|, which is the
- // configuration of the display. On entry |next_x| is the x-coordinate to
- // place the display at, on exit |next_x| is set to the x-coordinate to place
- // the next display at.
- RootWindowController* CreateRootWindowController(
- const std::string& display_spec,
- int* next_x);
-
- // Updates the display of an existing RootWindowController. See
- // CreateRootWindowController() for details on |next_x|.
- void UpdateDisplay(RootWindowController* root_window_controller,
- const std::string& display_spec,
- int* next_x);
-
- // Destroys a RootWindowController.
- void DestroyRootWindowController(
- RootWindowController* root_window_controller);
-
- std::unique_ptr<base::MessageLoop> message_loop_;
- std::unique_ptr<views::ViewsDelegate> views_delegate_;
- aura::TestWindowTreeClientSetup window_tree_client_setup_;
- std::unique_ptr<WindowManagerApplication> window_manager_app_;
- std::unique_ptr<aura::WindowTreeClientPrivate> window_tree_client_private_;
-
- // Id for the next Display created by CreateRootWindowController().
- int64_t next_display_id_ = 1;
-
- std::unique_ptr<base::SequencedWorkerPoolOwner> blocking_pool_owner_;
-
- std::unique_ptr<ui::InputDeviceClient> input_device_client_;
-
- DISALLOW_COPY_AND_ASSIGN(WmTestHelper);
-};
-
-} // namespace mus
-} // namespace ash
-
-#endif // ASH_MUS_TEST_WM_TEST_HELPER_H_
diff --git a/ash/mus/top_level_window_factory_unittest.cc b/ash/mus/top_level_window_factory_unittest.cc
index 7af8fe4..0d8de94 100644
--- a/ash/mus/top_level_window_factory_unittest.cc
+++ b/ash/mus/top_level_window_factory_unittest.cc
@@ -13,7 +13,6 @@
#include "ash/mus/window_manager.h"
#include "ash/mus/window_manager_application.h"
#include "ash/shell.h"
-#include "ash/test/ash_test.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "ash/wm/window_properties.h"
diff --git a/ash/mus/window_manager.h b/ash/mus/window_manager.h
index 84bb75f6..4d4dce8 100644
--- a/ash/mus/window_manager.h
+++ b/ash/mus/window_manager.h
@@ -59,7 +59,6 @@
namespace mus {
class AcceleratorHandler;
-class WmTestHelper;
// WindowManager serves as the WindowManagerDelegate and
// WindowTreeClientDelegate for mash. WindowManager creates (and owns)
@@ -127,7 +126,6 @@
private:
friend class test::AshTestHelper;
- friend class WmTestHelper;
using RootWindowControllers = std::set<std::unique_ptr<RootWindowController>>;
diff --git a/ash/mus/window_manager_application.h b/ash/mus/window_manager_application.h
index e878d39..1dc98d8d 100644
--- a/ash/mus/window_manager_application.h
+++ b/ash/mus/window_manager_application.h
@@ -71,8 +71,6 @@
private:
friend class ash::test::AshTestHelper;
- friend class WmTestBase;
- friend class WmTestHelper;
// If |init_network_handler| is true, chromeos::NetworkHandler is initialized.
void InitWindowManager(
diff --git a/ash/mus_property_mirror_ash_unittest.cc b/ash/mus_property_mirror_ash_unittest.cc
index 30a5b8e..81020af2 100644
--- a/ash/mus_property_mirror_ash_unittest.cc
+++ b/ash/mus_property_mirror_ash_unittest.cc
@@ -7,8 +7,7 @@
#include <string>
#include "ash/public/cpp/window_properties.h"
-#include "ash/test/ash_test.h"
-#include "ash/wm_window.h"
+#include "ash/test/ash_test_base.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.h"
@@ -16,22 +15,20 @@
namespace ash {
-using MusPropertyMirrorAshTest = AshTest;
+using MusPropertyMirrorAshTest = test::AshTestBase;
// Ensure the property mirror can copy primitive properties between windows.
TEST_F(MusPropertyMirrorAshTest, PrimitiveProperties) {
MusPropertyMirrorAsh mus_property_mirror_ash;
- std::unique_ptr<WindowOwner> window_owner_1(CreateTestWindow());
- std::unique_ptr<WindowOwner> window_owner_2(CreateTestWindow());
- aura::Window* window_1 = window_owner_1->window()->aura_window();
- aura::Window* window_2 = window_owner_2->window()->aura_window();
+ std::unique_ptr<aura::Window> window_1(CreateTestWindow());
+ std::unique_ptr<aura::Window> window_2(CreateTestWindow());
EXPECT_EQ(TYPE_UNDEFINED, window_1->GetProperty(kShelfItemTypeKey));
EXPECT_EQ(TYPE_UNDEFINED, window_2->GetProperty(kShelfItemTypeKey));
window_1->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
EXPECT_EQ(TYPE_APP, window_1->GetProperty(kShelfItemTypeKey));
mus_property_mirror_ash.MirrorPropertyFromWidgetWindowToRootWindow(
- window_1, window_2, kShelfItemTypeKey);
+ window_1.get(), window_2.get(), kShelfItemTypeKey);
EXPECT_EQ(TYPE_APP, window_2->GetProperty(kShelfItemTypeKey));
EXPECT_FALSE(window_1->GetProperty(aura::client::kDrawAttentionKey));
@@ -39,24 +36,22 @@
window_1->SetProperty(aura::client::kDrawAttentionKey, true);
EXPECT_TRUE(window_1->GetProperty(aura::client::kDrawAttentionKey));
mus_property_mirror_ash.MirrorPropertyFromWidgetWindowToRootWindow(
- window_1, window_2, aura::client::kDrawAttentionKey);
+ window_1.get(), window_2.get(), aura::client::kDrawAttentionKey);
EXPECT_TRUE(window_2->GetProperty(aura::client::kDrawAttentionKey));
}
// Ensure the property mirror can copy owned object properties between windows.
TEST_F(MusPropertyMirrorAshTest, OwnedProperties) {
MusPropertyMirrorAsh mus_property_mirror_ash;
- std::unique_ptr<WindowOwner> window_owner_1(CreateTestWindow());
- std::unique_ptr<WindowOwner> window_owner_2(CreateTestWindow());
- aura::Window* window_1 = window_owner_1->window()->aura_window();
- aura::Window* window_2 = window_owner_2->window()->aura_window();
+ std::unique_ptr<aura::Window> window_1(CreateTestWindow());
+ std::unique_ptr<aura::Window> window_2(CreateTestWindow());
EXPECT_EQ(nullptr, window_1->GetProperty(aura::client::kAppIdKey));
EXPECT_EQ(nullptr, window_2->GetProperty(aura::client::kAppIdKey));
window_1->SetProperty(aura::client::kAppIdKey, new std::string("abc"));
EXPECT_EQ("abc", *window_1->GetProperty(aura::client::kAppIdKey));
mus_property_mirror_ash.MirrorPropertyFromWidgetWindowToRootWindow(
- window_1, window_2, aura::client::kAppIdKey);
+ window_1.get(), window_2.get(), aura::client::kAppIdKey);
EXPECT_EQ("abc", *window_2->GetProperty(aura::client::kAppIdKey));
EXPECT_NE(window_1->GetProperty(aura::client::kAppIdKey),
window_2->GetProperty(aura::client::kAppIdKey));
@@ -68,7 +63,7 @@
EXPECT_EQ(base::ASCIIToUTF16("def"),
*window_1->GetProperty(aura::client::kTitleKey));
mus_property_mirror_ash.MirrorPropertyFromWidgetWindowToRootWindow(
- window_1, window_2, aura::client::kTitleKey);
+ window_1.get(), window_2.get(), aura::client::kTitleKey);
EXPECT_EQ(base::ASCIIToUTF16("def"),
*window_2->GetProperty(aura::client::kTitleKey));
EXPECT_NE(window_1->GetProperty(aura::client::kTitleKey),
@@ -81,7 +76,7 @@
window_1->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia());
EXPECT_NE(nullptr, window_1->GetProperty(aura::client::kWindowIconKey));
mus_property_mirror_ash.MirrorPropertyFromWidgetWindowToRootWindow(
- window_1, window_2, aura::client::kWindowIconKey);
+ window_1.get(), window_2.get(), aura::client::kWindowIconKey);
EXPECT_NE(nullptr, window_2->GetProperty(aura::client::kWindowIconKey));
EXPECT_NE(window_1->GetProperty(aura::client::kWindowIconKey),
window_2->GetProperty(aura::client::kWindowIconKey));
diff --git a/ash/system/audio/tray_audio_unittest.cc b/ash/system/audio/tray_audio_unittest.cc
index 16d7e89..592f7550 100644
--- a/ash/system/audio/tray_audio_unittest.cc
+++ b/ash/system/audio/tray_audio_unittest.cc
@@ -5,11 +5,11 @@
#include "ash/system/audio/tray_audio.h"
#include "ash/system/tray/system_tray.h"
-#include "ash/test/ash_test.h"
+#include "ash/test/ash_test_base.h"
namespace ash {
-using TrayAudioTest = AshTest;
+using TrayAudioTest = test::AshTestBase;
// Tests that the volume popup view can be explicitly shown.
TEST_F(TrayAudioTest, ShowPopUpVolumeView) {
diff --git a/ash/system/update/tray_update_unittest.cc b/ash/system/update/tray_update_unittest.cc
index a7c131c2..df0d5c9 100644
--- a/ash/system/update/tray_update_unittest.cc
+++ b/ash/system/update/tray_update_unittest.cc
@@ -8,14 +8,14 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_controller.h"
-#include "ash/test/ash_test.h"
+#include "ash/test/ash_test_base.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/events/event.h"
#include "ui/views/controls/label.h"
namespace ash {
-using TrayUpdateTest = AshTest;
+using TrayUpdateTest = test::AshTestBase;
// Tests that the update icon becomes visible when an update becomes
// available.
diff --git a/ash/test/BUILD.gn b/ash/test/BUILD.gn
index e011939..d7ad07b 100644
--- a/ash/test/BUILD.gn
+++ b/ash/test/BUILD.gn
@@ -54,26 +54,15 @@
"../laser/laser_pointer_controller_test_api.h",
"../laser/laser_pointer_points_test_api.cc",
"../laser/laser_pointer_points_test_api.h",
- "../mus/test/ash_test_impl_mus.cc",
- "../mus/test/ash_test_impl_mus.h",
- "../mus/test/wm_test_base.cc",
- "../mus/test/wm_test_base.h",
- "../mus/test/wm_test_helper.cc",
- "../mus/test/wm_test_helper.h",
"../rotator/test/screen_rotation_animator_test_api.cc",
"../rotator/test/screen_rotation_animator_test_api.h",
"../shell/toplevel_window.cc",
"../shell/toplevel_window.h",
- "ash_test.cc",
- "ash_test.h",
"ash_test_base.cc",
"ash_test_base.h",
"ash_test_environment.h",
"ash_test_helper.cc",
"ash_test_helper.h",
- "ash_test_impl.h",
- "ash_test_impl_aura.cc",
- "ash_test_impl_aura.h",
"ash_test_views_delegate.cc",
"ash_test_views_delegate.h",
"child_modal_window.cc",
diff --git a/ash/test/ash_test.cc b/ash/test/ash_test.cc
deleted file mode 100644
index 125dfc1..0000000
--- a/ash/test/ash_test.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright 2016 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 "ash/test/ash_test.h"
-
-#include "ash/public/cpp/config.h"
-#include "ash/root_window_controller.h"
-#include "ash/shelf/wm_shelf.h"
-#include "ash/shell.h"
-#include "ash/shell_port.h"
-#include "ash/system/status_area_widget.h"
-#include "ash/test/ash_test_impl.h"
-#include "ash/test/test_session_state_delegate.h"
-#include "ash/test/test_system_tray_delegate.h"
-#include "ash/wm_window.h"
-#include "base/memory/ptr_util.h"
-#include "base/run_loop.h"
-#include "ui/aura/window.h"
-#include "ui/compositor/layer_type.h"
-#include "ui/display/display.h"
-
-namespace ash {
-
-WindowOwner::WindowOwner(WmWindow* window) : window_(window) {}
-
-WindowOwner::~WindowOwner() {
- window_->Destroy();
-}
-
-AshTest::AshTest() : test_impl_(AshTestImpl::Create()) {}
-
-AshTest::~AshTest() {}
-
-// static
-WmShelf* AshTest::GetPrimaryShelf() {
- return ShellPort::Get()
- ->GetPrimaryRootWindow()
- ->GetRootWindowController()
- ->GetShelf();
-}
-
-// static
-SystemTray* AshTest::GetPrimarySystemTray() {
- return GetPrimaryShelf()->GetStatusAreaWidget()->system_tray();
-}
-
-// static
-test::TestSystemTrayDelegate* AshTest::GetSystemTrayDelegate() {
- return static_cast<test::TestSystemTrayDelegate*>(
- Shell::Get()->system_tray_delegate());
-}
-
-void AshTest::UpdateDisplay(const std::string& display_spec) {
- return test_impl_->UpdateDisplay(display_spec);
-}
-
-std::unique_ptr<WindowOwner> AshTest::CreateTestWindow(const gfx::Rect& bounds,
- ui::wm::WindowType type,
- int shell_window_id) {
- return test_impl_->CreateTestWindow(bounds, type, shell_window_id);
-}
-
-std::unique_ptr<WindowOwner> AshTest::CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) {
- return test_impl_->CreateToplevelTestWindow(bounds_in_screen,
- shell_window_id);
-}
-
-std::unique_ptr<WindowOwner> AshTest::CreateChildWindow(WmWindow* parent,
- const gfx::Rect& bounds,
- int shell_window_id) {
- aura::Window* window = new aura::Window(nullptr, ui::wm::WINDOW_TYPE_NORMAL);
- window->Init(ui::LAYER_NOT_DRAWN);
- std::unique_ptr<WindowOwner> window_owner =
- base::MakeUnique<WindowOwner>(WmWindow::Get(window));
- window->SetBounds(bounds);
- window->set_id(shell_window_id);
- parent->aura_window()->AddChild(window);
- window->Show();
- return window_owner;
-}
-
-// static
-std::unique_ptr<views::Widget> AshTest::CreateTestWidget(
- const gfx::Rect& bounds,
- views::WidgetDelegate* delegate,
- int container_id) {
- std::unique_ptr<views::Widget> widget(new views::Widget);
- views::Widget::InitParams params;
- params.delegate = delegate;
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = bounds;
- ShellPort::Get()
- ->GetPrimaryRootWindow()
- ->GetRootWindowController()
- ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
- ¶ms);
- widget->Init(params);
- widget->Show();
- return widget;
-}
-
-display::Display AshTest::GetSecondaryDisplay() {
- return test_impl_->GetSecondaryDisplay();
-}
-
-bool AshTest::SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) {
- if (Shell::GetAshConfig() == Config::MASH) {
- NOTIMPLEMENTED();
- return false;
- }
- return test_impl_->SetSecondaryDisplayPlacement(position, offset);
-}
-
-void AshTest::ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) {
- test_impl_->ConfigureWidgetInitParamsForDisplay(window, init_params);
-}
-
-void AshTest::ParentWindowInPrimaryRootWindow(WmWindow* window) {
- window->SetParentUsingContext(ShellPort::Get()->GetPrimaryRootWindow(),
- gfx::Rect());
-}
-
-void AshTest::AddTransientChild(WmWindow* parent, WmWindow* window) {
- test_impl_->AddTransientChild(parent, window);
-}
-
-void AshTest::RunAllPendingInMessageLoop() {
- base::RunLoop run_loop;
- run_loop.RunUntilIdle();
-}
-
-void AshTest::SetUp() {
- test_impl_->SetUp();
-}
-
-void AshTest::TearDown() {
- test_impl_->TearDown();
-}
-
-} // namespace ash
diff --git a/ash/test/ash_test.h b/ash/test/ash_test.h
deleted file mode 100644
index e368497..0000000
--- a/ash/test/ash_test.h
+++ /dev/null
@@ -1,148 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_TEST_ASH_TEST_H_
-#define ASH_TEST_ASH_TEST_H_
-
-#include <memory>
-#include <string>
-
-#include "ash/public/cpp/shell_window_ids.h"
-#include "base/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/display/display_layout.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/views/widget/widget.h"
-#include "ui/wm/public/window_types.h"
-
-namespace display {
-class Display;
-}
-
-namespace views {
-class WidgetDelegate;
-}
-
-namespace ash {
-
-class AshTestImpl;
-class SystemTray;
-class WmShelf;
-class WmWindow;
-
-namespace test {
-class TestSystemTrayDelegate;
-}
-
-// Wraps a WmWindow calling WmWindow::Destroy() from the destructor. WmWindow is
-// owned by the corresponding window implementation. The only way to delete
-// WmWindow is to call WmWindow::Destroy(), which deletes the corresponding
-// window, then the WmWindow. This class calls WmWindow::Destroy() from its
-// destructor.
-class WindowOwner {
- public:
- explicit WindowOwner(WmWindow* window);
- ~WindowOwner();
-
- WmWindow* window() { return window_; }
-
- private:
- WmWindow* window_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowOwner);
-};
-
-// Base class for ash tests. This class calls through to AshTestImpl for the
-// real implementation. This class exists so that tests can be written to
-// run in both mus and aura.
-//
-// TODO: this class is deprecated and should be removed.
-// http://crbug.com/707057.
-class AshTest : public testing::Test {
- public:
- AshTest();
- ~AshTest() override;
-
- // Returns the WmShelf for the primary display.
- static WmShelf* GetPrimaryShelf();
-
- // Returns the system tray on the primary display.
- static SystemTray* GetPrimarySystemTray();
-
- static test::TestSystemTrayDelegate* GetSystemTrayDelegate();
-
- // Update the display configuration as given in |display_spec|.
- // See test::DisplayManagerTestApi::UpdateDisplay for more details.
- void UpdateDisplay(const std::string& display_spec);
-
- // Creates a visible window in the appropriate container. If
- // |bounds_in_screen| is empty the window is added to the primary root
- // window, otherwise the window is added to the display matching
- // |bounds_in_screen|. |shell_window_id| is the shell window id to give to
- // the new window.
- std::unique_ptr<WindowOwner> CreateTestWindow(
- const gfx::Rect& bounds_in_screen = gfx::Rect(),
- ui::wm::WindowType type = ui::wm::WINDOW_TYPE_NORMAL,
- int shell_window_id = kShellWindowId_Invalid);
-
- // Creates a visible top-level window. For aura a top-level window is a Window
- // that has a delegate, see aura::Window::GetToplevelWindow() for more
- // details.
- std::unique_ptr<WindowOwner> CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen = gfx::Rect(),
- int shell_window_id = kShellWindowId_Invalid);
-
- // Creates a visible window parented to |parent| with the specified bounds and
- // id.
- std::unique_ptr<WindowOwner> CreateChildWindow(
- WmWindow* parent,
- const gfx::Rect& bounds = gfx::Rect(),
- int shell_window_id = kShellWindowId_Invalid);
-
- // Creates and shows a widget. See ash/public/cpp/shell_window_ids.h for
- // values for |container_id|.
- static std::unique_ptr<views::Widget> CreateTestWidget(
- const gfx::Rect& bounds,
- views::WidgetDelegate* delegate = nullptr,
- int container_id = kShellWindowId_DefaultContainer);
-
- // Returns the Display for the secondary display. It's assumed there are two
- // displays.
- display::Display GetSecondaryDisplay();
-
- // Sets the placement of the secondary display. Returns true if the secondary
- // display can be moved, false otherwise. The false return value is temporary
- // until mus fully supports this.
- bool SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset);
-
- // Configures |init_params| so that the widget will be created on the same
- // display as |window|.
- void ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params);
-
- // Adds |window| to the appropriate container in the primary root window.
- void ParentWindowInPrimaryRootWindow(WmWindow* window);
-
- // Adds |window| as as a transient child of |parent|.
- void AddTransientChild(WmWindow* parent, WmWindow* window);
-
- void RunAllPendingInMessageLoop();
-
- protected:
- // testing::Test:
- void SetUp() override;
- void TearDown() override;
-
- private:
- std::unique_ptr<AshTestImpl> test_impl_;
-
- DISALLOW_COPY_AND_ASSIGN(AshTest);
-};
-
-} // namespace ash
-
-#endif // ASH_TEST_ASH_TEST_H_
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 5e62df8a..2c22ca4 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -288,10 +288,27 @@
ash_test_helper_->window_manager_app()->window_manager();
aura::Window* window = mus::CreateAndParentTopLevelWindow(
window_manager, mus_window_type, &properties);
+ window->set_id(shell_window_id);
window->Show();
return base::WrapUnique<aura::Window>(window);
}
+std::unique_ptr<aura::Window> AshTestBase::CreateToplevelTestWindow(
+ const gfx::Rect& bounds_in_screen,
+ int shell_window_id) {
+ if (AshTestHelper::config() == Config::MASH) {
+ return CreateTestWindow(bounds_in_screen, ui::wm::WINDOW_TYPE_NORMAL,
+ shell_window_id);
+ }
+
+ aura::test::TestWindowDelegate* delegate =
+ aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
+ return base::WrapUnique<aura::Window>(
+ CreateTestWindowInShellWithDelegateAndType(
+ delegate, ui::wm::WINDOW_TYPE_NORMAL, shell_window_id,
+ bounds_in_screen));
+}
+
aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
}
diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h
index afbc64c6..ddcb800b 100644
--- a/ash/test/ash_test_base.h
+++ b/ash/test/ash_test_base.h
@@ -49,7 +49,6 @@
}
namespace ash {
-class AshTestImplAura;
class SystemTray;
class WmShelf;
@@ -103,6 +102,13 @@
ui::wm::WindowType type = ui::wm::WINDOW_TYPE_NORMAL,
int shell_window_id = kShellWindowId_Invalid);
+ // Creates a visible top-level window. For Config::CLASSIC and Config::MUS
+ // this creates a Window with a delegate. For Config::MASH this creates a
+ // window as if the client requested a top-level window.
+ std::unique_ptr<aura::Window> CreateToplevelTestWindow(
+ const gfx::Rect& bounds_in_screen = gfx::Rect(),
+ int shell_window_id = kShellWindowId_Invalid);
+
// Versions of the functions in aura::test:: that go through our shell
// StackingController instead of taking a parent.
aura::Window* CreateTestWindowInShellWithId(int id);
@@ -193,8 +199,6 @@
display::Display GetSecondaryDisplay();
private:
- friend class ash::AshTestImplAura;
-
bool setup_called_;
bool teardown_called_;
// |SetUp()| doesn't activate session if this is set to false.
diff --git a/ash/test/ash_test_impl.h b/ash/test/ash_test_impl.h
deleted file mode 100644
index f1ba7f7..0000000
--- a/ash/test/ash_test_impl.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_TEST_ASH_TEST_IMPL_H_
-#define ASH_TEST_ASH_TEST_IMPL_H_
-
-#include <memory>
-#include <string>
-
-#include "ui/display/display_layout.h"
-#include "ui/views/widget/widget.h"
-#include "ui/wm/public/window_types.h"
-
-namespace display {
-class Display;
-}
-
-namespace gfx {
-class Rect;
-}
-
-namespace ash {
-
-class WindowOwner;
-class WmWindow;
-
-// Provides the real implementation of AshTest, see it for details.
-class AshTestImpl {
- public:
- virtual ~AshTestImpl() {}
-
- // Factory function for creating AshTestImpl. Implemention that is used
- // depends upon build dependencies.
- static std::unique_ptr<AshTestImpl> Create();
-
- // These functions mirror that of AshTest, see it for details.
- virtual void SetUp() = 0;
- virtual void TearDown() = 0;
- virtual void UpdateDisplay(const std::string& display_spec) = 0;
- virtual std::unique_ptr<WindowOwner> CreateTestWindow(
- const gfx::Rect& bounds_in_screen,
- ui::wm::WindowType type,
- int shell_window_id) = 0;
- virtual std::unique_ptr<WindowOwner> CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) = 0;
- virtual display::Display GetSecondaryDisplay() = 0;
- virtual bool SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) = 0;
- virtual void ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) = 0;
- virtual void AddTransientChild(WmWindow* parent, WmWindow* window) = 0;
-};
-
-} // namespace ash
-
-#endif // ASH_TEST_ASH_TEST_IMPL_H_
diff --git a/ash/test/ash_test_impl_aura.cc b/ash/test/ash_test_impl_aura.cc
deleted file mode 100644
index 4c458741..0000000
--- a/ash/test/ash_test_impl_aura.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2016 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 "ash/test/ash_test_impl_aura.h"
-
-#include "ash/mus/test/ash_test_impl_mus.h"
-#include "ash/public/cpp/config.h"
-#include "ash/screen_util.h"
-#include "ash/shell.h"
-#include "ash/test/ash_test.h"
-#include "ash/test/ash_test_base.h"
-#include "ash/test/ash_test_helper.h"
-#include "ash/wm_window.h"
-#include "base/memory/ptr_util.h"
-#include "ui/aura/test/test_window_delegate.h"
-#include "ui/display/display_layout.h"
-#include "ui/display/manager/display_manager.h"
-#include "ui/display/screen.h"
-#include "ui/display/test/display_manager_test_api.h"
-#include "ui/wm/core/window_util.h"
-
-namespace ash {
-namespace {
-
-// AshTestBase is abstract as TestBody() is pure virtual (the various TEST
-// macros have the implementation). In order to create AshTestBase we have to
-// subclass with an empty implementation of TestBody(). That's ok as the class
-// isn't used as a normal test here.
-class AshTestBaseImpl : public test::AshTestBase {
- public:
- AshTestBaseImpl() {}
- ~AshTestBaseImpl() override {}
-
- // AshTestBase:
- void TestBody() override {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AshTestBaseImpl);
-};
-
-} // namespace
-
-AshTestImplAura::AshTestImplAura()
- : ash_test_base_(base::MakeUnique<AshTestBaseImpl>()) {}
-
-AshTestImplAura::~AshTestImplAura() {}
-
-void AshTestImplAura::SetUp() {
- ash_test_base_->SetUp();
-}
-
-void AshTestImplAura::TearDown() {
- ash_test_base_->TearDown();
-}
-
-void AshTestImplAura::UpdateDisplay(const std::string& display_spec) {
- ash_test_base_->UpdateDisplay(display_spec);
-}
-
-std::unique_ptr<WindowOwner> AshTestImplAura::CreateTestWindow(
- const gfx::Rect& bounds_in_screen,
- ui::wm::WindowType type,
- int shell_window_id) {
- return base::MakeUnique<WindowOwner>(
- WmWindow::Get(ash_test_base_->CreateTestWindowInShellWithDelegateAndType(
- nullptr, type, shell_window_id, bounds_in_screen)));
-}
-
-std::unique_ptr<WindowOwner> AshTestImplAura::CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) {
- aura::test::TestWindowDelegate* delegate =
- aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
- return base::MakeUnique<WindowOwner>(
- WmWindow::Get(ash_test_base_->CreateTestWindowInShellWithDelegateAndType(
- delegate, ui::wm::WINDOW_TYPE_NORMAL, shell_window_id,
- bounds_in_screen)));
-}
-
-display::Display AshTestImplAura::GetSecondaryDisplay() {
- return Shell::Get()->display_manager()->GetSecondaryDisplay();
-}
-
-bool AshTestImplAura::SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) {
- Shell::Get()->display_manager()->SetLayoutForCurrentDisplays(
- display::test::CreateDisplayLayout(Shell::Get()->display_manager(),
- position, 0));
- return true;
-}
-
-void AshTestImplAura::ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) {
- init_params->context = WmWindow::GetAuraWindow(window);
-}
-
-void AshTestImplAura::AddTransientChild(WmWindow* parent, WmWindow* window) {
- ::wm::AddTransientChild(WmWindow::GetAuraWindow(parent),
- WmWindow::GetAuraWindow(window));
-}
-
-// static
-std::unique_ptr<AshTestImpl> AshTestImpl::Create() {
- if (test::AshTestHelper::config() == Config::CLASSIC)
- return base::MakeUnique<AshTestImplAura>();
-
- return base::MakeUnique<mus::AshTestImplMus>();
-}
-
-} // namespace ash
diff --git a/ash/test/ash_test_impl_aura.h b/ash/test/ash_test_impl_aura.h
deleted file mode 100644
index c723749..0000000
--- a/ash/test/ash_test_impl_aura.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef ASH_MUS_TEST_ASH_TEST_IMPL_AURA_H_
-#define ASH_MUS_TEST_ASH_TEST_IMPL_AURA_H_
-
-#include "ash/test/ash_test_impl.h"
-
-namespace ash {
-namespace test {
-class AshTestBase;
-}
-
-// Implementation of AshTestImpl on top of aura. Implementation of AshTestImpl
-// calls through to AshTestBase.
-class AshTestImplAura : public AshTestImpl {
- public:
- AshTestImplAura();
- ~AshTestImplAura() override;
-
- // AshTestImpl:
- void SetUp() override;
- void TearDown() override;
- void UpdateDisplay(const std::string& display_spec) override;
- std::unique_ptr<WindowOwner> CreateTestWindow(
- const gfx::Rect& bounds_in_screen,
- ui::wm::WindowType type,
- int shell_window_id) override;
- std::unique_ptr<WindowOwner> CreateToplevelTestWindow(
- const gfx::Rect& bounds_in_screen,
- int shell_window_id) override;
- display::Display GetSecondaryDisplay() override;
- bool SetSecondaryDisplayPlacement(
- display::DisplayPlacement::Position position,
- int offset) override;
- void ConfigureWidgetInitParamsForDisplay(
- WmWindow* window,
- views::Widget::InitParams* init_params) override;
- void AddTransientChild(WmWindow* parent, WmWindow* window) override;
-
- private:
- std::unique_ptr<test::AshTestBase> ash_test_base_;
-
- DISALLOW_COPY_AND_ASSIGN(AshTestImplAura);
-};
-
-} // namespace ash
-
-#endif // ASH_MUS_TEST_ASH_TEST_IMPL_AURA_H_
diff --git a/ash/window_user_data_unittest.cc b/ash/window_user_data_unittest.cc
index a76d9a1..9607f59 100644
--- a/ash/window_user_data_unittest.cc
+++ b/ash/window_user_data_unittest.cc
@@ -6,7 +6,7 @@
#include <memory>
-#include "ash/test/ash_test.h"
+#include "ash/test/ash_test_base.h"
#include "ash/window_user_data.h"
#include "base/memory/ptr_util.h"
#include "ui/aura/window.h"
@@ -30,7 +30,7 @@
} // namespace
-using WindowUserDataTest = AshTest;
+using WindowUserDataTest = test::AshTestBase;
// Verifies clear() deletes the data associated with a window.
TEST_F(WindowUserDataTest, ClearDestroys) {
diff --git a/ash/wm/workspace/workspace_layout_manager_keyboard_unittest.cc b/ash/wm/workspace/workspace_layout_manager_keyboard_unittest.cc
index 22cfe28..29947b8 100644
--- a/ash/wm/workspace/workspace_layout_manager_keyboard_unittest.cc
+++ b/ash/wm/workspace/workspace_layout_manager_keyboard_unittest.cc
@@ -16,10 +16,11 @@
#include "ash/shell.h"
#include "ash/shell_observer.h"
#include "ash/shell_port.h"
-#include "ash/test/ash_test.h"
+#include "ash/test/ash_test_base.h"
#include "ash/wm/fullscreen_window_finder.h"
#include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
#include "ash/wm/window_state.h"
+#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm/workspace/workspace_window_resizer.h"
@@ -46,13 +47,13 @@
} // namespace
-class WorkspaceLayoutManagerKeyboardTest : public AshTest {
+class WorkspaceLayoutManagerKeyboardTest2 : public test::AshTestBase {
public:
- WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {}
- ~WorkspaceLayoutManagerKeyboardTest() override {}
+ WorkspaceLayoutManagerKeyboardTest2() : layout_manager_(nullptr) {}
+ ~WorkspaceLayoutManagerKeyboardTest2() override {}
void SetUp() override {
- AshTest::SetUp();
+ test::AshTestBase::SetUp();
UpdateDisplay("800x600");
WmWindow* default_container =
ShellPort::Get()->GetPrimaryRootWindowController()->GetWmContainer(
@@ -97,10 +98,10 @@
gfx::Rect keyboard_bounds_;
WorkspaceLayoutManager* layout_manager_;
- DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
+ DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest2);
};
-TEST_F(WorkspaceLayoutManagerKeyboardTest, ChangeWorkAreaInNonStickyMode) {
+TEST_F(WorkspaceLayoutManagerKeyboardTest2, ChangeWorkAreaInNonStickyMode) {
keyboard::SetAccessibilityKeyboardEnabled(true);
InitKeyboardBounds();
Shell::Get()->CreateKeyboard();
@@ -112,12 +113,11 @@
gfx::Rect orig_window_bounds(0, 100, work_area.width(),
work_area.height() - 100);
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateToplevelTestWindow(orig_window_bounds));
- WmWindow* window = window_owner->window();
- window->Activate();
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ wm::ActivateWindow(window.get());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
// Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false);
@@ -130,26 +130,26 @@
gfx::Rect changed_window_bounds(orig_window_bounds);
changed_window_bounds.Offset(0, -shift);
// Window should be shifted up.
- EXPECT_EQ(changed_window_bounds, window->GetBounds());
+ EXPECT_EQ(changed_window_bounds, window->bounds());
kb_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
// Open keyboard in sticky mode.
kb_controller->ShowKeyboard(true);
// Window should be shifted up.
- EXPECT_EQ(changed_window_bounds, window->GetBounds());
+ EXPECT_EQ(changed_window_bounds, window->bounds());
kb_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
}
// When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility
// keyboard work area in non-sticky mode.
-TEST_F(WorkspaceLayoutManagerKeyboardTest,
+TEST_F(WorkspaceLayoutManagerKeyboardTest2,
IgnoreWorkAreaChangeinNonStickyMode) {
// Append flag to ignore work area change in non-sticky mode.
EnableNewVKMode();
@@ -165,12 +165,11 @@
gfx::Rect orig_window_bounds(0, 100, work_area.width(),
work_area.height() - 100);
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateToplevelTestWindow(orig_window_bounds));
- WmWindow* window = window_owner->window();
- window->Activate();
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ wm::ActivateWindow(window.get());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
// Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false);
@@ -179,11 +178,11 @@
ShellPort::Get()->GetPrimaryRootWindow()->GetBounds(), 100));
// Window should not be shifted up.
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
kb_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
// Open keyboard in sticky mode.
kb_controller->ShowKeyboard(true);
@@ -193,11 +192,11 @@
gfx::Rect changed_window_bounds(orig_window_bounds);
changed_window_bounds.Offset(0, -shift);
// Window should be shifted up.
- EXPECT_EQ(changed_window_bounds, window->GetBounds());
+ EXPECT_EQ(changed_window_bounds, window->bounds());
kb_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
- EXPECT_EQ(orig_window_bounds, window->GetBounds());
+ EXPECT_EQ(orig_window_bounds, window->bounds());
}
} // namespace ash
diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc
index 539cd2c..d97a31f 100644
--- a/ash/wm/workspace/workspace_layout_manager_unittest.cc
+++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc
@@ -10,6 +10,7 @@
#include "ash/public/cpp/config.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
+#include "ash/screen_util.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_layout_manager.h"
@@ -17,9 +18,9 @@
#include "ash/shell.h"
#include "ash/shell_observer.h"
#include "ash/shell_port.h"
-#include "ash/test/ash_test.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_session_controller_client.h"
+#include "ash/test/wm_window_test_api.h"
#include "ash/wm/fullscreen_window_finder.h"
#include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
#include "ash/wm/window_state.h"
@@ -31,16 +32,25 @@
#include "ash/wm_window.h"
#include "base/command_line.h"
#include "base/run_loop.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/layer_type.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display.h"
+#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
+#include "ui/display/test/display_manager_test_api.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
+#include "ui/wm/core/window_util.h"
+
+// NOTE: many of these tests use GlobalMinimumSizeLock. This is needed as the
+// tests assume a minimum size of 0x0. In mash the minimum size, for top-level
+// windows, is not 0x0, so without this the tests fails.
namespace ash {
namespace {
@@ -90,32 +100,36 @@
DISALLOW_COPY_AND_ASSIGN(TestShellObserver);
};
+display::Display GetDisplayNearestWindow(aura::Window* window) {
+ return display::Screen::GetScreen()->GetDisplayNearestWindow(window);
+}
+
} // namespace
-using WorkspaceLayoutManagerTest = AshTest;
+using WorkspaceLayoutManagerTest = test::AshTestBase;
// Verifies that a window containing a restore coordinate will be restored to
// to the size prior to minimize, keeping the restore rectangle in tact (if
// there is one).
TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) {
- std::unique_ptr<WindowOwner> window_owner(
- CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window = window_owner->window();
+ // See comment at top of file for why this is needed.
+ WmWindowTestApi::GlobalMinimumSizeLock min_size_lock;
+ std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
gfx::Rect bounds(10, 15, 25, 35);
window->SetBounds(bounds);
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
// This will not be used for un-minimizing window.
window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
window_state->Minimize();
window_state->Restore();
EXPECT_EQ("0,0 100x100", window_state->GetRestoreBoundsInScreen().ToString());
- EXPECT_EQ("10,15 25x35", window->GetBounds().ToString());
+ EXPECT_EQ("10,15 25x35", window->bounds().ToString());
UpdateDisplay("400x300,500x400");
window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), GetSecondaryDisplay());
- EXPECT_EQ(ShellPort::Get()->GetAllRootWindows()[1], window->GetRootWindow());
+ EXPECT_EQ(Shell::Get()->GetAllRootWindows()[1], window->GetRootWindow());
window_state->Minimize();
// This will not be used for un-minimizing window.
window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
@@ -127,30 +141,34 @@
window_state->Minimize();
UpdateDisplay("400x300");
window_state->Restore();
- EXPECT_EQ(ShellPort::Get()->GetPrimaryRootWindow(), window->GetRootWindow());
- EXPECT_TRUE(ShellPort::Get()->GetPrimaryRootWindow()->GetBounds().Intersects(
- window->GetBounds()));
+ EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow());
+ EXPECT_TRUE(
+ Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
}
TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) {
UpdateDisplay("300x400,400x500");
- WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows();
+ aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
- if (!SetSecondaryDisplayPlacement(display::DisplayPlacement::TOP, 0))
+ if (Shell::GetAshConfig() != Config::CLASSIC) {
+ // TODO(sky): should work for mus/mash once http://crbug.com/706589 is
+ // fixed.
return;
+ }
+ Shell::Get()->display_manager()->SetLayoutForCurrentDisplays(
+ display::test::CreateDisplayLayout(Shell::Get()->display_manager(),
+ display::DisplayPlacement::TOP, 0));
EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString());
- std::unique_ptr<WindowOwner> window1_owner(
+ std::unique_ptr<aura::Window> window1(
CreateTestWindow(gfx::Rect(10, -400, 200, 200)));
- EXPECT_EQ("10,-400 200x200",
- window1_owner->window()->GetBoundsInScreen().ToString());
+ EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString());
// Make sure the caption is visible.
- std::unique_ptr<WindowOwner> window2_owner(
+ std::unique_ptr<aura::Window> window2(
CreateTestWindow(gfx::Rect(10, -600, 200, 200)));
- EXPECT_EQ("10,-500 200x200",
- window2_owner->window()->GetBoundsInScreen().ToString());
+ EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) {
@@ -158,63 +176,62 @@
// Create a popup window out of display boundaries and make sure it is not
// moved to have minimum visibility.
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP));
- EXPECT_EQ("400,100 50x50",
- window_owner->window()->GetBoundsInScreen().ToString());
+ EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
- std::unique_ptr<WindowOwner> window_owner(
+ // See comment at top of file for why this is needed.
+ WmWindowTestApi::GlobalMinimumSizeLock min_size_lock;
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
- WmWindow* window = window_owner->window();
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
// Maximized -> Normal transition.
window_state->Maximize();
window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
window_state->Restore();
- EXPECT_TRUE(ShellPort::Get()->GetPrimaryRootWindow()->GetBounds().Intersects(
- window->GetBounds()));
+ EXPECT_TRUE(
+ Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
// Y bounds should not be negative.
- EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString());
+ EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
// Minimized -> Normal transition.
window->SetBounds(gfx::Rect(-100, -100, 30, 40));
window_state->Minimize();
- EXPECT_FALSE(ShellPort::Get()->GetPrimaryRootWindow()->GetBounds().Intersects(
- window->GetBounds()));
- EXPECT_EQ("-100,-100 30x40", window->GetBounds().ToString());
+ EXPECT_FALSE(
+ Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
+ EXPECT_EQ("-100,-100 30x40", window->bounds().ToString());
window->Show();
- EXPECT_TRUE(ShellPort::Get()->GetPrimaryRootWindow()->GetBounds().Intersects(
- window->GetBounds()));
+ EXPECT_TRUE(
+ Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
// Y bounds should not be negative.
- EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString());
+ EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
// Fullscreen -> Normal transition.
window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds.
- ASSERT_EQ("0,0 30x40", window->GetBounds().ToString());
- window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
- EXPECT_EQ(window->GetBounds(), window->GetRootWindow()->GetBounds());
+ ASSERT_EQ("0,0 30x40", window->bounds().ToString());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
+ EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds());
window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
window_state->Restore();
- EXPECT_TRUE(ShellPort::Get()->GetPrimaryRootWindow()->GetBounds().Intersects(
- window->GetBounds()));
+ EXPECT_TRUE(
+ Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
// Y bounds should not be negative.
- EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString());
+ EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {
UpdateDisplay("300x400,400x500");
- WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows();
+ aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
- WmWindow* window = window_owner->window();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
// Maximize the window in 2nd display as the restore bounds
// is inside 2nd display.
@@ -244,37 +261,33 @@
views::Widget::InitParams params;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
- ConfigureWidgetInitParamsForDisplay(root_windows[0], ¶ms);
+ params.context = root_windows[0];
w1->Init(params);
- EXPECT_EQ(root_windows[0],
- WmWindow::Get(w1->GetNativeWindow())->GetRootWindow());
+ EXPECT_EQ(root_windows[0], w1->GetNativeWindow()->GetRootWindow());
w1->Show();
EXPECT_TRUE(w1->IsMaximized());
- EXPECT_EQ(root_windows[1],
- WmWindow::Get(w1->GetNativeWindow())->GetRootWindow());
+ EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(gfx::Rect(300, 0, 400, 500 - kShelfSize).ToString(),
w1->GetWindowBoundsInScreen().ToString());
w1->Restore();
- EXPECT_EQ(root_windows[1],
- WmWindow::Get(w1->GetNativeWindow())->GetRootWindow());
+ EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow());
EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) {
UpdateDisplay("300x400,400x500");
- WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows();
+ aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
- WmWindow* window = window_owner->window();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
// Maximize the window in 2nd display as the restore bounds
// is inside 2nd display.
- window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
@@ -285,7 +298,7 @@
// If the restore bounds intersects with the current display,
// don't move.
window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40));
- window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
@@ -303,7 +316,7 @@
public:
DontClobberRestoreBoundsWindowObserver() : window_(nullptr) {}
- void set_window(WmWindow* window) { window_ = window; }
+ void set_window(aura::Window* window) { window_ = window; }
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window,
@@ -313,18 +326,19 @@
return;
if (wm::GetWindowState(window)->IsMaximized()) {
- WmWindow* w = window_;
+ aura::Window* w = window_;
window_ = nullptr;
- gfx::Rect shelf_bounds(AshTest::GetPrimaryShelf()->GetIdealBounds());
- const gfx::Rect& window_bounds(w->GetBounds());
+ gfx::Rect shelf_bounds(
+ test::AshTestBase::GetPrimaryShelf()->GetIdealBounds());
+ const gfx::Rect& window_bounds(w->bounds());
w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1,
window_bounds.width(), window_bounds.height()));
}
}
private:
- WmWindow* window_;
+ aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver);
};
@@ -341,19 +355,18 @@
// NOTE: for this test to exercise the failure the observer needs to be added
// before the parent set. This mimics what BrowserFrameAsh does.
window->AddObserver(&window_observer);
- ParentWindowInPrimaryRootWindow(WmWindow::Get(window.get()));
+ ParentWindowInPrimaryRootWindow(window.get());
window->Show();
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Activate();
- std::unique_ptr<WindowOwner> window2_owner(
+ std::unique_ptr<aura::Window> window2(
CreateTestWindow(gfx::Rect(12, 20, 30, 40)));
- WmWindow* window2 = window2_owner->window();
- AddTransientChild(WmWindow::Get(window.get()), window2);
+ ::wm::AddTransientChild(window.get(), window2.get());
window2->Show();
- window_observer.set_window(window2);
+ window_observer.set_window(window2.get());
window_state->Maximize();
EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString());
window->RemoveObserver(&window_observer);
@@ -361,17 +374,15 @@
// Verifies when a window is maximized all descendant windows have a size.
TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) {
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
- WmWindow* window = window_owner->window();
window->Show();
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Activate();
- std::unique_ptr<WindowOwner> child_window_owner(
- CreateChildWindow(window, gfx::Rect(5, 6, 7, 8)));
- WmWindow* child_window = child_window_owner->window();
+ std::unique_ptr<aura::Window> child_window(
+ CreateChildWindow(window.get(), gfx::Rect(5, 6, 7, 8)));
window_state->Maximize();
- EXPECT_EQ("5,6 7x8", child_window->GetBounds().ToString());
+ EXPECT_EQ("5,6 7x8", child_window->bounds().ToString());
}
// Verifies a window created with maximized state has the maximized
@@ -382,7 +393,7 @@
window->Init(ui::LAYER_TEXTURED);
wm::GetWindowState(window.get())->Maximize();
WmWindow* default_container =
- ShellPort::Get()->GetPrimaryRootWindowController()->GetWmContainer(
+ Shell::GetPrimaryRootWindowController()->GetWmContainer(
kShellWindowId_DefaultContainer);
default_container->aura_window()->AddChild(window.get());
window->Show();
@@ -400,34 +411,30 @@
// Normal window bounds shouldn't be changed.
gfx::Rect window_bounds(100, 100, 200, 200);
- std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds));
- WmWindow* window = window_owner->window();
- EXPECT_EQ(window_bounds, window->GetBounds());
+ std::unique_ptr<aura::Window> window(CreateTestWindow(window_bounds));
+ EXPECT_EQ(window_bounds, window->bounds());
// If the window is out of the workspace, it would be moved on screen.
- gfx::Rect root_window_bounds =
- ShellPort::Get()->GetPrimaryRootWindow()->GetBounds();
+ gfx::Rect root_window_bounds = Shell::GetPrimaryRootWindow()->bounds();
window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height());
ASSERT_FALSE(window_bounds.Intersects(root_window_bounds));
- std::unique_ptr<WindowOwner> out_window_owner(
- CreateTestWindow(window_bounds));
- WmWindow* out_window = out_window_owner->window();
- EXPECT_EQ(window_bounds.size(), out_window->GetBounds().size());
- gfx::Rect bounds = out_window->GetBounds();
+ std::unique_ptr<aura::Window> out_window(CreateTestWindow(window_bounds));
+ EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
+ gfx::Rect bounds = out_window->bounds();
bounds.Intersect(root_window_bounds);
// 30% of the window edge must be visible.
- EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29);
- EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29);
+ EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
+ EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
- WmWindow* parent = out_window->GetParent();
- parent->RemoveChild(out_window);
+ aura::Window* parent = out_window->parent();
+ parent->RemoveChild(out_window.get());
out_window->SetBounds(gfx::Rect(-200, -200, 200, 200));
// UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior.
- window->GetWindowState()->set_bounds_changed_by_user(true);
- parent->AddChild(out_window);
- EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29);
- EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29);
+ wm::GetWindowState(window.get())->set_bounds_changed_by_user(true);
+ parent->AddChild(out_window.get());
+ EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
+ EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
// Make sure we always make more than 1/3 of the window edge visible even
// if the initial bounds intersects with display.
@@ -437,35 +444,32 @@
// Make sure that the initial bounds' visible area is less than 26%
// so that the auto adjustment logic kicks in.
- ASSERT_LT(bounds.width(), out_window->GetBounds().width() * 0.26);
- ASSERT_LT(bounds.height(), out_window->GetBounds().height() * 0.26);
+ ASSERT_LT(bounds.width(), out_window->bounds().width() * 0.26);
+ ASSERT_LT(bounds.height(), out_window->bounds().height() * 0.26);
ASSERT_TRUE(window_bounds.Intersects(root_window_bounds));
- std::unique_ptr<WindowOwner> partially_out_window_owner(
+ std::unique_ptr<aura::Window> partially_out_window(
CreateTestWindow(window_bounds));
- WmWindow* partially_out_window = partially_out_window_owner->window();
- EXPECT_EQ(window_bounds.size(), partially_out_window->GetBounds().size());
- bounds = partially_out_window->GetBounds();
+ EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size());
+ bounds = partially_out_window->bounds();
bounds.Intersect(root_window_bounds);
- EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29);
- EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29);
+ EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
+ EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
// Make sure the window whose 30% width/height is bigger than display
// will be placed correctly.
window_bounds.SetRect(-1900, -1900, 3000, 3000);
- std::unique_ptr<WindowOwner> window_bigger_than_display_owner(
+ std::unique_ptr<aura::Window> window_bigger_than_display(
CreateTestWindow(window_bounds));
- WmWindow* window_bigger_than_display =
- window_bigger_than_display_owner->window();
EXPECT_GE(root_window_bounds.width(),
- window_bigger_than_display->GetBounds().width());
+ window_bigger_than_display->bounds().width());
EXPECT_GE(root_window_bounds.height(),
- window_bigger_than_display->GetBounds().height());
+ window_bigger_than_display->bounds().height());
- bounds = window_bigger_than_display->GetBounds();
+ bounds = window_bigger_than_display->bounds();
bounds.Intersect(root_window_bounds);
- EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29);
- EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29);
+ EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
+ EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
}
// Verifies the size of a window is enforced to be smaller than the work area.
@@ -475,33 +479,30 @@
display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size());
const gfx::Rect window_bounds(100, 101, work_area.width() + 1,
work_area.height() + 2);
- std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds));
- WmWindow* window = window_owner->window();
+ std::unique_ptr<aura::Window> window(CreateTestWindow(window_bounds));
// TODO: fix. This test verifies that when a window is added the bounds are
// adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes
// from NativeWidgetAura), which means this test now fails for aura-mus.
if (Shell::GetAshConfig() == Config::CLASSIC) {
EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
- window->GetBounds().ToString());
+ window->bounds().ToString());
}
// Directly setting the bounds triggers a slightly different code path. Verify
// that too.
window->SetBounds(window_bounds);
EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
- window->GetBounds().ToString());
+ window->bounds().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) {
TestShellObserver observer;
- std::unique_ptr<WindowOwner> window1_owner(
+ std::unique_ptr<aura::Window> window1(
CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
- WmWindow* window1 = window1_owner->window();
- std::unique_ptr<WindowOwner> window2_owner(
+ std::unique_ptr<aura::Window> window2(
CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
- WmWindow* window2 = window2_owner->window();
- wm::WindowState* window_state1 = window1->GetWindowState();
- wm::WindowState* window_state2 = window2->GetWindowState();
+ wm::WindowState* window_state1 = wm::GetWindowState(window1.get());
+ wm::WindowState* window_state2 = wm::GetWindowState(window2.get());
window_state2->Activate();
const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
@@ -528,7 +529,7 @@
EXPECT_TRUE(observer.is_fullscreen());
// Closing the window should change the fullscreen state.
- window2_owner.reset();
+ window2.reset();
EXPECT_EQ(6, observer.call_count());
EXPECT_FALSE(observer.is_fullscreen());
}
@@ -539,12 +540,12 @@
TEST_F(WorkspaceLayoutManagerTest,
SnappedWindowMayNotAdjustBoundsOnWorkAreaChanged) {
UpdateDisplay("300x400");
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(10, 20, 100, 200)));
- WmWindow* window = window_owner->window();
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
gfx::Insets insets(0, 0, 50, 0);
- ShellPort::Get()->SetDisplayWorkAreaInsets(window, insets);
+ ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()),
+ insets);
const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT);
window_state->OnWMEvent(&snap_left);
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
@@ -553,20 +554,22 @@
gfx::Rect expected_bounds =
gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(),
kWorkAreaBounds.width() / 2, kWorkAreaBounds.height());
- EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// The following two SetDisplayWorkAreaInsets calls simulate the case of
// crbug.com/673803 that work area first becomes fullscreen and then returns
// to the original state.
- ShellPort::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets(0, 0, 0, 0));
- ui::LayerAnimator* animator = window->GetLayer()->GetAnimator();
+ ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()),
+ gfx::Insets(0, 0, 0, 0));
+ ui::LayerAnimator* animator = window->layer()->GetAnimator();
EXPECT_TRUE(animator->is_animating());
- ShellPort::Get()->SetDisplayWorkAreaInsets(window, insets);
+ ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()),
+ insets);
animator->StopAnimating();
EXPECT_FALSE(animator->is_animating());
- EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
// Do not adjust window bounds to ensure minimum visibility for transient
@@ -578,19 +581,18 @@
base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
window->Init(ui::LAYER_TEXTURED);
window->SetBounds(gfx::Rect(10, 0, 100, 200));
- ParentWindowInPrimaryRootWindow(WmWindow::Get(window.get()));
+ ParentWindowInPrimaryRootWindow(window.get());
window->Show();
- std::unique_ptr<WindowOwner> window2_owner(
+ std::unique_ptr<aura::Window> window2(
CreateTestWindow(gfx::Rect(10, 0, 40, 20)));
- WmWindow* window2 = window2_owner->window();
- AddTransientChild(WmWindow::Get(window.get()), window2);
+ ::wm::AddTransientChild(window.get(), window2.get());
window2->Show();
- gfx::Rect expected_bounds = window2->GetBounds();
+ gfx::Rect expected_bounds = window2->bounds();
ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()),
gfx::Insets(50, 0, 0, 0));
- EXPECT_EQ(expected_bounds.ToString(), window2->GetBounds().ToString());
+ EXPECT_EQ(expected_bounds.ToString(), window2->bounds().ToString());
}
// Following "Solo" tests were originally written for BaseLayoutManager.
@@ -599,31 +601,30 @@
// Tests normal->maximize->normal.
TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
- window->SetShowState(ui::SHOW_STATE_MAXIMIZED);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
// Maximized window fills the work area, not the whole display.
- EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(),
- window->GetBounds().ToString());
- window->SetShowState(ui::SHOW_STATE_NORMAL);
- EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
+ window->bounds().ToString());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+ EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
}
// Tests normal->minimize->normal.
TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
- window->SetShowState(ui::SHOW_STATE_MINIMIZED);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_FALSE(window->IsVisible());
- EXPECT_TRUE(window->GetWindowState()->IsMinimized());
- EXPECT_EQ(bounds, window->GetBounds());
- window->SetShowState(ui::SHOW_STATE_NORMAL);
+ EXPECT_TRUE(wm::GetWindowState(window.get())->IsMinimized());
+ EXPECT_EQ(bounds, window->bounds());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_TRUE(window->IsVisible());
- EXPECT_FALSE(window->GetWindowState()->IsMinimized());
- EXPECT_EQ(bounds, window->GetBounds());
+ EXPECT_FALSE(wm::GetWindowState(window.get())->IsMinimized());
+ EXPECT_EQ(bounds, window->bounds());
}
// A aura::WindowObserver which sets the focus when the window becomes visible.
@@ -633,20 +634,20 @@
: window_(nullptr), show_state_(ui::SHOW_STATE_END) {}
~FocusDuringUnminimizeWindowObserver() override { SetWindow(nullptr); }
- void SetWindow(WmWindow* window) {
+ void SetWindow(aura::Window* window) {
if (window_)
- window_->aura_window()->RemoveObserver(this);
+ window_->RemoveObserver(this);
window_ = window;
if (window_)
- window_->aura_window()->AddObserver(this);
+ window_->AddObserver(this);
}
// aura::WindowObserver:
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
if (window_) {
if (visible)
- window_->SetFocused();
- show_state_ = window_->GetShowState();
+ aura::client::GetFocusClient(window_)->FocusWindow(window_);
+ show_state_ = window_->GetProperty(aura::client::kShowStateKey);
}
}
@@ -657,7 +658,7 @@
}
private:
- WmWindow* window_;
+ aura::Window* window_;
ui::WindowShowState show_state_;
DISALLOW_COPY_AND_ASSIGN(FocusDuringUnminimizeWindowObserver);
@@ -668,11 +669,10 @@
// callback doesn't cause DCHECK error. See crbug.com/168383.
TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) {
FocusDuringUnminimizeWindowObserver observer;
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
- WmWindow* window = WmWindow::Get(window_owner.get());
- observer.SetWindow(window);
- window->SetShowState(ui::SHOW_STATE_MINIMIZED);
+ observer.SetWindow(window.get());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_FALSE(window->IsVisible());
EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, observer.GetShowStateAndReset());
window->Show();
@@ -684,188 +684,185 @@
// Tests maximized window size during root window resize.
TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeRootWindowResize) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
- window->SetShowState(ui::SHOW_STATE_MAXIMIZED);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
gfx::Rect initial_work_area_bounds =
- wm::GetMaximizedWindowBoundsInParent(window);
- EXPECT_EQ(initial_work_area_bounds.ToString(),
- window->GetBounds().ToString());
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get());
+ EXPECT_EQ(initial_work_area_bounds.ToString(), window->bounds().ToString());
// Enlarge the root window. We should still match the work area size.
UpdateDisplay("900x700");
- EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(),
- window->GetBounds().ToString());
- EXPECT_NE(initial_work_area_bounds.ToString(),
- wm::GetMaximizedWindowBoundsInParent(window).ToString());
+ EXPECT_EQ(
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
+ window->bounds().ToString());
+ EXPECT_NE(
+ initial_work_area_bounds.ToString(),
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString());
}
// Tests normal->fullscreen->normal.
TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
- window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
// Fullscreen window fills the whole display.
- EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(),
- window->GetBounds().ToString());
- window->SetShowState(ui::SHOW_STATE_NORMAL);
- EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(GetDisplayNearestWindow(window.get()).bounds().ToString(),
+ window->bounds().ToString());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+ EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
}
// Tests that fullscreen window causes always_on_top windows to stack below.
TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> fullscreen_window_owner(
+ std::unique_ptr<aura::Window> fullscreen_window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* fullscreen_window = WmWindow::Get(fullscreen_window_owner.get());
- std::unique_ptr<aura::Window> always_on_top_window1_owner(
+ std::unique_ptr<aura::Window> always_on_top_window1(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window1 =
- WmWindow::Get(always_on_top_window1_owner.get());
- std::unique_ptr<aura::Window> always_on_top_window2_owner(
+ std::unique_ptr<aura::Window> always_on_top_window2(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window2 =
- WmWindow::Get(always_on_top_window2_owner.get());
- always_on_top_window1->SetAlwaysOnTop(true);
- always_on_top_window2->SetAlwaysOnTop(true);
+ always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true);
+ always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true);
// Making a window fullscreen temporarily suspends always on top state.
- fullscreen_window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
- EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop());
- EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop());
- EXPECT_NE(nullptr, wm::GetWindowForFullscreenMode(fullscreen_window));
+ fullscreen_window->SetProperty(aura::client::kShowStateKey,
+ ui::SHOW_STATE_FULLSCREEN);
+ EXPECT_FALSE(
+ always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_FALSE(
+ always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_NE(nullptr, wm::GetWindowForFullscreenMode(
+ WmWindow::Get(fullscreen_window.get())));
// Adding a new always-on-top window is not affected by fullscreen.
- std::unique_ptr<aura::Window> always_on_top_window3_owner(
+ std::unique_ptr<aura::Window> always_on_top_window3(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window3 =
- WmWindow::Get(always_on_top_window3_owner.get());
- always_on_top_window3->SetAlwaysOnTop(true);
- EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop());
+ always_on_top_window3->SetProperty(aura::client::kAlwaysOnTopKey, true);
+ EXPECT_TRUE(
+ always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey));
// Making fullscreen window normal restores always on top windows.
- fullscreen_window->SetShowState(ui::SHOW_STATE_NORMAL);
- EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop());
- EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop());
- EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop());
- EXPECT_EQ(nullptr, wm::GetWindowForFullscreenMode(fullscreen_window));
+ fullscreen_window->SetProperty(aura::client::kShowStateKey,
+ ui::SHOW_STATE_NORMAL);
+ EXPECT_TRUE(
+ always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_TRUE(
+ always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_TRUE(
+ always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_EQ(nullptr, wm::GetWindowForFullscreenMode(
+ WmWindow::Get(fullscreen_window.get())));
}
// Similary, pinned window causes always_on_top_ windows to stack below.
TEST_F(WorkspaceLayoutManagerSoloTest, PinnedSuspendsAlwaysOnTop) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> pinned_window_owner(
+ std::unique_ptr<aura::Window> pinned_window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* pinned_window = WmWindow::Get(pinned_window_owner.get());
- std::unique_ptr<aura::Window> always_on_top_window1_owner(
+ std::unique_ptr<aura::Window> always_on_top_window1(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window1 =
- WmWindow::Get(always_on_top_window1_owner.get());
- std::unique_ptr<aura::Window> always_on_top_window2_owner(
+ std::unique_ptr<aura::Window> always_on_top_window2(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window2 =
- WmWindow::Get(always_on_top_window2_owner.get());
- always_on_top_window1->SetAlwaysOnTop(true);
- always_on_top_window2->SetAlwaysOnTop(true);
+ always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true);
+ always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true);
// Making a window pinned temporarily suspends always on top state.
const bool trusted = false;
- wm::PinWindow(pinned_window->aura_window(), trusted);
- EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop());
- EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop());
+ wm::PinWindow(pinned_window.get(), trusted);
+ EXPECT_FALSE(
+ always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_FALSE(
+ always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
// Adding a new always-on-top window also is affected by pinned mode.
- std::unique_ptr<aura::Window> always_on_top_window3_owner(
+ std::unique_ptr<aura::Window> always_on_top_window3(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* always_on_top_window3 =
- WmWindow::Get(always_on_top_window3_owner.get());
- always_on_top_window3->SetAlwaysOnTop(true);
- EXPECT_FALSE(always_on_top_window3->IsAlwaysOnTop());
+ always_on_top_window3->SetProperty(aura::client::kAlwaysOnTopKey, true);
+ EXPECT_FALSE(
+ always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey));
// Making pinned window normal restores always on top windows.
- pinned_window->GetWindowState()->Restore();
- EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop());
- EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop());
- EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop());
+ wm::GetWindowState(pinned_window.get())->Restore();
+ EXPECT_TRUE(
+ always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_TRUE(
+ always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
+ EXPECT_TRUE(
+ always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey));
}
// Tests fullscreen window size during root window resize.
TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) {
gfx::Rect bounds(100, 100, 200, 200);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
// Fullscreen window fills the whole display.
- window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
- EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(),
- window->GetBounds().ToString());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
+ EXPECT_EQ(GetDisplayNearestWindow(window.get()).bounds().ToString(),
+ window->bounds().ToString());
// Enlarge the root window. We should still match the display size.
UpdateDisplay("800x600");
- EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(),
- window->GetBounds().ToString());
+ EXPECT_EQ(GetDisplayNearestWindow(window.get()).bounds().ToString(),
+ window->bounds().ToString());
}
// Tests that when the screen gets smaller the windows aren't bigger than
// the screen.
TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) {
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 500, 400)));
- WmWindow* window = WmWindow::Get(window_owner.get());
- gfx::Rect work_area = window->GetDisplayNearestWindow().work_area();
+ gfx::Rect work_area = GetDisplayNearestWindow(window.get()).work_area();
// Invariant: Window is smaller than work area.
- EXPECT_LE(window->GetBounds().width(), work_area.width());
- EXPECT_LE(window->GetBounds().height(), work_area.height());
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
// Make the root window narrower than our window.
UpdateDisplay("300x400");
- work_area = window->GetDisplayNearestWindow().work_area();
- EXPECT_LE(window->GetBounds().width(), work_area.width());
- EXPECT_LE(window->GetBounds().height(), work_area.height());
+ work_area = GetDisplayNearestWindow(window.get()).work_area();
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
// Make the root window shorter than our window.
UpdateDisplay("300x200");
- work_area = window->GetDisplayNearestWindow().work_area();
- EXPECT_LE(window->GetBounds().width(), work_area.width());
- EXPECT_LE(window->GetBounds().height(), work_area.height());
+ work_area = GetDisplayNearestWindow(window.get()).work_area();
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
// Enlarging the root window does not change the window bounds.
- gfx::Rect old_bounds = window->GetBounds();
+ gfx::Rect old_bounds = window->bounds();
UpdateDisplay("800x600");
- EXPECT_EQ(old_bounds.width(), window->GetBounds().width());
- EXPECT_EQ(old_bounds.height(), window->GetBounds().height());
+ EXPECT_EQ(old_bounds.width(), window->bounds().width());
+ EXPECT_EQ(old_bounds.height(), window->bounds().height());
}
// Verifies maximizing sets the restore bounds, and restoring
// restores the bounds.
TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) {
const gfx::Rect initial_bounds(10, 20, 30, 40);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(initial_bounds));
- WmWindow* window = WmWindow::Get(window_owner.get());
- EXPECT_EQ(initial_bounds, window->GetBounds());
- wm::WindowState* window_state = window->GetWindowState();
+ EXPECT_EQ(initial_bounds, window->bounds());
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
// Maximize it, which will keep the previous restore bounds.
- window->SetShowState(ui::SHOW_STATE_MAXIMIZED);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString());
// Restore it, which should restore bounds and reset restore bounds.
- window->SetShowState(ui::SHOW_STATE_NORMAL);
- EXPECT_EQ("10,20 30x40", window->GetBounds().ToString());
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+ EXPECT_EQ("10,20 30x40", window->bounds().ToString());
EXPECT_FALSE(window_state->HasRestoreBounds());
}
// Verifies maximizing keeps the restore bounds if set.
TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) {
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window = WmWindow::Get(window_owner.get());
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13));
// Maximize it, which will keep the previous restore bounds.
- window->SetShowState(ui::SHOW_STATE_MAXIMIZED);
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString());
}
@@ -873,13 +870,12 @@
// maximzied state from a minimized state.
TEST_F(WorkspaceLayoutManagerSoloTest,
BoundsAfterRestoringToMaximizeFromMinimize) {
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window = WmWindow::Get(window_owner.get());
gfx::Rect bounds(10, 15, 25, 35);
window->SetBounds(bounds);
- wm::WindowState* window_state = window->GetWindowState();
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
// Maximize it, which should reset restore bounds.
window_state->Maximize();
EXPECT_EQ(bounds.ToString(),
@@ -897,67 +893,70 @@
EXPECT_TRUE(window_state->IsMaximized());
window_state->Restore();
- EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
}
// Verify if the window is not resized during screen lock. See: crbug.com/173127
TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) {
SetCanLockScreen(true);
- std::unique_ptr<aura::Window> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window = WmWindow::Get(window_owner.get());
// window with AlwaysOnTop will be managed by BaseLayoutManager.
- window->SetAlwaysOnTop(true);
+ window->SetProperty(aura::client::kAlwaysOnTopKey, true);
window->Show();
WmShelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
- window->SetBounds(wm::GetMaximizedWindowBoundsInParent(window));
- gfx::Rect window_bounds = window->GetBounds();
- EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(),
- window_bounds.ToString());
+ window->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()));
+ gfx::Rect window_bounds = window->bounds();
+ EXPECT_EQ(
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
+ window_bounds.ToString());
// The window size should not get touched while we are in lock screen.
Shell::Get()->session_controller()->LockScreenAndFlushForTest();
ShelfLayoutManager* shelf_layout_manager = shelf->shelf_layout_manager();
shelf_layout_manager->UpdateVisibilityState();
- EXPECT_EQ(window_bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
// Coming out of the lock screen the window size should still remain.
GetSessionControllerClient()->UnlockScreen();
shelf_layout_manager->UpdateVisibilityState();
- EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(),
- window_bounds.ToString());
- EXPECT_EQ(window_bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
+ window_bounds.ToString());
+ EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
}
// Following tests are written to test the backdrop functionality.
namespace {
-WorkspaceLayoutManager* GetWorkspaceLayoutManager(WmWindow* container) {
- return static_cast<WorkspaceLayoutManager*>(container->GetLayoutManager());
+WorkspaceLayoutManager* GetWorkspaceLayoutManager(aura::Window* container) {
+ return static_cast<WorkspaceLayoutManager*>(
+ WmWindow::Get(container)->GetLayoutManager());
}
-class WorkspaceLayoutManagerBackdropTest : public AshTest {
+class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase {
public:
WorkspaceLayoutManagerBackdropTest() : default_container_(nullptr) {}
~WorkspaceLayoutManagerBackdropTest() override {}
void SetUp() override {
- AshTest::SetUp();
+ AshTestBase::SetUp();
UpdateDisplay("800x600");
- default_container_ =
- ShellPort::Get()->GetPrimaryRootWindowController()->GetWmContainer(
- kShellWindowId_DefaultContainer);
+ default_container_ = Shell::GetPrimaryRootWindowController()->GetContainer(
+ kShellWindowId_DefaultContainer);
}
// Turn the top window back drop on / off.
void ShowTopWindowBackdrop(bool show) {
std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> backdrop;
- if (show)
- backdrop.reset(new WorkspaceBackdropDelegate(default_container_));
+ if (show) {
+ backdrop.reset(
+ new WorkspaceBackdropDelegate(WmWindow::Get(default_container_)));
+ }
GetWorkspaceLayoutManager(default_container_)
->SetMaximizeBackdropDelegate(std::move(backdrop));
// Closing and / or opening can be a delayed operation.
@@ -965,18 +964,18 @@
}
// Return the default container.
- WmWindow* default_container() { return default_container_; }
+ aura::Window* default_container() { return default_container_; }
// Return the order of windows (top most first) as they are in the default
// container. If the window is visible it will be a big letter, otherwise a
// small one. The backdrop will be an X and unknown windows will be shown as
// '!'.
- std::string GetWindowOrderAsString(WmWindow* backdrop,
- WmWindow* wa,
- WmWindow* wb,
- WmWindow* wc) {
+ std::string GetWindowOrderAsString(aura::Window* backdrop,
+ aura::Window* wa,
+ aura::Window* wb,
+ aura::Window* wc) {
std::string result;
- WmWindow::Windows children = default_container()->GetChildren();
+ aura::Window::Windows children = default_container()->children();
for (int i = static_cast<int>(children.size()) - 1; i >= 0; --i) {
if (!result.empty())
result += ",";
@@ -996,7 +995,7 @@
private:
// The default container.
- WmWindow* default_container_;
+ aura::Window* default_container_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest);
};
@@ -1015,83 +1014,82 @@
// that the size is the same as the default container as well as that it is
// not visible.
ShowTopWindowBackdrop(true);
- ASSERT_EQ(1U, default_container()->GetChildren().size());
- EXPECT_FALSE(default_container()->GetChildren()[0]->IsVisible());
+ ASSERT_EQ(1U, default_container()->children().size());
+ EXPECT_FALSE(default_container()->children()[0]->IsVisible());
{
// Add a window and make sure that the backdrop is the second child.
- std::unique_ptr<WindowOwner> window_owner(
+ std::unique_ptr<aura::Window> window(
CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window = window_owner->window();
window->Show();
- ASSERT_EQ(2U, default_container()->GetChildren().size());
- EXPECT_TRUE(default_container()->GetChildren()[0]->IsVisible());
- EXPECT_TRUE(default_container()->GetChildren()[1]->IsVisible());
- EXPECT_EQ(window, default_container()->GetChildren()[1]);
- EXPECT_EQ(default_container()->GetBounds().ToString(),
- default_container()->GetChildren()[0]->GetBounds().ToString());
+ ASSERT_EQ(2U, default_container()->children().size());
+ EXPECT_TRUE(default_container()->children()[0]->IsVisible());
+ EXPECT_TRUE(default_container()->children()[1]->IsVisible());
+ EXPECT_EQ(window.get(), default_container()->children()[1]);
+ EXPECT_EQ(default_container()->bounds().ToString(),
+ default_container()->children()[0]->bounds().ToString());
}
// With the window gone the backdrop should be invisible again.
- ASSERT_EQ(1U, default_container()->GetChildren().size());
- EXPECT_FALSE(default_container()->GetChildren()[0]->IsVisible());
+ ASSERT_EQ(1U, default_container()->children().size());
+ EXPECT_FALSE(default_container()->children()[0]->IsVisible());
// Destroying the Backdrop should empty the container.
ShowTopWindowBackdrop(false);
- ASSERT_EQ(0U, default_container()->GetChildren().size());
+ ASSERT_EQ(0U, default_container()->children().size());
}
// Verify that the backdrop gets properly created and placed.
TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) {
- std::unique_ptr<WindowOwner> window1_owner(
+ std::unique_ptr<aura::Window> window1(
CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
- WmWindow* window1 = window1_owner->window();
window1->Show();
// Get the default container and check that only a single window is in there.
- ASSERT_EQ(1U, default_container()->GetChildren().size());
- EXPECT_EQ(window1, default_container()->GetChildren()[0]);
- EXPECT_EQ("A", GetWindowOrderAsString(nullptr, window1, nullptr, nullptr));
+ ASSERT_EQ(1U, default_container()->children().size());
+ EXPECT_EQ(window1.get(), default_container()->children()[0]);
+ EXPECT_EQ("A",
+ GetWindowOrderAsString(nullptr, window1.get(), nullptr, nullptr));
// Create 2 more windows and check that they are also in the container.
- std::unique_ptr<WindowOwner> window2_owner(
+ std::unique_ptr<aura::Window> window2(
CreateTestWindow(gfx::Rect(10, 2, 3, 4)));
- WmWindow* window2 = window2_owner->window();
- std::unique_ptr<WindowOwner> window3_owner(
+ std::unique_ptr<aura::Window> window3(
CreateTestWindow(gfx::Rect(20, 2, 3, 4)));
- WmWindow* window3 = window3_owner->window();
window2->Show();
window3->Show();
- WmWindow* backdrop = nullptr;
- EXPECT_EQ("C,B,A",
- GetWindowOrderAsString(backdrop, window1, window2, window3));
+ aura::Window* backdrop = nullptr;
+ EXPECT_EQ("C,B,A", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
// Turn on the backdrop mode and check that the window shows up where it
// should be (second highest number).
ShowTopWindowBackdrop(true);
- backdrop = default_container()->GetChildren()[2];
- EXPECT_EQ("C,X,B,A",
- GetWindowOrderAsString(backdrop, window1, window2, window3));
+ backdrop = default_container()->children()[2];
+ EXPECT_EQ("C,X,B,A", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
// Switch the order of windows and check that it still remains in that
// location.
- default_container()->StackChildAtTop(window2);
- EXPECT_EQ("B,X,C,A",
- GetWindowOrderAsString(backdrop, window1, window2, window3));
+ default_container()->StackChildAtTop(window2.get());
+ EXPECT_EQ("B,X,C,A", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
// Make the top window invisible and check.
window2->Hide();
- EXPECT_EQ("b,C,X,A",
- GetWindowOrderAsString(backdrop, window1, window2, window3));
+ EXPECT_EQ("b,C,X,A", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
// Then delete window after window and see that everything is in order.
- window1_owner.reset();
- EXPECT_EQ("b,C,X",
- GetWindowOrderAsString(backdrop, window1, window2, window3));
- window3_owner.reset();
- EXPECT_EQ("b,x", GetWindowOrderAsString(backdrop, window1, window2, window3));
+ window1.reset();
+ EXPECT_EQ("b,C,X", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
+ window3.reset();
+ EXPECT_EQ("b,x", GetWindowOrderAsString(backdrop, window1.get(),
+ window2.get(), window3.get()));
ShowTopWindowBackdrop(false);
- EXPECT_EQ("b", GetWindowOrderAsString(nullptr, window1, window2, window3));
+ EXPECT_EQ("b", GetWindowOrderAsString(nullptr, window1.get(), window2.get(),
+ window3.get()));
}
// Tests that when hidding the shelf, that the backdrop stays fullscreen.
@@ -1106,7 +1104,7 @@
ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
EXPECT_EQ(fullscreen_size,
- default_container()->GetChildren()[0]->GetBounds().size());
+ default_container()->children()[0]->bounds().size());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
shelf_layout_manager->UpdateVisibilityState();
@@ -1115,24 +1113,24 @@
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf_layout_manager->UpdateVisibilityState();
EXPECT_EQ(fullscreen_size,
- default_container()->GetChildren()[0]->GetBounds().size());
+ default_container()->children()[0]->bounds().size());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
shelf_layout_manager->UpdateVisibilityState();
EXPECT_EQ(fullscreen_size,
- default_container()->GetChildren()[0]->GetBounds().size());
+ default_container()->children()[0]->bounds().size());
}
-class WorkspaceLayoutManagerKeyboardTest : public AshTest {
+class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
public:
WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {}
~WorkspaceLayoutManagerKeyboardTest() override {}
void SetUp() override {
- AshTest::SetUp();
+ AshTestBase::SetUp();
UpdateDisplay("800x600");
- WmWindow* default_container =
- ShellPort::Get()->GetPrimaryRootWindowController()->GetWmContainer(
+ aura::Window* default_container =
+ Shell::GetPrimaryRootWindowController()->GetContainer(
kShellWindowId_DefaultContainer);
layout_manager_ = GetWorkspaceLayoutManager(default_container);
}
@@ -1142,13 +1140,14 @@
restore_work_area_insets_ =
display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets();
ShellPort::Get()->SetDisplayWorkAreaInsets(
- ShellPort::Get()->GetPrimaryRootWindow(),
+ WmWindow::Get(Shell::GetPrimaryRootWindow()),
gfx::Insets(0, 0, keyboard_bounds_.height(), 0));
}
void HideKeyboard() {
ShellPort::Get()->SetDisplayWorkAreaInsets(
- ShellPort::Get()->GetPrimaryRootWindow(), restore_work_area_insets_);
+ WmWindow::Get(Shell::GetPrimaryRootWindow()),
+ restore_work_area_insets_);
layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
}
@@ -1180,19 +1179,20 @@
// Tests that when a child window gains focus the top level window containing it
// is resized to fit the remaining workspace area.
TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
+ // See comment at top of file for why this is needed.
+ WmWindowTestApi::GlobalMinimumSizeLock min_size_lock;
+
InitKeyboardBounds();
gfx::Rect work_area(
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
- std::unique_ptr<WindowOwner> parent_window_owner(
+ std::unique_ptr<aura::Window> parent_window(
CreateToplevelTestWindow(work_area));
- WmWindow* parent_window = parent_window_owner->window();
- std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(work_area));
- WmWindow* window = window_owner->window();
- parent_window->AddChild(window);
+ std::unique_ptr<aura::Window> window(CreateTestWindow(work_area));
+ parent_window->AddChild(window.get());
- window->Activate();
+ wm::ActivateWindow(window.get());
int available_height =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
@@ -1201,23 +1201,23 @@
gfx::Rect initial_window_bounds(50, 50, 100, 500);
parent_window->SetBounds(initial_window_bounds);
EXPECT_EQ(initial_window_bounds.ToString(),
- parent_window->GetBounds().ToString());
+ parent_window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
- parent_window->GetBounds().ToString());
+ parent_window->bounds().ToString());
HideKeyboard();
EXPECT_EQ(initial_window_bounds.ToString(),
- parent_window->GetBounds().ToString());
+ parent_window->bounds().ToString());
}
TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
+ // See comment at top of file for why this is needed.
+ WmWindowTestApi::GlobalMinimumSizeLock min_size_lock;
InitKeyboardBounds();
gfx::Rect work_area(
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
- std::unique_ptr<WindowOwner> window_owner(
- CreateToplevelTestWindow(work_area));
- WmWindow* window = window_owner->window();
+ std::unique_ptr<aura::Window> window(CreateToplevelTestWindow(work_area));
// The additional SetBounds() is needed as the aura-mus case uses Widget,
// which alters the supplied bounds.
window->SetBounds(work_area);
@@ -1226,25 +1226,25 @@
display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
keyboard_bounds().height();
- window->Activate();
+ wm::ActivateWindow(window.get());
- EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(work_area.origin(),
gfx::Size(work_area.width(), available_height))
.ToString(),
- window->GetBounds().ToString());
+ window->bounds().ToString());
HideKeyboard();
- EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
gfx::Rect small_window_bound(50, 50, 100, 500);
window->SetBounds(small_window_bound);
- EXPECT_EQ(small_window_bound.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
- window->GetBounds().ToString());
+ window->bounds().ToString());
HideKeyboard();
- EXPECT_EQ(small_window_bound.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
gfx::Rect occluded_window_bounds(
50, keyboard_bounds().y() + keyboard_bounds().height() / 2, 50,
@@ -1257,26 +1257,24 @@
gfx::Rect(50, keyboard_bounds().y() - keyboard_bounds().height() / 2,
occluded_window_bounds.width(), occluded_window_bounds.height())
.ToString(),
- window->GetBounds().ToString());
+ window->bounds().ToString());
HideKeyboard();
- EXPECT_EQ(occluded_window_bounds.ToString(), window->GetBounds().ToString());
+ EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
}
TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChange) {
InitKeyboardBounds();
- std::unique_ptr<WindowOwner> window_owner(
- CreateTestWindow(keyboard_bounds()));
- WmWindow* window = window_owner->window();
+ std::unique_ptr<aura::Window> window(CreateTestWindow(keyboard_bounds()));
// The additional SetBounds() is needed as the aura-mus case uses Widget,
// which alters the supplied bounds.
window->SetBounds(keyboard_bounds());
- window->GetWindowState()->set_ignore_keyboard_bounds_change(true);
- window->Activate();
+ wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true);
+ wm::ActivateWindow(window.get());
- EXPECT_EQ(keyboard_bounds(), window->GetBounds());
+ EXPECT_EQ(keyboard_bounds(), window->bounds());
ShowKeyboard();
- EXPECT_EQ(keyboard_bounds(), window->GetBounds());
+ EXPECT_EQ(keyboard_bounds(), window->bounds());
}
} // namespace ash
diff --git a/ash/wm_window_unittest.cc b/ash/wm_window_unittest.cc
deleted file mode 100644
index 5ba883c..0000000
--- a/ash/wm_window_unittest.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2016 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 "ash/wm_window.h"
-
-#include <memory>
-
-#include "ash/test/ash_test.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_observer.h"
-
-namespace ash {
-
-using WmWindowTest = AshTest;
-
-namespace {
-
-// Tracks calls to OnWindowVisibilityChanged().
-class VisibilityObserver : public aura::WindowObserver {
- public:
- // Attaches a aura::WindowObserver to |window_to_add_observer_to| and sets
- // |last_observed_window_| and |last_observed_visible_value_| to the values
- // of the last call to OnWindowVisibilityChanged().
- explicit VisibilityObserver(WmWindow* window_to_add_observer_to)
- : window_to_add_observer_to_(window_to_add_observer_to) {
- window_to_add_observer_to_->aura_window()->AddObserver(this);
- }
- ~VisibilityObserver() override {
- window_to_add_observer_to_->aura_window()->RemoveObserver(this);
- }
-
- // The values last supplied to OnWindowVisibilityChanged().
- WmWindow* last_observed_window() { return last_observed_window_; }
- bool last_observed_visible_value() const {
- return last_observed_visible_value_;
- }
-
- // aura::WindowObserver:
- void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
- last_observed_window_ = WmWindow::Get(window);
- last_observed_visible_value_ = visible;
- }
-
- private:
- WmWindow* window_to_add_observer_to_;
- WmWindow* last_observed_window_ = nullptr;
- bool last_observed_visible_value_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(VisibilityObserver);
-};
-
-} // namespace
-
-// Verifies OnWindowVisibilityChanged() is called on a aura::WindowObserver
-// attached
-// to the parent when the child window's visibility changes.
-TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) {
- std::unique_ptr<WindowOwner> window_owner = CreateTestWindow();
- WmWindow* window = window_owner->window();
- std::unique_ptr<WindowOwner> child_owner =
- CreateChildWindow(window_owner->window());
- WmWindow* child_window = child_owner->window();
- VisibilityObserver observer(window);
- child_window->Hide();
- EXPECT_EQ(child_window, observer.last_observed_window());
- EXPECT_FALSE(observer.last_observed_visible_value());
-}
-
-// Verifies OnWindowVisibilityChanged() is called on a aura::WindowObserver
-// attached
-// to a child when the parent window's visibility changes.
-TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnChild) {
- std::unique_ptr<WindowOwner> parent_window_owner = CreateTestWindow();
- WmWindow* parent_window = parent_window_owner->window();
- std::unique_ptr<WindowOwner> child_owner = CreateChildWindow(parent_window);
- WmWindow* child_window = child_owner->window();
- VisibilityObserver observer(child_window);
- parent_window->Hide();
- EXPECT_EQ(parent_window, observer.last_observed_window());
- EXPECT_FALSE(observer.last_observed_visible_value());
-}
-
-} // namespace ash