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

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

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/notifications/desktop_notifications_unittest.h" 5 #include "chrome/browser/notifications/desktop_notifications_unittest.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/notifications/fake_balloon_view.h" 9 #include "chrome/browser/notifications/fake_balloon_view.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return params; 132 return params;
133 } 133 }
134 134
135 TEST_F(DesktopNotificationsTest, TestShow) { 135 TEST_F(DesktopNotificationsTest, TestShow) {
136 content::ShowDesktopNotificationHostMsgParams params = 136 content::ShowDesktopNotificationHostMsgParams params =
137 StandardTestNotification(); 137 StandardTestNotification();
138 params.notification_id = 1; 138 params.notification_id = 1;
139 139
140 EXPECT_TRUE(service_->ShowDesktopNotification( 140 EXPECT_TRUE(service_->ShowDesktopNotification(
141 params, 0, 0, DesktopNotificationService::PageNotification)); 141 params, 0, 0, DesktopNotificationService::PageNotification));
142 MessageLoopForUI::current()->RunAllPending(); 142 MessageLoopForUI::current()->RunUntilIdle();
143 EXPECT_EQ(1, balloon_collection_->count()); 143 EXPECT_EQ(1, balloon_collection_->count());
144 144
145 content::ShowDesktopNotificationHostMsgParams params2; 145 content::ShowDesktopNotificationHostMsgParams params2;
146 params2.origin = GURL("http://www.google.com"); 146 params2.origin = GURL("http://www.google.com");
147 params2.is_html = true; 147 params2.is_html = true;
148 params2.contents_url = GURL("http://www.google.com/notification.html"); 148 params2.contents_url = GURL("http://www.google.com/notification.html");
149 params2.notification_id = 2; 149 params2.notification_id = 2;
150 150
151 EXPECT_TRUE(service_->ShowDesktopNotification( 151 EXPECT_TRUE(service_->ShowDesktopNotification(
152 params2, 0, 0, DesktopNotificationService::PageNotification)); 152 params2, 0, 0, DesktopNotificationService::PageNotification));
153 MessageLoopForUI::current()->RunAllPending(); 153 MessageLoopForUI::current()->RunUntilIdle();
154 EXPECT_EQ(2, balloon_collection_->count()); 154 EXPECT_EQ(2, balloon_collection_->count());
155 155
156 EXPECT_EQ("notification displayed\n" 156 EXPECT_EQ("notification displayed\n"
157 "notification displayed\n", 157 "notification displayed\n",
158 log_output_); 158 log_output_);
159 } 159 }
160 160
161 TEST_F(DesktopNotificationsTest, TestClose) { 161 TEST_F(DesktopNotificationsTest, TestClose) {
162 content::ShowDesktopNotificationHostMsgParams params = 162 content::ShowDesktopNotificationHostMsgParams params =
163 StandardTestNotification(); 163 StandardTestNotification();
164 params.notification_id = 1; 164 params.notification_id = 1;
165 165
166 // Request a notification; should open a balloon. 166 // Request a notification; should open a balloon.
167 EXPECT_TRUE(service_->ShowDesktopNotification( 167 EXPECT_TRUE(service_->ShowDesktopNotification(
168 params, 0, 0, DesktopNotificationService::PageNotification)); 168 params, 0, 0, DesktopNotificationService::PageNotification));
169 MessageLoopForUI::current()->RunAllPending(); 169 MessageLoopForUI::current()->RunUntilIdle();
170 EXPECT_EQ(1, balloon_collection_->count()); 170 EXPECT_EQ(1, balloon_collection_->count());
171 171
172 // Close all the open balloons. 172 // Close all the open balloons.
173 while (balloon_collection_->count() > 0) { 173 while (balloon_collection_->count() > 0) {
174 (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true); 174 (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true);
175 } 175 }
176 176
177 EXPECT_EQ("notification displayed\n" 177 EXPECT_EQ("notification displayed\n"
178 "notification closed by user\n", 178 "notification closed by user\n",
179 log_output_); 179 log_output_);
180 } 180 }
181 181
182 TEST_F(DesktopNotificationsTest, TestCancel) { 182 TEST_F(DesktopNotificationsTest, TestCancel) {
183 int process_id = 0; 183 int process_id = 0;
184 int route_id = 0; 184 int route_id = 0;
185 int notification_id = 1; 185 int notification_id = 1;
186 186
187 content::ShowDesktopNotificationHostMsgParams params = 187 content::ShowDesktopNotificationHostMsgParams params =
188 StandardTestNotification(); 188 StandardTestNotification();
189 params.notification_id = notification_id; 189 params.notification_id = notification_id;
190 190
191 // Request a notification; should open a balloon. 191 // Request a notification; should open a balloon.
192 EXPECT_TRUE(service_->ShowDesktopNotification( 192 EXPECT_TRUE(service_->ShowDesktopNotification(
193 params, process_id, route_id, 193 params, process_id, route_id,
194 DesktopNotificationService::PageNotification)); 194 DesktopNotificationService::PageNotification));
195 MessageLoopForUI::current()->RunAllPending(); 195 MessageLoopForUI::current()->RunUntilIdle();
196 EXPECT_EQ(1, balloon_collection_->count()); 196 EXPECT_EQ(1, balloon_collection_->count());
197 197
198 // Cancel the same notification 198 // Cancel the same notification
199 service_->CancelDesktopNotification(process_id, 199 service_->CancelDesktopNotification(process_id,
200 route_id, 200 route_id,
201 notification_id); 201 notification_id);
202 MessageLoopForUI::current()->RunAllPending(); 202 MessageLoopForUI::current()->RunUntilIdle();
203 // Verify that the balloon collection is now empty. 203 // Verify that the balloon collection is now empty.
204 EXPECT_EQ(0, balloon_collection_->count()); 204 EXPECT_EQ(0, balloon_collection_->count());
205 205
206 EXPECT_EQ("notification displayed\n" 206 EXPECT_EQ("notification displayed\n"
207 "notification closed by script\n", 207 "notification closed by script\n",
208 log_output_); 208 log_output_);
209 } 209 }
210 210
211 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 211 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
212 TEST_F(DesktopNotificationsTest, TestPositioning) { 212 TEST_F(DesktopNotificationsTest, TestPositioning) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // Request lots of identical notifications. 280 // Request lots of identical notifications.
281 content::ShowDesktopNotificationHostMsgParams params = 281 content::ShowDesktopNotificationHostMsgParams params =
282 StandardTestNotification(); 282 StandardTestNotification();
283 const int kLotsOfToasts = 20; 283 const int kLotsOfToasts = 20;
284 for (int id = 1; id <= kLotsOfToasts; ++id) { 284 for (int id = 1; id <= kLotsOfToasts; ++id) {
285 params.notification_id = id; 285 params.notification_id = id;
286 EXPECT_TRUE(service_->ShowDesktopNotification( 286 EXPECT_TRUE(service_->ShowDesktopNotification(
287 params, process_id, route_id, 287 params, process_id, route_id,
288 DesktopNotificationService::PageNotification)); 288 DesktopNotificationService::PageNotification));
289 } 289 }
290 MessageLoopForUI::current()->RunAllPending(); 290 MessageLoopForUI::current()->RunUntilIdle();
291 291
292 // Build up an expected log of what should be happening. 292 // Build up an expected log of what should be happening.
293 std::string expected_log; 293 std::string expected_log;
294 for (int i = 0; i < balloon_collection_->max_balloon_count(); ++i) { 294 for (int i = 0; i < balloon_collection_->max_balloon_count(); ++i) {
295 expected_log.append("notification displayed\n"); 295 expected_log.append("notification displayed\n");
296 } 296 }
297 297
298 // The max number that our balloon collection can hold should be 298 // The max number that our balloon collection can hold should be
299 // shown. 299 // shown.
300 EXPECT_EQ(balloon_collection_->max_balloon_count(), 300 EXPECT_EQ(balloon_collection_->max_balloon_count(),
301 balloon_collection_->count()); 301 balloon_collection_->count());
302 EXPECT_EQ(expected_log, log_output_); 302 EXPECT_EQ(expected_log, log_output_);
303 303
304 // Cancel the notifications from the start; the balloon space should 304 // Cancel the notifications from the start; the balloon space should
305 // remain full. 305 // remain full.
306 { 306 {
307 int id; 307 int id;
308 for (id = 1; 308 for (id = 1;
309 id <= kLotsOfToasts - balloon_collection_->max_balloon_count(); 309 id <= kLotsOfToasts - balloon_collection_->max_balloon_count();
310 ++id) { 310 ++id) {
311 service_->CancelDesktopNotification(process_id, route_id, id); 311 service_->CancelDesktopNotification(process_id, route_id, id);
312 MessageLoopForUI::current()->RunAllPending(); 312 MessageLoopForUI::current()->RunUntilIdle();
313 expected_log.append("notification closed by script\n"); 313 expected_log.append("notification closed by script\n");
314 expected_log.append("notification displayed\n"); 314 expected_log.append("notification displayed\n");
315 EXPECT_EQ(balloon_collection_->max_balloon_count(), 315 EXPECT_EQ(balloon_collection_->max_balloon_count(),
316 balloon_collection_->count()); 316 balloon_collection_->count());
317 EXPECT_EQ(expected_log, log_output_); 317 EXPECT_EQ(expected_log, log_output_);
318 } 318 }
319 319
320 // Now cancel the rest. It should empty the balloon space. 320 // Now cancel the rest. It should empty the balloon space.
321 for (; id <= kLotsOfToasts; ++id) { 321 for (; id <= kLotsOfToasts; ++id) {
322 service_->CancelDesktopNotification(process_id, route_id, id); 322 service_->CancelDesktopNotification(process_id, route_id, id);
323 expected_log.append("notification closed by script\n"); 323 expected_log.append("notification closed by script\n");
324 MessageLoopForUI::current()->RunAllPending(); 324 MessageLoopForUI::current()->RunUntilIdle();
325 EXPECT_EQ(expected_log, log_output_); 325 EXPECT_EQ(expected_log, log_output_);
326 } 326 }
327 } 327 }
328 328
329 // Verify that the balloon collection is now empty. 329 // Verify that the balloon collection is now empty.
330 EXPECT_EQ(0, balloon_collection_->count()); 330 EXPECT_EQ(0, balloon_collection_->count());
331 } 331 }
332 332
333 TEST_F(DesktopNotificationsTest, TestEarlyDestruction) { 333 TEST_F(DesktopNotificationsTest, TestEarlyDestruction) {
334 // Create some toasts and then prematurely delete the notification service, 334 // Create some toasts and then prematurely delete the notification service,
(...skipping 12 matching lines...) Expand all
347 // Create a test script with some HTML; assert that it doesn't get into the 347 // Create a test script with some HTML; assert that it doesn't get into the
348 // data:// URL that's produced for the balloon. 348 // data:// URL that's produced for the balloon.
349 content::ShowDesktopNotificationHostMsgParams params = 349 content::ShowDesktopNotificationHostMsgParams params =
350 StandardTestNotification(); 350 StandardTestNotification();
351 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>"); 351 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>");
352 params.body = ASCIIToUTF16("<i>this text is in italics</i>"); 352 params.body = ASCIIToUTF16("<i>this text is in italics</i>");
353 params.notification_id = 1; 353 params.notification_id = 1;
354 EXPECT_TRUE(service_->ShowDesktopNotification( 354 EXPECT_TRUE(service_->ShowDesktopNotification(
355 params, 0, 0, DesktopNotificationService::PageNotification)); 355 params, 0, 0, DesktopNotificationService::PageNotification));
356 356
357 MessageLoopForUI::current()->RunAllPending(); 357 MessageLoopForUI::current()->RunUntilIdle();
358 EXPECT_EQ(1, balloon_collection_->count()); 358 EXPECT_EQ(1, balloon_collection_->count());
359 Balloon* balloon = (*balloon_collection_->balloons().begin()); 359 Balloon* balloon = (*balloon_collection_->balloons().begin());
360 GURL data_url = balloon->notification().content_url(); 360 GURL data_url = balloon->notification().content_url();
361 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); 361 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>"));
362 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); 362 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>"));
363 // URL-encoded versions of tags should also not be found. 363 // URL-encoded versions of tags should also not be found.
364 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e")); 364 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e"));
365 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e")); 365 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e"));
366 } 366 }
367 367
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 466 }
467 467
468 // Now change the position to upper left. Confirm that the X value for the 468 // Now change the position to upper left. Confirm that the X value for the
469 // balloons gets smaller. 469 // balloons gets smaller.
470 local_state_.SetInteger(prefs::kDesktopNotificationPosition, 470 local_state_.SetInteger(prefs::kDesktopNotificationPosition,
471 BalloonCollection::UPPER_LEFT); 471 BalloonCollection::UPPER_LEFT);
472 472
473 int current_x = (*balloons.begin())->GetPosition().x(); 473 int current_x = (*balloons.begin())->GetPosition().x();
474 EXPECT_LT(current_x, last_x); 474 EXPECT_LT(current_x, last_x);
475 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/net/transport_security_persister_unittest.cc ('k') | chrome/browser/page_cycler/page_cycler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698