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

Side by Side Diff: ash/shell_unittest.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ash/shell_init_params.cc ('k') | ash/snap_to_pixel_layout_manager.cc » ('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 "ash/shell.h" 5 #include "ash/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 void TestCreateWindow(views::Widget::InitParams::Type type, 140 void TestCreateWindow(views::Widget::InitParams::Type type,
141 bool always_on_top, 141 bool always_on_top,
142 aura::Window* expected_container) { 142 aura::Window* expected_container) {
143 views::Widget::InitParams widget_params(type); 143 views::Widget::InitParams widget_params(type);
144 widget_params.keep_on_top = always_on_top; 144 widget_params.keep_on_top = always_on_top;
145 145
146 views::Widget* widget = CreateTestWindow(widget_params); 146 views::Widget* widget = CreateTestWindow(widget_params);
147 widget->Show(); 147 widget->Show();
148 148
149 EXPECT_TRUE( 149 EXPECT_TRUE(
150 expected_container->Contains(widget->GetNativeWindow()->parent())) << 150 expected_container->Contains(widget->GetNativeWindow()->parent()))
151 "TestCreateWindow: type=" << type << ", always_on_top=" << 151 << "TestCreateWindow: type=" << type
152 always_on_top; 152 << ", always_on_top=" << always_on_top;
153 153
154 widget->Close(); 154 widget->Close();
155 } 155 }
156 156
157 void LockScreenAndVerifyMenuClosed() { 157 void LockScreenAndVerifyMenuClosed() {
158 // Verify a menu is open before locking. 158 // Verify a menu is open before locking.
159 views::MenuController* menu_controller = 159 views::MenuController* menu_controller =
160 views::MenuController::GetActiveInstance(); 160 views::MenuController::GetActiveInstance();
161 DCHECK(menu_controller); 161 DCHECK(menu_controller);
162 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); 162 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 TEST_F(ShellTest, ChangeAlwaysOnTop) { 207 TEST_F(ShellTest, ChangeAlwaysOnTop) {
208 views::Widget::InitParams widget_params( 208 views::Widget::InitParams widget_params(
209 views::Widget::InitParams::TYPE_WINDOW); 209 views::Widget::InitParams::TYPE_WINDOW);
210 210
211 // Creates a normal window 211 // Creates a normal window
212 views::Widget* widget = CreateTestWindow(widget_params); 212 views::Widget* widget = CreateTestWindow(widget_params);
213 widget->Show(); 213 widget->Show();
214 214
215 // It should be in default container. 215 // It should be in default container.
216 EXPECT_TRUE(GetDefaultContainer()->Contains( 216 EXPECT_TRUE(
217 widget->GetNativeWindow()->parent())); 217 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
218 218
219 // Flip always-on-top flag. 219 // Flip always-on-top flag.
220 widget->SetAlwaysOnTop(true); 220 widget->SetAlwaysOnTop(true);
221 // And it should in always on top container now. 221 // And it should in always on top container now.
222 EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent()); 222 EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent());
223 223
224 // Flip always-on-top flag. 224 // Flip always-on-top flag.
225 widget->SetAlwaysOnTop(false); 225 widget->SetAlwaysOnTop(false);
226 // It should go back to default container. 226 // It should go back to default container.
227 EXPECT_TRUE(GetDefaultContainer()->Contains( 227 EXPECT_TRUE(
228 widget->GetNativeWindow()->parent())); 228 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
229 229
230 // Set the same always-on-top flag again. 230 // Set the same always-on-top flag again.
231 widget->SetAlwaysOnTop(false); 231 widget->SetAlwaysOnTop(false);
232 // Should have no effect and we are still in the default container. 232 // Should have no effect and we are still in the default container.
233 EXPECT_TRUE(GetDefaultContainer()->Contains( 233 EXPECT_TRUE(
234 widget->GetNativeWindow()->parent())); 234 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
235 235
236 widget->Close(); 236 widget->Close();
237 } 237 }
238 238
239 TEST_F(ShellTest, CreateModalWindow) { 239 TEST_F(ShellTest, CreateModalWindow) {
240 views::Widget::InitParams widget_params( 240 views::Widget::InitParams widget_params(
241 views::Widget::InitParams::TYPE_WINDOW); 241 views::Widget::InitParams::TYPE_WINDOW);
242 242
243 // Create a normal window. 243 // Create a normal window.
244 views::Widget* widget = CreateTestWindow(widget_params); 244 views::Widget* widget = CreateTestWindow(widget_params);
245 widget->Show(); 245 widget->Show();
246 246
247 // It should be in default container. 247 // It should be in default container.
248 EXPECT_TRUE(GetDefaultContainer()->Contains( 248 EXPECT_TRUE(
249 widget->GetNativeWindow()->parent())); 249 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
250 250
251 // Create a modal window. 251 // Create a modal window.
252 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( 252 views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
253 new ModalWindow(), widget->GetNativeView()); 253 new ModalWindow(), widget->GetNativeView());
254 modal_widget->Show(); 254 modal_widget->Show();
255 255
256 // It should be in modal container. 256 // It should be in modal container.
257 aura::Window* modal_container = Shell::GetContainer( 257 aura::Window* modal_container = Shell::GetContainer(
258 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); 258 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
259 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); 259 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
(...skipping 13 matching lines...) Expand all
273 TEST_F(ShellTest, CreateLockScreenModalWindow) { 273 TEST_F(ShellTest, CreateLockScreenModalWindow) {
274 views::Widget::InitParams widget_params( 274 views::Widget::InitParams widget_params(
275 views::Widget::InitParams::TYPE_WINDOW); 275 views::Widget::InitParams::TYPE_WINDOW);
276 276
277 // Create a normal window. 277 // Create a normal window.
278 views::Widget* widget = CreateTestWindow(widget_params); 278 views::Widget* widget = CreateTestWindow(widget_params);
279 widget->Show(); 279 widget->Show();
280 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); 280 EXPECT_TRUE(widget->GetNativeView()->HasFocus());
281 281
282 // It should be in default container. 282 // It should be in default container.
283 EXPECT_TRUE(GetDefaultContainer()->Contains( 283 EXPECT_TRUE(
284 widget->GetNativeWindow()->parent())); 284 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
285 285
286 Shell::GetInstance()->session_state_delegate()->LockScreen(); 286 Shell::GetInstance()->session_state_delegate()->LockScreen();
287 // Create a LockScreen window. 287 // Create a LockScreen window.
288 views::Widget* lock_widget = CreateTestWindow(widget_params); 288 views::Widget* lock_widget = CreateTestWindow(widget_params);
289 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), 289 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
290 ash::kShellWindowId_LockScreenContainer) 290 ash::kShellWindowId_LockScreenContainer)
291 ->AddChild(lock_widget->GetNativeView()); 291 ->AddChild(lock_widget->GetNativeView());
292 lock_widget->Show(); 292 lock_widget->Show();
293 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); 293 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
294 294
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 EXPECT_TRUE(delegate->IsScreenLocked()); 346 EXPECT_TRUE(delegate->IsScreenLocked());
347 delegate->UnlockScreen(); 347 delegate->UnlockScreen();
348 EXPECT_FALSE(delegate->IsScreenLocked()); 348 EXPECT_FALSE(delegate->IsScreenLocked());
349 } 349 }
350 350
351 TEST_F(ShellTest, LockScreenClosesActiveMenu) { 351 TEST_F(ShellTest, LockScreenClosesActiveMenu) {
352 SimpleMenuDelegate menu_delegate; 352 SimpleMenuDelegate menu_delegate;
353 std::unique_ptr<ui::SimpleMenuModel> menu_model( 353 std::unique_ptr<ui::SimpleMenuModel> menu_model(
354 new ui::SimpleMenuModel(&menu_delegate)); 354 new ui::SimpleMenuModel(&menu_delegate));
355 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); 355 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item"));
356 views::Widget* widget = ash::Shell::GetPrimaryRootWindowController()-> 356 views::Widget* widget = ash::Shell::GetPrimaryRootWindowController()
357 wallpaper_controller()->widget(); 357 ->wallpaper_controller()
358 ->widget();
358 std::unique_ptr<views::MenuRunner> menu_runner( 359 std::unique_ptr<views::MenuRunner> menu_runner(
359 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU)); 360 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU));
360 361
361 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed 362 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed
362 // command will fire, check the menu state and ensure the nested menu loop 363 // command will fire, check the menu state and ensure the nested menu loop
363 // is exited so that the test will terminate. 364 // is exited so that the test will terminate.
364 base::ThreadTaskRunnerHandle::Get()->PostTask( 365 base::ThreadTaskRunnerHandle::Get()->PostTask(
365 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed, 366 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed,
366 base::Unretained(this))); 367 base::Unretained(this)));
367 368
368 EXPECT_EQ(views::MenuRunner::NORMAL_EXIT, 369 EXPECT_EQ(views::MenuRunner::NORMAL_EXIT,
369 menu_runner->RunMenuAt(widget, 370 menu_runner->RunMenuAt(widget, NULL, gfx::Rect(),
370 NULL,
371 gfx::Rect(),
372 views::MENU_ANCHOR_TOPLEFT, 371 views::MENU_ANCHOR_TOPLEFT,
373 ui::MENU_SOURCE_MOUSE)); 372 ui::MENU_SOURCE_MOUSE));
374 } 373 }
375 374
376 TEST_F(ShellTest, ManagedWindowModeBasics) { 375 TEST_F(ShellTest, ManagedWindowModeBasics) {
377 if (!SupportsHostWindowResize()) 376 if (!SupportsHostWindowResize())
378 return; 377 return;
379 378
380 // We start with the usual window containers. 379 // We start with the usual window containers.
381 ExpectAllContainers(); 380 ExpectAllContainers();
(...skipping 30 matching lines...) Expand all
412 411
413 // Create a normal window. It is not maximized. 412 // Create a normal window. It is not maximized.
414 views::Widget::InitParams widget_params( 413 views::Widget::InitParams widget_params(
415 views::Widget::InitParams::TYPE_WINDOW); 414 views::Widget::InitParams::TYPE_WINDOW);
416 widget_params.bounds.SetRect(11, 22, 300, 400); 415 widget_params.bounds.SetRect(11, 22, 300, 400);
417 views::Widget* widget = CreateTestWindow(widget_params); 416 views::Widget* widget = CreateTestWindow(widget_params);
418 widget->Show(); 417 widget->Show();
419 EXPECT_FALSE(widget->IsMaximized()); 418 EXPECT_FALSE(widget->IsMaximized());
420 419
421 // Shelf defaults to visible. 420 // Shelf defaults to visible.
422 EXPECT_EQ( 421 EXPECT_EQ(SHELF_VISIBLE, Shell::GetPrimaryRootWindowController()
423 SHELF_VISIBLE, 422 ->GetShelfLayoutManager()
424 Shell::GetPrimaryRootWindowController()-> 423 ->visibility_state());
425 GetShelfLayoutManager()->visibility_state());
426 424
427 // Fullscreen window hides it. 425 // Fullscreen window hides it.
428 widget->SetFullscreen(true); 426 widget->SetFullscreen(true);
429 EXPECT_EQ( 427 EXPECT_EQ(SHELF_HIDDEN, Shell::GetPrimaryRootWindowController()
430 SHELF_HIDDEN, 428 ->GetShelfLayoutManager()
431 Shell::GetPrimaryRootWindowController()-> 429 ->visibility_state());
432 GetShelfLayoutManager()->visibility_state());
433 430
434 // Restoring the window restores it. 431 // Restoring the window restores it.
435 widget->Restore(); 432 widget->Restore();
436 EXPECT_EQ( 433 EXPECT_EQ(SHELF_VISIBLE, Shell::GetPrimaryRootWindowController()
437 SHELF_VISIBLE, 434 ->GetShelfLayoutManager()
438 Shell::GetPrimaryRootWindowController()-> 435 ->visibility_state());
439 GetShelfLayoutManager()->visibility_state());
440 436
441 // Clean up. 437 // Clean up.
442 widget->Close(); 438 widget->Close();
443 } 439 }
444 440
445 // Various assertions around auto-hide behavior. 441 // Various assertions around auto-hide behavior.
446 // TODO(jamescook): Move this to ShelfTest. 442 // TODO(jamescook): Move this to ShelfTest.
447 TEST_F(ShellTest, ToggleAutoHide) { 443 TEST_F(ShellTest, ToggleAutoHide) {
448 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); 444 std::unique_ptr<aura::Window> window(new aura::Window(NULL));
449 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 445 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
(...skipping 23 matching lines...) Expand all
473 // Tests that the cursor-filter is ahead of the drag-drop controller in the 469 // Tests that the cursor-filter is ahead of the drag-drop controller in the
474 // pre-target list. 470 // pre-target list.
475 TEST_F(ShellTest, TestPreTargetHandlerOrder) { 471 TEST_F(ShellTest, TestPreTargetHandlerOrder) {
476 Shell* shell = Shell::GetInstance(); 472 Shell* shell = Shell::GetInstance();
477 ui::EventTargetTestApi test_api(shell); 473 ui::EventTargetTestApi test_api(shell);
478 test::ShellTestApi shell_test_api(shell); 474 test::ShellTestApi shell_test_api(shell);
479 475
480 const ui::EventHandlerList& handlers = test_api.pre_target_handlers(); 476 const ui::EventHandlerList& handlers = test_api.pre_target_handlers();
481 ui::EventHandlerList::const_iterator cursor_filter = 477 ui::EventHandlerList::const_iterator cursor_filter =
482 std::find(handlers.begin(), handlers.end(), shell->mouse_cursor_filter()); 478 std::find(handlers.begin(), handlers.end(), shell->mouse_cursor_filter());
483 ui::EventHandlerList::const_iterator drag_drop = 479 ui::EventHandlerList::const_iterator drag_drop = std::find(
484 std::find(handlers.begin(), handlers.end(), 480 handlers.begin(), handlers.end(), shell_test_api.drag_drop_controller());
485 shell_test_api.drag_drop_controller());
486 EXPECT_NE(handlers.end(), cursor_filter); 481 EXPECT_NE(handlers.end(), cursor_filter);
487 EXPECT_NE(handlers.end(), drag_drop); 482 EXPECT_NE(handlers.end(), drag_drop);
488 EXPECT_GT(drag_drop, cursor_filter); 483 EXPECT_GT(drag_drop, cursor_filter);
489 } 484 }
490 485
491 // Verifies an EventHandler added to Env gets notified from EventGenerator. 486 // Verifies an EventHandler added to Env gets notified from EventGenerator.
492 TEST_F(ShellTest, EnvPreTargetHandler) { 487 TEST_F(ShellTest, EnvPreTargetHandler) {
493 ui::test::TestEventHandler event_handler; 488 ui::test::TestEventHandler event_handler;
494 aura::Env::GetInstance()->AddPreTargetHandler(&event_handler); 489 aura::Env::GetInstance()->AddPreTargetHandler(&event_handler);
495 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 490 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
(...skipping 20 matching lines...) Expand all
516 private: 511 private:
517 DISALLOW_COPY_AND_ASSIGN(ShellTest2); 512 DISALLOW_COPY_AND_ASSIGN(ShellTest2);
518 }; 513 };
519 514
520 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { 515 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
521 window_.reset(new aura::Window(NULL)); 516 window_.reset(new aura::Window(NULL));
522 window_->Init(ui::LAYER_NOT_DRAWN); 517 window_->Init(ui::LAYER_NOT_DRAWN);
523 } 518 }
524 519
525 } // namespace ash 520 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell_init_params.cc ('k') | ash/snap_to_pixel_layout_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698