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

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

Powered by Google App Engine
This is Rietveld 408576698