This source file includes following definitions.
- Show
- Hide
- Activate
- GetNativeWindow
- GetBounds
- browser
- CreateBrowser
- CreateTestBrowserWindow
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/scoped_target_root_window.h"
#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/window_positioner.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "base/compiler_specific.h"
#include "chrome/browser/ui/ash/ash_init.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/render_view_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/screen.h"
#include "ui/wm/public/activation_client.h"
typedef ash::test::AshTestBase WindowSizerAshTest;
namespace {
class TestBrowserWindowAura : public TestBrowserWindow {
public:
explicit TestBrowserWindowAura(aura::Window* native_window)
: native_window_(native_window) {
}
virtual ~TestBrowserWindowAura() {}
virtual void Show() OVERRIDE {
native_window_->Show();
Activate();
}
virtual void Hide() OVERRIDE {
native_window_->Hide();
}
virtual void Activate() OVERRIDE {
aura::client::GetActivationClient(
native_window_->GetRootWindow())->ActivateWindow(native_window_.get());
}
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE {
return native_window_.get();
}
virtual gfx::Rect GetBounds() const OVERRIDE {
return native_window_->bounds();
}
Browser* browser() { return browser_.get(); }
void CreateBrowser(const Browser::CreateParams& params) {
Browser::CreateParams create_params = params;
create_params.window = this;
browser_.reset(new Browser(create_params));
if (browser_->is_type_tabbed() || browser_->is_app()) {
ash::wm::GetWindowState(native_window_.get())->
set_window_position_managed(true);
}
}
private:
scoped_ptr<Browser> browser_;
scoped_ptr<aura::Window> native_window_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
};
scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow(
aura::Window* window,
const gfx::Rect& bounds,
const Browser::CreateParams& params) {
if (!bounds.IsEmpty())
window->SetBounds(bounds);
scoped_ptr<TestBrowserWindowAura> browser_window(
new TestBrowserWindowAura(window));
browser_window->CreateBrowser(params);
return browser_window.Pass();
}
}
TEST_F(WindowSizerAshTest, DefaultSizeCase) {
#if defined(OS_WIN)
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kOpenAsh);
#endif
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
768 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_bottom_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_bottom_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_right_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
taskbar_right_work_area.width() -
ash::WindowPositioner::kDesktopBorderSize * 2,
768 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() +
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
taskbar_left_work_area.width() -
ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_left_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_top_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
taskbar_top_work_area.y() +
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_top_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1280x1024, p1280x1024, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1280 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1024 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1200 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1680x1050, p1680x1050, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1680 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1050 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1920x1200, p1920x1200, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1920 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1200 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
}
TEST_F(WindowSizerAshTest, LastWindowBoundsCase) {
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, taskbar_top_work_area, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
std::max(kWindowTilePixels +
ash::WindowPositioner::kDesktopBorderSize,
34 ),
500, 400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 29, 29),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
30 ,
30 ).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
}
TEST_F(WindowSizerAshTest, PersistedBoundsCase) {
{
gfx::Rect initial_bounds(
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{
gfx::Rect initial_bounds(0, 0, 1024, 768);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{
gfx::Rect initial_bounds(-600, 10, 500, 400);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{
gfx::Rect initial_bounds(-1024, 0, 1024, 768);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{
gfx::Rect initial_bounds(1074, 50, 600, 500);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED, NULL,
gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{
gfx::Rect initial_bounds(1274, 50, 600, 500);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ("1224,50 600x500", window_bounds.ToString());
}
{
gfx::Rect initial_bounds(1274, 50, 900, 700);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ("1024,0 800x600", window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 29, 29),
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
30 , 30 ).ToString(),
window_bounds.ToString());
}
}
TEST_F(WindowSizerAshTest, LastWindowOffscreenWithNonAggressiveRepositioning) {
{
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, taskbar_left_work_area, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 500, 400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels,
738 ,
500,
400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994 ,
10 + kWindowTilePixels,
500,
400).ToString(),
window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994 ,
738 ,
500,
400).ToString(),
window_bounds.ToString());
}
}
TEST_F(WindowSizerAshTest, PlaceNewWindows) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
Browser::CreateParams native_params(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 128, 256),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
scoped_ptr<BrowserWindow> browser_panel(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(2),
gfx::Rect(32, 48, 256, 512),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
browser_window->Show();
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
PERSISTED, browser_popup->browser(),
gfx::Rect(), &window_bounds);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
}
browser_window->Hide();
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
PERSISTED, browser.get(), gfx::Rect(), &window_bounds);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
}
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(), bottom_s1600x1200,
DEFAULT, browser.get(), gfx::Rect(), &window_bounds);
EXPECT_EQ(
gfx::Rect(
std::max(ash::WindowPositioner::kDesktopBorderSize,
(1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2),
ash::WindowPositioner::kDesktopBorderSize,
std::min(ash::WindowPositioner::kMaximumWindowWidth,
1600 - 2 * ash::WindowPositioner::kDesktopBorderSize),
1200 - ash::WindowPositioner::kDesktopBorderSize).ToString(),
window_bounds.ToString());
}
}
TEST_F(WindowSizerAshTest, PlaceNewBrowserWindowOnEmptyDesktop) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
Browser::CreateParams native_params(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
const gfx::Rect p1366x768(0, 0, 1366, 768);
gfx::Rect window_bounds;
ui::WindowShowState out_show_state1 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1366x768,
p1366x768,
gfx::Rect(),
gfx::Rect(),
p1366x768,
ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_DEFAULT,
DEFAULT,
browser.get(),
gfx::Rect(),
&window_bounds,
&out_show_state1);
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state1);
ui::WindowShowState out_show_state2 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1366x768,
p1366x768,
gfx::Rect(),
gfx::Rect(50, 100, 300, 150),
p1366x768,
ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_DEFAULT,
PERSISTED,
browser.get(),
gfx::Rect(),
&window_bounds,
&out_show_state2);
EXPECT_EQ(ui::SHOW_STATE_NORMAL, out_show_state2);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
ui::WindowShowState out_show_state3 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1600x1200,
p1600x1200,
gfx::Rect(),
gfx::Rect(),
p1600x1200,
ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_DEFAULT,
DEFAULT,
browser.get(),
gfx::Rect(),
&window_bounds,
&out_show_state3);
#if defined(OS_WIN)
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state3);
#else
EXPECT_EQ(ui::SHOW_STATE_DEFAULT, out_show_state3);
#endif
}
#if defined(OS_CHROMEOS)
#define MAYBE_PlaceNewWindowsOnMultipleDisplays PlaceNewWindowsOnMultipleDisplays
#else
#define MAYBE_PlaceNewWindowsOnMultipleDisplays DISABLED_PlaceNewWindowsOnMultipleDisplays
#endif
TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindowsOnMultipleDisplays) {
UpdateDisplay("1600x1200,1600x1200");
gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()->
GetPrimaryDisplay().bounds();
gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds();
ash::Shell::GetInstance()->set_target_root_window(
ash::Shell::GetPrimaryRootWindow());
scoped_ptr<TestingProfile> profile(new TestingProfile());
scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(10, 10, 200, 200),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
browser_window->Show();
EXPECT_EQ(browser_window->GetNativeWindow()->GetRootWindow(),
ash::Shell::GetTargetRootWindow());
scoped_ptr<BrowserWindow> another_browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(400, 10, 300, 300),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
another_browser_window->Show();
scoped_ptr<TestBrowserWindowAura> new_browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(),
Browser::CreateParams(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
EXPECT_TRUE(primary_bounds.Contains(window_bounds));
}
{
gfx::Display second_display = ash::Shell::GetScreen()->
GetDisplayNearestPoint(gfx::Point(1600 + 100,10));
browser_window->GetNativeWindow()->SetBoundsInScreen(
gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200),
second_display);
browser_window->Activate();
EXPECT_NE(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
EXPECT_TRUE(secondary_bounds.Contains(window_bounds));
}
{
another_browser_window->Activate();
EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
EXPECT_TRUE(primary_bounds.Contains(window_bounds));
}
}
TEST_F(WindowSizerAshTest, TestShowState) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200));
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200));
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200));
EXPECT_EQ(ui::SHOW_STATE_NORMAL,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200));
scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(3),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window->browser(),
p1600x1200));
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MINIMIZED,
BOTH,
browser_popup->browser(),
p1600x1200));
int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2;
if (min_size > 0) {
const gfx::Rect tiny_screen(0, 0, min_size, min_size);
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window->browser(),
tiny_screen));
browser_window->Hide();
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window2->browser(),
tiny_screen));
}
}
TEST_F(WindowSizerAshTest, TestShowStateDefaults) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 128, 256),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
ui::WindowShowState window_show_state =
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
DEFAULT,
browser_window->browser(),
p1600x1200);
#if defined(OS_WIN)
EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED);
#else
EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT);
#endif
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
BOTH,
browser_window->browser(),
p1600x1200), ui::SHOW_STATE_MINIMIZED);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
BOTH,
browser_window->browser(),
p1600x1200), ui::SHOW_STATE_NORMAL);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200), ui::SHOW_STATE_MAXIMIZED);
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200), ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200), ui::SHOW_STATE_NORMAL);
}
TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) {
if (!SupportsMultipleDisplays() || !chrome::ShouldOpenAshOnStartup())
return;
UpdateDisplay("500x500,600x600");
{
aura::Window* first_root =
ash::Shell::GetAllRootWindows()[0];
ash::ScopedTargetRootWindow tmp(first_root);
gfx::Rect bounds;
ui::WindowShowState show_state;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(),
gfx::Rect(),
NULL,
&bounds,
&show_state);
EXPECT_TRUE(first_root->GetBoundsInScreen().Contains(bounds));
}
{
aura::Window* second_root =
ash::Shell::GetAllRootWindows()[1];
ash::ScopedTargetRootWindow tmp(second_root);
gfx::Rect bounds;
ui::WindowShowState show_state;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(),
gfx::Rect(),
NULL,
&bounds,
&show_state);
EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds));
}
}