OLD | NEW |
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 "ash/wm/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/test_shell_delegate.h" | 9 #include "ash/test/test_shell_delegate.h" |
10 #include "ash/wm/window_resizer.h" | 10 #include "ash/wm/window_resizer.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/host_desktop.h" | 14 #include "chrome/browser/ui/host_desktop.h" |
15 #include "chrome/test/base/test_browser_window.h" | 15 #include "chrome/test/base/test_browser_window_aura.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/render_view_test.h" | 17 #include "content/public/test/render_view_test.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
20 #include "ui/aura/test/test_windows.h" | 20 #include "ui/aura/test/test_windows.h" |
21 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 namespace test { | 25 namespace test { |
26 | 26 |
27 namespace { | |
28 | |
29 // A browser window proxy which is able to associate an aura native window with | |
30 // it. | |
31 class TestBrowserWindowAura : public TestBrowserWindow { | |
32 public: | |
33 explicit TestBrowserWindowAura(aura::Window* native_window); | |
34 ~TestBrowserWindowAura() override; | |
35 | |
36 gfx::NativeWindow GetNativeWindow() const override { return native_window_; } | |
37 | |
38 private: | |
39 gfx::NativeWindow native_window_; | |
40 | |
41 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); | |
42 }; | |
43 | |
44 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) | |
45 : native_window_(native_window) { | |
46 } | |
47 | |
48 TestBrowserWindowAura::~TestBrowserWindowAura() {} | |
49 | |
50 } // namespace | |
51 | |
52 // A test class for preparing window positioner tests - it creates a testing | 27 // A test class for preparing window positioner tests - it creates a testing |
53 // base by adding a window and a popup which can be independently | 28 // base by adding a window and a popup which can be independently |
54 // positioned to see where the positioner will place the window. | 29 // positioned to see where the positioner will place the window. |
55 class WindowPositionerTest : public AshTestBase { | 30 class WindowPositionerTest : public AshTestBase { |
56 public: | 31 public: |
57 WindowPositionerTest(); | 32 WindowPositionerTest(); |
58 | 33 |
59 void SetUp() override; | 34 void SetUp() override; |
60 void TearDown() override; | 35 void TearDown() override; |
61 | 36 |
62 protected: | 37 protected: |
63 aura::Window* window() { return window_.get(); } | 38 aura::Window* window() { return browser_->window()->GetNativeWindow(); } |
64 aura::Window* popup() { return popup_.get(); } | 39 aura::Window* popup() { return browser_popup_->window()->GetNativeWindow(); } |
65 | 40 |
66 Browser* window_browser() { return window_owning_browser_.get(); } | 41 WindowPositioner* window_positioner() { return window_positioner_.get(); } |
67 Browser* popup_browser() { return popup_owning_browser_.get(); } | |
68 | |
69 WindowPositioner* window_positioner() { return window_positioner_; } | |
70 | 42 |
71 // The positioner & desktop's used grid alignment size. | 43 // The positioner & desktop's used grid alignment size. |
72 const int grid_size_; | 44 const int grid_size_; |
73 | 45 |
74 private: | 46 private: |
75 WindowPositioner* window_positioner_; | 47 scoped_ptr<WindowPositioner> window_positioner_; |
76 | 48 |
77 // These two need to be deleted after everything else is gone. | |
78 TestingProfile profile_; | 49 TestingProfile profile_; |
79 | 50 |
80 // These get created for each session. | 51 scoped_ptr<Browser> browser_; |
81 scoped_ptr<aura::Window> window_; | 52 scoped_ptr<Browser> browser_popup_; |
82 scoped_ptr<aura::Window> popup_; | |
83 | |
84 scoped_ptr<BrowserWindow> browser_window_; | |
85 scoped_ptr<BrowserWindow> browser_popup_; | |
86 | |
87 scoped_ptr<Browser> window_owning_browser_; | |
88 scoped_ptr<Browser> popup_owning_browser_; | |
89 | 53 |
90 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest); | 54 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest); |
91 }; | 55 }; |
92 | 56 |
93 WindowPositionerTest::WindowPositionerTest() | 57 WindowPositionerTest::WindowPositionerTest() |
94 : grid_size_(WindowPositioner::kMinimumWindowOffset), | 58 : grid_size_(WindowPositioner::kMinimumWindowOffset) {} |
95 window_positioner_(NULL) { | |
96 } | |
97 | 59 |
98 void WindowPositionerTest::SetUp() { | 60 void WindowPositionerTest::SetUp() { |
99 AshTestBase::SetUp(); | 61 AshTestBase::SetUp(); |
100 // Create some default dummy windows. | 62 // Create some default dummy windows. |
101 window_.reset(CreateTestWindowInShellWithId(0)); | 63 scoped_ptr<aura::Window> dummy_window(CreateTestWindowInShellWithId(0)); |
102 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); | 64 dummy_window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
103 popup_.reset(CreateTestWindowInShellWithId(1)); | 65 scoped_ptr<aura::Window> dummy_popup(CreateTestWindowInShellWithId(1)); |
104 popup_->SetBounds(gfx::Rect(16, 32, 128, 256)); | 66 dummy_popup->SetBounds(gfx::Rect(16, 32, 128, 256)); |
105 | 67 |
106 // Create a browser for the window. | 68 // Create a browser for the window. |
107 browser_window_.reset(new TestBrowserWindowAura(window_.get())); | |
108 Browser::CreateParams window_params(&profile_, | 69 Browser::CreateParams window_params(&profile_, |
109 chrome::HOST_DESKTOP_TYPE_ASH); | 70 chrome::HOST_DESKTOP_TYPE_ASH); |
110 window_params.window = browser_window_.get(); | 71 browser_ = chrome::CreateBrowserWithAuraTestWindowForParams( |
111 window_owning_browser_.reset(new Browser(window_params)); | 72 dummy_window.Pass(), &window_params); |
112 | 73 |
113 // Creating a browser for the popup. | 74 // Creating a browser for the popup. |
114 browser_popup_.reset(new TestBrowserWindowAura(popup_.get())); | |
115 Browser::CreateParams popup_params(Browser::TYPE_POPUP, &profile_, | 75 Browser::CreateParams popup_params(Browser::TYPE_POPUP, &profile_, |
116 chrome::HOST_DESKTOP_TYPE_ASH); | 76 chrome::HOST_DESKTOP_TYPE_ASH); |
117 popup_params.window = browser_popup_.get(); | 77 browser_popup_ = chrome::CreateBrowserWithAuraTestWindowForParams( |
118 popup_owning_browser_.reset(new Browser(popup_params)); | 78 dummy_popup.Pass(), &popup_params); |
119 | 79 |
120 // We hide all windows upon start - each user is required to set it up | 80 // We hide all windows upon start - each user is required to set it up |
121 // as he needs it. | 81 // as he needs it. |
122 window()->Hide(); | 82 window()->Hide(); |
123 popup()->Hide(); | 83 popup()->Hide(); |
124 window_positioner_ = new WindowPositioner(); | 84 window_positioner_.reset(new WindowPositioner()); |
125 } | 85 } |
126 | 86 |
127 void WindowPositionerTest::TearDown() { | 87 void WindowPositionerTest::TearDown() { |
128 // Since the AuraTestBase is needed to create our assets, we have to | 88 // Since the AuraTestBase is needed to create our assets, we have to |
129 // also delete them before we tear it down. | 89 // also delete them before we tear it down. |
130 window_owning_browser_.reset(NULL); | 90 browser_.reset(); |
131 popup_owning_browser_.reset(NULL); | 91 browser_popup_.reset(); |
132 | 92 window_positioner_.reset(); |
133 browser_window_.reset(NULL); | |
134 browser_popup_.reset(NULL); | |
135 | |
136 window_.reset(NULL); | |
137 popup_.reset(NULL); | |
138 | |
139 AshTestBase::TearDown(); | 93 AshTestBase::TearDown(); |
140 delete window_positioner_; | |
141 window_positioner_ = NULL; | |
142 } | 94 } |
143 | 95 |
144 int AlignToGridRoundDown(int location, int grid_size) { | 96 int AlignToGridRoundDown(int location, int grid_size) { |
145 if (grid_size <= 1 || location % grid_size == 0) | 97 if (grid_size <= 1 || location % grid_size == 0) |
146 return location; | 98 return location; |
147 return location / grid_size * grid_size; | 99 return location / grid_size * grid_size; |
148 } | 100 } |
149 | 101 |
150 TEST_F(WindowPositionerTest, cascading) { | 102 TEST_F(WindowPositionerTest, cascading) { |
151 const gfx::Rect work_area = | 103 const gfx::Rect work_area = |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 223 |
272 // Check that the popup is placed full screen. | 224 // Check that the popup is placed full screen. |
273 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 225 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
274 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 226 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
275 pop_position.width(), pop_position.height()), | 227 pop_position.width(), pop_position.height()), |
276 full); | 228 full); |
277 } | 229 } |
278 | 230 |
279 } // namespace test | 231 } // namespace test |
280 } // namespace ash | 232 } // namespace ash |
OLD | NEW |