| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "ui/keyboard/keyboard_test_util.h" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_observer.h" |
| 10 #include "ui/keyboard/keyboard_controller.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 class WindowVisibilityChangeWaiter : public aura::WindowObserver { |
| 15 public: |
| 16 explicit WindowVisibilityChangeWaiter(aura::Window* window, bool wait_until) |
| 17 : window_(window), wait_until_(wait_until) { |
| 18 window_->AddObserver(this); |
| 19 } |
| 20 ~WindowVisibilityChangeWaiter() override { window_->RemoveObserver(this); } |
| 21 |
| 22 void Wait() { run_loop_.Run(); } |
| 23 |
| 24 private: |
| 25 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override { |
| 26 if (window_ == window && visible == wait_until_) { |
| 27 run_loop_.QuitWhenIdle(); |
| 28 } |
| 29 } |
| 30 |
| 31 aura::Window* window_; |
| 32 base::RunLoop run_loop_; |
| 33 bool const wait_until_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(WindowVisibilityChangeWaiter); |
| 36 }; |
| 37 |
| 38 bool WaitVisibilityChangesTo(bool visibility) { |
| 39 aura::Window* keyboard_window = |
| 40 keyboard::KeyboardController::GetInstance() |
| 41 ->GetContainerWindowWithoutCreationForTest(); |
| 42 if (!keyboard_window) |
| 43 return false; |
| 44 WindowVisibilityChangeWaiter waiter(keyboard_window, visibility); |
| 45 waiter.Wait(); |
| 46 return true; |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 namespace keyboard { |
| 52 |
| 53 bool WaitUntilShown() { |
| 54 return WaitVisibilityChangesTo(true); |
| 55 } |
| 56 |
| 57 bool WaitUntilHidden() { |
| 58 return WaitVisibilityChangesTo(false); |
| 59 } |
| 60 |
| 61 } // namespace keyboard |
| OLD | NEW |