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

Side by Side Diff: chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc

Issue 8511075: Move the struct used when showing a desktop notification to content/public/common, so that chrome... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/notifications/desktop_notifications_unittest.h " 5 #include "chrome/browser/chromeos/notifications/desktop_notifications_unittest.h "
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/prefs/browser_prefs.h" 9 #include "chrome/browser/prefs/browser_prefs.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "content/common/desktop_notification_messages.h" 11 #include "content/public/common/show_desktop_notification_params.h"
12 12
13 using content::BrowserThread; 13 using content::BrowserThread;
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 // static 17 // static
18 std::string DesktopNotificationsTest::log_output_; 18 std::string DesktopNotificationsTest::log_output_;
19 19
20 class MockNotificationUI : public BalloonCollectionImpl::NotificationUI { 20 class MockNotificationUI : public BalloonCollectionImpl::NotificationUI {
21 public: 21 public:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); 89 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get()));
90 log_output_.clear(); 90 log_output_.clear();
91 } 91 }
92 92
93 void DesktopNotificationsTest::TearDown() { 93 void DesktopNotificationsTest::TearDown() {
94 service_.reset(NULL); 94 service_.reset(NULL);
95 ui_manager_.reset(NULL); 95 ui_manager_.reset(NULL);
96 profile_.reset(NULL); 96 profile_.reset(NULL);
97 } 97 }
98 98
99 DesktopNotificationHostMsg_Show_Params 99 content::ShowDesktopNotificationHostMsgParams
100 DesktopNotificationsTest::StandardTestNotification() { 100 DesktopNotificationsTest::StandardTestNotification() {
101 DesktopNotificationHostMsg_Show_Params params; 101 content::ShowDesktopNotificationHostMsgParams params;
102 params.notification_id = 0; 102 params.notification_id = 0;
103 params.origin = GURL("http://www.google.com"); 103 params.origin = GURL("http://www.google.com");
104 params.is_html = false; 104 params.is_html = false;
105 params.icon_url = GURL("/icon.png"); 105 params.icon_url = GURL("/icon.png");
106 params.title = ASCIIToUTF16("Title"); 106 params.title = ASCIIToUTF16("Title");
107 params.body = ASCIIToUTF16("Text"); 107 params.body = ASCIIToUTF16("Text");
108 params.direction = WebKit::WebTextDirectionDefault; 108 params.direction = WebKit::WebTextDirectionDefault;
109 return params; 109 return params;
110 } 110 }
111 111
112 TEST_F(DesktopNotificationsTest, TestShow) { 112 TEST_F(DesktopNotificationsTest, TestShow) {
113 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); 113 content::ShowDesktopNotificationHostMsgParams params =
114 StandardTestNotification();
114 params.notification_id = 1; 115 params.notification_id = 1;
115 EXPECT_TRUE(service_->ShowDesktopNotification( 116 EXPECT_TRUE(service_->ShowDesktopNotification(
116 params, 0, 0, DesktopNotificationService::PageNotification)); 117 params, 0, 0, DesktopNotificationService::PageNotification));
117 118
118 MessageLoopForUI::current()->RunAllPending(); 119 MessageLoopForUI::current()->RunAllPending();
119 EXPECT_EQ(1, balloon_collection_->count()); 120 EXPECT_EQ(1, balloon_collection_->count());
120 121
121 DesktopNotificationHostMsg_Show_Params params2; 122 content::ShowDesktopNotificationHostMsgParams params2;
122 params2.origin = GURL("http://www.google.com"); 123 params2.origin = GURL("http://www.google.com");
123 params2.is_html = true; 124 params2.is_html = true;
124 params2.contents_url = GURL("http://www.google.com/notification.html"); 125 params2.contents_url = GURL("http://www.google.com/notification.html");
125 params2.notification_id = 2; 126 params2.notification_id = 2;
126 127
127 EXPECT_TRUE(service_->ShowDesktopNotification( 128 EXPECT_TRUE(service_->ShowDesktopNotification(
128 params2, 0, 0, DesktopNotificationService::PageNotification)); 129 params2, 0, 0, DesktopNotificationService::PageNotification));
129 MessageLoopForUI::current()->RunAllPending(); 130 MessageLoopForUI::current()->RunAllPending();
130 EXPECT_EQ(2, balloon_collection_->count()); 131 EXPECT_EQ(2, balloon_collection_->count());
131 132
132 EXPECT_EQ("notification displayed\n" 133 EXPECT_EQ("notification displayed\n"
133 "notification displayed\n", 134 "notification displayed\n",
134 log_output_); 135 log_output_);
135 } 136 }
136 137
137 TEST_F(DesktopNotificationsTest, TestClose) { 138 TEST_F(DesktopNotificationsTest, TestClose) {
138 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); 139 content::ShowDesktopNotificationHostMsgParams params =
140 StandardTestNotification();
139 params.notification_id = 1; 141 params.notification_id = 1;
140 142
141 // Request a notification; should open a balloon. 143 // Request a notification; should open a balloon.
142 EXPECT_TRUE(service_->ShowDesktopNotification( 144 EXPECT_TRUE(service_->ShowDesktopNotification(
143 params, 0, 0, DesktopNotificationService::PageNotification)); 145 params, 0, 0, DesktopNotificationService::PageNotification));
144 MessageLoopForUI::current()->RunAllPending(); 146 MessageLoopForUI::current()->RunAllPending();
145 EXPECT_EQ(1, balloon_collection_->count()); 147 EXPECT_EQ(1, balloon_collection_->count());
146 148
147 // Close all the open balloons. 149 // Close all the open balloons.
148 std::set<Balloon*> balloons = balloon_collection_->balloons(); 150 std::set<Balloon*> balloons = balloon_collection_->balloons();
149 std::set<Balloon*>::iterator iter; 151 std::set<Balloon*>::iterator iter;
150 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { 152 for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
151 (*iter)->OnClose(true); 153 (*iter)->OnClose(true);
152 } 154 }
153 155
154 // Verify that the balloon collection is now empty. 156 // Verify that the balloon collection is now empty.
155 EXPECT_EQ(0, balloon_collection_->count()); 157 EXPECT_EQ(0, balloon_collection_->count());
156 158
157 EXPECT_EQ("notification displayed\n" 159 EXPECT_EQ("notification displayed\n"
158 "notification closed by user\n", 160 "notification closed by user\n",
159 log_output_); 161 log_output_);
160 } 162 }
161 163
162 TEST_F(DesktopNotificationsTest, TestCancel) { 164 TEST_F(DesktopNotificationsTest, TestCancel) {
163 int process_id = 0; 165 int process_id = 0;
164 int route_id = 0; 166 int route_id = 0;
165 int notification_id = 1; 167 int notification_id = 1;
166 168
167 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); 169 content::ShowDesktopNotificationHostMsgParams params =
170 StandardTestNotification();
168 params.notification_id = notification_id; 171 params.notification_id = notification_id;
169 172
170 // Request a notification; should open a balloon. 173 // Request a notification; should open a balloon.
171 EXPECT_TRUE(service_->ShowDesktopNotification( 174 EXPECT_TRUE(service_->ShowDesktopNotification(
172 params, process_id, route_id, 175 params, process_id, route_id,
173 DesktopNotificationService::PageNotification)); 176 DesktopNotificationService::PageNotification));
174 MessageLoopForUI::current()->RunAllPending(); 177 MessageLoopForUI::current()->RunAllPending();
175 EXPECT_EQ(1, balloon_collection_->count()); 178 EXPECT_EQ(1, balloon_collection_->count());
176 179
177 // Cancel the same notification 180 // Cancel the same notification
(...skipping 10 matching lines...) Expand all
188 } 191 }
189 192
190 TEST_F(DesktopNotificationsTest, TestManyNotifications) { 193 TEST_F(DesktopNotificationsTest, TestManyNotifications) {
191 int process_id = 0; 194 int process_id = 0;
192 int route_id = 0; 195 int route_id = 0;
193 196
194 // Request lots of identical notifications. 197 // Request lots of identical notifications.
195 const int kLotsOfToasts = 20; 198 const int kLotsOfToasts = 20;
196 for (int id = 1; id <= kLotsOfToasts; ++id) { 199 for (int id = 1; id <= kLotsOfToasts; ++id) {
197 SCOPED_TRACE(base::StringPrintf("Creation loop: id=%d", id)); 200 SCOPED_TRACE(base::StringPrintf("Creation loop: id=%d", id));
198 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); 201 content::ShowDesktopNotificationHostMsgParams params =
202 StandardTestNotification();
199 params.notification_id = id; 203 params.notification_id = id;
200 EXPECT_TRUE(service_->ShowDesktopNotification( 204 EXPECT_TRUE(service_->ShowDesktopNotification(
201 params, process_id, route_id, 205 params, process_id, route_id,
202 DesktopNotificationService::PageNotification)); 206 DesktopNotificationService::PageNotification));
203 } 207 }
204 MessageLoopForUI::current()->RunAllPending(); 208 MessageLoopForUI::current()->RunAllPending();
205 209
206 // Build up an expected log of what should be happening. 210 // Build up an expected log of what should be happening.
207 std::string expected_log; 211 std::string expected_log;
208 for (int i = 0; i < kLotsOfToasts; ++i) { 212 for (int i = 0; i < kLotsOfToasts; ++i) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_TRUE(service_->ShowDesktopNotification( 253 EXPECT_TRUE(service_->ShowDesktopNotification(
250 StandardTestNotification(), 0, 0, 254 StandardTestNotification(), 0, 0,
251 DesktopNotificationService::PageNotification)); 255 DesktopNotificationService::PageNotification));
252 } 256 }
253 service_.reset(NULL); 257 service_.reset(NULL);
254 } 258 }
255 259
256 TEST_F(DesktopNotificationsTest, TestUserInputEscaping) { 260 TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
257 // Create a test script with some HTML; assert that it doesn't get into the 261 // Create a test script with some HTML; assert that it doesn't get into the
258 // data:// URL that's produced for the balloon. 262 // data:// URL that's produced for the balloon.
259 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); 263 content::ShowDesktopNotificationHostMsgParams params =
264 StandardTestNotification();
260 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>"); 265 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>");
261 params.body = ASCIIToUTF16("<i>this text is in italics</i>"); 266 params.body = ASCIIToUTF16("<i>this text is in italics</i>");
262 params.notification_id = 1; 267 params.notification_id = 1;
263 EXPECT_TRUE(service_->ShowDesktopNotification( 268 EXPECT_TRUE(service_->ShowDesktopNotification(
264 params, 0, 0, DesktopNotificationService::PageNotification)); 269 params, 0, 0, DesktopNotificationService::PageNotification));
265 270
266 MessageLoopForUI::current()->RunAllPending(); 271 MessageLoopForUI::current()->RunAllPending();
267 EXPECT_EQ(1, balloon_collection_->count()); 272 EXPECT_EQ(1, balloon_collection_->count());
268 Balloon* balloon = (*balloon_collection_->balloons().begin()); 273 Balloon* balloon = (*balloon_collection_->balloons().begin());
269 GURL data_url = balloon->notification().content_url(); 274 GURL data_url = balloon->notification().content_url();
270 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); 275 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>"));
271 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); 276 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>"));
272 } 277 }
273 278
274 } // namespace chromeos 279 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698