| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chromeos/login/test/app_window_waiter.h" | 5 #include "apps/test/app_window_waiter.h" |
| 6 | 6 |
| 7 #include "extensions/browser/app_window/app_window.h" | 7 #include "extensions/browser/app_window/app_window.h" |
| 8 #include "extensions/browser/app_window/native_app_window.h" |
| 8 | 9 |
| 9 namespace chromeos { | 10 namespace apps { |
| 10 | 11 |
| 11 AppWindowWaiter::AppWindowWaiter(extensions::AppWindowRegistry* registry, | 12 AppWindowWaiter::AppWindowWaiter(extensions::AppWindowRegistry* registry, |
| 12 const std::string& app_id) | 13 const std::string& app_id) |
| 13 : registry_(registry), app_id_(app_id) { | 14 : registry_(registry), app_id_(app_id) { |
| 14 registry_->AddObserver(this); | 15 registry_->AddObserver(this); |
| 15 } | 16 } |
| 16 | 17 |
| 17 AppWindowWaiter::~AppWindowWaiter() { | 18 AppWindowWaiter::~AppWindowWaiter() { |
| 18 registry_->RemoveObserver(this); | 19 registry_->RemoveObserver(this); |
| 19 } | 20 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 if (window_ && !window_->is_hidden()) | 36 if (window_ && !window_->is_hidden()) |
| 36 return window_; | 37 return window_; |
| 37 | 38 |
| 38 wait_type_ = WAIT_FOR_SHOWN; | 39 wait_type_ = WAIT_FOR_SHOWN; |
| 39 run_loop_.reset(new base::RunLoop); | 40 run_loop_.reset(new base::RunLoop); |
| 40 run_loop_->Run(); | 41 run_loop_->Run(); |
| 41 | 42 |
| 42 return window_; | 43 return window_; |
| 43 } | 44 } |
| 44 | 45 |
| 46 extensions::AppWindow* AppWindowWaiter::WaitForActivated() { |
| 47 window_ = registry_->GetCurrentAppWindowForApp(app_id_); |
| 48 if (window_ && window_->GetBaseWindow()->IsActive()) |
| 49 return window_; |
| 50 |
| 51 wait_type_ = WAIT_FOR_ACTIVATED; |
| 52 run_loop_.reset(new base::RunLoop); |
| 53 run_loop_->Run(); |
| 54 |
| 55 return window_; |
| 56 } |
| 57 |
| 45 void AppWindowWaiter::OnAppWindowAdded(extensions::AppWindow* app_window) { | 58 void AppWindowWaiter::OnAppWindowAdded(extensions::AppWindow* app_window) { |
| 46 if (wait_type_ != WAIT_FOR_ADDED || !run_loop_ || !run_loop_->running()) | 59 if (wait_type_ != WAIT_FOR_ADDED || !run_loop_ || !run_loop_->running()) |
| 47 return; | 60 return; |
| 48 | 61 |
| 49 if (app_window->extension_id() == app_id_) { | 62 if (app_window->extension_id() == app_id_) { |
| 50 window_ = app_window; | 63 window_ = app_window; |
| 51 run_loop_->Quit(); | 64 run_loop_->Quit(); |
| 52 } | 65 } |
| 53 } | 66 } |
| 54 | 67 |
| 55 void AppWindowWaiter::OnAppWindowShown(extensions::AppWindow* app_window, | 68 void AppWindowWaiter::OnAppWindowShown(extensions::AppWindow* app_window, |
| 56 bool was_hidden) { | 69 bool was_hidden) { |
| 57 if (wait_type_ != WAIT_FOR_SHOWN || !run_loop_ || !run_loop_->running()) | 70 if (wait_type_ != WAIT_FOR_SHOWN || !run_loop_ || !run_loop_->running()) |
| 58 return; | 71 return; |
| 59 | 72 |
| 60 if (app_window->extension_id() == app_id_) { | 73 if (app_window->extension_id() == app_id_) { |
| 61 window_ = app_window; | 74 window_ = app_window; |
| 62 run_loop_->Quit(); | 75 run_loop_->Quit(); |
| 63 } | 76 } |
| 64 } | 77 } |
| 65 | 78 |
| 66 } // namespace chromeos | 79 void AppWindowWaiter::OnAppWindowActivated(extensions::AppWindow* app_window) { |
| 80 if (wait_type_ != WAIT_FOR_ACTIVATED || !run_loop_ || !run_loop_->running()) |
| 81 return; |
| 82 |
| 83 if (app_window->extension_id() == app_id_) { |
| 84 window_ = app_window; |
| 85 run_loop_->Quit(); |
| 86 } |
| 87 } |
| 88 |
| 89 } // namespace apps |
| OLD | NEW |