Update To 11.40.268.0
[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 "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h"
17 #include "extensions/browser/notification_types.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   ~ExtensionNotificationObserver() override;
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(extensions::NotificationType type)
36       WARN_UNUSED_RESULT;
37   testing::AssertionResult CheckNotifications(extensions::NotificationType t1,
38                                               extensions::NotificationType t2)
39       WARN_UNUSED_RESULT;
40   testing::AssertionResult CheckNotifications(extensions::NotificationType t1,
41                                               extensions::NotificationType t2,
42                                               extensions::NotificationType t3)
43       WARN_UNUSED_RESULT;
44   testing::AssertionResult CheckNotifications(extensions::NotificationType t1,
45                                               extensions::NotificationType t2,
46                                               extensions::NotificationType t3,
47                                               extensions::NotificationType t4,
48                                               extensions::NotificationType t5,
49                                               extensions::NotificationType t6)
50       WARN_UNUSED_RESULT;
51
52  private:
53   // content::NotificationObserver implementation.
54   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<extensions::NotificationType>& types);
61
62   const std::set<std::string> extension_ids_;
63   std::vector<extensions::NotificationType> notifications_;
64   content::NotificationRegistrar registrar_;
65 };
66
67 }  // namespace extensions
68
69 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_NOTIFICATION_OBSERVER_H_