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

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

Issue 1010833002: Expose bits of the Web Notification database in the //content API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-DeleteInContext
Patch Set: update a comment 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"
6
7 #include "base/bind.h" 5 #include "base/bind.h"
8 #include "base/run_loop.h" 6 #include "base/run_loop.h"
9 #include "content/browser/notifications/notification_database_data.h" 7 #include "content/browser/notifications/platform_notification_context_impl.h"
8 #include "content/public/browser/notification_database_data.h"
10 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h" 11 #include "url/gurl.h"
13 12
14 namespace content { 13 namespace content {
15 14
16 class PlatformNotificationContextTest : public ::testing::Test { 15 class PlatformNotificationContextTest : public ::testing::Test {
17 public: 16 public:
18 PlatformNotificationContextTest() 17 PlatformNotificationContextTest()
19 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 18 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
(...skipping 11 matching lines...) Expand all
31 success_ = success; 30 success_ = success;
32 notification_id_ = notification_id; 31 notification_id_ = notification_id;
33 } 32 }
34 33
35 // Callback to provide when deleting notification data from the database. 34 // Callback to provide when deleting notification data from the database.
36 void DidDeleteNotificationData(bool success) { 35 void DidDeleteNotificationData(bool success) {
37 success_ = success; 36 success_ = success;
38 } 37 }
39 38
40 protected: 39 protected:
41 // Creates a new PlatformNotificationContext instance. When using this method, 40 // Creates a new PlatformNotificationContextImpl instance. When using this
42 // the underlying database will always be created in memory. The current 41 // method, the underlying database will always be created in memory. The
43 // message loop proxy will be used as the task runner. 42 // current message loop proxy will be used as the task runner.
44 PlatformNotificationContext* CreatePlatformNotificationContext() { 43 PlatformNotificationContextImpl* CreatePlatformNotificationContext() {
45 PlatformNotificationContext* context = 44 PlatformNotificationContextImpl* context =
46 new PlatformNotificationContext(base::FilePath()); 45 new PlatformNotificationContextImpl(base::FilePath());
47 46
48 context->SetTaskRunnerForTesting(base::MessageLoopProxy::current()); 47 context->SetTaskRunnerForTesting(base::MessageLoopProxy::current());
49 return context; 48 return context;
50 } 49 }
51 50
52 // Returns whether the last invoked callback finished successfully. 51 // Returns whether the last invoked callback finished successfully.
53 bool success() const { return success_; } 52 bool success() const { return success_; }
54 53
55 // Returns the NotificationDatabaseData associated with the last invoked 54 // Returns the NotificationDatabaseData associated with the last invoked
56 // ReadNotificationData callback. 55 // ReadNotificationData callback.
57 const NotificationDatabaseData& database_data() const { 56 const NotificationDatabaseData& database_data() const {
58 return database_data_; 57 return database_data_;
59 } 58 }
60 59
61 // Returns the notification id of the notification last written. 60 // Returns the notification id of the notification last written.
62 int64_t notification_id() const { return notification_id_; } 61 int64_t notification_id() const { return notification_id_; }
63 62
64 private: 63 private:
65 TestBrowserThreadBundle thread_bundle_; 64 TestBrowserThreadBundle thread_bundle_;
66 65
67 bool success_; 66 bool success_;
68 NotificationDatabaseData database_data_; 67 NotificationDatabaseData database_data_;
69 int64_t notification_id_; 68 int64_t notification_id_;
70 }; 69 };
71 70
72 TEST_F(PlatformNotificationContextTest, ReadNonExistentNotification) { 71 TEST_F(PlatformNotificationContextTest, ReadNonExistentNotification) {
73 scoped_refptr<PlatformNotificationContext> context = 72 scoped_refptr<PlatformNotificationContextImpl> context =
74 CreatePlatformNotificationContext(); 73 CreatePlatformNotificationContext();
75 74
76 context->ReadNotificationData( 75 context->ReadNotificationData(
77 42 /* notification_id */, 76 42 /* notification_id */,
78 GURL("https://example.com"), 77 GURL("https://example.com"),
79 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, 78 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData,
80 base::Unretained(this))); 79 base::Unretained(this)));
81 80
82 base::RunLoop().RunUntilIdle(); 81 base::RunLoop().RunUntilIdle();
83 82
84 // The read operation should have failed, as it does not exist. 83 // The read operation should have failed, as it does not exist.
85 ASSERT_FALSE(success()); 84 ASSERT_FALSE(success());
86 } 85 }
87 86
88 TEST_F(PlatformNotificationContextTest, WriteReadNotification) { 87 TEST_F(PlatformNotificationContextTest, WriteReadNotification) {
89 scoped_refptr<PlatformNotificationContext> context = 88 scoped_refptr<PlatformNotificationContextImpl> context =
90 CreatePlatformNotificationContext(); 89 CreatePlatformNotificationContext();
91 90
92 GURL origin("https://example.com"); 91 GURL origin("https://example.com");
93 NotificationDatabaseData notification_database_data; 92 NotificationDatabaseData notification_database_data;
94 notification_database_data.origin = origin; 93 notification_database_data.origin = origin;
95 94
96 context->WriteNotificationData( 95 context->WriteNotificationData(
97 origin, 96 origin,
98 notification_database_data, 97 notification_database_data,
99 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData, 98 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData,
(...skipping 14 matching lines...) Expand all
114 base::RunLoop().RunUntilIdle(); 113 base::RunLoop().RunUntilIdle();
115 114
116 // The read operation should have succeeded, with the right notification. 115 // The read operation should have succeeded, with the right notification.
117 ASSERT_TRUE(success()); 116 ASSERT_TRUE(success());
118 117
119 const NotificationDatabaseData& read_database_data = database_data(); 118 const NotificationDatabaseData& read_database_data = database_data();
120 EXPECT_EQ(notification_database_data.origin, read_database_data.origin); 119 EXPECT_EQ(notification_database_data.origin, read_database_data.origin);
121 } 120 }
122 121
123 TEST_F(PlatformNotificationContextTest, DeleteInvalidNotification) { 122 TEST_F(PlatformNotificationContextTest, DeleteInvalidNotification) {
124 scoped_refptr<PlatformNotificationContext> context = 123 scoped_refptr<PlatformNotificationContextImpl> context =
125 CreatePlatformNotificationContext(); 124 CreatePlatformNotificationContext();
126 125
127 context->DeleteNotificationData( 126 context->DeleteNotificationData(
128 42 /* notification_id */, 127 42 /* notification_id */,
129 GURL("https://example.com"), 128 GURL("https://example.com"),
130 base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData, 129 base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData,
131 base::Unretained(this))); 130 base::Unretained(this)));
132 131
133 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
134 133
135 // The notification may not have existed, but since the goal of deleting data 134 // 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, 135 // 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. 136 // deleting a non-existent notification is considered to be a success.
138 EXPECT_TRUE(success()); 137 EXPECT_TRUE(success());
139 } 138 }
140 139
141 TEST_F(PlatformNotificationContextTest, DeleteNotification) { 140 TEST_F(PlatformNotificationContextTest, DeleteNotification) {
142 scoped_refptr<PlatformNotificationContext> context = 141 scoped_refptr<PlatformNotificationContextImpl> context =
143 CreatePlatformNotificationContext(); 142 CreatePlatformNotificationContext();
144 143
145 GURL origin("https://example.com"); 144 GURL origin("https://example.com");
146 NotificationDatabaseData notification_database_data; 145 NotificationDatabaseData notification_database_data;
147 146
148 context->WriteNotificationData( 147 context->WriteNotificationData(
149 origin, 148 origin,
150 notification_database_data, 149 notification_database_data,
151 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData, 150 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData,
152 base::Unretained(this))); 151 base::Unretained(this)));
(...skipping 22 matching lines...) Expand all
175 base::Unretained(this))); 174 base::Unretained(this)));
176 175
177 base::RunLoop().RunUntilIdle(); 176 base::RunLoop().RunUntilIdle();
178 177
179 // The notification was removed, so we shouldn't be able to read it from 178 // The notification was removed, so we shouldn't be able to read it from
180 // the database anymore. 179 // the database anymore.
181 EXPECT_FALSE(success()); 180 EXPECT_FALSE(success());
182 } 181 }
183 182
184 } // namespace content 183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698