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

Side by Side Diff: content/browser/notifications/platform_notification_context_unittest.cc

Issue 1008003003: Teach the PlatformNotificationContext how to delete notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-PlatformNotificationContext
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/browser/notifications/platform_notification_context.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/browser/notifications/platform_notification_context.h" 5 #include "content/browser/notifications/platform_notification_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/browser/notifications/notification_database_data.h" 9 #include "content/browser/notifications/notification_database_data.h"
10 #include "content/public/test/test_browser_thread_bundle.h" 10 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 14 matching lines...) Expand all
25 success_ = success; 25 success_ = success;
26 database_data_ = database_data; 26 database_data_ = database_data;
27 } 27 }
28 28
29 // Callback to provide when writing a notification to the database. 29 // Callback to provide when writing a notification to the database.
30 void DidWriteNotificationData(bool success, int64_t notification_id) { 30 void DidWriteNotificationData(bool success, int64_t notification_id) {
31 success_ = success; 31 success_ = success;
32 notification_id_ = notification_id; 32 notification_id_ = notification_id;
33 } 33 }
34 34
35 // Callback to provide when deleting notification data from the database.
36 void DidDeleteNotificationData(bool success) {
37 success_ = success;
38 }
39
35 protected: 40 protected:
36 // Creates a new PlatformNotificationContext instance. When using this method, 41 // Creates a new PlatformNotificationContext instance. When using this method,
37 // the underlying database will always be created in memory. The current 42 // the underlying database will always be created in memory. The current
38 // message loop proxy will be used as the task runner. 43 // message loop proxy will be used as the task runner.
39 PlatformNotificationContext* CreatePlatformNotificationContext() { 44 PlatformNotificationContext* CreatePlatformNotificationContext() {
40 PlatformNotificationContext* context = 45 PlatformNotificationContext* context =
41 new PlatformNotificationContext(base::FilePath()); 46 new PlatformNotificationContext(base::FilePath());
42 47
43 context->SetTaskRunnerForTesting(base::MessageLoopProxy::current()); 48 context->SetTaskRunnerForTesting(base::MessageLoopProxy::current());
44 return context; 49 return context;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 113
109 base::RunLoop().RunUntilIdle(); 114 base::RunLoop().RunUntilIdle();
110 115
111 // The read operation should have succeeded, with the right notification. 116 // The read operation should have succeeded, with the right notification.
112 ASSERT_TRUE(success()); 117 ASSERT_TRUE(success());
113 118
114 const NotificationDatabaseData& read_database_data = database_data(); 119 const NotificationDatabaseData& read_database_data = database_data();
115 EXPECT_EQ(notification_database_data.origin, read_database_data.origin); 120 EXPECT_EQ(notification_database_data.origin, read_database_data.origin);
116 } 121 }
117 122
123 TEST_F(PlatformNotificationContextTest, DeleteInvalidNotification) {
124 scoped_refptr<PlatformNotificationContext> context =
125 CreatePlatformNotificationContext();
126
127 context->DeleteNotificationData(
128 42 /* notification_id */,
129 GURL("https://example.com"),
130 base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData,
131 base::Unretained(this)));
132
133 base::RunLoop().RunUntilIdle();
134
135 // The notification may not have existed, but since the goal of deleting data
136 // is to make sure that it's gone, the goal has been satisfied. As such,
137 // deleting a non-existent notification is considered to be a success.
138 EXPECT_TRUE(success());
139 }
140
141 TEST_F(PlatformNotificationContextTest, DeleteNotification) {
142 scoped_refptr<PlatformNotificationContext> context =
143 CreatePlatformNotificationContext();
144
145 GURL origin("https://example.com");
146 NotificationDatabaseData notification_database_data;
147
148 context->WriteNotificationData(
149 origin,
150 notification_database_data,
151 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData,
152 base::Unretained(this)));
153
154 base::RunLoop().RunUntilIdle();
155
156 // The write operation should have succeeded with a notification id.
157 ASSERT_TRUE(success());
158 EXPECT_GT(notification_id(), 0);
159
160 context->DeleteNotificationData(
161 notification_id(),
162 origin,
163 base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData,
164 base::Unretained(this)));
165
166 base::RunLoop().RunUntilIdle();
167
168 // The notification existed, so it should have been removed successfully.
169 ASSERT_TRUE(success());
170
171 context->ReadNotificationData(
172 notification_id(),
173 origin,
174 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData,
175 base::Unretained(this)));
176
177 base::RunLoop().RunUntilIdle();
178
179 // The notification was removed, so we shouldn't be able to read it from
180 // the database anymore.
181 EXPECT_FALSE(success());
182 }
183
118 } // namespace content 184 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/notifications/platform_notification_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698