OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ |
6 #define CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ | 6 #define CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 class MessageLoopRunner; | 13 class MessageLoopRunner; |
14 class NotificationSource; | 14 class NotificationSource; |
15 } | 15 } |
16 | 16 |
17 // Common base class for a custom notification observer that waits | 17 // Common base class for a custom notification observer that waits |
18 // on a notification until an expected state is achieved. | 18 // on a notification until an expected state is achieved. |
19 // Modeled after ui_test_utils notification observers, but can handle | 19 // Modeled after ui_test_utils notification observers, but can handle |
20 // more than one occurrence of the notification. | 20 // more than one occurrence of the notification. |
21 class TestPanelNotificationObserver : public content::NotificationObserver { | 21 class TestPanelNotificationObserver : public content::NotificationObserver { |
22 public: | 22 public: |
23 TestPanelNotificationObserver(int notification, | 23 TestPanelNotificationObserver(int notification, |
24 const content::NotificationSource& source); | 24 const content::NotificationSource& source); |
25 virtual ~TestPanelNotificationObserver(); | 25 ~TestPanelNotificationObserver() override; |
26 | 26 |
27 // Wait until the expected state is achieved. | 27 // Wait until the expected state is achieved. |
28 void Wait(); | 28 void Wait(); |
29 | 29 |
30 // content::NotificationObserver: | 30 // content::NotificationObserver: |
31 virtual void Observe(int type, | 31 void Observe(int type, |
32 const content::NotificationSource& source, | 32 const content::NotificationSource& source, |
33 const content::NotificationDetails& details) override; | 33 const content::NotificationDetails& details) override; |
34 | 34 |
35 protected: | 35 protected: |
36 virtual bool AtExpectedState() = 0; | 36 virtual bool AtExpectedState() = 0; |
37 | 37 |
38 bool seen_; // true after transition to expected state has been seen | 38 bool seen_; // true after transition to expected state has been seen |
39 bool running_; // indicates whether message loop is running | 39 bool running_; // indicates whether message loop is running |
40 content::NotificationRegistrar registrar_; | 40 content::NotificationRegistrar registrar_; |
41 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 41 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(TestPanelNotificationObserver); | 43 DISALLOW_COPY_AND_ASSIGN(TestPanelNotificationObserver); |
44 }; | 44 }; |
45 | 45 |
46 #endif // CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ | 46 #endif // CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ |
OLD | NEW |