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

Side by Side Diff: ash/focus_cycler_unittest.cc

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 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
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 "ash/focus_cycler.h" 5 #include "ash/focus_cycler.h"
6 6
7 #include <memory>
8
7 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf.h" 10 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h" 12 #include "ash/shell.h"
11 #include "ash/shell_factory.h" 13 #include "ash/shell_factory.h"
12 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
13 #include "ash/system/status_area_widget.h" 15 #include "ash/system/status_area_widget.h"
14 #include "ash/system/status_area_widget_delegate.h" 16 #include "ash/system/status_area_widget_delegate.h"
15 #include "ash/system/tray/system_tray.h" 17 #include "ash/system/tray/system_tray.h"
16 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 ShelfWidget* shelf_widget() { 114 ShelfWidget* shelf_widget() {
113 return Shelf::ForPrimaryDisplay()->shelf_widget(); 115 return Shelf::ForPrimaryDisplay()->shelf_widget();
114 } 116 }
115 117
116 void InstallFocusCycleOnShelf() { 118 void InstallFocusCycleOnShelf() {
117 // Add the shelf. 119 // Add the shelf.
118 shelf_widget()->SetFocusCycler(focus_cycler()); 120 shelf_widget()->SetFocusCycler(focus_cycler());
119 } 121 }
120 122
121 private: 123 private:
122 scoped_ptr<FocusCycler> focus_cycler_; 124 std::unique_ptr<FocusCycler> focus_cycler_;
123 scoped_ptr<SystemTray> tray_; 125 std::unique_ptr<SystemTray> tray_;
124 126
125 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); 127 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
126 }; 128 };
127 129
128 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { 130 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
129 // Create a single test window. 131 // Create a single test window.
130 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 132 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
131 wm::ActivateWindow(window0.get()); 133 wm::ActivateWindow(window0.get());
132 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 134 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
133 135
134 // Cycle the window 136 // Cycle the window
135 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 137 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
136 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 138 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
137 } 139 }
138 140
139 TEST_F(FocusCyclerTest, CycleFocusForward) { 141 TEST_F(FocusCyclerTest, CycleFocusForward) {
140 ASSERT_TRUE(CreateTray()); 142 ASSERT_TRUE(CreateTray());
141 143
142 InstallFocusCycleOnShelf(); 144 InstallFocusCycleOnShelf();
143 145
144 // Create a single test window. 146 // Create a single test window.
145 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 147 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
146 wm::ActivateWindow(window0.get()); 148 wm::ActivateWindow(window0.get());
147 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 149 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
148 150
149 // Cycle focus to the status area. 151 // Cycle focus to the status area.
150 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 152 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
151 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 153 EXPECT_TRUE(tray()->GetWidget()->IsActive());
152 154
153 // Cycle focus to the shelf. 155 // Cycle focus to the shelf.
154 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 156 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
155 EXPECT_TRUE(shelf_widget()->IsActive()); 157 EXPECT_TRUE(shelf_widget()->IsActive());
156 158
157 // Cycle focus to the browser. 159 // Cycle focus to the browser.
158 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 160 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
159 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 161 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
160 } 162 }
161 163
162 TEST_F(FocusCyclerTest, CycleFocusBackward) { 164 TEST_F(FocusCyclerTest, CycleFocusBackward) {
163 ASSERT_TRUE(CreateTray()); 165 ASSERT_TRUE(CreateTray());
164 166
165 InstallFocusCycleOnShelf(); 167 InstallFocusCycleOnShelf();
166 168
167 // Create a single test window. 169 // Create a single test window.
168 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 170 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
169 wm::ActivateWindow(window0.get()); 171 wm::ActivateWindow(window0.get());
170 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 172 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
171 173
172 // Cycle focus to the shelf. 174 // Cycle focus to the shelf.
173 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 175 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
174 EXPECT_TRUE(shelf_widget()->IsActive()); 176 EXPECT_TRUE(shelf_widget()->IsActive());
175 177
176 // Cycle focus to the status area. 178 // Cycle focus to the status area.
177 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 179 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
178 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 180 EXPECT_TRUE(tray()->GetWidget()->IsActive());
179 181
180 // Cycle focus to the browser. 182 // Cycle focus to the browser.
181 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 183 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
182 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 184 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
183 } 185 }
184 186
185 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { 187 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
186 ASSERT_TRUE(CreateTray()); 188 ASSERT_TRUE(CreateTray());
187 189
188 InstallFocusCycleOnShelf(); 190 InstallFocusCycleOnShelf();
189 191
190 // Create a single test window. 192 // Create a single test window.
191 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 193 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
192 wm::ActivateWindow(window0.get()); 194 wm::ActivateWindow(window0.get());
193 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 195 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
194 196
195 // Cycle focus to the shelf. 197 // Cycle focus to the shelf.
196 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 198 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
197 EXPECT_TRUE(shelf_widget()->IsActive()); 199 EXPECT_TRUE(shelf_widget()->IsActive());
198 200
199 // Cycle focus to the status area. 201 // Cycle focus to the status area.
200 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 202 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
201 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 203 EXPECT_TRUE(tray()->GetWidget()->IsActive());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 248 EXPECT_TRUE(tray()->GetWidget()->IsActive());
247 } 249 }
248 250
249 // Tests that focus cycles from the active browser to the status area and back. 251 // Tests that focus cycles from the active browser to the status area and back.
250 TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { 252 TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
251 ASSERT_TRUE(CreateTray()); 253 ASSERT_TRUE(CreateTray());
252 InstallFocusCycleOnShelf(); 254 InstallFocusCycleOnShelf();
253 shelf_widget()->Hide(); 255 shelf_widget()->Hide();
254 256
255 // Create two test windows. 257 // Create two test windows.
256 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 258 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
257 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); 259 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1));
258 wm::ActivateWindow(window1.get()); 260 wm::ActivateWindow(window1.get());
259 wm::ActivateWindow(window0.get()); 261 wm::ActivateWindow(window0.get());
260 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 262 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
261 263
262 // Cycle focus to the status area. 264 // Cycle focus to the status area.
263 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 265 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
264 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 266 EXPECT_TRUE(tray()->GetWidget()->IsActive());
265 267
266 // Cycle focus to the browser. 268 // Cycle focus to the browser.
267 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 269 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
268 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 270 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
269 271
270 // Cycle focus to the status area. 272 // Cycle focus to the status area.
271 focus_cycler()->RotateFocus(FocusCycler::FORWARD); 273 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
272 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 274 EXPECT_TRUE(tray()->GetWidget()->IsActive());
273 } 275 }
274 276
275 TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { 277 TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
276 ASSERT_TRUE(CreateTray()); 278 ASSERT_TRUE(CreateTray());
277 InstallFocusCycleOnShelf(); 279 InstallFocusCycleOnShelf();
278 shelf_widget()->Hide(); 280 shelf_widget()->Hide();
279 281
280 // Create a single test window. 282 // Create a single test window.
281 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); 283 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
282 wm::ActivateWindow(window0.get()); 284 wm::ActivateWindow(window0.get());
283 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 285 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
284 286
285 // Cycle focus to the status area. 287 // Cycle focus to the status area.
286 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 288 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
287 EXPECT_TRUE(tray()->GetWidget()->IsActive()); 289 EXPECT_TRUE(tray()->GetWidget()->IsActive());
288 290
289 // Cycle focus to the browser. 291 // Cycle focus to the browser.
290 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); 292 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
291 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); 293 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
292 } 294 }
293 295
294 TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { 296 TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
295 ASSERT_TRUE(CreateTray()); 297 ASSERT_TRUE(CreateTray());
296 298
297 InstallFocusCycleOnShelf(); 299 InstallFocusCycleOnShelf();
298 300
299 scoped_ptr<PanedWidgetDelegate> test_widget_delegate; 301 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate;
300 scoped_ptr<views::Widget> browser_widget(new views::Widget); 302 std::unique_ptr<views::Widget> browser_widget(new views::Widget);
301 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get())); 303 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get()));
302 views::Widget::InitParams widget_params( 304 views::Widget::InitParams widget_params(
303 views::Widget::InitParams::TYPE_WINDOW); 305 views::Widget::InitParams::TYPE_WINDOW);
304 widget_params.context = CurrentContext(); 306 widget_params.context = CurrentContext();
305 widget_params.delegate = test_widget_delegate.get(); 307 widget_params.delegate = test_widget_delegate.get();
306 widget_params.ownership = 308 widget_params.ownership =
307 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 309 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
308 browser_widget->Init(widget_params); 310 browser_widget->Init(widget_params);
309 browser_widget->Show(); 311 browser_widget->Show();
310 312
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // also be removed from focus cycler. 405 // also be removed from focus cycler.
404 TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) { 406 TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) {
405 // Two displays are added, so two shelf widgets and two status area widgets 407 // Two displays are added, so two shelf widgets and two status area widgets
406 // are added to focus cycler. 408 // are added to focus cycler.
407 UpdateDisplay("800x800, 500x500"); 409 UpdateDisplay("800x800, 500x500");
408 // Remove one display. Its shelf widget and status area widget should also be 410 // Remove one display. Its shelf widget and status area widget should also be
409 // removed from focus cycler. 411 // removed from focus cycler.
410 UpdateDisplay("800x800"); 412 UpdateDisplay("800x800");
411 413
412 // Create a single test window. 414 // Create a single test window.
413 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0)); 415 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0));
414 wm::ActivateWindow(window.get()); 416 wm::ActivateWindow(window.get());
415 EXPECT_TRUE(wm::IsActiveWindow(window.get())); 417 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
416 418
417 // Cycle focus to the status area. 419 // Cycle focus to the status area.
418 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); 420 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
419 EXPECT_FALSE(wm::IsActiveWindow(window.get())); 421 EXPECT_FALSE(wm::IsActiveWindow(window.get()));
420 422
421 // Cycle focus to the shelf. 423 // Cycle focus to the shelf.
422 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); 424 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
423 425
424 // Cycle focus should go back to the browser. 426 // Cycle focus should go back to the browser.
425 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); 427 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
426 EXPECT_TRUE(wm::IsActiveWindow(window.get())); 428 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
427 } 429 }
428 430
429 } // namespace test 431 } // namespace test
430 } // namespace ash 432 } // namespace ash
OLDNEW
« no previous file with comments | « ash/first_run/first_run_helper_unittest.cc ('k') | ash/frame/caption_buttons/frame_caption_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698