Chromium Code Reviews| Index: chrome/browser/chromeos/login/test/app_window_waiter.cc |
| diff --git a/chrome/browser/chromeos/login/test/app_window_waiter.cc b/chrome/browser/chromeos/login/test/app_window_waiter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..82aeba41ec34a1d2a8c60a9df2262ed338d9ab2d |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/test/app_window_waiter.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/test/app_window_waiter.h" |
| + |
| +#include "apps/app_window.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace chromeos { |
| + |
| +AppWindowWaiter::AppWindowWaiter(apps::AppWindowRegistry* registry, |
| + const std::string& app_id) |
| + : registry_(registry), app_id_(app_id), window_(NULL), running_(false) { |
| + registry_->AddObserver(this); |
| +} |
| + |
| +AppWindowWaiter::~AppWindowWaiter() { |
| + registry_->RemoveObserver(this); |
| +} |
| + |
| +apps::AppWindow* AppWindowWaiter::Wait() { |
| + window_ = registry_->GetCurrentAppWindowForApp(app_id_); |
| + if (window_) |
| + return window_; |
| + |
| + running_ = true; |
| + message_loop_runner_ = new content::MessageLoopRunner; |
| + message_loop_runner_->Run(); |
| + |
| + EXPECT_TRUE(window_); |
|
bartfab (slow)
2014/03/25 12:52:54
Nit: I think it would be better to let individual
rkc
2014/03/26 21:30:40
Done.
|
| + return window_; |
| +} |
| + |
| +void AppWindowWaiter::OnAppWindowAdded(apps::AppWindow* app_window) { |
| + if (!running_) |
| + return; |
| + |
| + if (app_window->extension_id() == app_id_) { |
| + window_ = app_window; |
| + message_loop_runner_->Quit(); |
| + running_ = false; |
|
bartfab (slow)
2014/03/25 12:52:54
Nit: If you just did message_loop_runner_ = NULL h
rkc
2014/03/26 21:30:40
Using run_loop_->running() instead.
Done.
|
| + } |
| +} |
| + |
| +void AppWindowWaiter::OnAppWindowIconChanged(apps::AppWindow* app_window) {} |
| + |
| +void AppWindowWaiter::OnAppWindowRemoved(apps::AppWindow* app_window) {} |
| + |
| +} // namespace chromeos |