| 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_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <unordered_map> | |
| 11 | 9 |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | 10 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 11 #include "content/test/mock_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" | 12 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 17 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 18 | 14 |
| 19 namespace base { | 15 namespace base { |
| 20 class NullableString16; | 16 class NullableString16; |
| 21 } | 17 } |
| 22 | 18 |
| 23 namespace content { | 19 namespace content { |
| 24 | 20 |
| 25 class DesktopNotificationDelegate; | |
| 26 struct NotificationResources; | |
| 27 struct PlatformNotificationData; | |
| 28 | |
| 29 // Responsible for tracking active notifications and allowed origins for the | 21 // Responsible for tracking active notifications and allowed origins for the |
| 30 // Web Notification API when running layout tests. | 22 // Web Notification API when running layout tests. |
| 31 class LayoutTestNotificationManager : public PlatformNotificationService { | 23 class LayoutTestNotificationManager : public MockPlatformNotificationService { |
| 32 public: | 24 public: |
| 33 LayoutTestNotificationManager(); | 25 LayoutTestNotificationManager(); |
| 34 ~LayoutTestNotificationManager() override; | 26 ~LayoutTestNotificationManager() override; |
| 35 | 27 |
| 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 | |
| 38 // clicked. |reply| indicates the user reply, if any. | |
| 39 // Must be called on the UI thread. | |
| 40 void SimulateClick(const std::string& title, | |
| 41 int action_index, | |
| 42 const base::NullableString16& reply); | |
| 43 | |
| 44 // Simulates the closing a notification titled |title|. Must be called on | |
| 45 // the UI thread. | |
| 46 void SimulateClose(const std::string& title, bool by_user); | |
| 47 | |
| 48 // PlatformNotificationService implementation. | |
| 49 blink::mojom::PermissionStatus CheckPermissionOnUIThread( | |
| 50 BrowserContext* browser_context, | |
| 51 const GURL& origin, | |
| 52 int render_process_id) override; | |
| 53 blink::mojom::PermissionStatus CheckPermissionOnIOThread( | |
| 54 ResourceContext* resource_context, | |
| 55 const GURL& origin, | |
| 56 int render_process_id) override; | |
| 57 void DisplayNotification( | |
| 58 BrowserContext* browser_context, | |
| 59 const std::string& notification_id, | |
| 60 const GURL& origin, | |
| 61 const PlatformNotificationData& notification_data, | |
| 62 const NotificationResources& notification_resources, | |
| 63 std::unique_ptr<DesktopNotificationDelegate> delegate, | |
| 64 base::Closure* cancel_callback) override; | |
| 65 void DisplayPersistentNotification( | |
| 66 BrowserContext* browser_context, | |
| 67 const std::string& notification_id, | |
| 68 const GURL& service_worker_scope, | |
| 69 const GURL& origin, | |
| 70 const PlatformNotificationData& notification_data, | |
| 71 const NotificationResources& notification_resources) override; | |
| 72 void ClosePersistentNotification(BrowserContext* browser_context, | |
| 73 const std::string& notification_id) override; | |
| 74 void GetDisplayedNotifications( | |
| 75 BrowserContext* browser_context, | |
| 76 const DisplayedNotificationsCallback& callback) override; | |
| 77 | |
| 78 private: | 28 private: |
| 79 // Structure to represent the information of a persistent notification. | 29 blink::mojom::PermissionStatus CheckPermission(const GURL& origin) override; |
| 80 struct PersistentNotification { | |
| 81 BrowserContext* browser_context = nullptr; | |
| 82 GURL origin; | |
| 83 }; | |
| 84 | |
| 85 // Closes the notification titled |title|. Must be called on the UI thread. | |
| 86 void Close(const std::string& title); | |
| 87 | |
| 88 // Fakes replacing the notification identified by |notification_id|. Both | |
| 89 // persistent and non-persistent notifications will be considered for this. | |
| 90 void ReplaceNotificationIfNeeded(const std::string& notification_id); | |
| 91 | |
| 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 persistent_notifications_; | |
| 98 std::unordered_map<std::string, std::unique_ptr<DesktopNotificationDelegate>> | |
| 99 non_persistent_notifications_; | |
| 100 | |
| 101 // Mapping of titles to notification ids giving test a usable identifier. | |
| 102 std::unordered_map<std::string, std::string> notification_id_map_; | |
| 103 | |
| 104 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); | 30 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); |
| 107 }; | 31 }; |
| 108 | 32 |
| 109 } // content | 33 } // content |
| 110 | 34 |
| 111 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 35 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |