| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 343 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 344 ASSERT_EQ("false - is not controlled", script_result); | 344 ASSERT_EQ("false - is not controlled", script_result); |
| 345 | 345 |
| 346 LoadTestPage(); // Reload to become controlled. | 346 LoadTestPage(); // Reload to become controlled. |
| 347 | 347 |
| 348 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 348 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 349 ASSERT_EQ("true - is controlled", script_result); | 349 ASSERT_EQ("true - is controlled", script_result); |
| 350 | 350 |
| 351 GCMClient::IncomingMessage message; | 351 GCMClient::IncomingMessage message; |
| 352 GCMClient::MessageData messageData; | 352 message.data["data"] = "testdata"; |
| 353 messageData.insert(std::pair<std::string, std::string>("data", "testdata")); | |
| 354 message.data = messageData; | |
| 355 push_service()->OnMessage(app_id.ToString(), message); | 353 push_service()->OnMessage(app_id.ToString(), message); |
| 356 ASSERT_TRUE(RunScript("pushData.get()", &script_result)); | 354 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 357 EXPECT_EQ("testdata", script_result); | 355 EXPECT_EQ("testdata", script_result); |
| 358 } | 356 } |
| 359 | 357 |
| 360 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 358 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| 361 std::string script_result; | 359 std::string script_result; |
| 362 | 360 |
| 363 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 361 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 364 | 362 |
| 365 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0LL); | 363 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0LL); |
| 366 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | 364 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 378 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 376 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 379 ASSERT_EQ("service worker unregistration status: true", script_result); | 377 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 380 | 378 |
| 381 // When the push service will receive it next message, given that there is no | 379 // When the push service will receive it next message, given that there is no |
| 382 // SW available, it should unregister |app_id|. | 380 // SW available, it should unregister |app_id|. |
| 383 UnregistrationCallback callback; | 381 UnregistrationCallback callback; |
| 384 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 382 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 385 base::Unretained(&callback))); | 383 base::Unretained(&callback))); |
| 386 | 384 |
| 387 GCMClient::IncomingMessage message; | 385 GCMClient::IncomingMessage message; |
| 388 GCMClient::MessageData messageData; | 386 message.data["data"] = "testdata"; |
| 389 messageData.insert(std::pair<std::string, std::string>("data", "testdata")); | |
| 390 message.data = messageData; | |
| 391 push_service()->OnMessage(app_id.ToString(), message); | 387 push_service()->OnMessage(app_id.ToString(), message); |
| 392 | 388 |
| 393 callback.WaitUntilSatisfied(); | 389 callback.WaitUntilSatisfied(); |
| 394 EXPECT_EQ(app_id.ToString(), callback.app_id()); | 390 EXPECT_EQ(app_id.ToString(), callback.app_id()); |
| 395 | 391 |
| 396 // No push data should have been received. | 392 // No push data should have been received. |
| 397 ASSERT_TRUE(RunScript("pushData.getImmediately()", &script_result)); | 393 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 398 EXPECT_EQ("null", script_result); | 394 EXPECT_EQ("null", script_result); |
| 399 } | 395 } |
| 400 | 396 |
| 401 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { | 397 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { |
| 402 std::string script_result; | 398 std::string script_result; |
| 403 | 399 |
| 404 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 400 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 405 | 401 |
| 406 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0LL); | 402 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0LL); |
| 407 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | 403 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 419 browser()->profile()->GetHostContentSettingsMap()-> | 415 browser()->profile()->GetHostContentSettingsMap()-> |
| 420 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 416 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 421 | 417 |
| 422 // When the push service will receive its next message, given that there is no | 418 // When the push service will receive its next message, given that there is no |
| 423 // SW available, it should unregister |app_id|. | 419 // SW available, it should unregister |app_id|. |
| 424 UnregistrationCallback callback; | 420 UnregistrationCallback callback; |
| 425 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 421 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 426 base::Unretained(&callback))); | 422 base::Unretained(&callback))); |
| 427 | 423 |
| 428 GCMClient::IncomingMessage message; | 424 GCMClient::IncomingMessage message; |
| 429 GCMClient::MessageData messageData; | 425 message.data["data"] = "testdata"; |
| 430 messageData.insert(std::pair<std::string, std::string>("data", "testdata")); | |
| 431 message.data = messageData; | |
| 432 push_service()->OnMessage(app_id.ToString(), message); | 426 push_service()->OnMessage(app_id.ToString(), message); |
| 433 | 427 |
| 434 callback.WaitUntilSatisfied(); | 428 callback.WaitUntilSatisfied(); |
| 435 EXPECT_EQ(app_id.ToString(), callback.app_id()); | 429 EXPECT_EQ(app_id.ToString(), callback.app_id()); |
| 436 | 430 |
| 437 // No push data should have been received. | 431 // No push data should have been received. |
| 438 ASSERT_TRUE(RunScript("pushData.getImmediately()", &script_result)); | 432 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 439 EXPECT_EQ("null", script_result); | 433 EXPECT_EQ("null", script_result); |
| 440 } | 434 } |
| 441 | 435 |
| 442 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { | 436 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { |
| 443 std::string script_result; | 437 std::string script_result; |
| 444 | 438 |
| 445 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 439 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 446 ASSERT_EQ("ok - service worker registered", script_result); | 440 ASSERT_EQ("ok - service worker registered", script_result); |
| 447 | 441 |
| 448 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 442 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 509 |
| 516 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 510 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
| 517 | 511 |
| 518 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 512 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
| 519 EXPECT_EQ("unregister error: " | 513 EXPECT_EQ("unregister error: " |
| 520 "UnknownError: Unexpected error while trying to unregister from the" | 514 "UnknownError: Unexpected error while trying to unregister from the" |
| 521 " push server.", script_result); | 515 " push server.", script_result); |
| 522 } | 516 } |
| 523 | 517 |
| 524 } // namespace gcm | 518 } // namespace gcm |
| OLD | NEW |