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