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

Side by Side Diff: chrome/browser/ui/ash/window_positioner_unittest.cc

Issue 13139004: Deprecate Browser::TYPE_PANEL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_item_controller.cc ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) 49 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window)
50 : native_window_(native_window) { 50 : native_window_(native_window) {
51 } 51 }
52 52
53 TestBrowserWindowAura::~TestBrowserWindowAura() {} 53 TestBrowserWindowAura::~TestBrowserWindowAura() {}
54 54
55 } // namespace 55 } // namespace
56 56
57 // A test class for preparing window positioner tests - it creates a testing 57 // A test class for preparing window positioner tests - it creates a testing
58 // base by adding a window, a popup and a panel which can be independently 58 // base by adding a window and a popup which can be independently
59 // positioned to see where the positioner will place the window. 59 // positioned to see where the positioner will place the window.
60 class WindowPositionerTest : public AshTestBase { 60 class WindowPositionerTest : public AshTestBase {
61 public: 61 public:
62 WindowPositionerTest(); 62 WindowPositionerTest();
63 virtual ~WindowPositionerTest(); 63 virtual ~WindowPositionerTest();
64 64
65 virtual void SetUp() OVERRIDE; 65 virtual void SetUp() OVERRIDE;
66 virtual void TearDown() OVERRIDE; 66 virtual void TearDown() OVERRIDE;
67 67
68 protected: 68 protected:
69 aura::Window* window() { return window_.get(); } 69 aura::Window* window() { return window_.get(); }
70 aura::Window* popup() { return popup_.get(); } 70 aura::Window* popup() { return popup_.get(); }
71 aura::Window* panel() { return panel_.get(); }
72 71
73 Browser* window_browser() { return window_owning_browser_.get(); } 72 Browser* window_browser() { return window_owning_browser_.get(); }
74 Browser* popup_browser() { return popup_owning_browser_.get(); } 73 Browser* popup_browser() { return popup_owning_browser_.get(); }
75 Browser* panel_browser() { return panel_owning_browser_.get(); }
76 74
77 WindowPositioner* window_positioner() { return window_positioner_; } 75 WindowPositioner* window_positioner() { return window_positioner_; }
78 76
79 // The positioner & desktop's used grid alignment size. 77 // The positioner & desktop's used grid alignment size.
80 const int grid_size_; 78 const int grid_size_;
81 79
82 private: 80 private:
83 WindowPositioner* window_positioner_; 81 WindowPositioner* window_positioner_;
84 82
85 // These two need to be deleted after everything else is gone. 83 // These two need to be deleted after everything else is gone.
86 scoped_ptr<content::TestBrowserThread> ui_thread_; 84 scoped_ptr<content::TestBrowserThread> ui_thread_;
87 scoped_ptr<TestingProfile> profile_; 85 scoped_ptr<TestingProfile> profile_;
88 86
89 // These get created for each session. 87 // These get created for each session.
90 scoped_ptr<aura::Window> window_; 88 scoped_ptr<aura::Window> window_;
91 scoped_ptr<aura::Window> popup_; 89 scoped_ptr<aura::Window> popup_;
92 scoped_ptr<aura::Window> panel_;
93 90
94 scoped_ptr<BrowserWindow> browser_window_; 91 scoped_ptr<BrowserWindow> browser_window_;
95 scoped_ptr<BrowserWindow> browser_popup_; 92 scoped_ptr<BrowserWindow> browser_popup_;
96 scoped_ptr<BrowserWindow> browser_panel_;
97 93
98 scoped_ptr<Browser> window_owning_browser_; 94 scoped_ptr<Browser> window_owning_browser_;
99 scoped_ptr<Browser> popup_owning_browser_; 95 scoped_ptr<Browser> popup_owning_browser_;
100 scoped_ptr<Browser> panel_owning_browser_;
101 96
102 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest); 97 DISALLOW_COPY_AND_ASSIGN(WindowPositionerTest);
103 }; 98 };
104 99
105 WindowPositionerTest::WindowPositionerTest() 100 WindowPositionerTest::WindowPositionerTest()
106 : grid_size_(WindowPositioner::kMinimumWindowOffset), 101 : grid_size_(WindowPositioner::kMinimumWindowOffset),
107 window_positioner_(NULL) { 102 window_positioner_(NULL) {
108 // Create a message loop. 103 // Create a message loop.
109 MessageLoopForUI* ui_loop = message_loop(); 104 MessageLoopForUI* ui_loop = message_loop();
110 ui_thread_.reset( 105 ui_thread_.reset(
111 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); 106 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
112 107
113 // Create a browser profile. 108 // Create a browser profile.
114 profile_.reset(new TestingProfile()); 109 profile_.reset(new TestingProfile());
115 } 110 }
116 111
117 WindowPositionerTest::~WindowPositionerTest() { 112 WindowPositionerTest::~WindowPositionerTest() {
118 profile_.reset(NULL); 113 profile_.reset(NULL);
119 ui_thread_.reset(NULL); 114 ui_thread_.reset(NULL);
120 } 115 }
121 116
122 void WindowPositionerTest::SetUp() { 117 void WindowPositionerTest::SetUp() {
123 AshTestBase::SetUp(); 118 AshTestBase::SetUp();
124 // Create some default dummy windows. 119 // Create some default dummy windows.
125 window_.reset(CreateTestWindowInShellWithId(0)); 120 window_.reset(CreateTestWindowInShellWithId(0));
126 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); 121 window_->SetBounds(gfx::Rect(16, 32, 640, 320));
127 popup_.reset(CreateTestWindowInShellWithId(1)); 122 popup_.reset(CreateTestWindowInShellWithId(1));
128 popup_->SetBounds(gfx::Rect(16, 32, 128, 256)); 123 popup_->SetBounds(gfx::Rect(16, 32, 128, 256));
129 panel_.reset(CreateTestWindowInShellWithId(2));
130 panel_->SetBounds(gfx::Rect(32, 48, 256, 512));
131 124
132 // Create a browser for the window. 125 // Create a browser for the window.
133 browser_window_.reset(new TestBrowserWindowAura(window_.get())); 126 browser_window_.reset(new TestBrowserWindowAura(window_.get()));
134 Browser::CreateParams window_params(profile_.get(), 127 Browser::CreateParams window_params(profile_.get(),
135 chrome::HOST_DESKTOP_TYPE_ASH); 128 chrome::HOST_DESKTOP_TYPE_ASH);
136 window_params.window = browser_window_.get(); 129 window_params.window = browser_window_.get();
137 window_owning_browser_.reset(new Browser(window_params)); 130 window_owning_browser_.reset(new Browser(window_params));
138 131
139 // Creating a browser for the popup. 132 // Creating a browser for the popup.
140 browser_popup_.reset(new TestBrowserWindowAura(popup_.get())); 133 browser_popup_.reset(new TestBrowserWindowAura(popup_.get()));
141 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile_.get(), 134 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile_.get(),
142 chrome::HOST_DESKTOP_TYPE_ASH); 135 chrome::HOST_DESKTOP_TYPE_ASH);
143 popup_params.window = browser_popup_.get(); 136 popup_params.window = browser_popup_.get();
144 popup_owning_browser_.reset(new Browser(popup_params)); 137 popup_owning_browser_.reset(new Browser(popup_params));
145 138
146 // Creating a browser for the panel.
147 browser_panel_.reset(new TestBrowserWindowAura(panel_.get()));
148 Browser::CreateParams panel_params(Browser::TYPE_PANEL, profile_.get(),
149 chrome::HOST_DESKTOP_TYPE_ASH);
150 panel_params.window = browser_panel_.get();
151 panel_owning_browser_.reset(new Browser(panel_params));
152 // We hide all windows upon start - each user is required to set it up 139 // We hide all windows upon start - each user is required to set it up
153 // as he needs it. 140 // as he needs it.
154 window()->Hide(); 141 window()->Hide();
155 popup()->Hide(); 142 popup()->Hide();
156 panel()->Hide();
157 window_positioner_ = new WindowPositioner(); 143 window_positioner_ = new WindowPositioner();
158 } 144 }
159 145
160 void WindowPositionerTest::TearDown() { 146 void WindowPositionerTest::TearDown() {
161 // Since the AuraTestBase is needed to create our assets, we have to 147 // Since the AuraTestBase is needed to create our assets, we have to
162 // also delete them before we tear it down. 148 // also delete them before we tear it down.
163 window_owning_browser_.reset(NULL); 149 window_owning_browser_.reset(NULL);
164 popup_owning_browser_.reset(NULL); 150 popup_owning_browser_.reset(NULL);
165 panel_owning_browser_.reset(NULL);
166 151
167 browser_window_.reset(NULL); 152 browser_window_.reset(NULL);
168 browser_popup_.reset(NULL); 153 browser_popup_.reset(NULL);
169 browser_panel_.reset(NULL);
170 154
171 window_.reset(NULL); 155 window_.reset(NULL);
172 popup_.reset(NULL); 156 popup_.reset(NULL);
173 panel_.reset(NULL);
174 157
175 AshTestBase::TearDown(); 158 AshTestBase::TearDown();
176 delete window_positioner_; 159 delete window_positioner_;
177 window_positioner_ = NULL; 160 window_positioner_ = NULL;
178 } 161 }
179 162
180 int AlignToGridRoundDown(int location, int grid_size) { 163 int AlignToGridRoundDown(int location, int grid_size) {
181 if (grid_size <= 1 || location % grid_size == 0) 164 if (grid_size <= 1 || location % grid_size == 0)
182 return location; 165 return location;
183 return location / grid_size * grid_size; 166 return location / grid_size * grid_size;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 1)); 275 1));
293 gfx::Rect top_right = window_positioner()->GetPopupPosition( 276 gfx::Rect top_right = window_positioner()->GetPopupPosition(
294 popup_position); 277 popup_position);
295 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() - 278 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() -
296 popup_position.width(), grid_size_), 279 popup_position.width(), grid_size_),
297 work_area.y(), 280 work_area.y(),
298 popup_position.width(), popup_position.height()), 281 popup_position.width(), popup_position.height()),
299 top_right); 282 top_right);
300 } 283 }
301 284
302 TEST_F(WindowPositionerTest, blockedByPanel) {
303 const gfx::Rect work_area =
304 Shell::GetScreen()->GetPrimaryDisplay().work_area();
305
306 gfx::Rect pop_position(0, 0, 200, 200);
307 // Let the panel cover everything.
308 panel()->SetBounds(work_area);
309 panel()->Show();
310
311 // Check that the popup does cascade due to the panel's existence.
312 gfx::Rect top_right = window_positioner()->GetPopupPosition(pop_position);
313 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_,
314 pop_position.width(), pop_position.height()),
315 top_right);
316 }
317
318 TEST_F(WindowPositionerTest, biggerThenBorder) { 285 TEST_F(WindowPositionerTest, biggerThenBorder) {
319 const gfx::Rect work_area = 286 const gfx::Rect work_area =
320 Shell::GetScreen()->GetPrimaryDisplay().work_area(); 287 Shell::GetScreen()->GetPrimaryDisplay().work_area();
321 288
322 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); 289 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height());
323 290
324 // Check that the popup is placed full screen. 291 // Check that the popup is placed full screen.
325 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); 292 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position);
326 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), 293 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(),
327 pop_position.width(), pop_position.height()), 294 pop_position.width(), pop_position.height()),
328 full); 295 full);
329 } 296 }
330 297
331 } // namespace test 298 } // namespace test
332 } // namespace ash 299 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_item_controller.cc ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698