shell_unittest.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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
  3. // found in the LICENSE file.
  4. #include "ash/shell.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include <queue>
  8. #include <vector>
  9. #include "ash/display/mouse_cursor_event_filter.h"
  10. #include "ash/drag_drop/drag_drop_controller.h"
  11. #include "ash/drag_drop/drag_drop_controller_test_api.h"
  12. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  13. #include "ash/keyboard/ui/keyboard_util.h"
  14. #include "ash/public/cpp/ash_prefs.h"
  15. #include "ash/public/cpp/keyboard/keyboard_switches.h"
  16. #include "ash/public/cpp/shell_window_ids.h"
  17. #include "ash/public/cpp/test/shell_test_api.h"
  18. #include "ash/root_window_controller.h"
  19. #include "ash/session/session_controller_impl.h"
  20. #include "ash/session/test_session_controller_client.h"
  21. #include "ash/shelf/home_button.h"
  22. #include "ash/shelf/shelf.h"
  23. #include "ash/shelf/shelf_layout_manager.h"
  24. #include "ash/shelf/shelf_navigation_widget.h"
  25. #include "ash/shelf/shelf_widget.h"
  26. #include "ash/system/status_area_widget.h"
  27. #include "ash/test/ash_test_base.h"
  28. #include "ash/test/ash_test_helper.h"
  29. #include "ash/test/test_widget_builder.h"
  30. #include "ash/test_shell_delegate.h"
  31. #include "ash/wallpaper/wallpaper_widget_controller.h"
  32. #include "ash/wm/desks/desks_util.h"
  33. #include "ash/wm/overview/overview_controller.h"
  34. #include "base/command_line.h"
  35. #include "base/containers/flat_set.h"
  36. #include "base/strings/utf_string_conversions.h"
  37. #include "base/threading/thread_task_runner_handle.h"
  38. #include "components/account_id/account_id.h"
  39. #include "ui/aura/env.h"
  40. #include "ui/aura/window.h"
  41. #include "ui/aura/window_event_dispatcher.h"
  42. #include "ui/base/models/simple_menu_model.h"
  43. #include "ui/display/scoped_display_for_new_windows.h"
  44. #include "ui/events/test/event_generator.h"
  45. #include "ui/events/test/events_test_utils.h"
  46. #include "ui/events/test/test_event_handler.h"
  47. #include "ui/gfx/geometry/size.h"
  48. #include "ui/views/controls/menu/menu_controller.h"
  49. #include "ui/views/controls/menu/menu_runner.h"
  50. #include "ui/views/widget/widget.h"
  51. #include "ui/views/widget/widget_delegate.h"
  52. #include "ui/views/window/dialog_delegate.h"
  53. using aura::RootWindow;
  54. namespace ash {
  55. namespace {
  56. aura::Window* GetActiveDeskContainer() {
  57. return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  58. desks_util::GetActiveDeskContainerId());
  59. }
  60. aura::Window* GetAlwaysOnTopContainer() {
  61. return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  62. kShellWindowId_AlwaysOnTopContainer);
  63. }
  64. // Expect ALL the containers!
  65. void ExpectAllContainers() {
  66. aura::Window* root_window = Shell::GetPrimaryRootWindow();
  67. // Validate no duplicate container IDs.
  68. base::flat_set<int> container_ids;
  69. std::queue<aura::Window*> window_queue;
  70. window_queue.push(root_window);
  71. while (!window_queue.empty()) {
  72. aura::Window* current_window = window_queue.front();
  73. window_queue.pop();
  74. for (aura::Window* child : current_window->children())
  75. window_queue.push(child);
  76. const int id = current_window->GetId();
  77. // Skip windows with no IDs.
  78. if (id == aura::Window::kInitialId)
  79. continue;
  80. EXPECT_TRUE(container_ids.insert(id).second)
  81. << "Found duplicate ID: " << id
  82. << " at window: " << current_window->GetName();
  83. }
  84. EXPECT_TRUE(
  85. Shell::GetContainer(root_window, kShellWindowId_WallpaperContainer));
  86. for (int desk_id : desks_util::GetDesksContainersIds())
  87. EXPECT_TRUE(Shell::GetContainer(root_window, desk_id));
  88. EXPECT_TRUE(
  89. Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer));
  90. EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer));
  91. EXPECT_TRUE(
  92. Shell::GetContainer(root_window, kShellWindowId_SystemModalContainer));
  93. EXPECT_TRUE(Shell::GetContainer(root_window,
  94. kShellWindowId_LockScreenWallpaperContainer));
  95. EXPECT_TRUE(
  96. Shell::GetContainer(root_window, kShellWindowId_LockScreenContainer));
  97. EXPECT_TRUE(Shell::GetContainer(root_window,
  98. kShellWindowId_LockSystemModalContainer));
  99. EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_MenuContainer));
  100. EXPECT_TRUE(Shell::GetContainer(root_window,
  101. kShellWindowId_DragImageAndTooltipContainer));
  102. EXPECT_TRUE(
  103. Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer));
  104. EXPECT_TRUE(
  105. Shell::GetContainer(root_window, kShellWindowId_OverlayContainer));
  106. EXPECT_TRUE(Shell::GetContainer(root_window,
  107. kShellWindowId_ImeWindowParentContainer));
  108. EXPECT_TRUE(Shell::GetContainer(root_window,
  109. kShellWindowId_VirtualKeyboardContainer));
  110. EXPECT_TRUE(
  111. Shell::GetContainer(root_window, kShellWindowId_MouseCursorContainer));
  112. // Phantom window is not a container.
  113. EXPECT_EQ(0u, container_ids.count(kShellWindowId_PhantomWindow));
  114. EXPECT_FALSE(Shell::GetContainer(root_window, kShellWindowId_PhantomWindow));
  115. }
  116. std::unique_ptr<views::WidgetDelegateView> CreateModalWidgetDelegate() {
  117. auto delegate = std::make_unique<views::WidgetDelegateView>();
  118. delegate->SetCanResize(true);
  119. delegate->SetModalType(ui::MODAL_TYPE_SYSTEM);
  120. delegate->SetOwnedByWidget(true);
  121. delegate->SetTitle(u"Modal Window");
  122. return delegate;
  123. }
  124. class SimpleMenuDelegate : public ui::SimpleMenuModel::Delegate {
  125. public:
  126. SimpleMenuDelegate() = default;
  127. SimpleMenuDelegate(const SimpleMenuDelegate&) = delete;
  128. SimpleMenuDelegate& operator=(const SimpleMenuDelegate&) = delete;
  129. ~SimpleMenuDelegate() override = default;
  130. bool IsCommandIdChecked(int command_id) const override { return false; }
  131. bool IsCommandIdEnabled(int command_id) const override { return true; }
  132. void ExecuteCommand(int command_id, int event_flags) override {}
  133. };
  134. } // namespace
  135. class ShellTest : public AshTestBase {
  136. public:
  137. void TestCreateWindow(views::Widget::InitParams::Type type,
  138. bool always_on_top,
  139. aura::Window* expected_container) {
  140. TestWidgetBuilder builder;
  141. if (always_on_top)
  142. builder.SetZOrderLevel(ui::ZOrderLevel::kFloatingWindow);
  143. views::Widget* widget =
  144. builder.SetWidgetType(type).BuildOwnedByNativeWidget();
  145. EXPECT_TRUE(
  146. expected_container->Contains(widget->GetNativeWindow()->parent()))
  147. << "TestCreateWindow: type=" << type
  148. << ", always_on_top=" << always_on_top;
  149. widget->Close();
  150. }
  151. void LockScreenAndVerifyMenuClosed() {
  152. // Verify a menu is open before locking.
  153. views::MenuController* menu_controller =
  154. views::MenuController::GetActiveInstance();
  155. DCHECK(menu_controller);
  156. EXPECT_EQ(views::MenuController::ExitType::kNone,
  157. menu_controller->exit_type());
  158. // Create a LockScreen window.
  159. views::Widget* lock_widget =
  160. TestWidgetBuilder()
  161. .SetWidgetType(views::Widget::InitParams::TYPE_WINDOW)
  162. .SetShow(false)
  163. .BuildOwnedByNativeWidget();
  164. Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  165. kShellWindowId_LockScreenContainer)
  166. ->AddChild(lock_widget->GetNativeView());
  167. lock_widget->Show();
  168. // Simulate real screen locker to change session state to LOCKED
  169. // when it is shown.
  170. GetSessionControllerClient()->LockScreen();
  171. SessionControllerImpl* controller = Shell::Get()->session_controller();
  172. EXPECT_TRUE(controller->IsScreenLocked());
  173. EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
  174. // Verify menu is closed.
  175. EXPECT_EQ(nullptr, views::MenuController::GetActiveInstance());
  176. lock_widget->Close();
  177. GetSessionControllerClient()->UnlockScreen();
  178. }
  179. };
  180. TEST_F(ShellTest, CreateWindow) {
  181. // Normal window should be created in default container.
  182. TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
  183. false, // always_on_top
  184. GetActiveDeskContainer());
  185. TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
  186. false, // always_on_top
  187. GetActiveDeskContainer());
  188. // Always-on-top window and popup are created in always-on-top container.
  189. TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
  190. true, // always_on_top
  191. GetAlwaysOnTopContainer());
  192. TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
  193. true, // always_on_top
  194. GetAlwaysOnTopContainer());
  195. }
  196. // Verifies that a window with a preferred size is created centered on the
  197. // default display for new windows. Mojo apps like shortcut_viewer rely on this
  198. // behavior.
  199. TEST_F(ShellTest, CreateWindowWithPreferredSize) {
  200. UpdateDisplay("1024x768,800x600");
  201. aura::Window* secondary_root = Shell::GetAllRootWindows()[1];
  202. display::ScopedDisplayForNewWindows scoped_display(secondary_root);
  203. views::Widget::InitParams params;
  204. params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  205. // Don't specify bounds, parent or context.
  206. {
  207. auto delegate = std::make_unique<views::WidgetDelegateView>();
  208. delegate->SetPreferredSize(gfx::Size(400, 300));
  209. params.delegate = delegate.release();
  210. }
  211. views::Widget widget;
  212. params.context = GetContext();
  213. widget.Init(std::move(params));
  214. // Widget is centered on secondary display.
  215. EXPECT_EQ(secondary_root, widget.GetNativeWindow()->GetRootWindow());
  216. EXPECT_EQ(GetSecondaryDisplay().work_area().CenterPoint(),
  217. widget.GetRestoredBounds().CenterPoint());
  218. }
  219. TEST_F(ShellTest, ChangeZOrderLevel) {
  220. // Creates a normal window.
  221. views::Widget* widget = TestWidgetBuilder().BuildOwnedByNativeWidget();
  222. // It should be in the active desk container.
  223. EXPECT_TRUE(
  224. GetActiveDeskContainer()->Contains(widget->GetNativeWindow()->parent()));
  225. // Set the z-order to float.
  226. widget->SetZOrderLevel(ui::ZOrderLevel::kFloatingWindow);
  227. // And it should in always on top container now.
  228. EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent());
  229. // Put the z-order back to normal.
  230. widget->SetZOrderLevel(ui::ZOrderLevel::kNormal);
  231. // It should go back to the active desk container.
  232. EXPECT_TRUE(
  233. GetActiveDeskContainer()->Contains(widget->GetNativeWindow()->parent()));
  234. // Set the z-order again to the normal value.
  235. widget->SetZOrderLevel(ui::ZOrderLevel::kNormal);
  236. // Should have no effect and we are still in the the active desk container.
  237. EXPECT_TRUE(
  238. GetActiveDeskContainer()->Contains(widget->GetNativeWindow()->parent()));
  239. widget->Close();
  240. }
  241. TEST_F(ShellTest, CreateModalWindow) {
  242. // Create a normal window.
  243. views::Widget* widget = TestWidgetBuilder().BuildOwnedByNativeWidget();
  244. // It should be in the active desk container.
  245. EXPECT_TRUE(
  246. GetActiveDeskContainer()->Contains(widget->GetNativeWindow()->parent()));
  247. // Create a modal window.
  248. views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
  249. CreateModalWidgetDelegate(), widget->GetNativeView());
  250. modal_widget->Show();
  251. // It should be in modal container.
  252. aura::Window* modal_container = Shell::GetContainer(
  253. Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
  254. EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
  255. modal_widget->Close();
  256. widget->Close();
  257. }
  258. TEST_F(ShellTest, CreateLockScreenModalWindow) {
  259. // Create a normal window.
  260. views::Widget* widget = TestWidgetBuilder().BuildOwnedByNativeWidget();
  261. EXPECT_TRUE(widget->GetNativeView()->HasFocus());
  262. // It should be in the active desk container.
  263. EXPECT_TRUE(
  264. GetActiveDeskContainer()->Contains(widget->GetNativeWindow()->parent()));
  265. GetSessionControllerClient()->LockScreen();
  266. // Create a LockScreen window.
  267. views::Widget* lock_widget =
  268. TestWidgetBuilder().SetShow(false).BuildOwnedByNativeWidget();
  269. Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  270. kShellWindowId_LockScreenContainer)
  271. ->AddChild(lock_widget->GetNativeView());
  272. lock_widget->Show();
  273. EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
  274. // It should be in LockScreen container.
  275. aura::Window* lock_screen = Shell::GetContainer(
  276. Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
  277. EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent());
  278. // Create a modal window with a lock window as parent.
  279. views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent(
  280. CreateModalWidgetDelegate(), lock_widget->GetNativeView());
  281. lock_modal_widget->Show();
  282. EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
  283. // It should be in LockScreen modal container.
  284. aura::Window* lock_modal_container =
  285. Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  286. kShellWindowId_LockSystemModalContainer);
  287. EXPECT_EQ(lock_modal_container,
  288. lock_modal_widget->GetNativeWindow()->parent());
  289. // Create a modal window with a normal window as parent.
  290. views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
  291. CreateModalWidgetDelegate(), widget->GetNativeView());
  292. modal_widget->Show();
  293. // Window on lock screen shouldn't lost focus.
  294. EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus());
  295. EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
  296. // It should be in non-LockScreen modal container.
  297. aura::Window* modal_container = Shell::GetContainer(
  298. Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
  299. EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
  300. // Modal widget without parent, caused crash see crbug.com/226141
  301. views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget(
  302. CreateModalWidgetDelegate(), GetContext(), nullptr);
  303. modal_dialog->Show();
  304. EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus());
  305. EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
  306. modal_dialog->Close();
  307. modal_widget->Close();
  308. modal_widget->Close();
  309. lock_modal_widget->Close();
  310. lock_widget->Close();
  311. widget->Close();
  312. }
  313. TEST_F(ShellTest, IsScreenLocked) {
  314. SessionControllerImpl* controller = Shell::Get()->session_controller();
  315. GetSessionControllerClient()->LockScreen();
  316. EXPECT_TRUE(controller->IsScreenLocked());
  317. GetSessionControllerClient()->UnlockScreen();
  318. EXPECT_FALSE(controller->IsScreenLocked());
  319. }
  320. TEST_F(ShellTest, LockScreenClosesActiveMenu) {
  321. SimpleMenuDelegate menu_delegate;
  322. std::unique_ptr<ui::SimpleMenuModel> menu_model(
  323. new ui::SimpleMenuModel(&menu_delegate));
  324. menu_model->AddItem(0, u"Menu item");
  325. views::Widget* widget = Shell::GetPrimaryRootWindowController()
  326. ->wallpaper_widget_controller()
  327. ->GetWidget();
  328. std::unique_ptr<views::MenuRunner> menu_runner(
  329. new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU));
  330. menu_runner->RunMenuAt(widget, nullptr, gfx::Rect(),
  331. views::MenuAnchorPosition::kTopLeft,
  332. ui::MENU_SOURCE_MOUSE);
  333. LockScreenAndVerifyMenuClosed();
  334. }
  335. TEST_F(ShellTest, ManagedWindowModeBasics) {
  336. // We start with the usual window containers.
  337. ExpectAllContainers();
  338. // Shelf is visible.
  339. ShelfWidget* shelf_widget = GetPrimaryShelf()->shelf_widget();
  340. EXPECT_TRUE(shelf_widget->IsVisible());
  341. // Shelf is at bottom-left of screen.
  342. EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x());
  343. EXPECT_EQ(
  344. Shell::GetPrimaryRootWindow()->GetHost()->GetBoundsInPixels().height(),
  345. shelf_widget->GetWindowBoundsInScreen().bottom());
  346. // We have a wallpaper but not a bare layer.
  347. // TODO (antrim): enable once we find out why it fails component build.
  348. // WallpaperWidgetController* wallpaper =
  349. // Shell::GetPrimaryRootWindow()->
  350. // GetProperty(kWindowDesktopComponent);
  351. // EXPECT_TRUE(wallpaper);
  352. // EXPECT_TRUE(wallpaper->widget());
  353. // EXPECT_FALSE(wallpaper->layer());
  354. // Create a normal window. It is not maximized.
  355. views::Widget* widget = TestWidgetBuilder()
  356. .SetBounds(gfx::Rect(11, 22, 300, 400))
  357. .BuildOwnedByNativeWidget();
  358. EXPECT_FALSE(widget->IsMaximized());
  359. // Clean up.
  360. widget->Close();
  361. }
  362. // Tests that the cursor-filter is ahead of the drag-drop controller in the
  363. // pre-target list.
  364. TEST_F(ShellTest, TestPreTargetHandlerOrder) {
  365. Shell* shell = Shell::Get();
  366. ui::EventTargetTestApi test_api(shell);
  367. ShellTestApi shell_test_api;
  368. ui::EventHandlerList handlers = test_api.GetPreTargetHandlers();
  369. ui::EventHandlerList::const_iterator cursor_filter =
  370. std::find(handlers.begin(), handlers.end(), shell->mouse_cursor_filter());
  371. ui::EventHandlerList::const_iterator drag_drop = std::find(
  372. handlers.begin(), handlers.end(), shell_test_api.drag_drop_controller());
  373. EXPECT_NE(handlers.end(), cursor_filter);
  374. EXPECT_NE(handlers.end(), drag_drop);
  375. EXPECT_GT(drag_drop, cursor_filter);
  376. }
  377. // Verifies an EventHandler added to Env gets notified from EventGenerator.
  378. TEST_F(ShellTest, EnvPreTargetHandler) {
  379. ui::test::TestEventHandler event_handler;
  380. aura::Env::GetInstance()->AddPreTargetHandler(&event_handler);
  381. ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
  382. generator.MoveMouseBy(1, 1);
  383. EXPECT_NE(0, event_handler.num_mouse_events());
  384. aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler);
  385. }
  386. // Verifies that pressing tab on an empty shell (one with no windows visible)
  387. // will put focus on the shelf. This enables keyboard only users to get to the
  388. // shelf without knowing the more obscure accelerators. Tab should move focus to
  389. // the home button, shift + tab to the status widget. From there, normal shelf
  390. // tab behaviour takes over, and the shell no longer catches that event.
  391. TEST_F(ShellTest, NoWindowTabFocus) {
  392. ExpectAllContainers();
  393. StatusAreaWidget* status_area_widget =
  394. GetPrimaryShelf()->status_area_widget();
  395. ShelfNavigationWidget* home_button = GetPrimaryShelf()->navigation_widget();
  396. // Create a normal window. It is not maximized.
  397. auto widget = CreateTestWidget();
  398. // Hit tab with window open, and expect that focus is not on the navigation
  399. // widget or status widget.
  400. PressAndReleaseKey(ui::VKEY_TAB);
  401. EXPECT_FALSE(home_button->GetNativeView()->HasFocus());
  402. EXPECT_FALSE(status_area_widget->GetNativeView()->HasFocus());
  403. // Minimize the window, hit tab and expect that focus is on the launcher.
  404. widget->Minimize();
  405. PressAndReleaseKey(ui::VKEY_TAB);
  406. EXPECT_TRUE(home_button->GetNativeView()->HasFocus());
  407. // Show (to steal focus back before continuing testing) and close the window.
  408. widget->Show();
  409. widget->Close();
  410. EXPECT_FALSE(home_button->GetNativeView()->HasFocus());
  411. // Confirm that pressing tab when overview mode is open does not go to home
  412. // button. Tab should be handled by overview mode and not hit the shell event
  413. // handler.
  414. EnterOverview();
  415. PressAndReleaseKey(ui::VKEY_TAB);
  416. EXPECT_FALSE(home_button->GetNativeView()->HasFocus());
  417. ExitOverview();
  418. // Hit shift tab and expect that focus is on status widget.
  419. PressAndReleaseKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN);
  420. EXPECT_TRUE(status_area_widget->GetNativeView()->HasFocus());
  421. }
  422. // This verifies WindowObservers are removed when a window is destroyed after
  423. // the Shell is destroyed. This scenario (aura::Windows being deleted after the
  424. // Shell) occurs if someone is holding a reference to an unparented Window, as
  425. // is the case with a RenderWidgetHostViewAura that isn't on screen. As long as
  426. // everything is ok, we won't crash. If there is a bug, window's destructor will
  427. // notify some deleted object (say VideoDetector or ActivationController) and
  428. // this will crash.
  429. class ShellTest2 : public AshTestBase {
  430. public:
  431. ShellTest2() = default;
  432. ShellTest2(const ShellTest2&) = delete;
  433. ShellTest2& operator=(const ShellTest2&) = delete;
  434. ~ShellTest2() override = default;
  435. protected:
  436. std::unique_ptr<aura::Window> window_;
  437. };
  438. TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
  439. window_ = std::make_unique<aura::Window>(nullptr,
  440. aura::client::WINDOW_TYPE_UNKNOWN);
  441. window_->Init(ui::LAYER_NOT_DRAWN);
  442. }
  443. using ShellLoginTest = NoSessionAshTestBase;
  444. TEST_F(ShellLoginTest, DragAndDropDisabledBeforeLogin) {
  445. DragDropController* drag_drop_controller =
  446. ShellTestApi().drag_drop_controller();
  447. DragDropControllerTestApi drag_drop_controller_test_api(drag_drop_controller);
  448. EXPECT_FALSE(drag_drop_controller_test_api.enabled());
  449. SimulateUserLogin("user1@test.com");
  450. EXPECT_TRUE(drag_drop_controller_test_api.enabled());
  451. }
  452. using NoDuplicateShellContainerIdsTest = AshTestBase;
  453. TEST_F(NoDuplicateShellContainerIdsTest, ValidateContainersIds) {
  454. ExpectAllContainers();
  455. }
  456. } // namespace ash