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