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_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ | 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ |
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ | 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | |
10 #include <string> | 9 #include <string> |
11 | 10 |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
13 #include "third_party/WebKit/public/web/WebNotification.h" | 12 #include "third_party/WebKit/public/web/WebNotification.h" |
14 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" | 13 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" |
15 | 14 |
16 namespace WebTestRunner { | 15 namespace WebTestRunner { |
17 class WebTestDelegate; | 16 class WebTestDelegate; |
18 } | 17 } |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 | 20 |
22 // A class that implements WebNotificationPresenter for the TestRunner library. | 21 // A class that implements WebNotificationPresenter for the TestRunner library. |
23 class NotificationPresenter : public blink::WebNotificationPresenter { | 22 class NotificationPresenter : public blink::WebNotificationPresenter { |
24 public: | 23 public: |
25 NotificationPresenter(); | 24 NotificationPresenter(); |
26 virtual ~NotificationPresenter(); | 25 virtual ~NotificationPresenter(); |
27 | 26 |
28 // Called by the TestRunner to simulate a user granting permission. | 27 // Called by the TestRunner to simulate a user granting permission. |
29 void GrantPermission(const std::string& origin); | 28 void GrantPermission(const std::string& origin, bool permission_granted); |
30 | 29 |
31 // Called by the TestRunner to simulate a user clicking on a notification. | 30 // Called by the TestRunner to simulate a user clicking on a notification. |
32 bool SimulateClick(const std::string& title); | 31 bool SimulateClick(const std::string& title); |
33 | 32 |
34 // Called by the TestRunner to cancel all active notications. | 33 // Called by the TestRunner to cancel all active notications. |
35 void CancelAllActiveNotifications(); | 34 void CancelAllActiveNotifications(); |
36 | 35 |
37 // Called by the TestRunner to reset the presenter to an default state. | 36 // Called by the TestRunner to reset the presenter to an default state. |
38 void Reset(); | 37 void Reset(); |
39 | 38 |
40 void set_delegate(WebTestRunner::WebTestDelegate* delegate) { | 39 void set_delegate(WebTestRunner::WebTestDelegate* delegate) { |
41 delegate_ = delegate; | 40 delegate_ = delegate; |
42 } | 41 } |
43 | 42 |
44 // blink::WebNotificationPresenter interface | 43 // blink::WebNotificationPresenter interface |
45 virtual bool show(const blink::WebNotification& notification); | 44 virtual bool show(const blink::WebNotification& notification); |
46 virtual void cancel(const blink::WebNotification& notification); | 45 virtual void cancel(const blink::WebNotification& notification); |
47 virtual void objectDestroyed(const blink::WebNotification& notification); | 46 virtual void objectDestroyed(const blink::WebNotification& notification); |
48 virtual Permission checkPermission( | 47 virtual Permission checkPermission( |
49 const blink::WebSecurityOrigin& security_origin); | 48 const blink::WebSecurityOrigin& security_origin); |
50 virtual void requestPermission( | 49 virtual void requestPermission( |
51 const blink::WebSecurityOrigin& security_origin, | 50 const blink::WebSecurityOrigin& security_origin, |
52 blink::WebNotificationPermissionCallback* callback); | 51 blink::WebNotificationPermissionCallback* callback); |
53 | 52 |
54 private: | 53 private: |
55 WebTestRunner::WebTestDelegate* delegate_; | 54 WebTestRunner::WebTestDelegate* delegate_; |
56 | 55 |
57 // Set of origins which are allowed to show notifications. | 56 // Map of known origins and whether they are allowed to show notifications. |
58 std::set<std::string> allowed_origins_; | 57 typedef std::map<std::string, bool> KnownOriginMap; |
| 58 KnownOriginMap known_origins_; |
59 | 59 |
60 // Map of currently active notifications. | 60 // Map of currently active notifications. |
61 typedef std::map<std::string, blink::WebNotification> ActiveNotificationMap; | 61 typedef std::map<std::string, blink::WebNotification> ActiveNotificationMap; |
62 ActiveNotificationMap active_notifications_; | 62 ActiveNotificationMap active_notifications_; |
63 | 63 |
64 // Map of replacement identifiers to the titles of those notifications. | 64 // Map of replacement identifiers to the titles of those notifications. |
65 std::map<std::string, std::string> replacements_; | 65 std::map<std::string, std::string> replacements_; |
66 | 66 |
67 DISALLOW_COPY_AND_ASSIGN(NotificationPresenter); | 67 DISALLOW_COPY_AND_ASSIGN(NotificationPresenter); |
68 }; | 68 }; |
69 | 69 |
70 } // namespace content | 70 } // namespace content |
71 | 71 |
72 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ | 72 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_ |
OLD | NEW |