OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 390 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
391 ASSERT_EQ("false - is not controlled", script_result); | 391 ASSERT_EQ("false - is not controlled", script_result); |
392 | 392 |
393 LoadTestPage(); // Reload to become controlled. | 393 LoadTestPage(); // Reload to become controlled. |
394 | 394 |
395 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 395 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
396 ASSERT_EQ("true - is controlled", script_result); | 396 ASSERT_EQ("true - is controlled", script_result); |
397 | 397 |
398 GCMClient::IncomingMessage message; | 398 GCMClient::IncomingMessage message; |
| 399 message.sender_id = "1234567890"; |
399 message.data["data"] = "testdata"; | 400 message.data["data"] = "testdata"; |
400 push_service()->OnMessage(app_id.app_id_guid, message); | 401 push_service()->OnMessage(app_id.app_id_guid, message); |
401 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 402 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
402 EXPECT_EQ("testdata", script_result); | 403 EXPECT_EQ("testdata", script_result); |
403 } | 404 } |
404 | 405 |
405 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 406 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
406 std::string script_result; | 407 std::string script_result; |
407 | 408 |
408 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 409 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
(...skipping 14 matching lines...) Expand all Loading... |
423 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 424 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
424 ASSERT_EQ("service worker unregistration status: true", script_result); | 425 ASSERT_EQ("service worker unregistration status: true", script_result); |
425 | 426 |
426 // When the push service will receive it next message, given that there is no | 427 // When the push service will receive it next message, given that there is no |
427 // SW available, it should unregister |app_id|. | 428 // SW available, it should unregister |app_id|. |
428 UnregistrationCallback callback; | 429 UnregistrationCallback callback; |
429 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 430 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
430 base::Unretained(&callback))); | 431 base::Unretained(&callback))); |
431 | 432 |
432 GCMClient::IncomingMessage message; | 433 GCMClient::IncomingMessage message; |
| 434 message.sender_id = "1234567890"; |
433 message.data["data"] = "testdata"; | 435 message.data["data"] = "testdata"; |
434 push_service()->OnMessage(app_id.app_id_guid, message); | 436 push_service()->OnMessage(app_id.app_id_guid, message); |
435 | 437 |
436 callback.WaitUntilSatisfied(); | 438 callback.WaitUntilSatisfied(); |
437 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 439 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); |
438 | 440 |
439 // No push data should have been received. | 441 // No push data should have been received. |
440 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 442 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
441 EXPECT_EQ("null", script_result); | 443 EXPECT_EQ("null", script_result); |
442 } | 444 } |
(...skipping 19 matching lines...) Expand all Loading... |
462 browser()->profile()->GetHostContentSettingsMap()-> | 464 browser()->profile()->GetHostContentSettingsMap()-> |
463 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 465 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
464 | 466 |
465 // When the push service will receive its next message, given that there is no | 467 // When the push service will receive its next message, given that there is no |
466 // SW available, it should unregister |app_id|. | 468 // SW available, it should unregister |app_id|. |
467 UnregistrationCallback callback; | 469 UnregistrationCallback callback; |
468 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 470 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
469 base::Unretained(&callback))); | 471 base::Unretained(&callback))); |
470 | 472 |
471 GCMClient::IncomingMessage message; | 473 GCMClient::IncomingMessage message; |
| 474 message.sender_id = "1234567890"; |
472 message.data["data"] = "testdata"; | 475 message.data["data"] = "testdata"; |
473 push_service()->OnMessage(app_id.app_id_guid, message); | 476 push_service()->OnMessage(app_id.app_id_guid, message); |
474 | 477 |
475 callback.WaitUntilSatisfied(); | 478 callback.WaitUntilSatisfied(); |
476 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 479 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); |
477 | 480 |
478 // No push data should have been received. | 481 // No push data should have been received. |
479 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 482 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
480 EXPECT_EQ("null", script_result); | 483 EXPECT_EQ("null", script_result); |
481 } | 484 } |
(...skipping 21 matching lines...) Expand all Loading... |
503 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 506 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
504 | 507 |
505 // We'll need to specify the web_contents in which to eval script, since we're | 508 // We'll need to specify the web_contents in which to eval script, since we're |
506 // going to run script in a background tab. | 509 // going to run script in a background tab. |
507 content::WebContents* web_contents = | 510 content::WebContents* web_contents = |
508 browser()->tab_strip_model()->GetActiveWebContents(); | 511 browser()->tab_strip_model()->GetActiveWebContents(); |
509 | 512 |
510 // If the site is visible in an active tab, we should not force a notification | 513 // If the site is visible in an active tab, we should not force a notification |
511 // to be shown. Try it twice, since we allow one mistake per 10 push events. | 514 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
512 GCMClient::IncomingMessage message; | 515 GCMClient::IncomingMessage message; |
| 516 message.sender_id = "1234567890"; |
513 for (int n = 0; n < 2; n++) { | 517 for (int n = 0; n < 2; n++) { |
514 message.data["data"] = "testdata"; | 518 message.data["data"] = "testdata"; |
515 push_service()->OnMessage(app_id.app_id_guid, message); | 519 push_service()->OnMessage(app_id.app_id_guid, message); |
516 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 520 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
517 EXPECT_EQ("testdata", script_result); | 521 EXPECT_EQ("testdata", script_result); |
518 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 522 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
519 } | 523 } |
520 | 524 |
521 // Open a blank foreground tab so site is no longer visible. | 525 // Open a blank foreground tab so site is no longer visible. |
522 ui_test_utils::NavigateToURLWithDisposition( | 526 ui_test_utils::NavigateToURLWithDisposition( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 653 |
650 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 654 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
651 | 655 |
652 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 656 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
653 EXPECT_EQ("unregister error: " | 657 EXPECT_EQ("unregister error: " |
654 "UnknownError: Unexpected error while trying to unregister from the" | 658 "UnknownError: Unexpected error while trying to unregister from the" |
655 " push server.", script_result); | 659 " push server.", script_result); |
656 } | 660 } |
657 | 661 |
658 } // namespace gcm | 662 } // namespace gcm |
OLD | NEW |