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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/platform_notification_service.h" |
13 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" | 14 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 struct ShowDesktopNotificationHostMsgParams; | 19 struct ShowDesktopNotificationHostMsgParams; |
19 class DesktopNotificationDelegate; | 20 class DesktopNotificationDelegate; |
20 | 21 |
21 // Responsible for tracking active notifications and allowed origins for the | 22 // Responsible for tracking active notifications and allowed origins for the |
22 // Web Notification API when running layout tests. | 23 // Web Notification API when running layout tests. |
23 class LayoutTestNotificationManager { | 24 class LayoutTestNotificationManager : public PlatformNotificationService { |
24 public: | 25 public: |
25 LayoutTestNotificationManager(); | 26 LayoutTestNotificationManager(); |
26 ~LayoutTestNotificationManager(); | 27 ~LayoutTestNotificationManager() override; |
27 | |
28 // Checks whether |origin| has permission to display notifications in tests. | |
29 // Must be called on the IO thread. | |
30 blink::WebNotificationPermission CheckPermission(const GURL& origin); | |
31 | 28 |
32 // Requests permission for |origin| to display notifications in layout tests. | 29 // Requests permission for |origin| to display notifications in layout tests. |
33 // Must be called on the IO thread. | 30 // Must be called on the IO thread. |
34 // Returns whether the permission is granted. | 31 // Returns whether the permission is granted. |
35 bool RequestPermission(const GURL& origin); | 32 bool RequestPermission(const GURL& origin); |
36 | 33 |
37 // Sets the permission to display notifications for |origin| to |permission|. | 34 // Sets the permission to display notifications for |origin| to |permission|. |
38 // Must be called on the IO thread. | 35 // Must be called on the IO thread. |
39 void SetPermission(const GURL& origin, | 36 void SetPermission(const GURL& origin, |
40 blink::WebNotificationPermission permission); | 37 blink::WebNotificationPermission permission); |
41 | 38 |
42 // Clears the currently granted permissions. Must be called on the IO thread. | 39 // Clears the currently granted permissions. Must be called on the IO thread. |
43 void ClearPermissions(); | 40 void ClearPermissions(); |
44 | 41 |
45 // Pretends to show the given notification for testing, storing a delegate so | |
46 // that interaction with the notification can be simulated later on. Must | |
47 // be called on the UI thread. | |
48 void Show(const ShowDesktopNotificationHostMsgParams& params, | |
49 scoped_ptr<DesktopNotificationDelegate> delegate, | |
50 base::Closure* cancel_callback); | |
51 | |
52 // Simulates a click on the notification titled |title|. Must be called on the | 42 // Simulates a click on the notification titled |title|. Must be called on the |
53 // UI thread. | 43 // UI thread. |
54 void SimulateClick(const std::string& title); | 44 void SimulateClick(const std::string& title); |
55 | 45 |
| 46 // PlatformNotificationService implementation. |
| 47 blink::WebNotificationPermission CheckPermission( |
| 48 ResourceContext* resource_context, |
| 49 const GURL& origin, |
| 50 int render_process_id) override; |
| 51 void DisplayNotification(BrowserContext* browser_context, |
| 52 const ShowDesktopNotificationHostMsgParams& params, |
| 53 scoped_ptr<DesktopNotificationDelegate> delegate, |
| 54 int render_process_id, |
| 55 base::Closure* cancel_callback) override; |
| 56 |
56 private: | 57 private: |
57 // Closes the notification titled |title|. Must be called on the UI thread. | 58 // Closes the notification titled |title|. Must be called on the UI thread. |
58 void Close(const std::string& title); | 59 void Close(const std::string& title); |
59 | 60 |
60 typedef std::map<GURL, blink::WebNotificationPermission> | 61 typedef std::map<GURL, blink::WebNotificationPermission> |
61 NotificationPermissionMap; | 62 NotificationPermissionMap; |
62 NotificationPermissionMap permission_map_; | 63 NotificationPermissionMap permission_map_; |
63 | 64 |
64 std::map<std::string, DesktopNotificationDelegate*> notifications_; | 65 std::map<std::string, DesktopNotificationDelegate*> notifications_; |
65 std::map<std::string, std::string> replacements_; | 66 std::map<std::string, std::string> replacements_; |
66 | 67 |
67 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; | 68 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); | 70 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); |
70 }; | 71 }; |
71 | 72 |
72 } // content | 73 } // content |
73 | 74 |
74 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 75 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
OLD | NEW |