Index: chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc |
diff --git a/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc b/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc |
index 4cb09de078633a5d81b45e6d22d2022ad02ecd9c..13cba501db70af093291a0f95a11de2175ec071e 100644 |
--- a/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc |
+++ b/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc |
@@ -2,57 +2,27 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/window_sizer/window_sizer.h" |
- |
-#include <vector> |
+#include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" |
#include "ash/shell.h" |
#include "ash/test/ash_test_base.h" |
#include "ash/test/test_shell_delegate.h" |
#include "ash/wm/window_resizer.h" |
#include "base/compiler_specific.h" |
-#include "base/logging.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 "chrome/test/base/test_browser_window.h" |
-#include "content/public/browser/browser_thread.h" |
#include "content/public/test/render_view_test.h" |
-#include "content/public/test/test_browser_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
#include "ui/aura/env.h" |
#include "ui/aura/root_window.h" |
#include "ui/aura/test/test_windows.h" |
- |
-namespace { |
+#include "ui/aura/client/aura_constants.h" |
sky
2012/10/08 21:01:25
sort
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
typedef ash::test::AshTestBase WindowSizerTest; |
-// A special test class for use with browser creation - it will create a |
-// browser thread and deletes it after all other things have been destroyed. |
-class WindowSizerTestWithBrowser : public WindowSizerTest { |
- public: |
- WindowSizerTestWithBrowser(); |
- virtual ~WindowSizerTestWithBrowser(); |
- |
- private: |
- // Note: It is important to delete the thread after the browser instances got |
- // deleted. For this we transfer the thread here. |
- scoped_ptr<content::TestBrowserThread> ui_thread_; |
- |
- DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser); |
-}; |
- |
-WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() { |
- // Set up a UI message thread. |
- MessageLoopForUI* ui_loop = message_loop(); |
- ui_thread_.reset( |
- new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); |
-} |
- |
-WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() { |
-} |
+namespace { |
// A browser window proxy which is able to associate an aura native window with |
// it. |
@@ -61,34 +31,63 @@ class TestBrowserWindowAura : public TestBrowserWindow { |
explicit TestBrowserWindowAura(aura::Window* native_window); |
virtual ~TestBrowserWindowAura(); |
- virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { |
- return native_window_; |
- } |
+ virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; |
- virtual gfx::Rect GetBounds() const { |
- return native_window_->bounds(); |
- } |
+ virtual gfx::Rect GetBounds() const OVERRIDE; |
private: |
- gfx::NativeWindow native_window_; |
+ aura::Window* native_window_; |
sky
2012/10/08 21:01:25
Document ownership.
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); |
}; |
-} // namespace |
- |
TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) |
: native_window_(native_window) { |
} |
TestBrowserWindowAura::~TestBrowserWindowAura() {} |
+gfx::NativeWindow TestBrowserWindowAura::GetNativeWindow() { |
+ return native_window_; |
+} |
+ |
+gfx::Rect TestBrowserWindowAura::GetBounds() const { |
+ return native_window_->bounds(); |
+} |
+ |
int AlignToGridRoundDown(int location, int grid_size) { |
if (grid_size <= 1 || location % grid_size == 0) |
return location; |
return location / grid_size * grid_size; |
} |
+// A special test class for use with browser creation - it will create a |
+// browser thread and deletes it after all other things have been destroyed. |
+class WindowSizerTestWithBrowser : public WindowSizerTest { |
+ public: |
+ WindowSizerTestWithBrowser(); |
+ virtual ~WindowSizerTestWithBrowser(); |
+ |
+ private: |
+ // Note: It is important to delete the thread after the browser instances got |
+ // deleted. For this we transfer the thread here. |
+ scoped_ptr<content::TestBrowserThread> ui_thread_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser); |
+}; |
+ |
+// The class function definitions from window_sizer_common_unittest.h |
+WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() { |
+ // Set up a UI message thread. |
+ MessageLoopForUI* ui_loop = message_loop(); |
+ ui_thread_.reset( |
+ new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); |
+} |
+ |
+WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() { |
+} |
+ |
+} |
// Test that the window is sized appropriately for the first run experience |
// where the default window bounds calculation is invoked. |
TEST_F(WindowSizerTest, DefaultSizeCase) { |
@@ -763,3 +762,147 @@ TEST_F(WindowSizerTest, AdjustFitSize) { |
EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
} |
} |
+ |
+// Test that the show state is properly returned for non default cases. |
+TEST_F(WindowSizerTestWithBrowser, TestShowState) { |
+ // Creating a browser & window to play with. |
+ scoped_ptr<aura::Window> window( |
+ aura::test::CreateTestWindowWithId(0, NULL)); |
+ window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
+ |
+ scoped_ptr<TestingProfile> profile(new TestingProfile()); |
+ |
+ scoped_ptr<BrowserWindow> browser_window( |
+ new TestBrowserWindowAura(window.get())); |
+ Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get()); |
+ window_params.window = browser_window.get(); |
+ scoped_ptr<Browser> browser(new Browser(window_params)); |
+ |
+ // Create also a popup browser since that behaves different. |
+ scoped_ptr<aura::Window> popup( |
+ aura::test::CreateTestWindowWithId(1, NULL)); |
+ popup->SetBounds(gfx::Rect(16, 32, 128, 256)); |
+ |
+ scoped_ptr<BrowserWindow> browser_popup( |
+ new TestBrowserWindowAura(popup.get())); |
+ Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get()); |
+ popup_params.window = browser_window.get(); |
+ scoped_ptr<Browser> popup_browser(new Browser(popup_params)); |
+ |
+ // Tabbed windows should retrieve the saved window state - since there is a |
+ // top window. |
+ EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
+ GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ browser.get())); |
+ EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
+ GetWindowShowState(ui::SHOW_STATE_DEFAULT, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ browser.get())); |
+ // Non tabbed windows should always follow the window saved visibility state. |
+ EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
+ GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ popup_browser.get())); |
+ // The non tabbed window will take the status of the last active of its kind. |
+ EXPECT_EQ(ui::SHOW_STATE_NORMAL, |
+ GetWindowShowState(ui::SHOW_STATE_DEFAULT, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ popup_browser.get())); |
+ |
+ // Now create a top level window and check again for both. Only the tabbed |
+ // window should follow the top level window's state. |
+ // Creating a browser & window to play with. |
+ scoped_ptr<aura::Window> window2( |
+ aura::test::CreateTestWindowWithId(0, NULL)); |
+ window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
+ |
+ scoped_ptr<BrowserWindow> browser_window2( |
+ new TestBrowserWindowAura(window2.get())); |
+ Browser::CreateParams window2_params(Browser::TYPE_TABBED, profile.get()); |
+ window2_params.window = browser_window2.get(); |
+ scoped_ptr<Browser> browser2(new Browser(window2_params)); |
+ |
+ // A tabbed window should now take the top level window state. |
+ EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
+ GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_DEFAULT, |
+ BOTH, |
+ browser2.get())); |
+ // Non tabbed windows should always follow the window saved visibility state. |
+ EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
+ GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_MINIMIZED, |
+ BOTH, |
+ popup_browser.get())); |
+} |
+ |
+// Test that the default show state override behavior is properly handled. |
+TEST_F(WindowSizerTestWithBrowser, TestShowStateDefaults) { |
+ // Creating a browser & window to play with. |
+ scoped_ptr<aura::Window> window( |
+ aura::test::CreateTestWindowWithId(0, NULL)); |
+ window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
+ |
+ scoped_ptr<TestingProfile> profile(new TestingProfile()); |
+ |
+ scoped_ptr<BrowserWindow> browser_window( |
+ new TestBrowserWindowAura(window.get())); |
+ Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get()); |
+ window_params.window = browser_window.get(); |
+ scoped_ptr<Browser> browser(new Browser(window_params)); |
+ |
+ // Create also a popup browser since that behaves slightly different for |
+ // defaults. |
+ scoped_ptr<aura::Window> popup( |
+ aura::test::CreateTestWindowWithId(1, NULL)); |
+ popup->SetBounds(gfx::Rect(16, 32, 128, 256)); |
+ |
+ scoped_ptr<BrowserWindow> browser_popup( |
+ new TestBrowserWindowAura(popup.get())); |
+ Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get()); |
+ popup_params.window = browser_window.get(); |
+ scoped_ptr<Browser> popup_browser(new Browser(popup_params)); |
+ |
+ // Check that a browser creation state always get used if not given as |
+ // SHOW_STATE_DEFAULT. |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_MAXIMIZED, |
+ DEFAULT, |
+ browser.get()), ui::SHOW_STATE_DEFAULT); |
+ browser->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_MAXIMIZED, |
+ BOTH, |
+ browser.get()), ui::SHOW_STATE_MINIMIZED); |
+ browser->set_initial_show_state(ui::SHOW_STATE_NORMAL); |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
+ ui::SHOW_STATE_MAXIMIZED, |
+ BOTH, |
+ browser.get()), ui::SHOW_STATE_NORMAL); |
+ browser->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED); |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ browser.get()), ui::SHOW_STATE_MAXIMIZED); |
+ |
+ // Check that setting the maximized command line option is forcing the |
+ // maximized state. |
+ CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized); |
+ |
+ browser->set_initial_show_state(ui::SHOW_STATE_NORMAL); |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ browser.get()), ui::SHOW_STATE_MAXIMIZED); |
+ |
+ // The popup should favor the initial show state over the command line. |
+ EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
+ ui::SHOW_STATE_NORMAL, |
+ BOTH, |
+ popup_browser.get()), ui::SHOW_STATE_NORMAL); |
+} |