| 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_ACTIVE_STATE_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_TEST_PANEL_ACTIVE_STATE_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 class Panel; | |
| 13 | |
| 14 namespace content { | 12 namespace content { |
| 15 class MessageLoopRunner; | 13 class MessageLoopRunner; |
| 14 class NotificaitonSource; |
| 16 } | 15 } |
| 17 | 16 |
| 18 // Custom notification observer for waiting on panel active state. | 17 // Common base class for a custom notification observer that waits |
| 19 // Modeled after ui_test_utils notification observers. | 18 // on a notification until an expected state is achieved. |
| 20 class PanelActiveStateObserver : public content::NotificationObserver { | 19 // Modeled after ui_test_utils notification observers, but can handle |
| 20 // more than one occurrence of the notification. |
| 21 class TestPanelNotificationObserver : public content::NotificationObserver { |
| 21 public: | 22 public: |
| 22 // Register to listen for panel active state change notifications | 23 TestPanelNotificationObserver(int notification, |
| 23 // for the specified panel to detect a change to the expected active | 24 const content::NotificationSource& source); |
| 24 // state. | 25 virtual ~TestPanelNotificationObserver(); |
| 25 PanelActiveStateObserver(Panel* panel, bool expect_active); | |
| 26 virtual ~PanelActiveStateObserver(); | |
| 27 | 26 |
| 28 // Wait until the active state has changed to the expected state. | 27 // Wait until the expected state is achieved. |
| 29 void Wait(); | 28 void Wait(); |
| 30 | 29 |
| 31 // content::NotificationObserver: | 30 // content::NotificationObserver: |
| 32 virtual void Observe(int type, | 31 virtual void Observe(int type, |
| 33 const content::NotificationSource& source, | 32 const content::NotificationSource& source, |
| 34 const content::NotificationDetails& details) OVERRIDE; | 33 const content::NotificationDetails& details) OVERRIDE; |
| 35 | 34 |
| 36 private: | 35 protected: |
| 37 bool AtExpectedState(); | 36 virtual bool AtExpectedState() = 0; |
| 38 Panel* panel_; | 37 |
| 39 bool expect_active_; | |
| 40 bool seen_; // true after transition to expected state has been seen | 38 bool seen_; // true after transition to expected state has been seen |
| 41 bool running_; // indicates whether message loop is running | 39 bool running_; // indicates whether message loop is running |
| 42 content::NotificationRegistrar registrar_; | 40 content::NotificationRegistrar registrar_; |
| 43 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 41 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 44 | 42 |
| 45 DISALLOW_COPY_AND_ASSIGN(PanelActiveStateObserver); | 43 DISALLOW_COPY_AND_ASSIGN(TestPanelNotificationObserver); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 #endif // CHROME_BROWSER_UI_PANELS_TEST_PANEL_ACTIVE_STATE_OBSERVER_H_ | 46 #endif // CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_ |
| OLD | NEW |