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

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: 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"
11 #include "ash/test/test_shell_delegate.h" 8 #include "ash/test/test_shell_delegate.h"
12 #include "ash/wm/window_resizer.h" 9 #include "ash/wm/window_resizer.h"
13 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" 12 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/testing_profile.h" 13 #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" 14 #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" 15 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
24 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
25 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
26 #include "ui/aura/test/test_windows.h" 19 #include "ui/aura/test/test_windows.h"
27 20 #include "ui/aura/client/aura_constants.h"
28 namespace {
29
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
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 }
83
84 TestBrowserWindowAura::~TestBrowserWindowAura() {}
85 21
86 int AlignToGridRoundDown(int location, int grid_size) { 22 int AlignToGridRoundDown(int location, int grid_size) {
87 if (grid_size <= 1 || location % grid_size == 0) 23 if (grid_size <= 1 || location % grid_size == 0)
88 return location; 24 return location;
89 return location / grid_size * grid_size; 25 return location / grid_size * grid_size;
90 } 26 }
91 27
92 // Test that the window is sized appropriately for the first run experience 28 // Test that the window is sized appropriately for the first run experience
93 // where the default window bounds calculation is invoked. 29 // where the default window bounds calculation is invoked.
94 TEST_F(WindowSizerTest, DefaultSizeCase) { 30 TEST_F(WindowSizerTest, DefaultSizeCase) {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } 692 }
757 693
758 { // Check that a window which hangs out of the screen get moved back in. 694 { // Check that a window which hangs out of the screen get moved back in.
759 gfx::Rect window_bounds; 695 gfx::Rect window_bounds;
760 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), 696 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(),
761 gfx::Rect(), DEFAULT, &window_bounds, NULL, 697 gfx::Rect(), DEFAULT, &window_bounds, NULL,
762 gfx::Rect(1020, 700, 100, 100)); 698 gfx::Rect(1020, 700, 100, 100));
763 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); 699 EXPECT_EQ("924,668 100x100", window_bounds.ToString());
764 } 700 }
765 } 701 }
702
703 // Test that the show state is properly returned for non default cases.
704 TEST_F(WindowSizerTestWithBrowser, TestShowState) {
705 // Creating a browser & window to play with.
706 scoped_ptr<aura::Window> window(
707 aura::test::CreateTestWindowWithId(0, NULL));
708 window->SetBounds(gfx::Rect(16, 32, 640, 320));
709
710 scoped_ptr<TestingProfile> profile(new TestingProfile());
711
712 scoped_ptr<BrowserWindow> browser_window(
713 new TestBrowserWindowAura(window.get()));
714 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get());
715 window_params.window = browser_window.get();
716 scoped_ptr<Browser> browser(new Browser(window_params));
717
718 // Create also a popup browser since that behaves different.
719 scoped_ptr<aura::Window> popup(
720 aura::test::CreateTestWindowWithId(1, NULL));
721 popup->SetBounds(gfx::Rect(16, 32, 128, 256));
722
723 scoped_ptr<BrowserWindow> browser_popup(
724 new TestBrowserWindowAura(popup.get()));
725 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get());
726 popup_params.window = browser_window.get();
727 scoped_ptr<Browser> popup_browser(new Browser(popup_params));
728
729 // Tabbed windows should retrieve the saved window state - since there is a
730 // top window.
731 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
732 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
733 ui::SHOW_STATE_NORMAL,
734 BOTH,
735 browser.get()));
736 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
737 GetWindowShowState(ui::SHOW_STATE_DEFAULT,
738 ui::SHOW_STATE_NORMAL,
739 BOTH,
740 browser.get()));
741 // Non tabbed windows should always follow the window saved visibility state.
742 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
743 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
744 ui::SHOW_STATE_NORMAL,
745 BOTH,
746 popup_browser.get()));
747 // The non tabbed window will take the status of the last active of its kind.
748 EXPECT_EQ(ui::SHOW_STATE_NORMAL,
749 GetWindowShowState(ui::SHOW_STATE_DEFAULT,
750 ui::SHOW_STATE_NORMAL,
751 BOTH,
752 popup_browser.get()));
753
754 // Now create a top level window and check again for both. Only the tabbed
755 // window should follow the top level window's state.
756 // Creating a browser & window to play with.
757 scoped_ptr<aura::Window> window2(
758 aura::test::CreateTestWindowWithId(0, NULL));
759 window->SetBounds(gfx::Rect(16, 32, 640, 320));
760
761 scoped_ptr<BrowserWindow> browser_window2(
762 new TestBrowserWindowAura(window2.get()));
763 Browser::CreateParams window2_params(Browser::TYPE_TABBED, profile.get());
764 window2_params.window = browser_window2.get();
765 scoped_ptr<Browser> browser2(new Browser(window2_params));
766
767 // A tabbed window should now take the top level window state.
768 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
769 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
770 ui::SHOW_STATE_DEFAULT,
771 BOTH,
772 browser2.get()));
773 // Non tabbed windows should always follow the window saved visibility state.
774 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
775 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
776 ui::SHOW_STATE_MINIMIZED,
777 BOTH,
778 popup_browser.get()));
779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698