OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_ | 5 #ifndef APPS_TEST_APP_WINDOW_WAITER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_ | 6 #define APPS_TEST_APP_WINDOW_WAITER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "extensions/browser/app_window/app_window_registry.h" | 14 #include "extensions/browser/app_window/app_window_registry.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 class AppWindow; | 17 class AppWindow; |
18 } | 18 } |
19 | 19 |
20 namespace chromeos { | 20 namespace apps { |
21 | 21 |
22 // Helper class that monitors app windows to wait for a window to appear. | 22 // Helper class that monitors app windows to wait for a window to |
23 // Use a new instance for each use, one instance will only work for one Wait. | 23 // appear/activated. Use a new instance for each use, one instance will only |
| 24 // work for one Wait. |
24 class AppWindowWaiter : public extensions::AppWindowRegistry::Observer { | 25 class AppWindowWaiter : public extensions::AppWindowRegistry::Observer { |
25 public: | 26 public: |
26 AppWindowWaiter(extensions::AppWindowRegistry* registry, | 27 AppWindowWaiter(extensions::AppWindowRegistry* registry, |
27 const std::string& app_id); | 28 const std::string& app_id); |
28 ~AppWindowWaiter() override; | 29 ~AppWindowWaiter() override; |
29 | 30 |
30 // Waits for an AppWindow of the app to be added. | 31 // Waits for an AppWindow of the app to be added. |
31 extensions::AppWindow* Wait(); | 32 extensions::AppWindow* Wait(); |
32 | 33 |
33 // Waits for an AppWindow of the app to be shown. | 34 // Waits for an AppWindow of the app to be shown. |
34 extensions::AppWindow* WaitForShown(); | 35 extensions::AppWindow* WaitForShown(); |
35 | 36 |
| 37 // Waits for an AppWindow of the app to be activated. |
| 38 extensions::AppWindow* WaitForActivated(); |
| 39 |
36 // AppWindowRegistry::Observer: | 40 // AppWindowRegistry::Observer: |
37 void OnAppWindowAdded(extensions::AppWindow* app_window) override; | 41 void OnAppWindowAdded(extensions::AppWindow* app_window) override; |
38 void OnAppWindowShown(extensions::AppWindow* app_window, | 42 void OnAppWindowShown(extensions::AppWindow* app_window, |
39 bool was_hidden) override; | 43 bool was_hidden) override; |
| 44 void OnAppWindowActivated(extensions::AppWindow* app_window) override; |
40 | 45 |
41 private: | 46 private: |
42 enum WaitType { | 47 enum WaitType { |
43 WAIT_FOR_NONE, | 48 WAIT_FOR_NONE, |
44 WAIT_FOR_ADDED, | 49 WAIT_FOR_ADDED, |
45 WAIT_FOR_SHOWN, | 50 WAIT_FOR_SHOWN, |
| 51 WAIT_FOR_ACTIVATED, |
46 }; | 52 }; |
47 | 53 |
48 extensions::AppWindowRegistry* const registry_; | 54 extensions::AppWindowRegistry* const registry_; |
49 const std::string app_id_; | 55 const std::string app_id_; |
50 std::unique_ptr<base::RunLoop> run_loop_; | 56 std::unique_ptr<base::RunLoop> run_loop_; |
51 WaitType wait_type_ = WAIT_FOR_NONE; | 57 WaitType wait_type_ = WAIT_FOR_NONE; |
52 extensions::AppWindow* window_ = nullptr; | 58 extensions::AppWindow* window_ = nullptr; |
53 | 59 |
54 DISALLOW_COPY_AND_ASSIGN(AppWindowWaiter); | 60 DISALLOW_COPY_AND_ASSIGN(AppWindowWaiter); |
55 }; | 61 }; |
56 | 62 |
57 } // namespace chromeos | 63 } // namespace apps |
58 | 64 |
59 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_APP_WINDOW_WAITER_H_ | 65 #endif // APPS_TEST_APP_WINDOW_WAITER_H_ |
OLD | NEW |