| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/wm/workspace/phantom_window_controller.h" | |
| 6 | |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ui/aura/root_window.h" | |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/aura/window_observer.h" | |
| 13 #include "ui/views/widget/widget.h" | |
| 14 | |
| 15 namespace ash { | |
| 16 namespace internal { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Returns true if |window| is non-NULL and is visible. | |
| 21 bool IsVisible(aura::Window* window) { | |
| 22 return window && window->IsVisible(); | |
| 23 } | |
| 24 | |
| 25 // Observes |window|'s deletion. | |
| 26 class WindowDeletionObserver : public aura::WindowObserver { | |
| 27 public: | |
| 28 WindowDeletionObserver(aura::Window* window) : window_(window) { | |
| 29 window_->AddObserver(this); | |
| 30 } | |
| 31 | |
| 32 virtual ~WindowDeletionObserver() { | |
| 33 if (window_) | |
| 34 window_->RemoveObserver(this); | |
| 35 } | |
| 36 | |
| 37 // Returns true if the window has not been deleted yet. | |
| 38 bool IsWindowAlive() { | |
| 39 return !!window_; | |
| 40 } | |
| 41 | |
| 42 // aura::WindowObserver: | |
| 43 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | |
| 44 window_->RemoveObserver(this); | |
| 45 window_ = NULL; | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 aura::Window* window_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(WindowDeletionObserver); | |
| 52 }; | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 class PhantomWindowControllerTest : public ash::test::AshTestBase { | |
| 57 public: | |
| 58 PhantomWindowControllerTest() { | |
| 59 } | |
| 60 virtual ~PhantomWindowControllerTest() { | |
| 61 } | |
| 62 | |
| 63 // ash::test::AshTestBase: | |
| 64 virtual void SetUp() OVERRIDE { | |
| 65 ash::test::AshTestBase::SetUp(); | |
| 66 | |
| 67 UpdateDisplay("500x400,500x400"); | |
| 68 window_ = CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 60)); | |
| 69 controller_.reset(new PhantomWindowController(window_)); | |
| 70 } | |
| 71 | |
| 72 void DeleteController() { | |
| 73 controller_.reset(); | |
| 74 } | |
| 75 | |
| 76 PhantomWindowController* controller() { | |
| 77 return controller_.get(); | |
| 78 } | |
| 79 | |
| 80 aura::Window* window() { return window_; } | |
| 81 | |
| 82 aura::Window* phantom_window_in_target_root() { | |
| 83 return controller_->phantom_widget_in_target_root_ ? | |
| 84 controller_->phantom_widget_in_target_root_->GetNativeView() : | |
| 85 NULL; | |
| 86 } | |
| 87 | |
| 88 aura::Window* phantom_window_in_start_root() { | |
| 89 return controller_->phantom_widget_in_start_root_ ? | |
| 90 controller_->phantom_widget_in_start_root_->GetNativeView() : | |
| 91 NULL; | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 aura::Window* window_; | |
| 96 scoped_ptr<PhantomWindowController> controller_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(PhantomWindowControllerTest); | |
| 99 }; | |
| 100 | |
| 101 // Test that two phantom windows are used when animating to bounds at least | |
| 102 // partially in another display. | |
| 103 TEST_F(PhantomWindowControllerTest, PhantomWindowShow) { | |
| 104 if (!SupportsMultipleDisplays()) | |
| 105 return; | |
| 106 | |
| 107 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 108 EXPECT_EQ(root_windows[0], window()->GetRootWindow()); | |
| 109 | |
| 110 // Phantom preview only in the left screen. | |
| 111 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 112 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 113 EXPECT_FALSE(IsVisible(phantom_window_in_start_root())); | |
| 114 EXPECT_EQ(root_windows[0], phantom_window_in_target_root()->GetRootWindow()); | |
| 115 | |
| 116 // Move phantom preview into the right screen. Test that 2 windows got | |
| 117 // created. | |
| 118 controller()->Show(gfx::Rect(600, 100, 50, 60)); | |
| 119 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 120 EXPECT_TRUE(IsVisible(phantom_window_in_start_root())); | |
| 121 EXPECT_EQ(root_windows[1], phantom_window_in_target_root()->GetRootWindow()); | |
| 122 EXPECT_EQ(root_windows[0], phantom_window_in_start_root()->GetRootWindow()); | |
| 123 | |
| 124 // Move phantom preview only in the right screen. Start window should close. | |
| 125 controller()->Show(gfx::Rect(700, 100, 50, 60)); | |
| 126 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 127 EXPECT_FALSE(IsVisible(phantom_window_in_start_root())); | |
| 128 EXPECT_EQ(root_windows[1], phantom_window_in_target_root()->GetRootWindow()); | |
| 129 | |
| 130 // Move phantom preview into the left screen. Start window should open. | |
| 131 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 132 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 133 EXPECT_TRUE(IsVisible(phantom_window_in_start_root())); | |
| 134 EXPECT_EQ(root_windows[0], phantom_window_in_target_root()->GetRootWindow()); | |
| 135 EXPECT_EQ(root_windows[1], phantom_window_in_start_root()->GetRootWindow()); | |
| 136 | |
| 137 // Move phantom preview while in the left screen. Start window should close. | |
| 138 controller()->Show(gfx::Rect(200, 100, 50, 60)); | |
| 139 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 140 EXPECT_FALSE(IsVisible(phantom_window_in_start_root())); | |
| 141 EXPECT_EQ(root_windows[0], phantom_window_in_target_root()->GetRootWindow()); | |
| 142 | |
| 143 // Move phantom preview spanning both screens with most of the preview in the | |
| 144 // right screen. Two windows are created. | |
| 145 controller()->Show(gfx::Rect(495, 100, 50, 60)); | |
| 146 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 147 EXPECT_TRUE(IsVisible(phantom_window_in_start_root())); | |
| 148 EXPECT_EQ(root_windows[1], phantom_window_in_target_root()->GetRootWindow()); | |
| 149 EXPECT_EQ(root_windows[0], phantom_window_in_start_root()->GetRootWindow()); | |
| 150 | |
| 151 // Move phantom preview back into the left screen. Phantom windows should | |
| 152 // swap. | |
| 153 controller()->Show(gfx::Rect(200, 100, 50, 60)); | |
| 154 EXPECT_TRUE(IsVisible(phantom_window_in_target_root())); | |
| 155 EXPECT_TRUE(IsVisible(phantom_window_in_start_root())); | |
| 156 EXPECT_EQ(root_windows[0], phantom_window_in_target_root()->GetRootWindow()); | |
| 157 EXPECT_EQ(root_windows[1], phantom_window_in_start_root()->GetRootWindow()); | |
| 158 | |
| 159 // Destroy phantom controller. Both windows should close. | |
| 160 WindowDeletionObserver target_deletion_observer( | |
| 161 phantom_window_in_target_root()); | |
| 162 WindowDeletionObserver start_deletion_observer( | |
| 163 phantom_window_in_start_root()); | |
| 164 DeleteController(); | |
| 165 EXPECT_FALSE(target_deletion_observer.IsWindowAlive()); | |
| 166 EXPECT_FALSE(start_deletion_observer.IsWindowAlive()); | |
| 167 } | |
| 168 | |
| 169 } // namespace internal | |
| 170 } // namespace ash | |
| OLD | NEW |