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