| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 5 #ifndef CONTENT_TEST_MOCK_PLATFORM_NOTIFICATION_SERVICE_H_ |
| 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 6 #define CONTENT_TEST_MOCK_PLATFORM_NOTIFICATION_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/public/browser/platform_notification_service.h" | 15 #include "content/public/browser/platform_notification_service.h" |
| 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class NullableString16; | 20 class NullableString16; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 class DesktopNotificationDelegate; | 25 class DesktopNotificationDelegate; |
| 26 struct NotificationResources; | 26 struct NotificationResources; |
| 27 struct PlatformNotificationData; | 27 struct PlatformNotificationData; |
| 28 | 28 |
| 29 // Responsible for tracking active notifications and allowed origins for the | 29 // Responsible for tracking active notifications and allowed origins for the |
| 30 // Web Notification API when running layout tests. | 30 // Web Notification API when running layout and content tests. |
| 31 class LayoutTestNotificationManager : public PlatformNotificationService { | 31 class MockPlatformNotificationService : public PlatformNotificationService { |
| 32 public: | 32 public: |
| 33 LayoutTestNotificationManager(); | 33 MockPlatformNotificationService(); |
| 34 ~LayoutTestNotificationManager() override; | 34 ~MockPlatformNotificationService() override; |
| 35 | 35 |
| 36 // Simulates a click on the notification titled |title|. |action_index| | 36 // Simulates a click on the notification titled |title|. |action_index| |
| 37 // indicates which action was clicked, or -1 if the main notification body was | 37 // indicates which action was clicked, or -1 if the main notification body was |
| 38 // clicked. |reply| indicates the user reply, if any. | 38 // clicked. |reply| indicates the user reply, if any. |
| 39 // Must be called on the UI thread. | 39 // Must be called on the UI thread. |
| 40 void SimulateClick(const std::string& title, | 40 void SimulateClick(const std::string& title, |
| 41 int action_index, | 41 int action_index, |
| 42 const base::NullableString16& reply); | 42 const base::NullableString16& reply); |
| 43 | 43 |
| 44 // Simulates the closing a notification titled |title|. Must be called on | 44 // Simulates the closing a notification titled |title|. Must be called on |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 const GURL& service_worker_scope, | 68 const GURL& service_worker_scope, |
| 69 const GURL& origin, | 69 const GURL& origin, |
| 70 const PlatformNotificationData& notification_data, | 70 const PlatformNotificationData& notification_data, |
| 71 const NotificationResources& notification_resources) override; | 71 const NotificationResources& notification_resources) override; |
| 72 void ClosePersistentNotification(BrowserContext* browser_context, | 72 void ClosePersistentNotification(BrowserContext* browser_context, |
| 73 const std::string& notification_id) override; | 73 const std::string& notification_id) override; |
| 74 bool GetDisplayedNotifications( | 74 bool GetDisplayedNotifications( |
| 75 BrowserContext* browser_context, | 75 BrowserContext* browser_context, |
| 76 std::set<std::string>* displayed_notifications) override; | 76 std::set<std::string>* displayed_notifications) override; |
| 77 | 77 |
| 78 protected: |
| 79 // Checks if |origin| has permission to display notifications. May be called |
| 80 // on both the IO and the UI threads. |
| 81 virtual blink::mojom::PermissionStatus CheckPermission(const GURL& origin); |
| 82 |
| 78 private: | 83 private: |
| 79 // Structure to represent the information of a persistent notification. | 84 // Structure to represent the information of a persistent notification. |
| 80 struct PersistentNotification { | 85 struct PersistentNotification { |
| 81 BrowserContext* browser_context = nullptr; | 86 BrowserContext* browser_context = nullptr; |
| 82 GURL origin; | 87 GURL origin; |
| 83 }; | 88 }; |
| 84 | 89 |
| 85 // Closes the notification titled |title|. Must be called on the UI thread. | 90 // Closes the notification titled |title|. Must be called on the UI thread. |
| 86 void Close(const std::string& title); | 91 void Close(const std::string& title); |
| 87 | 92 |
| 88 // Fakes replacing the notification identified by |notification_id|. Both | 93 // Fakes replacing the notification identified by |notification_id|. Both |
| 89 // persistent and non-persistent notifications will be considered for this. | 94 // persistent and non-persistent notifications will be considered for this. |
| 90 void ReplaceNotificationIfNeeded(const std::string& notification_id); | 95 void ReplaceNotificationIfNeeded(const std::string& notification_id); |
| 91 | 96 |
| 92 // Checks if |origin| has permission to display notifications. May be called | |
| 93 // on both the IO and the UI threads. | |
| 94 blink::mojom::PermissionStatus CheckPermission(const GURL& origin); | |
| 95 | |
| 96 std::unordered_map<std::string, PersistentNotification> | 97 std::unordered_map<std::string, PersistentNotification> |
| 97 persistent_notifications_; | 98 persistent_notifications_; |
| 98 std::unordered_map<std::string, std::unique_ptr<DesktopNotificationDelegate>> | 99 std::unordered_map<std::string, std::unique_ptr<DesktopNotificationDelegate>> |
| 99 non_persistent_notifications_; | 100 non_persistent_notifications_; |
| 100 | 101 |
| 101 // Mapping of titles to notification ids giving test a usable identifier. | 102 // Mapping of titles to notification ids giving test a usable identifier. |
| 102 std::unordered_map<std::string, std::string> notification_id_map_; | 103 std::unordered_map<std::string, std::string> notification_id_map_; |
| 103 | 104 |
| 104 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; | 105 base::WeakPtrFactory<MockPlatformNotificationService> weak_factory_; |
| 105 | 106 |
| 106 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); | 107 DISALLOW_COPY_AND_ASSIGN(MockPlatformNotificationService); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // content | 110 } // content |
| 110 | 111 |
| 111 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 112 #endif // CONTENT_TEST_MOCK_PLATFORM_NOTIFICATION_SERVICE_H_ |
| OLD | NEW |