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