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

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
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 did not exist, so DeleteNotificationData() should inform
136 // us of that. Most callers won't actually care about this return status
137 // except for correctness reasons - their goal has been satisfied: the data
138 // does not exist in the database.
139 EXPECT_FALSE(success());
140 }
141
142 TEST_F(PlatformNotificationContextTest, DeleteNotification) {
143 scoped_refptr<PlatformNotificationContext> context =
144 CreatePlatformNotificationContext();
145
146 GURL origin("https://example.com");
147 NotificationDatabaseData notification_database_data;
148
149 context->WriteNotificationData(
150 origin,
151 notification_database_data,
152 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData,
153 base::Unretained(this)));
154
155 base::RunLoop().RunUntilIdle();
156
157 // The write operation should have succeeded with a notification id.
158 ASSERT_TRUE(success());
159 EXPECT_GT(notification_id(), 0);
160
161 context->DeleteNotificationData(
162 notification_id(),
163 origin,
164 base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData,
165 base::Unretained(this)));
166
167 base::RunLoop().RunUntilIdle();
168
169 // The notification existed, so it should have been removed successfully.
170 ASSERT_TRUE(success());
171
172 context->ReadNotificationData(
173 notification_id(),
174 origin,
175 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData,
176 base::Unretained(this)));
177
178 base::RunLoop().RunUntilIdle();
179
180 // The notification was removed, so we shouldn't be able to read it from
181 // the database anymore.
182 EXPECT_FALSE(success());
183 }
184
118 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698