Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc

Issue 11072002: Combined window positioning and show state determiniation in the WindowSizer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More include issues Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/window_sizer/window_sizer.h" 5 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h"
6
7 #include <vector>
8 6
9 #include "ash/shell.h" 7 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_shell_delegate.h" 9 #include "ash/test/test_shell_delegate.h"
12 #include "ash/wm/window_resizer.h" 10 #include "ash/wm/window_resizer.h"
13 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" 13 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/test_browser_window.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/render_view_test.h" 15 #include "content/public/test/render_view_test.h"
21 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
24 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
25 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
26 #include "ui/aura/test/test_windows.h" 20 #include "ui/aura/test/test_windows.h"
21 #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.
22
23 typedef ash::test::AshTestBase WindowSizerTest;
27 24
28 namespace { 25 namespace {
29 26
30 typedef ash::test::AshTestBase WindowSizerTest;
31
32 // A special test class for use with browser creation - it will create a
33 // browser thread and deletes it after all other things have been destroyed.
34 class WindowSizerTestWithBrowser : public WindowSizerTest {
35 public:
36 WindowSizerTestWithBrowser();
37 virtual ~WindowSizerTestWithBrowser();
38
39 private:
40 // Note: It is important to delete the thread after the browser instances got
41 // deleted. For this we transfer the thread here.
42 scoped_ptr<content::TestBrowserThread> ui_thread_;
43
44 DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser);
45 };
46
47 WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() {
48 // Set up a UI message thread.
49 MessageLoopForUI* ui_loop = message_loop();
50 ui_thread_.reset(
51 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
52 }
53
54 WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() {
55 }
56
57 // A browser window proxy which is able to associate an aura native window with 27 // A browser window proxy which is able to associate an aura native window with
58 // it. 28 // it.
59 class TestBrowserWindowAura : public TestBrowserWindow { 29 class TestBrowserWindowAura : public TestBrowserWindow {
60 public: 30 public:
61 explicit TestBrowserWindowAura(aura::Window* native_window); 31 explicit TestBrowserWindowAura(aura::Window* native_window);
62 virtual ~TestBrowserWindowAura(); 32 virtual ~TestBrowserWindowAura();
63 33
64 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { 34 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
65 return native_window_;
66 }
67 35
68 virtual gfx::Rect GetBounds() const { 36 virtual gfx::Rect GetBounds() const OVERRIDE;
69 return native_window_->bounds();
70 }
71 37
72 private: 38 private:
73 gfx::NativeWindow native_window_; 39 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.
74 40
75 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); 41 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
76 }; 42 };
77 43
78 } // namespace
79
80 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) 44 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window)
81 : native_window_(native_window) { 45 : native_window_(native_window) {
82 } 46 }
83 47
84 TestBrowserWindowAura::~TestBrowserWindowAura() {} 48 TestBrowserWindowAura::~TestBrowserWindowAura() {}
85 49
50 gfx::NativeWindow TestBrowserWindowAura::GetNativeWindow() {
51 return native_window_;
52 }
53
54 gfx::Rect TestBrowserWindowAura::GetBounds() const {
55 return native_window_->bounds();
56 }
57
86 int AlignToGridRoundDown(int location, int grid_size) { 58 int AlignToGridRoundDown(int location, int grid_size) {
87 if (grid_size <= 1 || location % grid_size == 0) 59 if (grid_size <= 1 || location % grid_size == 0)
88 return location; 60 return location;
89 return location / grid_size * grid_size; 61 return location / grid_size * grid_size;
90 } 62 }
91 63
64 // A special test class for use with browser creation - it will create a
65 // browser thread and deletes it after all other things have been destroyed.
66 class WindowSizerTestWithBrowser : public WindowSizerTest {
67 public:
68 WindowSizerTestWithBrowser();
69 virtual ~WindowSizerTestWithBrowser();
70
71 private:
72 // Note: It is important to delete the thread after the browser instances got
73 // deleted. For this we transfer the thread here.
74 scoped_ptr<content::TestBrowserThread> ui_thread_;
75
76 DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser);
77 };
78
79 // The class function definitions from window_sizer_common_unittest.h
80 WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() {
81 // Set up a UI message thread.
82 MessageLoopForUI* ui_loop = message_loop();
83 ui_thread_.reset(
84 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
85 }
86
87 WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() {
88 }
89
90 }
92 // Test that the window is sized appropriately for the first run experience 91 // Test that the window is sized appropriately for the first run experience
93 // where the default window bounds calculation is invoked. 92 // where the default window bounds calculation is invoked.
94 TEST_F(WindowSizerTest, DefaultSizeCase) { 93 TEST_F(WindowSizerTest, DefaultSizeCase) {
95 int grid = WindowSizer::kDesktopBorderSize; 94 int grid = WindowSizer::kDesktopBorderSize;
96 { // 4:3 monitor case, 1024x768, no taskbar 95 { // 4:3 monitor case, 1024x768, no taskbar
97 gfx::Rect window_bounds; 96 gfx::Rect window_bounds;
98 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), 97 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(),
99 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); 98 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect());
100 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, 99 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize,
101 WindowSizer::kDesktopBorderSize, 100 WindowSizer::kDesktopBorderSize,
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } 755 }
757 756
758 { // Check that a window which hangs out of the screen get moved back in. 757 { // Check that a window which hangs out of the screen get moved back in.
759 gfx::Rect window_bounds; 758 gfx::Rect window_bounds;
760 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), 759 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(),
761 gfx::Rect(), DEFAULT, &window_bounds, NULL, 760 gfx::Rect(), DEFAULT, &window_bounds, NULL,
762 gfx::Rect(1020, 700, 100, 100)); 761 gfx::Rect(1020, 700, 100, 100));
763 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); 762 EXPECT_EQ("924,668 100x100", window_bounds.ToString());
764 } 763 }
765 } 764 }
765
766 // Test that the show state is properly returned for non default cases.
767 TEST_F(WindowSizerTestWithBrowser, TestShowState) {
768 // Creating a browser & window to play with.
769 scoped_ptr<aura::Window> window(
770 aura::test::CreateTestWindowWithId(0, NULL));
771 window->SetBounds(gfx::Rect(16, 32, 640, 320));
772
773 scoped_ptr<TestingProfile> profile(new TestingProfile());
774
775 scoped_ptr<BrowserWindow> browser_window(
776 new TestBrowserWindowAura(window.get()));
777 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get());
778 window_params.window = browser_window.get();
779 scoped_ptr<Browser> browser(new Browser(window_params));
780
781 // Create also a popup browser since that behaves different.
782 scoped_ptr<aura::Window> popup(
783 aura::test::CreateTestWindowWithId(1, NULL));
784 popup->SetBounds(gfx::Rect(16, 32, 128, 256));
785
786 scoped_ptr<BrowserWindow> browser_popup(
787 new TestBrowserWindowAura(popup.get()));
788 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get());
789 popup_params.window = browser_window.get();
790 scoped_ptr<Browser> popup_browser(new Browser(popup_params));
791
792 // Tabbed windows should retrieve the saved window state - since there is a
793 // top window.
794 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
795 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
796 ui::SHOW_STATE_NORMAL,
797 BOTH,
798 browser.get()));
799 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
800 GetWindowShowState(ui::SHOW_STATE_DEFAULT,
801 ui::SHOW_STATE_NORMAL,
802 BOTH,
803 browser.get()));
804 // Non tabbed windows should always follow the window saved visibility state.
805 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
806 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
807 ui::SHOW_STATE_NORMAL,
808 BOTH,
809 popup_browser.get()));
810 // The non tabbed window will take the status of the last active of its kind.
811 EXPECT_EQ(ui::SHOW_STATE_NORMAL,
812 GetWindowShowState(ui::SHOW_STATE_DEFAULT,
813 ui::SHOW_STATE_NORMAL,
814 BOTH,
815 popup_browser.get()));
816
817 // Now create a top level window and check again for both. Only the tabbed
818 // window should follow the top level window's state.
819 // Creating a browser & window to play with.
820 scoped_ptr<aura::Window> window2(
821 aura::test::CreateTestWindowWithId(0, NULL));
822 window->SetBounds(gfx::Rect(16, 32, 640, 320));
823
824 scoped_ptr<BrowserWindow> browser_window2(
825 new TestBrowserWindowAura(window2.get()));
826 Browser::CreateParams window2_params(Browser::TYPE_TABBED, profile.get());
827 window2_params.window = browser_window2.get();
828 scoped_ptr<Browser> browser2(new Browser(window2_params));
829
830 // A tabbed window should now take the top level window state.
831 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
832 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
833 ui::SHOW_STATE_DEFAULT,
834 BOTH,
835 browser2.get()));
836 // Non tabbed windows should always follow the window saved visibility state.
837 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
838 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
839 ui::SHOW_STATE_MINIMIZED,
840 BOTH,
841 popup_browser.get()));
842 }
843
844 // Test that the default show state override behavior is properly handled.
845 TEST_F(WindowSizerTestWithBrowser, TestShowStateDefaults) {
846 // Creating a browser & window to play with.
847 scoped_ptr<aura::Window> window(
848 aura::test::CreateTestWindowWithId(0, NULL));
849 window->SetBounds(gfx::Rect(16, 32, 640, 320));
850
851 scoped_ptr<TestingProfile> profile(new TestingProfile());
852
853 scoped_ptr<BrowserWindow> browser_window(
854 new TestBrowserWindowAura(window.get()));
855 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get());
856 window_params.window = browser_window.get();
857 scoped_ptr<Browser> browser(new Browser(window_params));
858
859 // Create also a popup browser since that behaves slightly different for
860 // defaults.
861 scoped_ptr<aura::Window> popup(
862 aura::test::CreateTestWindowWithId(1, NULL));
863 popup->SetBounds(gfx::Rect(16, 32, 128, 256));
864
865 scoped_ptr<BrowserWindow> browser_popup(
866 new TestBrowserWindowAura(popup.get()));
867 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get());
868 popup_params.window = browser_window.get();
869 scoped_ptr<Browser> popup_browser(new Browser(popup_params));
870
871 // Check that a browser creation state always get used if not given as
872 // SHOW_STATE_DEFAULT.
873 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
874 ui::SHOW_STATE_MAXIMIZED,
875 DEFAULT,
876 browser.get()), ui::SHOW_STATE_DEFAULT);
877 browser->set_initial_show_state(ui::SHOW_STATE_MINIMIZED);
878 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
879 ui::SHOW_STATE_MAXIMIZED,
880 BOTH,
881 browser.get()), ui::SHOW_STATE_MINIMIZED);
882 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
883 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
884 ui::SHOW_STATE_MAXIMIZED,
885 BOTH,
886 browser.get()), ui::SHOW_STATE_NORMAL);
887 browser->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
888 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
889 ui::SHOW_STATE_NORMAL,
890 BOTH,
891 browser.get()), ui::SHOW_STATE_MAXIMIZED);
892
893 // Check that setting the maximized command line option is forcing the
894 // maximized state.
895 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized);
896
897 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
898 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
899 ui::SHOW_STATE_NORMAL,
900 BOTH,
901 browser.get()), ui::SHOW_STATE_MAXIMIZED);
902
903 // The popup should favor the initial show state over the command line.
904 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
905 ui::SHOW_STATE_NORMAL,
906 BOTH,
907 popup_browser.get()), ui::SHOW_STATE_NORMAL);
908 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698