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> |
8 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> |
9 | 11 |
| 12 #include "base/callback.h" |
10 #include "base/macros.h" | 13 #include "base/macros.h" |
11 #include "content/test/mock_platform_notification_service.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/public/browser/platform_notification_service.h" |
12 #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" |
13 #include "url/gurl.h" | 17 #include "url/gurl.h" |
14 | 18 |
15 namespace base { | 19 namespace base { |
16 class NullableString16; | 20 class NullableString16; |
17 } | 21 } |
18 | 22 |
19 namespace content { | 23 namespace content { |
20 | 24 |
| 25 class DesktopNotificationDelegate; |
| 26 struct NotificationResources; |
| 27 struct PlatformNotificationData; |
| 28 |
21 // Responsible for tracking active notifications and allowed origins for the | 29 // Responsible for tracking active notifications and allowed origins for the |
22 // Web Notification API when running layout tests. | 30 // Web Notification API when running layout tests. |
23 class LayoutTestNotificationManager : public MockPlatformNotificationService { | 31 class LayoutTestNotificationManager : public PlatformNotificationService { |
24 public: | 32 public: |
25 LayoutTestNotificationManager(); | 33 LayoutTestNotificationManager(); |
26 ~LayoutTestNotificationManager() override; | 34 ~LayoutTestNotificationManager() override; |
27 | 35 |
| 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 bool GetDisplayedNotifications( |
| 75 BrowserContext* browser_context, |
| 76 std::set<std::string>* displayed_notifications) override; |
| 77 |
28 private: | 78 private: |
29 blink::mojom::PermissionStatus CheckPermission(const GURL& origin) override; | 79 // Structure to represent the information of a persistent notification. |
| 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 |
30 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); | 106 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); |
31 }; | 107 }; |
32 | 108 |
33 } // content | 109 } // content |
34 | 110 |
35 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 111 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
OLD | NEW |