Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: content/shell/browser/layout_test/layout_test_notification_manager.h

Issue 2672313004: Test the platform notification context synchronize operation (Closed)
Patch Set: - Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h>
9 #include <string> 8 #include <string>
10 #include <unordered_map>
11 9
12 #include "base/callback.h"
13 #include "base/macros.h" 10 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 11 #include "content/test/mock_platform_notification_service.h"
15 #include "content/public/browser/platform_notification_service.h"
16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 12 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
17 #include "url/gurl.h" 13 #include "url/gurl.h"
18 14
19 namespace content { 15 namespace content {
20 16
21 class DesktopNotificationDelegate;
22 struct NotificationResources;
23 struct PlatformNotificationData;
24
25 // Responsible for tracking active notifications and allowed origins for the 17 // Responsible for tracking active notifications and allowed origins for the
26 // Web Notification API when running layout tests. 18 // Web Notification API when running layout tests.
27 class LayoutTestNotificationManager : public PlatformNotificationService { 19 class LayoutTestNotificationManager : public MockPlatformNotificationService {
28 public: 20 public:
29 LayoutTestNotificationManager(); 21 LayoutTestNotificationManager();
30 ~LayoutTestNotificationManager() override; 22 ~LayoutTestNotificationManager() override;
31 23
32 // Simulates a click on the notification titled |title|. |action_index|
33 // indicates which action was clicked, or -1 if the main notification body was
34 // clicked. |reply| indicates the user reply, if any.
35 // Must be called on the UI thread.
36 void SimulateClick(const std::string& title,
37 int action_index,
38 const base::NullableString16& reply);
39
40 // Simulates the closing a notification titled |title|. Must be called on
41 // the UI thread.
42 void SimulateClose(const std::string& title, bool by_user);
43
44 // PlatformNotificationService implementation.
45 blink::mojom::PermissionStatus CheckPermissionOnUIThread(
46 BrowserContext* browser_context,
47 const GURL& origin,
48 int render_process_id) override;
49 blink::mojom::PermissionStatus CheckPermissionOnIOThread(
50 ResourceContext* resource_context,
51 const GURL& origin,
52 int render_process_id) override;
53 void DisplayNotification(
54 BrowserContext* browser_context,
55 const std::string& notification_id,
56 const GURL& origin,
57 const PlatformNotificationData& notification_data,
58 const NotificationResources& notification_resources,
59 std::unique_ptr<DesktopNotificationDelegate> delegate,
60 base::Closure* cancel_callback) override;
61 void DisplayPersistentNotification(
62 BrowserContext* browser_context,
63 const std::string& notification_id,
64 const GURL& service_worker_scope,
65 const GURL& origin,
66 const PlatformNotificationData& notification_data,
67 const NotificationResources& notification_resources) override;
68 void ClosePersistentNotification(BrowserContext* browser_context,
69 const std::string& notification_id) override;
70 bool GetDisplayedNotifications( 24 bool GetDisplayedNotifications(
Peter Beverloo 2017/02/08 14:05:11 nit: // MockPlatformNotificationService overrides
Miguel Garcia 2017/02/08 17:03:41 Done.
71 BrowserContext* browser_context, 25 BrowserContext* browser_context,
72 std::set<std::string>* displayed_notifications) override; 26 std::set<std::string>* displayed_notifications) override;
73 27
74 private: 28 private:
75 // Structure to represent the information of a persistent notification. 29 blink::mojom::PermissionStatus CheckPermission(const GURL& origin) override;
76 struct PersistentNotification {
77 BrowserContext* browser_context = nullptr;
78 GURL origin;
79 };
80
81 // Closes the notification titled |title|. Must be called on the UI thread.
82 void Close(const std::string& title);
83
84 // Fakes replacing the notification identified by |notification_id|. Both
85 // persistent and non-persistent notifications will be considered for this.
86 void ReplaceNotificationIfNeeded(const std::string& notification_id);
87
88 // Checks if |origin| has permission to display notifications. May be called
89 // on both the IO and the UI threads.
90 blink::mojom::PermissionStatus CheckPermission(const GURL& origin);
91
92 std::unordered_map<std::string, PersistentNotification>
93 persistent_notifications_;
94 std::unordered_map<std::string, std::unique_ptr<DesktopNotificationDelegate>>
95 non_persistent_notifications_;
96
97 // Mapping of titles to notification ids giving test a usable identifier.
98 std::unordered_map<std::string, std::string> notification_id_map_;
99
100 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); 30 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager);
103 }; 31 };
104 32
105 } // content 33 } // content
106 34
107 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ 35 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698