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