Commit 6e5be9d3 authored by sky's avatar sky Committed by Commit bot

chromeos: converts TopLevelWindowFactoryTest to AshTestBase

This makes AshTestBase::CreateTestWindow() get the logic (when in
mash) that is in
WmTestHelper::CreateTestWindow(). I added
AshTestBase::CreateTestWindow() for migration from AshTest/WmTestBase
to AshTestBase.

BUG=707057
TEST=test only changes
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2840393002
Cr-Commit-Position: refs/heads/master@{#467566}
parent 7e9153cd
...@@ -180,11 +180,6 @@ class TestObserver : public WindowTreeHostManager::Observer, ...@@ -180,11 +180,6 @@ class TestObserver : public WindowTreeHostManager::Observer,
DISALLOW_COPY_AND_ASSIGN(TestObserver); DISALLOW_COPY_AND_ASSIGN(TestObserver);
}; };
display::Display GetPrimaryDisplay() {
return display::Screen::GetScreen()->GetDisplayNearestWindow(
Shell::GetAllRootWindows()[0]);
}
class TestHelper { class TestHelper {
public: public:
explicit TestHelper(test::AshTestBase* delegate); explicit TestHelper(test::AshTestBase* delegate);
......
...@@ -128,24 +128,6 @@ aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, ...@@ -128,24 +128,6 @@ aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds,
return window; return window;
} }
aura::Window* WmTestBase::CreateFullscreenTestWindow(int64_t display_id) {
std::map<std::string, std::vector<uint8_t>> properties;
properties[ui::mojom::WindowManager::kShowState_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<aura::PropertyConverter::PrimitiveType>(
ui::mojom::ShowState::FULLSCREEN));
if (display_id != display::kInvalidDisplayId) {
properties[ui::mojom::WindowManager::kDisplayId_InitProperty] =
mojo::ConvertTo<std::vector<uint8_t>>(display_id);
}
WindowManager* window_manager =
test_helper_->window_manager_app()->window_manager();
aura::Window* window = CreateAndParentTopLevelWindow(
window_manager, ui::mojom::WindowType::WINDOW, &properties);
window->Show();
return window;
}
aura::Window* WmTestBase::CreateChildTestWindow(aura::Window* parent, aura::Window* WmTestBase::CreateChildTestWindow(aura::Window* parent,
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
std::map<std::string, std::vector<uint8_t>> properties; std::map<std::string, std::vector<uint8_t>> properties;
......
...@@ -62,11 +62,6 @@ class WmTestBase : public testing::Test { ...@@ -62,11 +62,6 @@ class WmTestBase : public testing::Test {
aura::Window* CreateTestWindow(const gfx::Rect& bounds, aura::Window* CreateTestWindow(const gfx::Rect& bounds,
ui::wm::WindowType window_type); ui::wm::WindowType window_type);
// Creates a visibile fullscreen top level window on the display corresponding
// to the display_id provided.
aura::Window* CreateFullscreenTestWindow(
int64_t display_id = display::kInvalidDisplayId);
// Creates a window parented to |parent|. The returned window is visible. // Creates a window parented to |parent|. The returned window is visible.
aura::Window* CreateChildTestWindow(aura::Window* parent, aura::Window* CreateChildTestWindow(aura::Window* parent,
const gfx::Rect& bounds); const gfx::Rect& bounds);
......
...@@ -10,16 +10,20 @@ ...@@ -10,16 +10,20 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ash/mus/test/wm_test_base.h"
#include "ash/mus/window_manager.h" #include "ash/mus/window_manager.h"
#include "ash/mus/window_manager_application.h" #include "ash/mus/window_manager_application.h"
#include "ash/shell_port.h" #include "ash/shell.h"
#include "ash/test/ash_test.h" #include "ash/test/ash_test.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h" #include "ash/test/ash_test_helper.h"
#include "ash/wm_window.h" #include "ash/wm/window_properties.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "ui/aura/mus/property_converter.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/test/gfx_util.h"
#include "ui/wm/core/window_util.h"
namespace ash { namespace ash {
...@@ -29,28 +33,47 @@ int64_t GetDisplayId(aura::Window* window) { ...@@ -29,28 +33,47 @@ int64_t GetDisplayId(aura::Window* window) {
return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id();
} }
aura::Window* CreateFullscreenTestWindow(mus::WindowManager* window_manager,
int64_t display_id) {
std::map<std::string, std::vector<uint8_t>> properties;
properties[ui::mojom::WindowManager::kShowState_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<aura::PropertyConverter::PrimitiveType>(
ui::mojom::ShowState::FULLSCREEN));
if (display_id != display::kInvalidDisplayId) {
properties[ui::mojom::WindowManager::kDisplayId_InitProperty] =
mojo::ConvertTo<std::vector<uint8_t>>(display_id);
}
aura::Window* window = mus::CreateAndParentTopLevelWindow(
window_manager, ui::mojom::WindowType::WINDOW, &properties);
window->Show();
return window;
}
} // namespace } // namespace
using TopLevelWindowFactoryTest = AshTest; using TopLevelWindowFactoryTest = test::AshTestBase;
TEST_F(TopLevelWindowFactoryTest, CreateFullscreenWindow) { TEST_F(TopLevelWindowFactoryTest, CreateFullscreenWindow) {
std::unique_ptr<WindowOwner> window_owner = CreateToplevelTestWindow(); std::unique_ptr<aura::Window> window = CreateTestWindow();
WmWindow* window = window_owner->window(); ::wm::SetWindowFullscreen(window.get(), true);
window->SetFullscreen(true); aura::Window* root_window = Shell::GetPrimaryRootWindow();
WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow(); EXPECT_EQ(root_window->bounds(), window->bounds());
EXPECT_EQ(root_window->GetBounds(), window->GetBounds());
} }
using TopLevelWindowFactoryWmTest = mus::WmTestBase; using TopLevelWindowFactoryWmTest = test::AshTestBase;
TEST_F(TopLevelWindowFactoryWmTest, IsWindowShownInCorrectDisplay) { TEST_F(TopLevelWindowFactoryWmTest, IsWindowShownInCorrectDisplay) {
UpdateDisplay("400x400,400x400"); UpdateDisplay("400x400,400x400");
EXPECT_NE(GetPrimaryDisplay().id(), GetSecondaryDisplay().id()); EXPECT_NE(GetPrimaryDisplay().id(), GetSecondaryDisplay().id());
mus::WindowManager* window_manager =
ash_test_helper()->window_manager_app()->window_manager();
std::unique_ptr<aura::Window> window_primary_display( std::unique_ptr<aura::Window> window_primary_display(
CreateFullscreenTestWindow(GetPrimaryDisplay().id())); CreateFullscreenTestWindow(window_manager, GetPrimaryDisplay().id()));
std::unique_ptr<aura::Window> window_secondary_display( std::unique_ptr<aura::Window> window_secondary_display(
CreateFullscreenTestWindow(GetSecondaryDisplay().id())); CreateFullscreenTestWindow(window_manager, GetSecondaryDisplay().id()));
EXPECT_EQ(GetPrimaryDisplay().id(), EXPECT_EQ(GetPrimaryDisplay().id(),
GetDisplayId(window_primary_display.get())); GetDisplayId(window_primary_display.get()));
...@@ -69,4 +92,27 @@ TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) { ...@@ -69,4 +92,27 @@ TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) {
EXPECT_FALSE(window->IsVisible()); EXPECT_FALSE(window->IsVisible());
} }
TEST_F(TopLevelWindowFactoryAshTest, CreateTopLevelWindow) {
const gfx::Rect bounds(1, 2, 124, 345);
std::map<std::string, std::vector<uint8_t>> properties;
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));
mus::WindowManager* window_manager =
ash_test_helper()->window_manager_app()->window_manager();
// |window| is owned by its parent.
aura::Window* window = CreateAndParentTopLevelWindow(
window_manager, ui::mojom::WindowType::WINDOW, &properties);
ASSERT_TRUE(window->parent());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(bounds, window->bounds());
EXPECT_EQ(WidgetCreationType::FOR_CLIENT,
window->GetProperty(kWidgetCreationTypeKey));
}
} // namespace ash } // namespace ash
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "ash/display/unified_mouse_warp_controller.h" #include "ash/display/unified_mouse_warp_controller.h"
#include "ash/display/window_tree_host_manager.h" #include "ash/display/window_tree_host_manager.h"
#include "ash/ime/input_method_event_handler.h" #include "ash/ime/input_method_event_handler.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/config.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
...@@ -26,11 +29,14 @@ ...@@ -26,11 +29,14 @@
#include "ash/test/test_system_tray_delegate.h" #include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/window_positioner.h" #include "ash/wm/window_positioner.h"
#include "ash/wm_window.h" #include "ash/wm_window.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h" #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/screen_position_client.h"
#include "ui/aura/client/window_parenting_client.h" #include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/mus/property_converter.h"
#include "ui/aura/test/event_generator_delegate_aura.h" #include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -85,6 +91,35 @@ class AshEventGeneratorDelegate ...@@ -85,6 +91,35 @@ class AshEventGeneratorDelegate
DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate);
}; };
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 } // namespace
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -226,9 +261,35 @@ std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow( ...@@ -226,9 +261,35 @@ std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow(
const gfx::Rect& bounds_in_screen, const gfx::Rect& bounds_in_screen,
ui::wm::WindowType type, ui::wm::WindowType type,
int shell_window_id) { int shell_window_id) {
return base::WrapUnique<aura::Window>( if (AshTestHelper::config() != Config::MASH) {
CreateTestWindowInShellWithDelegateAndType(nullptr, type, shell_window_id, return base::WrapUnique<aura::Window>(
bounds_in_screen)); CreateTestWindowInShellWithDelegateAndType(
nullptr, type, shell_window_id, bounds_in_screen));
}
// For mash route creation through the window manager. This better simulates
// what happens when a client creates a top level window.
std::map<std::string, std::vector<uint8_t>> properties;
if (!bounds_in_screen.IsEmpty()) {
properties[ui::mojom::WindowManager::kBounds_InitProperty] =
mojo::ConvertTo<std::vector<uint8_t>>(bounds_in_screen);
}
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(type);
mus::WindowManager* window_manager =
ash_test_helper_->window_manager_app()->window_manager();
aura::Window* window = mus::CreateAndParentTopLevelWindow(
window_manager, mus_window_type, &properties);
window->Show();
return base::WrapUnique<aura::Window>(window);
} }
aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
...@@ -413,6 +474,11 @@ void AshTestBase::SwapPrimaryDisplay() { ...@@ -413,6 +474,11 @@ void AshTestBase::SwapPrimaryDisplay() {
display_manager()->GetSecondaryDisplay().id()); display_manager()->GetSecondaryDisplay().id());
} }
display::Display AshTestBase::GetPrimaryDisplay() {
return display::Screen::GetScreen()->GetDisplayNearestWindow(
Shell::GetPrimaryRootWindow());
}
display::Display AshTestBase::GetSecondaryDisplay() { display::Display AshTestBase::GetSecondaryDisplay() {
return ash_test_helper_->GetSecondaryDisplay(); return ash_test_helper_->GetSecondaryDisplay();
} }
......
...@@ -189,6 +189,7 @@ class AshTestBase : public testing::Test { ...@@ -189,6 +189,7 @@ class AshTestBase : public testing::Test {
// Swap the primary display with the secondary. // Swap the primary display with the secondary.
void SwapPrimaryDisplay(); void SwapPrimaryDisplay();
display::Display GetPrimaryDisplay();
display::Display GetSecondaryDisplay(); display::Display GetSecondaryDisplay();
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment