• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "ash/shell.h"
6 
7 #include <algorithm>
8 #include <vector>
9 
10 #include "ash/ash_switches.h"
11 #include "ash/desktop_background/desktop_background_widget_controller.h"
12 #include "ash/display/mouse_cursor_event_filter.h"
13 #include "ash/drag_drop/drag_drop_controller.h"
14 #include "ash/root_window_controller.h"
15 #include "ash/session/session_state_delegate.h"
16 #include "ash/shelf/shelf.h"
17 #include "ash/shelf/shelf_layout_manager.h"
18 #include "ash/shelf/shelf_widget.h"
19 #include "ash/shell_delegate.h"
20 #include "ash/shell_window_ids.h"
21 #include "ash/test/ash_test_base.h"
22 #include "ash/test/shell_test_api.h"
23 #include "ash/wm/root_window_layout_manager.h"
24 #include "ash/wm/window_util.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/env.h"
28 #include "ui/aura/test/event_generator.h"
29 #include "ui/aura/window.h"
30 #include "ui/aura/window_event_dispatcher.h"
31 #include "ui/base/models/simple_menu_model.h"
32 #include "ui/events/test/events_test_utils.h"
33 #include "ui/events/test/test_event_handler.h"
34 #include "ui/gfx/size.h"
35 #include "ui/views/controls/menu/menu_controller.h"
36 #include "ui/views/controls/menu/menu_runner.h"
37 #include "ui/views/widget/widget.h"
38 #include "ui/views/widget/widget_delegate.h"
39 #include "ui/views/window/dialog_delegate.h"
40 
41 using aura::RootWindow;
42 
43 namespace ash {
44 
45 namespace {
46 
GetDefaultContainer()47 aura::Window* GetDefaultContainer() {
48   return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
49                              kShellWindowId_DefaultContainer);
50 }
51 
GetAlwaysOnTopContainer()52 aura::Window* GetAlwaysOnTopContainer() {
53   return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
54                              kShellWindowId_AlwaysOnTopContainer);
55 }
56 
57 // Expect ALL the containers!
ExpectAllContainers()58 void ExpectAllContainers() {
59   aura::Window* root_window = Shell::GetPrimaryRootWindow();
60   EXPECT_TRUE(Shell::GetContainer(root_window,
61                                   kShellWindowId_DesktopBackgroundContainer));
62   EXPECT_TRUE(
63       Shell::GetContainer(root_window, kShellWindowId_DefaultContainer));
64   EXPECT_TRUE(
65       Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer));
66   EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_PanelContainer));
67   EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer));
68   EXPECT_TRUE(
69       Shell::GetContainer(root_window, kShellWindowId_SystemModalContainer));
70   EXPECT_TRUE(Shell::GetContainer(
71       root_window, kShellWindowId_LockScreenBackgroundContainer));
72   EXPECT_TRUE(
73       Shell::GetContainer(root_window, kShellWindowId_LockScreenContainer));
74   EXPECT_TRUE(Shell::GetContainer(root_window,
75                                   kShellWindowId_LockSystemModalContainer));
76   EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_StatusContainer));
77   EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_MenuContainer));
78   EXPECT_TRUE(Shell::GetContainer(root_window,
79                                   kShellWindowId_DragImageAndTooltipContainer));
80   EXPECT_TRUE(
81       Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer));
82   EXPECT_TRUE(
83       Shell::GetContainer(root_window, kShellWindowId_OverlayContainer));
84   EXPECT_TRUE(Shell::GetContainer(
85       root_window, kShellWindowId_VirtualKeyboardParentContainer));
86 #if defined(OS_CHROMEOS)
87   EXPECT_TRUE(
88       Shell::GetContainer(root_window, kShellWindowId_MouseCursorContainer));
89 #endif
90 }
91 
92 class ModalWindow : public views::WidgetDelegateView {
93  public:
ModalWindow()94   ModalWindow() {}
~ModalWindow()95   virtual ~ModalWindow() {}
96 
97   // Overridden from views::WidgetDelegate:
GetContentsView()98   virtual views::View* GetContentsView() OVERRIDE {
99     return this;
100   }
CanResize() const101   virtual bool CanResize() const OVERRIDE {
102     return true;
103   }
GetWindowTitle() const104   virtual base::string16 GetWindowTitle() const OVERRIDE {
105     return base::ASCIIToUTF16("Modal Window");
106   }
GetModalType() const107   virtual ui::ModalType GetModalType() const OVERRIDE {
108     return ui::MODAL_TYPE_SYSTEM;
109   }
110 
111  private:
112   DISALLOW_COPY_AND_ASSIGN(ModalWindow);
113 };
114 
115 class SimpleMenuDelegate : public ui::SimpleMenuModel::Delegate {
116  public:
SimpleMenuDelegate()117   SimpleMenuDelegate() {}
~SimpleMenuDelegate()118   virtual ~SimpleMenuDelegate() {}
119 
IsCommandIdChecked(int command_id) const120   virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
121     return false;
122   }
123 
IsCommandIdEnabled(int command_id) const124   virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
125     return true;
126   }
127 
GetAcceleratorForCommandId(int command_id,ui::Accelerator * accelerator)128   virtual bool GetAcceleratorForCommandId(
129       int command_id,
130       ui::Accelerator* accelerator) OVERRIDE {
131     return false;
132   }
133 
ExecuteCommand(int command_id,int event_flags)134   virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {
135   }
136 
137  private:
138   DISALLOW_COPY_AND_ASSIGN(SimpleMenuDelegate);
139 };
140 
141 }  // namespace
142 
143 class ShellTest : public test::AshTestBase {
144  public:
CreateTestWindow(views::Widget::InitParams params)145   views::Widget* CreateTestWindow(views::Widget::InitParams params) {
146     views::Widget* widget = new views::Widget;
147     params.context = CurrentContext();
148     widget->Init(params);
149     return widget;
150   }
151 
TestCreateWindow(views::Widget::InitParams::Type type,bool always_on_top,aura::Window * expected_container)152   void TestCreateWindow(views::Widget::InitParams::Type type,
153                         bool always_on_top,
154                         aura::Window* expected_container) {
155     views::Widget::InitParams widget_params(type);
156     widget_params.keep_on_top = always_on_top;
157 
158     views::Widget* widget = CreateTestWindow(widget_params);
159     widget->Show();
160 
161     EXPECT_TRUE(
162         expected_container->Contains(widget->GetNativeWindow()->parent())) <<
163         "TestCreateWindow: type=" << type << ", always_on_top=" <<
164         always_on_top;
165 
166     widget->Close();
167   }
168 
LockScreenAndVerifyMenuClosed()169   void LockScreenAndVerifyMenuClosed() {
170     // Verify a menu is open before locking.
171     views::MenuController* menu_controller =
172         views::MenuController::GetActiveInstance();
173     DCHECK(menu_controller);
174     EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type());
175 
176     // Create a LockScreen window.
177     views::Widget::InitParams widget_params(
178         views::Widget::InitParams::TYPE_WINDOW);
179     SessionStateDelegate* delegate =
180         Shell::GetInstance()->session_state_delegate();
181     delegate->LockScreen();
182     views::Widget* lock_widget = CreateTestWindow(widget_params);
183     ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
184                              ash::kShellWindowId_LockScreenContainer)
185         ->AddChild(lock_widget->GetNativeView());
186     lock_widget->Show();
187     EXPECT_TRUE(delegate->IsScreenLocked());
188     EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
189 
190     // Verify menu is closed.
191     EXPECT_NE(views::MenuController::EXIT_NONE, menu_controller->exit_type());
192     lock_widget->Close();
193     delegate->UnlockScreen();
194 
195     // In case the menu wasn't closed, cancel the menu to exit the nested menu
196     // run loop so that the test will not time out.
197     menu_controller->CancelAll();
198   }
199 };
200 
TEST_F(ShellTest,CreateWindow)201 TEST_F(ShellTest, CreateWindow) {
202   // Normal window should be created in default container.
203   TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
204                    false,  // always_on_top
205                    GetDefaultContainer());
206   TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
207                    false,  // always_on_top
208                    GetDefaultContainer());
209 
210   // Always-on-top window and popup are created in always-on-top container.
211   TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
212                    true,  // always_on_top
213                    GetAlwaysOnTopContainer());
214   TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
215                    true,  // always_on_top
216                    GetAlwaysOnTopContainer());
217 }
218 
TEST_F(ShellTest,ChangeAlwaysOnTop)219 TEST_F(ShellTest, ChangeAlwaysOnTop) {
220   views::Widget::InitParams widget_params(
221       views::Widget::InitParams::TYPE_WINDOW);
222 
223   // Creates a normal window
224   views::Widget* widget = CreateTestWindow(widget_params);
225   widget->Show();
226 
227   // It should be in default container.
228   EXPECT_TRUE(GetDefaultContainer()->Contains(
229                   widget->GetNativeWindow()->parent()));
230 
231   // Flip always-on-top flag.
232   widget->SetAlwaysOnTop(true);
233   // And it should in always on top container now.
234   EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent());
235 
236   // Flip always-on-top flag.
237   widget->SetAlwaysOnTop(false);
238   // It should go back to default container.
239   EXPECT_TRUE(GetDefaultContainer()->Contains(
240                   widget->GetNativeWindow()->parent()));
241 
242   // Set the same always-on-top flag again.
243   widget->SetAlwaysOnTop(false);
244   // Should have no effect and we are still in the default container.
245   EXPECT_TRUE(GetDefaultContainer()->Contains(
246                   widget->GetNativeWindow()->parent()));
247 
248   widget->Close();
249 }
250 
TEST_F(ShellTest,CreateModalWindow)251 TEST_F(ShellTest, CreateModalWindow) {
252   views::Widget::InitParams widget_params(
253       views::Widget::InitParams::TYPE_WINDOW);
254 
255   // Create a normal window.
256   views::Widget* widget = CreateTestWindow(widget_params);
257   widget->Show();
258 
259   // It should be in default container.
260   EXPECT_TRUE(GetDefaultContainer()->Contains(
261                   widget->GetNativeWindow()->parent()));
262 
263   // Create a modal window.
264   views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
265       new ModalWindow(), widget->GetNativeView());
266   modal_widget->Show();
267 
268   // It should be in modal container.
269   aura::Window* modal_container = Shell::GetContainer(
270       Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
271   EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
272 
273   modal_widget->Close();
274   widget->Close();
275 }
276 
277 class TestModalDialogDelegate : public views::DialogDelegateView {
278  public:
TestModalDialogDelegate()279   TestModalDialogDelegate() {}
280 
281   // Overridden from views::WidgetDelegate:
GetModalType() const282   virtual ui::ModalType GetModalType() const OVERRIDE {
283     return ui::MODAL_TYPE_SYSTEM;
284   }
285 };
286 
TEST_F(ShellTest,CreateLockScreenModalWindow)287 TEST_F(ShellTest, CreateLockScreenModalWindow) {
288   views::Widget::InitParams widget_params(
289       views::Widget::InitParams::TYPE_WINDOW);
290 
291   // Create a normal window.
292   views::Widget* widget = CreateTestWindow(widget_params);
293   widget->Show();
294   EXPECT_TRUE(widget->GetNativeView()->HasFocus());
295 
296   // It should be in default container.
297   EXPECT_TRUE(GetDefaultContainer()->Contains(
298                   widget->GetNativeWindow()->parent()));
299 
300   Shell::GetInstance()->session_state_delegate()->LockScreen();
301   // Create a LockScreen window.
302   views::Widget* lock_widget = CreateTestWindow(widget_params);
303   ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
304                            ash::kShellWindowId_LockScreenContainer)
305       ->AddChild(lock_widget->GetNativeView());
306   lock_widget->Show();
307   EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
308 
309   // It should be in LockScreen container.
310   aura::Window* lock_screen = Shell::GetContainer(
311       Shell::GetPrimaryRootWindow(), ash::kShellWindowId_LockScreenContainer);
312   EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent());
313 
314   // Create a modal window with a lock window as parent.
315   views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent(
316       new ModalWindow(), lock_widget->GetNativeView());
317   lock_modal_widget->Show();
318   EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
319 
320   // It should be in LockScreen modal container.
321   aura::Window* lock_modal_container =
322       Shell::GetContainer(Shell::GetPrimaryRootWindow(),
323                           ash::kShellWindowId_LockSystemModalContainer);
324   EXPECT_EQ(lock_modal_container,
325             lock_modal_widget->GetNativeWindow()->parent());
326 
327   // Create a modal window with a normal window as parent.
328   views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
329       new ModalWindow(), widget->GetNativeView());
330   modal_widget->Show();
331   // Window on lock screen shouldn't lost focus.
332   EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus());
333   EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
334 
335   // It should be in non-LockScreen modal container.
336   aura::Window* modal_container = Shell::GetContainer(
337       Shell::GetPrimaryRootWindow(), ash::kShellWindowId_SystemModalContainer);
338   EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
339 
340   // Modal dialog without parent, caused crash see crbug.com/226141
341   views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget(
342       new TestModalDialogDelegate(), CurrentContext(), NULL);
343 
344   modal_dialog->Show();
345   EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus());
346   EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
347 
348   modal_dialog->Close();
349   modal_widget->Close();
350   modal_widget->Close();
351   lock_modal_widget->Close();
352   lock_widget->Close();
353   widget->Close();
354 }
355 
TEST_F(ShellTest,IsScreenLocked)356 TEST_F(ShellTest, IsScreenLocked) {
357   SessionStateDelegate* delegate =
358       Shell::GetInstance()->session_state_delegate();
359   delegate->LockScreen();
360   EXPECT_TRUE(delegate->IsScreenLocked());
361   delegate->UnlockScreen();
362   EXPECT_FALSE(delegate->IsScreenLocked());
363 }
364 
TEST_F(ShellTest,LockScreenClosesActiveMenu)365 TEST_F(ShellTest, LockScreenClosesActiveMenu) {
366   SimpleMenuDelegate menu_delegate;
367   scoped_ptr<ui::SimpleMenuModel> menu_model(
368       new ui::SimpleMenuModel(&menu_delegate));
369   menu_model->AddItem(0, base::ASCIIToUTF16("Menu item"));
370   views::Widget* widget = ash::Shell::GetPrimaryRootWindowController()->
371       wallpaper_controller()->widget();
372   scoped_ptr<views::MenuRunner> menu_runner(
373       new views::MenuRunner(menu_model.get()));
374 
375   // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed
376   // command will fire, check the menu state and ensure the nested menu loop
377   // is exited so that the test will terminate.
378   base::MessageLoopForUI::current()->PostTask(FROM_HERE,
379       base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed,
380                  base::Unretained(this)));
381 
382   EXPECT_EQ(views::MenuRunner::NORMAL_EXIT,
383             menu_runner->RunMenuAt(widget,
384                                    NULL,
385                                    gfx::Rect(),
386                                    views::MENU_ANCHOR_TOPLEFT,
387                                    ui::MENU_SOURCE_MOUSE,
388                                    views::MenuRunner::CONTEXT_MENU));
389 }
390 
TEST_F(ShellTest,ManagedWindowModeBasics)391 TEST_F(ShellTest, ManagedWindowModeBasics) {
392   // We start with the usual window containers.
393   ExpectAllContainers();
394   // Shelf is visible.
395   ShelfWidget* shelf_widget = Shelf::ForPrimaryDisplay()->shelf_widget();
396   EXPECT_TRUE(shelf_widget->IsVisible());
397   // Shelf is at bottom-left of screen.
398   EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x());
399   EXPECT_EQ(Shell::GetPrimaryRootWindow()->GetHost()->GetBounds().height(),
400             shelf_widget->GetWindowBoundsInScreen().bottom());
401   // We have a desktop background but not a bare layer.
402   // TODO (antrim): enable once we find out why it fails component build.
403   //  DesktopBackgroundWidgetController* background =
404   //      Shell::GetPrimaryRootWindow()->
405   //          GetProperty(kWindowDesktopComponent);
406   //  EXPECT_TRUE(background);
407   //  EXPECT_TRUE(background->widget());
408   //  EXPECT_FALSE(background->layer());
409 
410   // Create a normal window.  It is not maximized.
411   views::Widget::InitParams widget_params(
412       views::Widget::InitParams::TYPE_WINDOW);
413   widget_params.bounds.SetRect(11, 22, 300, 400);
414   views::Widget* widget = CreateTestWindow(widget_params);
415   widget->Show();
416   EXPECT_FALSE(widget->IsMaximized());
417 
418   // Clean up.
419   widget->Close();
420 }
421 
TEST_F(ShellTest,FullscreenWindowHidesShelf)422 TEST_F(ShellTest, FullscreenWindowHidesShelf) {
423   ExpectAllContainers();
424 
425   // Create a normal window.  It is not maximized.
426   views::Widget::InitParams widget_params(
427       views::Widget::InitParams::TYPE_WINDOW);
428   widget_params.bounds.SetRect(11, 22, 300, 400);
429   views::Widget* widget = CreateTestWindow(widget_params);
430   widget->Show();
431   EXPECT_FALSE(widget->IsMaximized());
432 
433   // Shelf defaults to visible.
434   EXPECT_EQ(
435       SHELF_VISIBLE,
436       Shell::GetPrimaryRootWindowController()->
437           GetShelfLayoutManager()->visibility_state());
438 
439   // Fullscreen window hides it.
440   widget->SetFullscreen(true);
441   EXPECT_EQ(
442       SHELF_HIDDEN,
443       Shell::GetPrimaryRootWindowController()->
444           GetShelfLayoutManager()->visibility_state());
445 
446   // Restoring the window restores it.
447   widget->Restore();
448   EXPECT_EQ(
449       SHELF_VISIBLE,
450       Shell::GetPrimaryRootWindowController()->
451           GetShelfLayoutManager()->visibility_state());
452 
453   // Clean up.
454   widget->Close();
455 }
456 
457 // Various assertions around SetShelfAutoHideBehavior() and
458 // GetShelfAutoHideBehavior().
TEST_F(ShellTest,ToggleAutoHide)459 TEST_F(ShellTest, ToggleAutoHide) {
460   scoped_ptr<aura::Window> window(new aura::Window(NULL));
461   window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
462   window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
463   window->Init(aura::WINDOW_LAYER_TEXTURED);
464   ParentWindowInPrimaryRootWindow(window.get());
465   window->Show();
466   wm::ActivateWindow(window.get());
467 
468   Shell* shell = Shell::GetInstance();
469   aura::Window* root_window = Shell::GetPrimaryRootWindow();
470   shell->SetShelfAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
471                                   root_window);
472   EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
473             shell->GetShelfAutoHideBehavior(root_window));
474   shell->SetShelfAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
475                                   root_window);
476   EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
477             shell->GetShelfAutoHideBehavior(root_window));
478   window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
479   EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
480             shell->GetShelfAutoHideBehavior(root_window));
481   shell->SetShelfAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
482                                   root_window);
483   EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
484             shell->GetShelfAutoHideBehavior(root_window));
485   shell->SetShelfAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
486                                   root_window);
487   EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
488             shell->GetShelfAutoHideBehavior(root_window));
489 }
490 
491 // Tests that the cursor-filter is ahead of the drag-drop controller in the
492 // pre-target list.
TEST_F(ShellTest,TestPreTargetHandlerOrder)493 TEST_F(ShellTest, TestPreTargetHandlerOrder) {
494   Shell* shell = Shell::GetInstance();
495   ui::EventTargetTestApi test_api(shell);
496   test::ShellTestApi shell_test_api(shell);
497 
498   const ui::EventHandlerList& handlers = test_api.pre_target_handlers();
499   ui::EventHandlerList::const_iterator cursor_filter =
500       std::find(handlers.begin(), handlers.end(), shell->mouse_cursor_filter());
501   ui::EventHandlerList::const_iterator drag_drop =
502       std::find(handlers.begin(), handlers.end(),
503                 shell_test_api.drag_drop_controller());
504   EXPECT_NE(handlers.end(), cursor_filter);
505   EXPECT_NE(handlers.end(), drag_drop);
506   EXPECT_GT(drag_drop, cursor_filter);
507 }
508 
509 // Verifies an EventHandler added to Env gets notified from EventGenerator.
TEST_F(ShellTest,EnvPreTargetHandler)510 TEST_F(ShellTest, EnvPreTargetHandler) {
511   ui::test::TestEventHandler event_handler;
512   aura::Env::GetInstance()->AddPreTargetHandler(&event_handler);
513   aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
514   generator.MoveMouseBy(1, 1);
515   EXPECT_NE(0, event_handler.num_mouse_events());
516   aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler);
517 }
518 
519 // This verifies WindowObservers are removed when a window is destroyed after
520 // the Shell is destroyed. This scenario (aura::Windows being deleted after the
521 // Shell) occurs if someone is holding a reference to an unparented Window, as
522 // is the case with a RenderWidgetHostViewAura that isn't on screen. As long as
523 // everything is ok, we won't crash. If there is a bug, window's destructor will
524 // notify some deleted object (say VideoDetector or ActivationController) and
525 // this will crash.
526 class ShellTest2 : public test::AshTestBase {
527  public:
ShellTest2()528   ShellTest2() {}
~ShellTest2()529   virtual ~ShellTest2() {}
530 
531  protected:
532   scoped_ptr<aura::Window> window_;
533 
534  private:
535   DISALLOW_COPY_AND_ASSIGN(ShellTest2);
536 };
537 
TEST_F(ShellTest2,DontCrashWhenWindowDeleted)538 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
539   window_.reset(new aura::Window(NULL));
540   window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
541 }
542 
543 }  // namespace ash
544