summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/test/app_window_waiter.h
blob: 91eadcd72cf80318af0ab4197bd7d41e3ad1f7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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.

#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/run_loop.h"
#include "extensions/browser/app_window/app_window_registry.h"

namespace extensions {
class AppWindow;
}

namespace chromeos {

// Helper class that monitors app windows to wait for a window to appear.
// Use a new instance for each use, one instance will only work for one Wait.
class AppWindowWaiter : public extensions::AppWindowRegistry::Observer {
 public:
  AppWindowWaiter(extensions::AppWindowRegistry* registry,
                  const std::string& app_id);
  virtual ~AppWindowWaiter();

  extensions::AppWindow* Wait();

  // AppWindowRegistry::Observer:
  virtual void OnAppWindowAdded(extensions::AppWindow* app_window) OVERRIDE;

 private:
  extensions::AppWindowRegistry* registry_;
  std::string app_id_;
  base::RunLoop run_loop_;
  extensions::AppWindow* window_;

  DISALLOW_COPY_AND_ASSIGN(AppWindowWaiter);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_