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

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

Powered by Google App Engine
This is Rietveld 408576698