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 "chrome/browser/ui/ash/window_positioner.h" | 5 #include "chrome/browser/ui/ash/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.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/test/render_view_test.h" | 18 #include "content/public/test/render_view_test.h" |
19 #include "content/public/test/test_browser_thread.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
22 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/test_windows.h" | 22 #include "ui/aura/test/test_windows.h" |
24 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
25 | 24 |
26 namespace ash { | 25 namespace ash { |
27 namespace test { | 26 namespace test { |
28 | 27 |
29 namespace { | 28 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
52 TestBrowserWindowAura::~TestBrowserWindowAura() {} | 51 TestBrowserWindowAura::~TestBrowserWindowAura() {} |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 // A test class for preparing window positioner tests - it creates a testing | 55 // A test class for preparing window positioner tests - it creates a testing |
57 // base by adding a window and a popup which can be independently | 56 // base by adding a window and a popup which can be independently |
58 // positioned to see where the positioner will place the window. | 57 // positioned to see where the positioner will place the window. |
59 class WindowPositionerTest : public AshTestBase { | 58 class WindowPositionerTest : public AshTestBase { |
60 public: | 59 public: |
61 WindowPositionerTest(); | 60 WindowPositionerTest(); |
62 virtual ~WindowPositionerTest(); | |
63 | 61 |
64 virtual void SetUp() OVERRIDE; | 62 virtual void SetUp() OVERRIDE; |
65 virtual void TearDown() OVERRIDE; | 63 virtual void TearDown() OVERRIDE; |
66 | 64 |
67 protected: | 65 protected: |
68 aura::Window* window() { return window_.get(); } | 66 aura::Window* window() { return window_.get(); } |
69 aura::Window* popup() { return popup_.get(); } | 67 aura::Window* popup() { return popup_.get(); } |
70 | 68 |
71 Browser* window_browser() { return window_owning_browser_.get(); } | 69 Browser* window_browser() { return window_owning_browser_.get(); } |
72 Browser* popup_browser() { return popup_owning_browser_.get(); } | 70 Browser* popup_browser() { return popup_owning_browser_.get(); } |
73 | 71 |
74 WindowPositioner* window_positioner() { return window_positioner_; } | 72 WindowPositioner* window_positioner() { return window_positioner_; } |
75 | 73 |
76 // The positioner & desktop's used grid alignment size. | 74 // The positioner & desktop's used grid alignment size. |
77 const int grid_size_; | 75 const int grid_size_; |
78 | 76 |
79 private: | 77 private: |
80 WindowPositioner* window_positioner_; | 78 WindowPositioner* window_positioner_; |
81 | 79 |
82 // These two need to be deleted after everything else is gone. | 80 // These two need to be deleted after everything else is gone. |
83 scoped_ptr<content::TestBrowserThread> ui_thread_; | 81 TestingProfile profile_; |
84 scoped_ptr<TestingProfile> profile_; | |
85 | 82 |
86 // These get created for each session. | 83 // These get created for each session. |
87 scoped_ptr<aura::Window> window_; | 84 scoped_ptr<aura::Window> window_; |
88 scoped_ptr<aura::Window> popup_; | 85 scoped_ptr<aura::Window> popup_; |
89 | 86 |
90 scoped_ptr<BrowserWindow> browser_window_; | 87 scoped_ptr<BrowserWindow> browser_window_; |
91 scoped_ptr<BrowserWindow> browser_popup_; | 88 scoped_ptr<BrowserWindow> browser_popup_; |
92 | 89 |
93 scoped_ptr<Browser> window_owning_browser_; | 90 scoped_ptr<Browser> window_owning_browser_; |
94 scoped_ptr<Browser> popup_owning_browser_; | 91 scoped_ptr<Browser> popup_owning_browser_; |
95 | 92 |
96 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest); | 93 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest); |
97 }; | 94 }; |
98 | 95 |
99 WindowPositionerTest::WindowPositionerTest() | 96 WindowPositionerTest::WindowPositionerTest() |
100 : grid_size_(WindowPositioner::kMinimumWindowOffset), | 97 : grid_size_(WindowPositioner::kMinimumWindowOffset), |
101 window_positioner_(NULL) { | 98 window_positioner_(NULL) { |
102 // Create a message loop. | |
103 base::MessageLoopForUI* ui_loop = message_loop(); | |
104 ui_thread_.reset( | |
105 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | |
106 | |
107 // Create a browser profile. | |
108 profile_.reset(new TestingProfile()); | |
109 } | |
110 | |
111 WindowPositionerTest::~WindowPositionerTest() { | |
112 profile_.reset(NULL); | |
113 ui_thread_.reset(NULL); | |
114 } | 99 } |
115 | 100 |
116 void WindowPositionerTest::SetUp() { | 101 void WindowPositionerTest::SetUp() { |
117 AshTestBase::SetUp(); | 102 AshTestBase::SetUp(); |
118 // Create some default dummy windows. | 103 // Create some default dummy windows. |
119 window_.reset(CreateTestWindowInShellWithId(0)); | 104 window_.reset(CreateTestWindowInShellWithId(0)); |
120 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); | 105 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); |
121 popup_.reset(CreateTestWindowInShellWithId(1)); | 106 popup_.reset(CreateTestWindowInShellWithId(1)); |
122 popup_->SetBounds(gfx::Rect(16, 32, 128, 256)); | 107 popup_->SetBounds(gfx::Rect(16, 32, 128, 256)); |
123 | 108 |
124 // Create a browser for the window. | 109 // Create a browser for the window. |
125 browser_window_.reset(new TestBrowserWindowAura(window_.get())); | 110 browser_window_.reset(new TestBrowserWindowAura(window_.get())); |
126 Browser::CreateParams window_params(profile_.get(), | 111 Browser::CreateParams window_params(&profile_, |
127 chrome::HOST_DESKTOP_TYPE_ASH); | 112 chrome::HOST_DESKTOP_TYPE_ASH); |
128 window_params.window = browser_window_.get(); | 113 window_params.window = browser_window_.get(); |
129 window_owning_browser_.reset(new Browser(window_params)); | 114 window_owning_browser_.reset(new Browser(window_params)); |
130 | 115 |
131 // Creating a browser for the popup. | 116 // Creating a browser for the popup. |
132 browser_popup_.reset(new TestBrowserWindowAura(popup_.get())); | 117 browser_popup_.reset(new TestBrowserWindowAura(popup_.get())); |
133 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile_.get(), | 118 Browser::CreateParams popup_params(Browser::TYPE_POPUP, &profile_, |
134 chrome::HOST_DESKTOP_TYPE_ASH); | 119 chrome::HOST_DESKTOP_TYPE_ASH); |
135 popup_params.window = browser_popup_.get(); | 120 popup_params.window = browser_popup_.get(); |
136 popup_owning_browser_.reset(new Browser(popup_params)); | 121 popup_owning_browser_.reset(new Browser(popup_params)); |
137 | 122 |
138 // We hide all windows upon start - each user is required to set it up | 123 // We hide all windows upon start - each user is required to set it up |
139 // as he needs it. | 124 // as he needs it. |
140 window()->Hide(); | 125 window()->Hide(); |
141 popup()->Hide(); | 126 popup()->Hide(); |
142 window_positioner_ = new WindowPositioner(); | 127 window_positioner_ = new WindowPositioner(); |
143 } | 128 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 274 |
290 // Check that the popup is placed full screen. | 275 // Check that the popup is placed full screen. |
291 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 276 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
292 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 277 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
293 pop_position.width(), pop_position.height()), | 278 pop_position.width(), pop_position.height()), |
294 full); | 279 full); |
295 } | 280 } |
296 | 281 |
297 } // namespace test | 282 } // namespace test |
298 } // namespace ash | 283 } // namespace ash |
OLD | NEW |