window_sizer_ash_unittest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/scoped_target_root_window.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h" 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/test_shell_delegate.h" 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/window_positioner.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_resizer.h" 1268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/ash/ash_init.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_profile.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/render_view_test.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/activation_client.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/test/test_windows.h" 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/screen.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef ash::test::AshTestBase WindowSizerAshTest; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A browser window proxy which is able to associate an aura native window with 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestBrowserWindowAura : public TestBrowserWindow { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |native_window| will still be owned by the caller after the constructor 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // was called. 38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) explicit TestBrowserWindowAura(aura::Window* native_window) 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) : native_window_(native_window) { 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ~TestBrowserWindowAura() {} 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TestBrowserWindow overrides: 44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void Show() OVERRIDE { 45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) native_window_->Show(); 46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Activate(); 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void Hide() OVERRIDE { 49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) native_window_->Hide(); 50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void Activate() OVERRIDE { 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::GetActivationClient( 53424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) native_window_->GetRootWindow())->ActivateWindow(native_window_.get()); 54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { 56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return native_window_.get(); 57424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 58424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual gfx::Rect GetBounds() const OVERRIDE { 59424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return native_window_->bounds(); 60424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 61424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 62424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser* browser() { return browser_.get(); } 63424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 64424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void CreateBrowser(const Browser::CreateParams& params) { 65424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams create_params = params; 66424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) create_params.window = this; 67424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_.reset(new Browser(create_params)); 6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (browser_->is_type_tabbed() || browser_->is_app()) { 6968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ash::wm::GetWindowState(native_window_.get())-> 7058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) set_window_position_managed(true); 7158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 72424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<Browser> browser_; 76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<aura::Window> native_window_; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 81424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow( 82424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) aura::Window* window, 83424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const gfx::Rect& bounds, 84424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const Browser::CreateParams& params) { 85424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!bounds.IsEmpty()) 86424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) window->SetBounds(bounds); 87424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_window( 88424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) new TestBrowserWindowAura(window)); 89424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->CreateBrowser(params); 90424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return browser_window.Pass(); 91424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 92424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 93ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} // namespace 94ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the window is sized appropriately for the first run experience 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// where the default window bounds calculation is invoked. 97424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, DefaultSizeCase) { 98f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 99f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch(switches::kOpenAsh); 100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1024x768, no taskbar 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1024 - ash::WindowPositioner::kDesktopBorderSize * 2, 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 768 - ash::WindowPositioner::kDesktopBorderSize), 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1024x768, taskbar on bottom 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, taskbar_bottom_work_area, gfx::Rect(), 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(), 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1024 - ash::WindowPositioner::kDesktopBorderSize * 2, 1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) taskbar_bottom_work_area.height() - 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize), 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1024x768, taskbar on right 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, taskbar_right_work_area, gfx::Rect(), 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(), 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) taskbar_right_work_area.width() - 1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize * 2, 1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 768 - ash::WindowPositioner::kDesktopBorderSize), 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1024x768, taskbar on left 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(), 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(), 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) taskbar_left_work_area.width() - 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize * 2, 1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) taskbar_left_work_area.height() - 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize), 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1024x768, taskbar on top 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, taskbar_top_work_area, gfx::Rect(), 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(), 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) taskbar_top_work_area.y() + 1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1024 - ash::WindowPositioner::kDesktopBorderSize * 2, 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) taskbar_top_work_area.height() - 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize), 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1280x1024 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1280x1024, p1280x1024, gfx::Rect(), gfx::Rect(), 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); 1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect((1280 - ash::WindowPositioner::kMaximumWindowWidth) / 2, 1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kMaximumWindowWidth, 1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1024 - ash::WindowPositioner::kDesktopBorderSize), 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 4:3 monitor case, 1600x1200 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), gfx::Rect(), 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect((1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2, 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kMaximumWindowWidth, 1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1200 - ash::WindowPositioner::kDesktopBorderSize), 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 16:10 monitor case, 1680x1050 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1680x1050, p1680x1050, gfx::Rect(), gfx::Rect(), 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect((1680 - ash::WindowPositioner::kMaximumWindowWidth) / 2, 1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kMaximumWindowWidth, 1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1050 - ash::WindowPositioner::kDesktopBorderSize), 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // 16:10 monitor case, 1920x1200 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1920x1200, p1920x1200, gfx::Rect(), gfx::Rect(), 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect((1920 - ash::WindowPositioner::kMaximumWindowWidth) / 2, 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kMaximumWindowWidth, 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1200 - ash::WindowPositioner::kDesktopBorderSize), 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the next opened window is positioned appropriately given the 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// bounds of an existing window of the same type. 214424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, LastWindowBoundsCase) { 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // normal, in the middle of the screen somewhere. 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, p1024x768, gfx::Rect(), 2194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 500, 400), 2214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(), 2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) &window_bounds); 2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 500, 400).ToString(), 2274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // taskbar on top. 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 2334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, taskbar_top_work_area, gfx::Rect(), 2344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 500, 400), 2364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(), 2374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) &window_bounds); 2384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 2394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::max(kWindowTilePixels + 2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 34 /* toolbar height */), 2434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 500, 400).ToString(), 2444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Too small to satisify the minimum visibility condition. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 2504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, p1024x768, gfx::Rect(), 2514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 2524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 29, 29), 2534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(), 2544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) &window_bounds); 2554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 2564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 30 /* not 29 */, 2594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 30 /* not 29 */).ToString(), 2604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Normal. 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 2674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, p1024x768, gfx::Rect(), 2684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 2694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 500, 400), 2704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(), 2714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) &window_bounds); 2724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 2734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 500, 400).ToString(), 2764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the window opened is sized appropriately given persisted sizes. 281424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, PersistedBoundsCase) { 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // normal, in the middle of the screen somewhere. 2834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect initial_bounds( 2844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 500, 400); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds, 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Normal. 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(0, 0, 1024, 768); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds, 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // normal, on non-primary monitor in negative coords. 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(-600, 10, 500, 400); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, left_s1024x768, 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(), 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // normal, on non-primary monitor in negative coords. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(-1024, 0, 1024, 768); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, left_s1024x768, 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(), 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &window_bounds); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Non-primary monitor resoultion has changed, but the monitor still 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // completely contains the window. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(1074, 50, 600, 500); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600), 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) initial_bounds, right_s1024x768, PERSISTED, NULL, 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), &window_bounds); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Non-primary monitor resoultion has changed, and the window is partially 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // off-screen. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(1274, 50, 600, 500); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600), 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) initial_bounds, right_s1024x768, PERSISTED, 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("1224,50 600x500", window_bounds.ToString()); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Non-primary monitor resoultion has changed, and the window is now too 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // large for the monitor. 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect initial_bounds(1274, 50, 900, 700); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600), 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) initial_bounds, right_s1024x768, PERSISTED, 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("1024,0 800x600", window_bounds.ToString()); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // width and height too small 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 3614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, p1024x768, gfx::Rect(), 3624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 3634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 29, 29), 3644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds); 3654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 3664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 30 /* not 29 */, 30 /* not 29 */).ToString(), 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////// 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The following unittests have different results on Mac/non-Mac because we 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// reposition windows aggressively on Mac. The *WithAggressiveReposition tests 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// are run on Mac, and the *WithNonAggressiveRepositioning tests are run on 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// other platforms. 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, LastWindowOffscreenWithNonAggressiveRepositioning) { 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // taskbar on left. 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetWindowBounds( 3824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) p1024x768, taskbar_left_work_area, gfx::Rect(), 3834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(ash::WindowPositioner::kDesktopBorderSize, 3844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 500, 400), 3854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(), 3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) &window_bounds); 3874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 3884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 3894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize, 3904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 500, 400).ToString(), 3914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // offset would put the new window offscreen at the bottom but the minimum 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // visibility condition is barely satisfied without relocation. 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 500, 400).ToString(), 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // offset would put the new window offscreen at the bottom and the minimum 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // visibility condition is satisified by relocation. 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 738 /* not 739 */, 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 500, 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 400).ToString(), 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // offset would put the new window offscreen at the right but the minimum 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // visibility condition is barely satisfied without relocation. 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400).ToString(), 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // offset would put the new window offscreen at the right and the minimum 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // visibility condition is satisified by relocation. 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(994 /* not 995 */, 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10 + kWindowTilePixels, 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 500, 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 400).ToString(), 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // offset would put the new window offscreen at the bottom right and the 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // minimum visibility condition is satisified by relocation. 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NULL, gfx::Rect(), &window_bounds); 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(gfx::Rect(994 /* not 995 */, 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 738 /* not 739 */, 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 500, 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 400).ToString(), 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.ToString()); 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test the placement of newly created windows. 455424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, PlaceNewWindows) { 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create a browser which we can use to pass into the GetWindowBounds 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function. 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TestingProfile> profile(new TestingProfile()); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a popup handler here to make sure it does not interfere with the 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // existing windows. 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser::CreateParams native_params(profile.get(), 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH); 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Browser> browser( 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::CreateBrowserWithTestWindowForParams(&native_params)); 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a popup handler here to make sure it does not interfere with the 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // existing windows. 468424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 469424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(0), 470424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 640, 320), 471424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a popup to make sure it does not interfere with the positioning. 474424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 475424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(1), 476424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 128, 256), 477424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 478424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a panel to make sure it does not interfere with the positioning. 481424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<BrowserWindow> browser_panel(CreateTestBrowserWindow( 482424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(2), 483424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(32, 48, 256, 512), 484424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 485424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 486424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->Show(); 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // Make sure that popups do not get changed. 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 491424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PERSISTED, browser_popup->browser(), 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect(), &window_bounds); 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 496424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->Hide(); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // If a window is there but not shown the persisted default should be used. 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PERSISTED, browser.get(), gfx::Rect(), &window_bounds); 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // If a window is there but not shown the default should be returned. 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds; 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(), bottom_s1600x1200, 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DEFAULT, browser.get(), gfx::Rect(), &window_bounds); 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Note: We need to also take the defaults maximum width into account here 5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // since that might get used if the resolution is too big. 5124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ( 5134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect( 5144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::max(ash::WindowPositioner::kDesktopBorderSize, 5154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) (1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2), 5164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ash::WindowPositioner::kDesktopBorderSize, 5174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::min(ash::WindowPositioner::kMaximumWindowWidth, 5184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1600 - 2 * ash::WindowPositioner::kDesktopBorderSize), 5194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1200 - ash::WindowPositioner::kDesktopBorderSize).ToString(), 5204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_bounds.ToString()); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 524c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Test the placement of newly created windows on an empty desktop. 525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// This test supplements "PlaceNewWindows" by testing the creation of a newly 526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// created browser window on an empty desktop. 527424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, PlaceNewBrowserWindowOnEmptyDesktop) { 528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Create a browser which we can use to pass into the GetWindowBounds 529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // function. 530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<TestingProfile> profile(new TestingProfile()); 531c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Browser::CreateParams native_params(profile.get(), 532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH); 533c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<Browser> browser( 534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::CreateBrowserWithTestWindowForParams(&native_params)); 535c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 536ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // A common screen size for Chrome OS devices where this behavior is 537ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // desirable. 538ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const gfx::Rect p1366x768(0, 0, 1366, 768); 539ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If there is no previous state the window should get maximized if the 541ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // screen is less than or equal to our limit (1366 pixels width). 542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect window_bounds; 543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::WindowShowState out_show_state1 = ui::SHOW_STATE_DEFAULT; 544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetWindowBoundsAndShowState( 545ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The screen resolution. 546ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The monitor work area. 547ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // The second monitor. 548ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // The (persisted) bounds. 549ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The overall work area. 550ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_NORMAL, // The persisted show state. 551ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_DEFAULT, // The last show state. 552ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch DEFAULT, // No persisted values. 553ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch browser.get(), // Use this browser. 554ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // Don't request valid bounds. 555ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &window_bounds, 556ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &out_show_state1); 557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state1); 558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If there is a stored coordinate however, that should be taken instead. 560c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::WindowShowState out_show_state2 = ui::SHOW_STATE_DEFAULT; 561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetWindowBoundsAndShowState( 562ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The screen resolution. 563ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The monitor work area. 564ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // The second monitor. 565ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(50, 100, 300, 150), // The (persisted) bounds. 566ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1366x768, // The overall work area. 567ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_NORMAL, // The persisted show state. 568ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_DEFAULT, // The last show state. 569ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch PERSISTED, // Set the persisted values. 570ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch browser.get(), // Use this browser. 571ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // Don't request valid bounds. 572ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &window_bounds, 573ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &out_show_state2); 574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_NORMAL, out_show_state2); 575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 577ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // A larger monitor should not trigger auto-maximize. 578ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::WindowShowState out_show_state3 = ui::SHOW_STATE_DEFAULT; 579ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch GetWindowBoundsAndShowState( 580ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1600x1200, // The screen resolution. 581ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1600x1200, // The monitor work area. 582ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // The second monitor. 583ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // The (persisted) bounds. 584ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch p1600x1200, // The overall work area. 585ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_NORMAL, // The persisted show state. 586ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ui::SHOW_STATE_DEFAULT, // The last show state. 587ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch DEFAULT, // No persisted values. 588ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch browser.get(), // Use this browser. 589ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect(), // Don't request valid bounds. 590ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &window_bounds, 591ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch &out_show_state3); 592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state3); 594f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#else 595ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(ui::SHOW_STATE_DEFAULT, out_show_state3); 596f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 597ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} 598c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_CHROMEOS) 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_PlaceNewWindowsOnMultipleDisplays PlaceNewWindowsOnMultipleDisplays 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// No multiple displays on windows ash. 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_PlaceNewWindowsOnMultipleDisplays DISABLED_PlaceNewWindowsOnMultipleDisplays 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Test the placement of newly created windows on multiple dislays. 607424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindowsOnMultipleDisplays) { 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateDisplay("1600x1200,1600x1200"); 609424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()-> 610424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetPrimaryDisplay().bounds(); 6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds(); 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 613d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ash::Shell::GetInstance()->set_target_root_window( 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ash::Shell::GetPrimaryRootWindow()); 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<TestingProfile> profile(new TestingProfile()); 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create browser windows that are used as reference. 619424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 620424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(0), 621424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(10, 10, 200, 200), 622424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window->Show(); 624424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_EQ(browser_window->GetNativeWindow()->GetRootWindow(), 625d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ash::Shell::GetTargetRootWindow()); 626424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 627424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<BrowserWindow> another_browser_window(CreateTestBrowserWindow( 628424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(1), 629424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(400, 10, 300, 300), 630424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) another_browser_window->Show(); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creating a new window to verify the new placement. 634424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> new_browser_window(CreateTestBrowserWindow( 635424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(0), 636424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), 637424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(profile.get(), 638424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure the primary root is active. 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(), 642d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ash::Shell::GetTargetRootWindow()); 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // First new window should be in the primary. 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect window_bounds; 647424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 648424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), secondary_bounds, 649424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PERSISTED, new_browser_window->browser(), 650424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), &window_bounds); 651424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // TODO(oshima): Use exact bounds when the window_sizer_ash is 652424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // moved to ash and changed to include the result from 653424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // RearrangeVisibleWindowOnShow. 654424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Move the window to the right side of the secondary display and create a new 658424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // window. It should be opened then on the secondary display. 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 660424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Display second_display = ash::Shell::GetScreen()-> 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetDisplayNearestPoint(gfx::Point(1600 + 100,10)); 662424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->GetNativeWindow()->SetBoundsInScreen( 663424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200), 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) second_display); 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window->Activate(); 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE(ash::Shell::GetPrimaryRootWindow(), 667d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ash::Shell::GetTargetRootWindow()); 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect window_bounds; 669424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 670424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), secondary_bounds, 671424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PERSISTED, new_browser_window->browser(), 672424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), &window_bounds); 673424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // TODO(oshima): Use exact bounds when the window_sizer_ash is 674424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // moved to ash and changed to include the result from 675424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // RearrangeVisibleWindowOnShow. 676424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(secondary_bounds.Contains(window_bounds)); 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Activate another window in the primary display and create a new window. 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // It should be created in the primary display. 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) another_browser_window->Activate(); 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(), 684d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ash::Shell::GetTargetRootWindow()); 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect window_bounds; 687424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 688424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), secondary_bounds, 689424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PERSISTED, new_browser_window->browser(), 690424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(), &window_bounds); 691424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // TODO(oshima): Use exact bounds when the window_sizer_ash is 692424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // moved to ash and changed to include the result from 693424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // RearrangeVisibleWindowOnShow. 694424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the show state is properly returned for non default cases. 699424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, TestShowState) { 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TestingProfile> profile(new TestingProfile()); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 702424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Creating a browser & window to play with. 703424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 704424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(0), 705424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 640, 320), 706424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 707424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create also a popup browser since that behaves different. 710424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 711424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(1), 712424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 640, 320), 713424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 714424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tabbed windows should retrieve the saved window state - since there is a 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // top window. 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 722424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_DEFAULT, 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 728424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Non tabbed windows should always follow the window saved visibility state. 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 735424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_popup->browser(), 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The non tabbed window will take the status of the last active of its kind. 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_NORMAL, 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_DEFAULT, 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 742424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_popup->browser(), 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now create a top level window and check again for both. Only the tabbed 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // window should follow the top level window's state. 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a browser & window to play with. 748424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow( 749424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(3), 750424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 640, 320), 751424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 752424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A tabbed window should now take the top level window state. 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_DEFAULT, 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 759424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Non tabbed windows should always follow the window saved visibility state. 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MINIMIZED, 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 766424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_popup->browser(), 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200)); 7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In smaller screen resolutions we default to maximized if there is no other 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // window visible. 7714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2; 7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (min_size > 0) { 7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect tiny_screen(0, 0, min_size, min_size); 7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::SHOW_STATE_DEFAULT, 7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BOTH, 778424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tiny_screen)); 780424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->Hide(); 7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::SHOW_STATE_DEFAULT, 7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BOTH, 785424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window2->browser(), 7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tiny_screen)); 7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the default show state override behavior is properly handled. 792424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSizerAshTest, TestShowStateDefaults) { 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creating a browser & window to play with. 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TestingProfile> profile(new TestingProfile()); 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 796424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 797424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(0), 798424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 640, 320), 799424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 800424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create also a popup browser since that behaves slightly different for 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // defaults. 804424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 805424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateTestWindowInShellWithId(1), 806424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Rect(16, 32, 128, 256), 807424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 808424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH))); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that a browser creation state always get used if not given as 811f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED. 812f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::WindowShowState window_show_state = 813f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 814f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::SHOW_STATE_MAXIMIZED, 815f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DEFAULT, 816f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) browser_window->browser(), 817f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) p1600x1200); 818f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 819f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED); 820f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#else 821f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT); 822f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 823f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 824424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MAXIMIZED, 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 828424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200), ui::SHOW_STATE_MINIMIZED); 830424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MAXIMIZED, 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 834424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200), ui::SHOW_STATE_NORMAL); 836424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED); 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 840424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200), ui::SHOW_STATE_MAXIMIZED); 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that setting the maximized command line option is forcing the 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maximized state. 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized); 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 847424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 851424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_window->browser(), 8522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200), ui::SHOW_STATE_MAXIMIZED); 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The popup should favor the initial show state over the command line. 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_NORMAL, 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOTH, 858424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) browser_popup->browser(), 8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) p1600x1200), ui::SHOW_STATE_NORMAL); 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 861a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 862a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that the target root window is used as the destionation of 863a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the non browser window. This differ from PersistedBoundsCase 864a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// in that this uses real ash shell implementations + StateProvider 865a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// TargetDisplayProvider, rather than mocks. 866a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) { 867a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!SupportsMultipleDisplays() || !chrome::ShouldOpenAshOnStartup()) 868a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 869a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UpdateDisplay("500x500,600x600"); 870a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { 871a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) aura::Window* first_root = 872a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::Shell::GetAllRootWindows()[0]; 873a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::internal::ScopedTargetRootWindow tmp( 874a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) first_root); 875a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect bounds; 876a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::WindowShowState show_state; 877a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) WindowSizer::GetBrowserWindowBoundsAndShowState( 878a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string(), 879a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect(), 880a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NULL, 881a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &bounds, 882a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &show_state); 883a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(first_root->GetBoundsInScreen().Contains(bounds)); 884a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 885a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { 886a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) aura::Window* second_root = 887a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::Shell::GetAllRootWindows()[1]; 888a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::internal::ScopedTargetRootWindow tmp( 889a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) second_root); 890a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect bounds; 891a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::WindowShowState show_state; 892a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) WindowSizer::GetBrowserWindowBoundsAndShowState( 893a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string(), 894a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect(), 895a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NULL, 896a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &bounds, 897a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &show_state); 898a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds)); 899a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 900a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 901