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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_apitest.cc

Issue 20136004: Allow partial update for notification update API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add more tests per feedback Created 7 years, 4 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 | 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 "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/api/notifications/notifications_api.h" 8 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 utils::NONE)); 184 utils::NONE));
185 185
186 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 186 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
187 bool copy_bool_value = false; 187 bool copy_bool_value = false;
188 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 188 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
189 ASSERT_TRUE(copy_bool_value); 189 ASSERT_TRUE(copy_bool_value);
190 } 190 }
191 } 191 }
192 192
193 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) { 193 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) {
194 scoped_refptr<extensions::NotificationsCreateFunction>
195 notification_create_function(
196 new extensions::NotificationsCreateFunction());
197 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 194 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
198 195
199 notification_create_function->set_extension(empty_extension.get()); 196 // Create a new notification with the minimum required properties.
200 notification_create_function->set_has_callback(true); 197 {
198 scoped_refptr<extensions::NotificationsCreateFunction>
199 notification_create_function(
200 new extensions::NotificationsCreateFunction());
201 notification_create_function->set_extension(empty_extension.get());
202 notification_create_function->set_has_callback(true);
201 203
202 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 204 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
203 notification_create_function.get(), 205 notification_create_function.get(),
204 "[\"\", " 206 "[\"\", "
205 "{" 207 "{"
206 "\"type\": \"basic\"," 208 "\"type\": \"basic\","
207 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 209 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
208 "\"title\": \"Attention!\"," 210 "\"title\": \"Attention!\","
209 "\"message\": \"Check out Cirque du Soleil\"," 211 "\"message\": \"Check out Cirque du Soleil\""
210 "\"priority\": 1," 212 "}]",
211 "\"eventTime\": 1234567890.12345678," 213 browser(),
212 "\"buttons\": [" 214 utils::NONE));
213 " {"
214 " \"title\": \"Up\","
215 " \"iconUrl\":\"http://www.google.com/logos/2012/\""
216 " },"
217 " {"
218 " \"title\": \"Down\"" // note: no iconUrl
219 " }"
220 "],"
221 "\"expandedMessage\": \"This is a longer expanded message.\","
222 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\""
223 "}]",
224 browser(),
225 utils::NONE));
226 215
227 std::string notification_id; 216 std::string notification_id;
228 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 217 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
229 ASSERT_TRUE(result->GetAsString(&notification_id)); 218 ASSERT_TRUE(result->GetAsString(&notification_id));
230 ASSERT_TRUE(notification_id.length() > 0); 219 ASSERT_TRUE(notification_id.length() > 0);
220 }
221
222 // Create another new notification with more than the required properties.
223 {
224 scoped_refptr<extensions::NotificationsCreateFunction>
225 notification_create_function(
226 new extensions::NotificationsCreateFunction());
227 notification_create_function->set_extension(empty_extension.get());
228 notification_create_function->set_has_callback(true);
229
230 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
231 notification_create_function.get(),
232 "[\"\", "
233 "{"
234 "\"type\": \"basic\","
235 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
236 "\"title\": \"Attention!\","
237 "\"message\": \"Check out Cirque du Soleil\","
238 "\"priority\": 1,"
239 "\"eventTime\": 1234567890.12345678,"
240 "\"buttons\": ["
241 " {"
242 " \"title\": \"Up\","
243 " \"iconUrl\":\"http://www.google.com/logos/2012/\""
244 " },"
245 " {"
246 " \"title\": \"Down\"" // note: no iconUrl
247 " }"
248 "],"
249 "\"expandedMessage\": \"This is a longer expanded message.\","
250 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\""
251 "}]",
252 browser(),
253 utils::NONE));
254
255 std::string notification_id;
256 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
257 ASSERT_TRUE(result->GetAsString(&notification_id));
258 ASSERT_TRUE(notification_id.length() > 0);
259 }
260
261 // Error case: missing type property.
262 {
263 scoped_refptr<extensions::NotificationsCreateFunction>
264 notification_create_function(
265 new extensions::NotificationsCreateFunction());
266 notification_create_function->set_extension(empty_extension.get());
267 notification_create_function->set_has_callback(true);
268
269 utils::RunFunction(
270 notification_create_function.get(),
271 "[\"\", "
272 "{"
273 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
274 "\"title\": \"Attention!\","
275 "\"message\": \"Check out Cirque du Soleil\""
276 "}]",
277 browser(),
278 utils::NONE);
279
280 EXPECT_FALSE(notification_create_function->GetError().empty());
281 }
282
283 // Error case: missing iconUrl property.
284 {
285 scoped_refptr<extensions::NotificationsCreateFunction>
286 notification_create_function(
287 new extensions::NotificationsCreateFunction());
288 notification_create_function->set_extension(empty_extension.get());
289 notification_create_function->set_has_callback(true);
290
291 utils::RunFunction(
292 notification_create_function.get(),
293 "[\"\", "
294 "{"
295 "\"type\": \"basic\","
296 "\"title\": \"Attention!\","
297 "\"message\": \"Check out Cirque du Soleil\""
298 "}]",
299 browser(),
300 utils::NONE);
301
302 EXPECT_FALSE(notification_create_function->GetError().empty());
303 }
304
305 // Error case: missing title property.
306 {
307 scoped_refptr<extensions::NotificationsCreateFunction>
308 notification_create_function(
309 new extensions::NotificationsCreateFunction());
310 notification_create_function->set_extension(empty_extension.get());
311 notification_create_function->set_has_callback(true);
312
313 utils::RunFunction(
314 notification_create_function.get(),
315 "[\"\", "
316 "{"
317 "\"type\": \"basic\","
318 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
319 "\"message\": \"Check out Cirque du Soleil\""
320 "}]",
321 browser(),
322 utils::NONE);
323
324 EXPECT_FALSE(notification_create_function->GetError().empty());
325 }
326
327 // Error case: missing message property.
328 {
329 scoped_refptr<extensions::NotificationsCreateFunction>
330 notification_create_function(
331 new extensions::NotificationsCreateFunction());
332 notification_create_function->set_extension(empty_extension.get());
333 notification_create_function->set_has_callback(true);
334
335 utils::RunFunction(
336 notification_create_function.get(),
337 "[\"\", "
338 "{"
339 "\"type\": \"basic\","
340 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
341 "\"title\": \"Attention!\""
342 "}]",
343 browser(),
344 utils::NONE);
345
346 EXPECT_FALSE(notification_create_function->GetError().empty());
347 }
231 } 348 }
232 349
233 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) { 350 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) {
234 scoped_refptr<extensions::NotificationsCreateFunction> 351 scoped_refptr<extensions::NotificationsCreateFunction>
235 notification_create_function( 352 notification_create_function(
236 new extensions::NotificationsCreateFunction()); 353 new extensions::NotificationsCreateFunction());
237 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 354 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
238 355
239 notification_create_function->set_extension(empty_extension.get()); 356 notification_create_function->set_extension(empty_extension.get());
240 notification_create_function->set_has_callback(true); 357 notification_create_function->set_has_callback(true);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 509
393 #if defined(OS_LINUX) 510 #if defined(OS_LINUX)
394 #define MAYBE_TestProgressNotification DISABLED_TestProgressNotification 511 #define MAYBE_TestProgressNotification DISABLED_TestProgressNotification
395 #else 512 #else
396 #define MAYBE_TestProgressNotification TestProgressNotification 513 #define MAYBE_TestProgressNotification TestProgressNotification
397 #endif 514 #endif
398 515
399 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) { 516 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) {
400 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 517 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
401 518
519 // Create a new progress notification.
520 std::string notification_id;
402 { 521 {
403 scoped_refptr<extensions::NotificationsCreateFunction> 522 scoped_refptr<extensions::NotificationsCreateFunction>
404 notification_create_function( 523 notification_create_function(
405 new extensions::NotificationsCreateFunction()); 524 new extensions::NotificationsCreateFunction());
406 notification_create_function->set_extension(empty_extension.get()); 525 notification_create_function->set_extension(empty_extension.get());
407 notification_create_function->set_has_callback(true); 526 notification_create_function->set_has_callback(true);
408 527
409 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 528 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
410 notification_create_function.get(), 529 notification_create_function.get(),
411 "[\"\", " 530 "[\"\", "
412 "{" 531 "{"
413 "\"type\": \"progress\"," 532 "\"type\": \"progress\","
414 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 533 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
415 "\"title\": \"Test!\"," 534 "\"title\": \"Test!\","
416 "\"message\": \"This is a progress notification.\"," 535 "\"message\": \"This is a progress notification.\","
417 "\"priority\": 1," 536 "\"priority\": 1,"
418 "\"eventTime\": 1234567890.12345678," 537 "\"eventTime\": 1234567890.12345678,"
419 "\"progress\": 30" 538 "\"progress\": 30"
420 "}]", 539 "}]",
421 browser(), 540 browser(),
422 utils::NONE)); 541 utils::NONE));
423 542
424 std::string notification_id;
425 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType()); 543 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType());
426 EXPECT_TRUE(result->GetAsString(&notification_id)); 544 EXPECT_TRUE(result->GetAsString(&notification_id));
427 EXPECT_TRUE(notification_id.length() > 0); 545 EXPECT_TRUE(notification_id.length() > 0);
428 } 546 }
429 547
548 // Update the progress property only.
549 {
550 scoped_refptr<extensions::NotificationsUpdateFunction>
551 notification_function(
552 new extensions::NotificationsUpdateFunction());
553 notification_function->set_extension(empty_extension.get());
554 notification_function->set_has_callback(true);
555
556 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
557 notification_function.get(),
558 "[\"" + notification_id +
559 "\", "
560 "{"
561 "\"progress\": 60"
562 "}]",
563 browser(),
564 utils::NONE));
565
566 EXPECT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
567 bool copy_bool_value = false;
568 EXPECT_TRUE(result->GetAsBoolean(&copy_bool_value));
569 EXPECT_TRUE(copy_bool_value);
570 }
571
430 // Error case: progress value provided for non-progress type. 572 // Error case: progress value provided for non-progress type.
431 { 573 {
432 scoped_refptr<extensions::NotificationsCreateFunction> 574 scoped_refptr<extensions::NotificationsCreateFunction>
433 notification_create_function( 575 notification_create_function(
434 new extensions::NotificationsCreateFunction()); 576 new extensions::NotificationsCreateFunction());
435 notification_create_function->set_extension(empty_extension.get()); 577 notification_create_function->set_extension(empty_extension.get());
436 notification_create_function->set_has_callback(true); 578 notification_create_function->set_has_callback(true);
437 579
438 utils::RunFunction( 580 utils::RunFunction(
439 notification_create_function.get(), 581 notification_create_function.get(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 "\"message\": \"This is a progress notification.\"," 637 "\"message\": \"This is a progress notification.\","
496 "\"priority\": 1," 638 "\"priority\": 1,"
497 "\"eventTime\": 1234567890.12345678," 639 "\"eventTime\": 1234567890.12345678,"
498 "\"progress\": 101" 640 "\"progress\": 101"
499 "}]", 641 "}]",
500 browser(), 642 browser(),
501 utils::NONE); 643 utils::NONE);
502 EXPECT_FALSE(notification_create_function->GetError().empty()); 644 EXPECT_FALSE(notification_create_function->GetError().empty());
503 } 645 }
504 } 646 }
647
648 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) {
649 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
650
651 // Create a new notification.
652 std::string notification_id;
653 {
654 scoped_refptr<extensions::NotificationsCreateFunction>
655 notification_function(
656 new extensions::NotificationsCreateFunction());
657 notification_function->set_extension(empty_extension.get());
658 notification_function->set_has_callback(true);
659
660 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
661 notification_function.get(),
662 "[\"\", " // Empty string: ask API to generate ID
663 "{"
664 "\"type\": \"basic\","
665 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
666 "\"title\": \"Attention!\","
667 "\"message\": \"Check out Cirque du Soleil\""
668 "}]",
669 browser(),
670 utils::NONE));
671
672 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
673 ASSERT_TRUE(result->GetAsString(&notification_id));
674 ASSERT_TRUE(notification_id.length() > 0);
675 }
676
677 // Update a few properties in the existing notification.
678 {
679 scoped_refptr<extensions::NotificationsUpdateFunction>
680 notification_function(
681 new extensions::NotificationsUpdateFunction());
682 notification_function->set_extension(empty_extension.get());
683 notification_function->set_has_callback(true);
684
685 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
686 notification_function.get(),
687 "[\"" + notification_id +
688 "\", "
689 "{"
690 "\"title\": \"Changed!\","
691 "\"message\": \"Too late! The show ended yesterday\""
692 "}]",
693 browser(),
694 utils::NONE));
695
696 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
697 bool copy_bool_value = false;
698 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
699 ASSERT_TRUE(copy_bool_value);
700 }
701
702 // Update another property in the existing notification.
703 {
704 scoped_refptr<extensions::NotificationsUpdateFunction>
705 notification_function(
706 new extensions::NotificationsUpdateFunction());
707 notification_function->set_extension(empty_extension.get());
708 notification_function->set_has_callback(true);
709
710 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
711 notification_function.get(),
712 "[\"" + notification_id +
713 "\", "
714 "{"
715 "\"priority\": 2"
716 "}]",
717 browser(),
718 utils::NONE));
719
720 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
721 bool copy_bool_value = false;
722 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
723 ASSERT_TRUE(copy_bool_value);
724 }
725 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/notifications/notifications_api.cc ('k') | chrome/browser/notifications/balloon_collection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698