- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_notification_observer.h
1 // Copyright 2013 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_EXTENSIONS_EXTENSION_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_NOTIFICATION_OBSERVER_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace extensions {
21
22 // Records LOADED, INSTALLED, and UNLOADED notifications for extensions with
23 // specific IDs. Use in tests only.
24 class ExtensionNotificationObserver : public content::NotificationObserver {
25  public:
26   ExtensionNotificationObserver(content::NotificationSource source,
27                                 const std::set<std::string>& extension_ids);
28
29   virtual ~ExtensionNotificationObserver();
30
31   // Each of these methods returns a testing::AssertionSuccess if exactly those
32   // notifications occurred for any extensions in |extension_ids|, and no more,
33   // since the last time any of these methods were called.
34   testing::AssertionResult CheckNotifications() WARN_UNUSED_RESULT;
35   testing::AssertionResult CheckNotifications(
36       chrome::NotificationType type) WARN_UNUSED_RESULT;
37   testing::AssertionResult CheckNotifications(
38       chrome::NotificationType t1,
39       chrome::NotificationType t2) WARN_UNUSED_RESULT;
40   testing::AssertionResult CheckNotifications(
41       chrome::NotificationType t1,
42       chrome::NotificationType t2,
43       chrome::NotificationType t3) WARN_UNUSED_RESULT;
44   testing::AssertionResult CheckNotifications(
45       chrome::NotificationType t1,
46       chrome::NotificationType t2,
47       chrome::NotificationType t3,
48       chrome::NotificationType t4,
49       chrome::NotificationType t5,
50       chrome::NotificationType t6) WARN_UNUSED_RESULT;
51
52  private:
53   // content::NotificationObserver implementation.
54   virtual void Observe(int type,
55                        const content::NotificationSource& source,
56                        const content::NotificationDetails& details) OVERRIDE;
57
58   // Checks then clears notifications for our extensions.
59   testing::AssertionResult CheckNotifications(
60       const std::vector<chrome::NotificationType>& types);
61
62   const std::set<std::string> extension_ids_;
63   std::vector<chrome::NotificationType> notifications_;
64   content::NotificationRegistrar registrar_;
65 };
66
67 }  // namespace extensions
68
69 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_NOTIFICATION_OBSERVER_H_