| 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 "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/display/mouse_cursor_event_filter.h" | 10 #include "ash/display/mouse_cursor_event_filter.h" |
| 11 #include "ash/drag_drop/drag_drop_controller.h" | 11 #include "ash/drag_drop/drag_drop_controller.h" |
| 12 #include "ash/public/cpp/config.h" | 12 #include "ash/public/cpp/config.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
| 15 #include "ash/session/session_controller.h" | 15 #include "ash/session/session_controller.h" |
| 16 #include "ash/shelf/shelf.h" | 16 #include "ash/shelf/shelf.h" |
| 17 #include "ash/shelf/shelf_layout_manager.h" | 17 #include "ash/shelf/shelf_layout_manager.h" |
| 18 #include "ash/shelf/shelf_widget.h" | 18 #include "ash/shelf/shelf_widget.h" |
| 19 #include "ash/shell_port.h" | 19 #include "ash/shell_port.h" |
| 20 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
| 21 #include "ash/test/shell_test_api.h" | 21 #include "ash/test/shell_test_api.h" |
| 22 #include "ash/test/test_session_controller_client.h" | 22 #include "ash/test/test_session_controller_client.h" |
| 23 #include "ash/wallpaper/wallpaper_widget_controller.h" | 23 #include "ash/wallpaper/wallpaper_widget_controller.h" |
| 24 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
| 25 #include "base/command_line.h" |
| 25 #include "base/macros.h" | 26 #include "base/macros.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/aura/env.h" | 30 #include "ui/aura/env.h" |
| 30 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
| 32 #include "ui/base/models/simple_menu_model.h" | 33 #include "ui/base/models/simple_menu_model.h" |
| 33 #include "ui/events/test/event_generator.h" | 34 #include "ui/events/test/event_generator.h" |
| 34 #include "ui/events/test/events_test_utils.h" | 35 #include "ui/events/test/events_test_utils.h" |
| 35 #include "ui/events/test/test_event_handler.h" | 36 #include "ui/events/test/test_event_handler.h" |
| 36 #include "ui/gfx/geometry/size.h" | 37 #include "ui/gfx/geometry/size.h" |
| 38 #include "ui/keyboard/keyboard_controller.h" |
| 39 #include "ui/keyboard/keyboard_switches.h" |
| 40 #include "ui/keyboard/keyboard_util.h" |
| 37 #include "ui/views/controls/menu/menu_controller.h" | 41 #include "ui/views/controls/menu/menu_controller.h" |
| 38 #include "ui/views/controls/menu/menu_runner.h" | 42 #include "ui/views/controls/menu/menu_runner.h" |
| 39 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 40 #include "ui/views/widget/widget_delegate.h" | 44 #include "ui/views/widget/widget_delegate.h" |
| 41 #include "ui/views/window/dialog_delegate.h" | 45 #include "ui/views/window/dialog_delegate.h" |
| 42 | 46 |
| 43 using aura::RootWindow; | 47 using aura::RootWindow; |
| 44 | 48 |
| 45 namespace ash { | 49 namespace ash { |
| 46 | 50 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // Verifies an EventHandler added to Env gets notified from EventGenerator. | 482 // Verifies an EventHandler added to Env gets notified from EventGenerator. |
| 479 TEST_F(ShellTest, EnvPreTargetHandler) { | 483 TEST_F(ShellTest, EnvPreTargetHandler) { |
| 480 ui::test::TestEventHandler event_handler; | 484 ui::test::TestEventHandler event_handler; |
| 481 aura::Env::GetInstance()->AddPreTargetHandler(&event_handler); | 485 aura::Env::GetInstance()->AddPreTargetHandler(&event_handler); |
| 482 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 486 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 483 generator.MoveMouseBy(1, 1); | 487 generator.MoveMouseBy(1, 1); |
| 484 EXPECT_NE(0, event_handler.num_mouse_events()); | 488 EXPECT_NE(0, event_handler.num_mouse_events()); |
| 485 aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler); | 489 aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 486 } | 490 } |
| 487 | 491 |
| 492 // Verifies keyboard is re-created on proper timing. |
| 493 TEST_F(ShellTest, KeyboardCreation) { |
| 494 if (Shell::GetAshConfig() == Config::MASH) |
| 495 return; |
| 496 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 497 keyboard::switches::kEnableVirtualKeyboard); |
| 498 |
| 499 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 500 |
| 501 SessionObserver* shell = Shell::Get(); |
| 502 EXPECT_FALSE(keyboard::KeyboardController::GetInstance()); |
| 503 shell->OnSessionStateChanged( |
| 504 session_manager::SessionState::LOGGED_IN_NOT_ACTIVE); |
| 505 |
| 506 EXPECT_TRUE(keyboard::KeyboardController::GetInstance()); |
| 507 } |
| 508 |
| 488 // This verifies WindowObservers are removed when a window is destroyed after | 509 // This verifies WindowObservers are removed when a window is destroyed after |
| 489 // the Shell is destroyed. This scenario (aura::Windows being deleted after the | 510 // the Shell is destroyed. This scenario (aura::Windows being deleted after the |
| 490 // Shell) occurs if someone is holding a reference to an unparented Window, as | 511 // Shell) occurs if someone is holding a reference to an unparented Window, as |
| 491 // is the case with a RenderWidgetHostViewAura that isn't on screen. As long as | 512 // is the case with a RenderWidgetHostViewAura that isn't on screen. As long as |
| 492 // everything is ok, we won't crash. If there is a bug, window's destructor will | 513 // everything is ok, we won't crash. If there is a bug, window's destructor will |
| 493 // notify some deleted object (say VideoDetector or ActivationController) and | 514 // notify some deleted object (say VideoDetector or ActivationController) and |
| 494 // this will crash. | 515 // this will crash. |
| 495 class ShellTest2 : public test::AshTestBase { | 516 class ShellTest2 : public test::AshTestBase { |
| 496 public: | 517 public: |
| 497 ShellTest2() {} | 518 ShellTest2() {} |
| 498 ~ShellTest2() override {} | 519 ~ShellTest2() override {} |
| 499 | 520 |
| 500 protected: | 521 protected: |
| 501 std::unique_ptr<aura::Window> window_; | 522 std::unique_ptr<aura::Window> window_; |
| 502 | 523 |
| 503 private: | 524 private: |
| 504 DISALLOW_COPY_AND_ASSIGN(ShellTest2); | 525 DISALLOW_COPY_AND_ASSIGN(ShellTest2); |
| 505 }; | 526 }; |
| 506 | 527 |
| 507 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { | 528 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { |
| 508 window_.reset(new aura::Window(NULL)); | 529 window_.reset(new aura::Window(NULL)); |
| 509 window_->Init(ui::LAYER_NOT_DRAWN); | 530 window_->Init(ui::LAYER_NOT_DRAWN); |
| 510 } | 531 } |
| 511 | 532 |
| 512 } // namespace ash | 533 } // namespace ash |
| OLD | NEW |