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.
5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/platform_notification_service.h"
15 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationPermission.h"
20 class DesktopNotificationDelegate
;
21 struct PlatformNotificationData
;
23 // Responsible for tracking active notifications and allowed origins for the
24 // Web Notification API when running layout tests.
25 class LayoutTestNotificationManager
: public PlatformNotificationService
{
27 LayoutTestNotificationManager();
28 ~LayoutTestNotificationManager() override
;
30 // Simulates a click on the notification titled |title|. |action_index|
31 // indicates which action was clicked, or -1 if the main notification body was
32 // clicked. Must be called on the UI thread.
33 void SimulateClick(const std::string
& title
, int action_index
);
35 // PlatformNotificationService implementation.
36 blink::WebNotificationPermission
CheckPermissionOnUIThread(
37 BrowserContext
* browser_context
,
39 int render_process_id
) override
;
40 blink::WebNotificationPermission
CheckPermissionOnIOThread(
41 ResourceContext
* resource_context
,
43 int render_process_id
) override
;
44 void DisplayNotification(BrowserContext
* browser_context
,
47 const PlatformNotificationData
& notification_data
,
48 scoped_ptr
<DesktopNotificationDelegate
> delegate
,
49 base::Closure
* cancel_callback
) override
;
50 void DisplayPersistentNotification(
51 BrowserContext
* browser_context
,
52 int64_t persistent_notification_id
,
55 const PlatformNotificationData
& notification_data
) override
;
56 void ClosePersistentNotification(
57 BrowserContext
* browser_context
,
58 int64_t persistent_notification_id
) override
;
59 bool GetDisplayedPersistentNotifications(
60 BrowserContext
* browser_context
,
61 std::set
<std::string
>* displayed_notifications
) override
;
64 // Structure to represent the information of a persistent notification.
65 struct PersistentNotification
{
66 BrowserContext
* browser_context
= nullptr;
68 int64_t persistent_id
= 0;
71 // Closes the notification titled |title|. Must be called on the UI thread.
72 void Close(const std::string
& title
);
74 // Fakes replacing the notification identified by |params| when it has a tag
75 // and a previous notification has been displayed using the same tag. All
76 // notifications, both page and persistent ones, will be considered for this.
77 void ReplaceNotificationIfNeeded(
78 const PlatformNotificationData
& notification_data
);
80 // Checks if |origin| has permission to display notifications. May be called
81 // on both the IO and the UI threads.
82 blink::WebNotificationPermission
CheckPermission(const GURL
& origin
);
84 std::map
<std::string
, DesktopNotificationDelegate
*> page_notifications_
;
85 std::map
<std::string
, PersistentNotification
> persistent_notifications_
;
87 std::map
<std::string
, std::string
> replacements_
;
89 base::WeakPtrFactory
<LayoutTestNotificationManager
> weak_factory_
;
91 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager
);
96 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_