This source file includes following definitions.
- GetWindowNames
- GetLayerNames
- CreateTestWindowUnparented
- CreateTestWindow
- CreateBrowserLikeWindow
- CreatePopupLikeWindow
- CreateTestPanel
- GetDesktop
- GetFullscreenBounds
- shelf_widget
- shelf_layout_manager
- GetWindowOverlapsShelf
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- set_window
- OnBoundsChanged
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- window_
- clear_change_count
- change_count
- OnWindowHierarchyChanged
- TEST_F
- SetUp
- docked_windows_enabled
- TEST_P
- TEST_P
- TEST_F
- TEST_F
- TEST_F
#include "ash/wm/workspace_controller.h"
#include <map>
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_shelf_delegate.h"
#include "ash/wm/panels/panel_layout_manager.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_animations.h"
#include "ui/wm/core/window_util.h"
using aura::Window;
namespace ash {
std::string GetWindowNames(const aura::Window* window) {
std::string result;
for (size_t i = 0; i < window->children().size(); ++i) {
if (i != 0)
result += " ";
result += window->children()[i]->name();
}
return result;
}
std::string GetLayerNames(const aura::Window* window) {
typedef std::map<const ui::Layer*, std::string> LayerToWindowNameMap;
LayerToWindowNameMap window_names;
for (size_t i = 0; i < window->children().size(); ++i) {
window_names[window->children()[i]->layer()] =
window->children()[i]->name();
}
std::string result;
const std::vector<ui::Layer*>& layers(window->layer()->children());
for (size_t i = 0; i < layers.size(); ++i) {
LayerToWindowNameMap::iterator layer_i =
window_names.find(layers[i]);
if (layer_i != window_names.end()) {
if (!result.empty())
result += " ";
result += layer_i->second;
}
}
return result;
}
class WorkspaceControllerTest : public test::AshTestBase {
public:
WorkspaceControllerTest() {}
virtual ~WorkspaceControllerTest() {}
aura::Window* CreateTestWindowUnparented() {
aura::Window* window = new aura::Window(NULL);
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
return window;
}
aura::Window* CreateTestWindow() {
aura::Window* window = new aura::Window(NULL);
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindowInPrimaryRootWindow(window);
return window;
}
aura::Window* CreateBrowserLikeWindow(const gfx::Rect& bounds) {
aura::Window* window = CreateTestWindow();
window->SetBounds(bounds);
wm::WindowState* window_state = wm::GetWindowState(window);
window_state->set_window_position_managed(true);
window->Show();
return window;
}
aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) {
aura::Window* window = CreateTestWindowInShellWithBounds(bounds);
window->Show();
return window;
}
aura::Window* CreateTestPanel(aura::WindowDelegate* delegate,
const gfx::Rect& bounds) {
aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
delegate,
ui::wm::WINDOW_TYPE_PANEL,
0,
bounds);
test::TestShelfDelegate* shelf_delegate =
test::TestShelfDelegate::instance();
shelf_delegate->AddShelfItem(window);
PanelLayoutManager* manager = static_cast<PanelLayoutManager*>(
Shell::GetContainer(window->GetRootWindow(),
kShellWindowId_PanelContainer)->layout_manager());
manager->Relayout();
return window;
}
aura::Window* GetDesktop() {
return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_DefaultContainer);
}
gfx::Rect GetFullscreenBounds(aura::Window* window) {
return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds();
}
ShelfWidget* shelf_widget() {
return Shell::GetPrimaryRootWindowController()->shelf();
}
ShelfLayoutManager* shelf_layout_manager() {
return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
}
bool GetWindowOverlapsShelf() {
return shelf_layout_manager()->window_overlaps_shelf();
}
private:
DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest);
};
TEST_F(WorkspaceControllerTest, AddNormalWindowWhenEmpty) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->SetBounds(gfx::Rect(0, 0, 250, 251));
wm::WindowState* window_state = wm::GetWindowState(w1.get());
EXPECT_FALSE(window_state->HasRestoreBounds());
w1->Show();
EXPECT_FALSE(window_state->HasRestoreBounds());
ASSERT_TRUE(w1->layer() != NULL);
EXPECT_TRUE(w1->layer()->visible());
EXPECT_EQ("0,0 250x251", w1->bounds().ToString());
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
}
TEST_F(WorkspaceControllerTest, SingleMaximizeWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->SetBounds(gfx::Rect(0, 0, 250, 251));
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
ASSERT_TRUE(w1->layer() != NULL);
EXPECT_TRUE(w1->layer()->visible());
EXPECT_EQ("0,0 250x251", w1->bounds().ToString());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get()).width(),
w1->bounds().width());
EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get()).height(),
w1->bounds().height());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ("0,0 250x251", w1->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, FullscreenWithNormalWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
scoped_ptr<Window> w2(CreateTestWindow());
w1->SetBounds(gfx::Rect(0, 0, 250, 251));
w1->Show();
ASSERT_TRUE(w1->layer() != NULL);
EXPECT_TRUE(w1->layer()->visible());
w2->SetBounds(gfx::Rect(0, 0, 50, 51));
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
w2->Show();
wm::ActivateWindow(w2.get());
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ(w2.get(), GetDesktop()->children()[1]);
gfx::Rect work_area(
ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get()));
EXPECT_EQ(work_area.width(), w2->bounds().width());
EXPECT_EQ(work_area.height(), w2->bounds().height());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(50, w2->bounds().width());
EXPECT_EQ(51, w2->bounds().height());
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
}
TEST_F(WorkspaceControllerTest, ChangeBoundsOfNormalWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->Show();
w1->SetBounds(gfx::Rect(0, 0, 200, 500));
EXPECT_EQ(200, w1->bounds().width());
EXPECT_EQ(500, w1->bounds().height());
}
TEST_F(WorkspaceControllerTest, SnapToGrid) {
scoped_ptr<Window> w1(CreateTestWindowUnparented());
w1->SetBounds(gfx::Rect(1, 6, 25, 30));
ParentWindowInPrimaryRootWindow(w1.get());
EXPECT_EQ("1,6 25x30", w1->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, SingleFullscreenWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->SetBounds(gfx::Rect(0, 0, 250, 251));
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width());
EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT);
EXPECT_EQ("0,0 250x251", w1->bounds().ToString());
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ(250, w1->bounds().width());
EXPECT_EQ(251, w1->bounds().height());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(w1.get(), GetDesktop()->children()[0]);
EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width());
EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height());
wm::WindowState* window_state = wm::GetWindowState(w1.get());
ASSERT_TRUE(window_state->HasRestoreBounds());
EXPECT_EQ("0,0 250x251", window_state->GetRestoreBoundsInScreen().ToString());
}
TEST_F(WorkspaceControllerTest, MinimizeSingleWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->Show();
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_FALSE(w1->layer()->IsDrawn());
EXPECT_TRUE(w1->layer()->GetTargetTransform().IsIdentity());
w1->Show();
EXPECT_TRUE(wm::GetWindowState(w1.get())->IsNormalStateType());
EXPECT_TRUE(w1->layer()->IsDrawn());
}
TEST_F(WorkspaceControllerTest, MinimizeFullscreenWindow) {
scoped_ptr<Window> w1(CreateTestWindow());
scoped_ptr<Window> w2(CreateTestWindow());
w1->Show();
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
w2->Show();
wm::WindowState* w1_state = wm::GetWindowState(w1.get());
wm::WindowState* w2_state = wm::GetWindowState(w2.get());
w2_state->Activate();
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_TRUE(w1->layer()->IsDrawn());
EXPECT_FALSE(w2->layer()->IsDrawn());
w2->Show();
w2_state->Activate();
EXPECT_TRUE(w2_state->IsFullscreen());
EXPECT_TRUE(w1->layer()->IsDrawn());
EXPECT_TRUE(w2->layer()->IsDrawn());
EXPECT_TRUE(w2_state->IsActive());
w2_state->Minimize();
EXPECT_FALSE(w2_state->IsActive());
EXPECT_FALSE(w2->layer()->IsDrawn());
EXPECT_TRUE(w1_state->IsActive());
EXPECT_EQ(w2.get(), GetDesktop()->children()[0]);
EXPECT_EQ(w1.get(), GetDesktop()->children()[1]);
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_FALSE(w2_state->IsActive());
EXPECT_TRUE(w1_state->IsActive());
EXPECT_EQ(w2.get(), GetDesktop()->children()[0]);
EXPECT_EQ(w1.get(), GetDesktop()->children()[1]);
EXPECT_TRUE(w2->layer()->IsDrawn());
}
TEST_F(WorkspaceControllerTest, ShelfStateUpdated) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
scoped_ptr<Window> w1(CreateTestWindow());
const gfx::Rect w1_bounds(0, 1, 101, 102);
ShelfLayoutManager* shelf = shelf_layout_manager();
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
const gfx::Rect touches_shelf_bounds(
0, shelf->GetIdealBounds().y() - 10, 101, 102);
w1->SetBounds(touches_shelf_bounds);
EXPECT_FALSE(GetWindowOverlapsShelf());
scoped_ptr<Window> w_ignored(CreateTestWindow());
w_ignored->SetBounds(touches_shelf_bounds);
wm::GetWindowState(&(*w_ignored))->set_ignored_by_shelf(true);
w_ignored->Show();
EXPECT_FALSE(GetWindowOverlapsShelf());
w1->Show();
EXPECT_TRUE(GetWindowOverlapsShelf());
wm::ActivateWindow(w1.get());
w1->SetBounds(w1_bounds);
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
EXPECT_FALSE(GetWindowOverlapsShelf());
w1->SetBounds(touches_shelf_bounds);
EXPECT_TRUE(GetWindowOverlapsShelf());
w1->SetBounds(w1_bounds);
EXPECT_FALSE(GetWindowOverlapsShelf());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
wm::WindowState* window_state = wm::GetWindowState(w1.get());
gfx::Rect restore = window_state->GetRestoreBoundsInScreen();
EXPECT_EQ("0,0 800x597", w1->bounds().ToString());
EXPECT_EQ("0,1 101x102", restore.ToString());
window_state->ClearRestoreBounds();
w1->SetBounds(restore);
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
scoped_ptr<Window> w2(CreateTestWindow());
w2->SetBounds(gfx::Rect(10, 11, 250, 251));
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
w2->Show();
wm::ActivateWindow(w2.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(
w2->parent()).ToString(),
w2->bounds().ToString());
wm::ActivateWindow(w1.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(
w2->parent()).ToString(),
w2->bounds().ToString());
wm::ActivateWindow(w2.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w2.get()).ToString(),
w2->bounds().ToString());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
wm::ActivateWindow(w2.get());
EXPECT_FALSE(GetWindowOverlapsShelf());
w1->SetBounds(touches_shelf_bounds);
EXPECT_FALSE(GetWindowOverlapsShelf());
wm::ActivateWindow(w1.get());
EXPECT_FALSE(GetWindowOverlapsShelf());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_TRUE(GetWindowOverlapsShelf());
}
TEST_F(WorkspaceControllerTest, MinimizeResetsVisibility) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, shelf_widget()->GetBackgroundType());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(SHELF_VISIBLE,
shelf_layout_manager()->visibility_state());
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, shelf_widget()->GetBackgroundType());
}
TEST_F(WorkspaceControllerTest, VisibilityTests) {
scoped_ptr<Window> w1(CreateTestWindow());
w1->Show();
EXPECT_TRUE(w1->IsVisible());
EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity());
scoped_ptr<Window> w2(CreateTestWindow());
w2->Show();
wm::ActivateWindow(w2.get());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_TRUE(w2->IsVisible());
EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity());
EXPECT_TRUE(w1->IsVisible());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(w1->IsVisible());
EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity());
EXPECT_TRUE(w2->IsVisible());
wm::ActivateWindow(w2.get());
EXPECT_TRUE(w2->IsVisible());
EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity());
EXPECT_TRUE(w1->IsVisible());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_TRUE(w1->IsVisible());
EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity());
EXPECT_TRUE(w2->IsVisible());
EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
w2->Hide();
EXPECT_FALSE(w2->IsVisible());
EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity());
EXPECT_TRUE(w1->IsVisible());
w2.reset(CreateTestWindow());
w2->Show();
wm::ActivateWindow(w2.get());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_TRUE(w2->IsVisible());
EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity());
EXPECT_TRUE(w1->IsVisible());
w2.reset();
EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity());
EXPECT_TRUE(w1->IsVisible());
}
TEST_F(WorkspaceControllerTest, DontMoveOnSwitch) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
scoped_ptr<Window> w1(CreateTestWindow());
ShelfLayoutManager* shelf = shelf_layout_manager();
const gfx::Rect touches_shelf_bounds(
0, shelf->GetIdealBounds().y() - 10, 101, 102);
w1->SetBounds(touches_shelf_bounds);
w1->Show();
wm::ActivateWindow(w1.get());
scoped_ptr<Window> w2(CreateTestWindow());
w2->SetBounds(gfx::Rect(10, 11, 250, 251));
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
w2->Show();
wm::ActivateWindow(w2.get());
wm::ActivateWindow(w1.get());
EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, MoveOnSwitch) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
scoped_ptr<Window> w1(CreateTestWindow());
ShelfLayoutManager* shelf = shelf_layout_manager();
const gfx::Rect w1_bounds(0, shelf->GetIdealBounds().y(), 100, 200);
w1->SetBounds(w1_bounds);
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(w1_bounds.ToString(), w1->bounds().ToString());
scoped_ptr<Window> w2(CreateTestWindow());
w2->SetBounds(gfx::Rect(10, 11, 250, 251));
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
w2->Show();
wm::ActivateWindow(w2.get());
gfx::Insets insets =
Shell::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets();
insets.Set(0, 0, insets.bottom() + 30, 0);
Shell::GetInstance()->SetDisplayWorkAreaInsets(w1.get(), insets);
wm::ActivateWindow(w1.get());
EXPECT_NE(w1_bounds.ToString(), w1->bounds().ToString());
}
namespace {
class DontCrashOnChangeAndActivateDelegate
: public aura::test::TestWindowDelegate {
public:
DontCrashOnChangeAndActivateDelegate() : window_(NULL) {}
void set_window(aura::Window* window) { window_ = window; }
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE {
if (window_) {
wm::ActivateWindow(window_);
window_ = NULL;
}
}
private:
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(DontCrashOnChangeAndActivateDelegate);
};
}
TEST_F(WorkspaceControllerTest, DontCrashOnChangeAndActivate) {
ShelfLayoutManager* shelf = shelf_layout_manager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
DontCrashOnChangeAndActivateDelegate delegate;
scoped_ptr<Window> w1(CreateTestWindowInShellWithDelegate(
&delegate, 1000, gfx::Rect(10, 11, 250, 251)));
w1->Show();
wm::WindowState* w1_state = wm::GetWindowState(w1.get());
w1_state->Activate();
w1_state->Maximize();
w1_state->Minimize();
w1->parent()->RemoveChild(w1.get());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
ParentWindowInPrimaryRootWindow(w1.get());
delegate.set_window(w1.get());
w1->Show();
}
TEST_F(WorkspaceControllerTest, TransientParent) {
scoped_ptr<Window> w2(CreateTestWindow());
w2->SetBounds(gfx::Rect(10, 11, 250, 251));
w2->Show();
wm::ActivateWindow(w2.get());
scoped_ptr<Window> w1(CreateTestWindowUnparented());
::wm::AddTransientChild(
Shell::GetInstance()->GetPrimaryRootWindow(), w1.get());
w1->SetBounds(gfx::Rect(10, 11, 250, 251));
ParentWindowInPrimaryRootWindow(w1.get());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(w2->parent(), w1->parent());
}
TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("1600x1200");
gfx::Rect source_browser_bounds(16, 32, 640, 320);
scoped_ptr<aura::Window> browser_window(CreateBrowserLikeWindow(
source_browser_bounds));
scoped_ptr<aura::Window> browser_popup(CreatePopupLikeWindow(
gfx::Rect(16, 32, 128, 256)));
browser_window->Show();
browser_popup->Show();
{
scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
source_browser_bounds));
EXPECT_EQ("960,32 640x320", new_browser_window->bounds().ToString());
}
{
gfx::Rect source_browser_bounds(gfx::Rect(1000, 600, 640, 320));
browser_window->SetBounds(source_browser_bounds);
scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
source_browser_bounds));
EXPECT_EQ("0,600 640x320", new_browser_window->bounds().ToString());
EXPECT_EQ("1000,600 640x320", browser_window->bounds().ToString());
}
{
scoped_ptr<aura::Window> new_popup_window(CreatePopupLikeWindow(
gfx::Rect(50, 100, 300, 150)));
EXPECT_EQ("50,100 300x150", new_popup_window->bounds().ToString());
}
browser_window->Hide();
{
scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
gfx::Rect(50, 100, 300, 150)));
EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString());
}
}
TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnShowHide) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
window2->Hide();
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
window2->Show();
EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
EXPECT_EQ("32,48 256x512", window2->bounds().ToString());
window2.reset();
EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->set_window_position_managed(true);
scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2));
wm::GetWindowState(window3.get())->set_window_position_managed(true);
window3->Hide();
window3->SetBounds(gfx::Rect(32, 48, 256, 512));
window3->Show();
EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
EXPECT_EQ(base::IntToString(
desktop_area.width() - window3->bounds().width()) +
",48 256x512", window3->bounds().ToString());
window3.reset();
EXPECT_EQ(
base::IntToString(
(desktop_area.width() - window1->bounds().width()) / 2) +
",32 640x320", window1->bounds().ToString());
scoped_ptr<aura::Window> window4(CreateTestWindowInShellWithId(3));
window1->Hide();
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
window4->SetBounds(gfx::Rect(32, 48, 256, 512));
window1->Show();
EXPECT_EQ(
base::IntToString(
(desktop_area.width() - window1->bounds().width()) / 2) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
window4.reset();
window1_state->set_bounds_changed_by_user(false);
window1->Hide();
window1->Show();
EXPECT_EQ(
base::IntToString(
(desktop_area.width() - window1->bounds().width()) / 2) +
",32 640x320", window1->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
window1->Hide();
window2->Hide();
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
wm::WindowState* window2_state = wm::GetWindowState(window2.get());
window1_state->set_window_position_managed(true);
window2_state->set_window_position_managed(true);
EXPECT_FALSE(window1_state->bounds_changed_by_user());
EXPECT_FALSE(window2_state->bounds_changed_by_user());
window1_state->set_bounds_changed_by_user(true);
window1->Show();
EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
EXPECT_TRUE(window1_state->bounds_changed_by_user());
EXPECT_FALSE(window2_state->bounds_changed_by_user());
window2->Show();
EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
EXPECT_EQ(
base::IntToString(desktop_area.width() - window2->bounds().width()) +
",48 256x512", window2->bounds().ToString());
EXPECT_FALSE(window1_state->bounds_changed_by_user());
EXPECT_FALSE(window2_state->bounds_changed_by_user());
window1_state->set_bounds_changed_by_user(true);
window2->Hide();
EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
EXPECT_TRUE(window1_state->bounds_changed_by_user());
}
TEST_F(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) {
scoped_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
scoped_ptr<aura::Window> window2(
CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100)));
scoped_ptr<aura::Window> window3(
CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100)));
window1->Hide();
window2->Hide();
window3->Hide();
wm::GetWindowState(window1.get())->set_window_position_managed(true);
wm::GetWindowState(window2.get())->set_window_position_managed(true);
wm::GetWindowState(window3.get())->set_window_position_managed(true);
window1->Show();
wm::ActivateWindow(window1.get());
window2->Show();
wm::ActivateWindow(window2.get());
window3->Show();
wm::ActivateWindow(window3.get());
EXPECT_EQ(0, window1->bounds().x());
EXPECT_EQ(window2->GetRootWindow()->bounds().right(),
window2->bounds().right());
EXPECT_EQ(0, window3->bounds().x());
window1->Hide();
EXPECT_EQ(window2->GetRootWindow()->bounds().right(),
window2->bounds().right());
EXPECT_EQ(0, window3->bounds().x());
window3->Hide();
wm::ActivateWindow(window2.get());
EXPECT_EQ("110,110 100x100", window2->bounds().ToString());
window3->Show();
wm::ActivateWindow(window3.get());
EXPECT_EQ(0, window2->bounds().x());
EXPECT_EQ(window3->GetRootWindow()->bounds().right(),
window3->bounds().right());
window2->Hide();
EXPECT_EQ("120,120 100x100", window3->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320);
window1->SetBounds(user_pos);
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->SetPreAutoManageWindowBounds(user_pos);
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
window1->Hide();
window2->Hide();
wm::GetWindowState(window1.get())->set_window_position_managed(true);
wm::GetWindowState(window2.get())->set_window_position_managed(true);
window1->Show();
EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
window2->Show();
EXPECT_EQ("0," + base::IntToString(user_pos.y()) +
" 640x320", window1->bounds().ToString());
EXPECT_EQ(
base::IntToString(desktop_area.width() - window2->bounds().width()) +
",48 256x512", window2->bounds().ToString());
window2->Hide();
EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds());
EXPECT_EQ(user_pos.ToString(),
window1_state->pre_auto_manage_window_bounds()->ToString());
}
TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->set_window_position_managed(true);
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
wm::WindowState* window2_state = wm::GetWindowState(window2.get());
window2_state->set_window_position_managed(true);
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
window1_state->Minimize();
EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window2_state->IsNormalStateType());
EXPECT_EQ(base::IntToString(
(desktop_area.width() - window2->bounds().width()) / 2) +
",48 256x512", window2->bounds().ToString());
window1_state->Restore();
EXPECT_EQ(base::IntToString(
desktop_area.width() - window1->bounds().width()) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->set_window_position_managed(true);
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
wm::WindowState* window2_state = wm::GetWindowState(window2.get());
window2_state->set_window_position_managed(true);
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
window1_state->Maximize();
window1_state->Minimize();
EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window2_state->IsNormalStateType());
EXPECT_EQ(base::IntToString(
(desktop_area.width() - window2->bounds().width()) / 2) +
",48 256x512", window2->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->set_window_position_managed(true);
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
wm::WindowState* window2_state = wm::GetWindowState(window2.get());
window2_state->set_window_position_managed(true);
window2->SetBounds(gfx::Rect(32, 40, 256, 512));
window1->Hide();
window1->Show();
EXPECT_EQ(base::IntToString(
desktop_area.width() - window1->bounds().width()) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
window1_state->Maximize();
window1_state->Minimize();
EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window2_state->IsNormalStateType());
EXPECT_EQ(base::IntToString(
(desktop_area.width() - window2->bounds().width()) / 2) +
",40 256x512", window2->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) {
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->set_window_position_managed(true);
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
wm::GetWindowState(window2.get())->set_window_position_managed(true);
window2->SetBounds(gfx::Rect(32, 40, 256, 512));
window1->Hide();
window1->Show();
EXPECT_EQ(base::IntToString(
desktop_area.width() - window1->bounds().width()) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
window1_state->Maximize();
window1_state->Restore();
EXPECT_EQ(base::IntToString(
desktop_area.width() - window1->bounds().width()) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) {
ui::ScopedAnimationDurationScaleMode normal_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
window1->Hide();
window1->SetBounds(gfx::Rect(16, 32, 640, 320));
gfx::Rect desktop_area = window1->parent()->bounds();
scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
window2->Hide();
window2->SetBounds(gfx::Rect(32, 48, 256, 512));
wm::GetWindowState(window1.get())->set_window_position_managed(true);
wm::GetWindowState(window2.get())->set_window_position_managed(true);
window1->layer()->GetAnimator()->StopAnimating();
window2->layer()->GetAnimator()->StopAnimating();
window2->Show();
EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating());
window2->layer()->GetAnimator()->StopAnimating();
window1->Show();
EXPECT_TRUE(window1->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating());
window1->layer()->GetAnimator()->StopAnimating();
window2->layer()->GetAnimator()->StopAnimating();
EXPECT_EQ(base::IntToString(
desktop_area.width() - window1->bounds().width()) +
",32 640x320", window1->bounds().ToString());
EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
}
TEST_F(WorkspaceControllerTest, VerifyLayerOrdering) {
scoped_ptr<Window> browser(aura::test::CreateTestWindowWithDelegate(
NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL));
browser->SetName("browser");
ParentWindowInPrimaryRootWindow(browser.get());
browser->Show();
wm::ActivateWindow(browser.get());
aura::test::TestWindowDelegate* status_bubble_delegate =
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
status_bubble_delegate->set_can_focus(false);
Window* status_bubble =
aura::test::CreateTestWindowWithDelegate(status_bubble_delegate,
ui::wm::WINDOW_TYPE_POPUP,
gfx::Rect(5, 6, 7, 8),
NULL);
::wm::AddTransientChild(browser.get(), status_bubble);
ParentWindowInPrimaryRootWindow(status_bubble);
status_bubble->SetName("status_bubble");
scoped_ptr<Window> app(aura::test::CreateTestWindowWithDelegate(
NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL));
app->SetName("app");
ParentWindowInPrimaryRootWindow(app.get());
aura::Window* parent = browser->parent();
app->Show();
wm::ActivateWindow(app.get());
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
app->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_TRUE(wm::IsActiveWindow(browser.get()));
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
browser->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_FALSE(wm::IsActiveWindow(browser.get()));
EXPECT_FALSE(wm::IsActiveWindow(app.get()));
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
browser->Show();
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
ash::wm::ActivateWindow(browser.get());
EXPECT_TRUE(wm::IsActiveWindow(browser.get()));
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
app->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
ash::wm::ActivateWindow(app.get());
EXPECT_TRUE(wm::IsActiveWindow(app.get()));
EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
}
namespace {
class DragMaximizedNonTrackedWindowObserver
: public aura::WindowObserver {
public:
DragMaximizedNonTrackedWindowObserver(aura::Window* window)
: change_count_(0),
window_(window) {
}
void clear_change_count() { change_count_ = 0; }
int change_count() const {
return change_count_;
}
virtual void OnWindowHierarchyChanged(
const HierarchyChangeParams& params) OVERRIDE {
if (params.target != window_ ||
(params.old_parent->id() == kShellWindowId_DefaultContainer &&
params.new_parent->id() == kShellWindowId_DockedContainer) ||
(params.old_parent->id() == kShellWindowId_DockedContainer &&
params.new_parent->id() == kShellWindowId_DefaultContainer)) {
return;
}
change_count_++;
}
private:
int change_count_;
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(DragMaximizedNonTrackedWindowObserver);
};
}
TEST_F(WorkspaceControllerTest, SwitchFromModal) {
scoped_ptr<Window> modal_window(CreateTestWindowUnparented());
modal_window->SetBounds(gfx::Rect(10, 11, 21, 22));
modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
ParentWindowInPrimaryRootWindow(modal_window.get());
modal_window->Show();
wm::ActivateWindow(modal_window.get());
scoped_ptr<Window> maximized_window(CreateTestWindow());
maximized_window->SetProperty(
aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
maximized_window->Show();
wm::ActivateWindow(maximized_window.get());
EXPECT_TRUE(maximized_window->IsVisible());
}
namespace {
class WorkspaceControllerTestDragging
: public WorkspaceControllerTest,
public testing::WithParamInterface<bool> {
public:
WorkspaceControllerTestDragging() {}
virtual ~WorkspaceControllerTestDragging() {}
virtual void SetUp() OVERRIDE {
WorkspaceControllerTest::SetUp();
if (!docked_windows_enabled()) {
CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshDisableDockedWindows);
}
}
bool docked_windows_enabled() const { return GetParam(); }
private:
DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTestDragging);
};
}
TEST_P(WorkspaceControllerTestDragging, DragWindowOverlapShelf) {
aura::test::TestWindowDelegate delegate;
delegate.set_window_component(HTCAPTION);
scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate(
&delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL));
ParentWindowInPrimaryRootWindow(w1.get());
ShelfLayoutManager* shelf = shelf_layout_manager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(10, 10);
generator.PressLeftButton();
generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 70);
EXPECT_FALSE(GetWindowOverlapsShelf());
generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 20);
EXPECT_TRUE(GetWindowOverlapsShelf());
generator.ReleaseLeftButton();
EXPECT_TRUE(GetWindowOverlapsShelf());
}
TEST_P(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) {
aura::test::TestWindowDelegate delegate;
delegate.set_window_component(HTCAPTION);
scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate(
&delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL));
ParentWindowInPrimaryRootWindow(w1.get());
ShelfLayoutManager* shelf = shelf_layout_manager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(10, 10);
generator.PressLeftButton();
generator.MoveMouseTo(12, 12);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.ReleaseLeftButton();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
}
INSTANTIATE_TEST_CASE_P(DockedOrNot, WorkspaceControllerTestDragging,
::testing::Bool());
TEST_F(WorkspaceControllerTest, WindowEdgeHitTest) {
aura::test::TestWindowDelegate d_first, d_second;
scoped_ptr<Window> first(aura::test::CreateTestWindowWithDelegate(&d_first,
123, gfx::Rect(20, 10, 100, 50), NULL));
ParentWindowInPrimaryRootWindow(first.get());
first->Show();
scoped_ptr<Window> second(aura::test::CreateTestWindowWithDelegate(&d_second,
234, gfx::Rect(30, 40, 40, 10), NULL));
ParentWindowInPrimaryRootWindow(second.get());
second->Show();
ui::EventTarget* root = first->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
const int kNumPoints = 4;
struct {
const char* direction;
gfx::Point location;
} points[kNumPoints] = {
{ "left", gfx::Point(28, 45) },
{ "top", gfx::Point(50, 38) },
{ "right", gfx::Point(72, 45) },
{ "bottom", gfx::Point(50, 52) },
};
for (int times = 0; times < 2; ++times) {
SCOPED_TRACE(times == 0 ? "Without transform" : "With transform");
aura::Window* expected_target = times == 0 ? second.get() : first.get();
for (int i = 0; i < kNumPoints; ++i) {
SCOPED_TRACE(points[i].direction);
const gfx::Point& location = points[i].location;
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
EXPECT_EQ(expected_target, target);
ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
ui::EventTimeForNow());
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_EQ(expected_target, target);
}
gfx::Transform transform;
transform.Translate(70, 40);
second->SetTransform(transform);
}
}
TEST_F(WorkspaceControllerTest, WindowEdgeHitTestPanel) {
aura::test::TestWindowDelegate delegate;
scoped_ptr<Window> window(CreateTestPanel(&delegate,
gfx::Rect(20, 10, 100, 50)));
ui::EventTarget* root = window->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
const gfx::Rect bounds = window->bounds();
const int kNumPoints = 5;
struct {
const char* direction;
gfx::Point location;
bool is_target_hit;
} points[kNumPoints] = {
{ "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true },
{ "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true },
{ "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true },
{ "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true },
{ "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false },
};
for (int i = 0; i < kNumPoints; ++i) {
SCOPED_TRACE(points[i].direction);
const gfx::Point& location = points[i].location;
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
if (points[i].is_target_hit)
EXPECT_EQ(window.get(), target);
else
EXPECT_NE(window.get(), target);
ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
ui::EventTimeForNow());
target = targeter->FindTargetForEvent(root, &touch);
if (points[i].is_target_hit)
EXPECT_EQ(window.get(), target);
else
EXPECT_NE(window.get(), target);
}
}
TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) {
if (!switches::UseDockedWindows())
return;
aura::test::TestWindowDelegate delegate;
delegate.set_maximum_size(gfx::Size(180, 200));
scoped_ptr<Window> window(aura::test::CreateTestWindowWithDelegate(&delegate,
123, gfx::Rect(20, 10, 100, 50), NULL));
ParentWindowInPrimaryRootWindow(window.get());
aura::Window* docked_container = Shell::GetContainer(
window->GetRootWindow(), kShellWindowId_DockedContainer);
docked_container->AddChild(window.get());
window->Show();
ui::EventTarget* root = window->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
const gfx::Rect bounds = window->bounds();
const int kNumPoints = 5;
struct {
const char* direction;
gfx::Point location;
bool is_target_hit;
} points[kNumPoints] = {
{ "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true },
{ "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true },
{ "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true },
{ "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true },
{ "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false },
};
for (int i = 0; i < kNumPoints; ++i) {
SCOPED_TRACE(points[i].direction);
const gfx::Point& location = points[i].location;
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
if (points[i].is_target_hit)
EXPECT_EQ(window.get(), target);
else
EXPECT_NE(window.get(), target);
ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
ui::EventTimeForNow());
target = targeter->FindTargetForEvent(root, &touch);
if (points[i].is_target_hit)
EXPECT_EQ(window.get(), target);
else
EXPECT_NE(window.get(), target);
}
}
}