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/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); | 143 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); |
144 }; | 144 }; |
145 | 145 |
146 } // namespace | 146 } // namespace |
147 | 147 |
148 class SystemModalContainerLayoutManagerTest : public AshTestBase { | 148 class SystemModalContainerLayoutManagerTest : public AshTestBase { |
149 public: | 149 public: |
150 virtual void SetUp() OVERRIDE { | 150 virtual void SetUp() OVERRIDE { |
151 // Allow a virtual keyboard (and initialize it per default). | 151 // Allow a virtual keyboard (and initialize it per default). |
152 CommandLine::ForCurrentProcess()->AppendSwitch( | 152 CommandLine::ForCurrentProcess()->AppendSwitch( |
153 keyboard::switches::kEnableVirtualKeyboard); | 153 keyboard::switches::kEnableVirtualKeyboard); |
154 AshTestBase::SetUp(); | 154 AshTestBase::SetUp(); |
155 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( | 155 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
156 keyboard::KeyboardController::GetInstance()); | 156 keyboard::KeyboardController::GetInstance()); |
157 } | 157 } |
158 | 158 |
159 virtual void TearDown() OVERRIDE { | 159 virtual void TearDown() OVERRIDE { |
160 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( | 160 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
161 keyboard::KeyboardController::GetInstance()); | 161 keyboard::KeyboardController::GetInstance()); |
162 AshTestBase::TearDown(); | 162 AshTestBase::TearDown(); |
163 } | 163 } |
(...skipping 13 matching lines...) Expand all Loading... |
177 } | 177 } |
178 | 178 |
179 // Show or hide the keyboard. | 179 // Show or hide the keyboard. |
180 void ShowKeyboard(bool show) { | 180 void ShowKeyboard(bool show) { |
181 keyboard::KeyboardController* keyboard = | 181 keyboard::KeyboardController* keyboard = |
182 keyboard::KeyboardController::GetInstance(); | 182 keyboard::KeyboardController::GetInstance(); |
183 ASSERT_TRUE(keyboard); | 183 ASSERT_TRUE(keyboard); |
184 if (show == keyboard->keyboard_visible()) | 184 if (show == keyboard->keyboard_visible()) |
185 return; | 185 return; |
186 | 186 |
187 // The animation has to run in order to get the notification. Run the | 187 if (show) { |
188 // animation and wait until its finished. | 188 keyboard->ShowKeyboard(true); |
189 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 189 if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) { |
190 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 190 keyboard->proxy()->GetKeyboardWindow()->SetBounds( |
191 if (show) | 191 keyboard::KeyboardBoundsFromWindowBounds( |
192 keyboard->ShowAndLockKeyboard(); | 192 keyboard->GetContainerWindow()->bounds(), 100)); |
193 else | 193 } |
| 194 } else { |
194 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); | 195 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
195 | 196 } |
196 WaitForWindowAnimationToBeFinished(keyboard->GetContainerWindow()); | |
197 | 197 |
198 DCHECK_EQ(show, keyboard->keyboard_visible()); | 198 DCHECK_EQ(show, keyboard->keyboard_visible()); |
199 } | 199 } |
200 | 200 |
201 void WaitForWindowAnimationToBeFinished(aura::Window* window) { | |
202 DCHECK(window); | |
203 ui::Layer* layer = window->layer(); | |
204 ui::LayerAnimatorTestController controller(layer->GetAnimator()); | |
205 gfx::AnimationContainerElement* element = layer->GetAnimator(); | |
206 while (controller.animator()->is_animating()) { | |
207 controller.StartThreadedAnimationsIfNeeded(); | |
208 base::TimeTicks step_time = controller.animator()->last_step_time(); | |
209 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); | |
210 } | |
211 } | |
212 }; | 201 }; |
213 | 202 |
214 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 203 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
215 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 204 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
216 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); | 205 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
217 TransientWindowObserver destruction_observer; | 206 TransientWindowObserver destruction_observer; |
218 transient->AddObserver(&destruction_observer); | 207 transient->AddObserver(&destruction_observer); |
219 | 208 |
220 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); | 209 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); |
221 EXPECT_EQ(parent->parent(), transient->parent()); | 210 EXPECT_EQ(parent->parent(), transient->parent()); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 569 |
581 // After the keyboard is gone, the window will remain where it was. | 570 // After the keyboard is gone, the window will remain where it was. |
582 ShowKeyboard(false); | 571 ShowKeyboard(false); |
583 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); | 572 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); |
584 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 573 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
585 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 574 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
586 } | 575 } |
587 | 576 |
588 } // namespace test | 577 } // namespace test |
589 } // namespace ash | 578 } // namespace ash |
OLD | NEW |