• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_
7 
8 #include "base/memory/ref_counted.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 
12 namespace content {
13 class MessageLoopRunner;
14 class NotificationSource;
15 }
16 
17 // Common base class for a custom notification observer that waits
18 // on a notification until an expected state is achieved.
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 {
22  public:
23   TestPanelNotificationObserver(int notification,
24                                 const content::NotificationSource& source);
25   virtual ~TestPanelNotificationObserver();
26 
27   // Wait until the expected state is achieved.
28   void Wait();
29 
30   // content::NotificationObserver:
31   virtual void Observe(int type,
32                        const content::NotificationSource& source,
33                        const content::NotificationDetails& details) OVERRIDE;
34 
35  protected:
36   virtual bool AtExpectedState() = 0;
37 
38   bool seen_;  // true after transition to expected state has been seen
39   bool running_;  // indicates whether message loop is running
40   content::NotificationRegistrar registrar_;
41   scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
42 
43   DISALLOW_COPY_AND_ASSIGN(TestPanelNotificationObserver);
44 };
45 
46 #endif  // CHROME_BROWSER_UI_PANELS_TEST_PANEL_NOTIFICATION_OBSERVER_H_
47