| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 browser()->profile(), origin, service_worker_registration_id); | 261 browser()->profile(), origin, service_worker_registration_id); |
| 262 EXPECT_TRUE(application_id.IsValid()); | 262 EXPECT_TRUE(application_id.IsValid()); |
| 263 return application_id; | 263 return application_id; |
| 264 } | 264 } |
| 265 | 265 |
| 266 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 266 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 267 RegisterSuccessNotificationsGranted) { | 267 RegisterSuccessNotificationsGranted) { |
| 268 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 268 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 269 | 269 |
| 270 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 270 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 271 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 271 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 272 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 272 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 273 } | 273 } |
| 274 | 274 |
| 275 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 275 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 276 RegisterSuccessNotificationsPrompt) { | 276 RegisterSuccessNotificationsPrompt) { |
| 277 std::string script_result; | 277 std::string script_result; |
| 278 | 278 |
| 279 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 279 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 280 ASSERT_EQ("ok - service worker registered", script_result); | 280 ASSERT_EQ("ok - service worker registered", script_result); |
| 281 | 281 |
| 282 InfoBarResponder accepting_responder(browser(), true); | 282 InfoBarResponder accepting_responder(browser(), true); |
| 283 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 283 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
| 284 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); | 284 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); |
| 285 | 285 |
| 286 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 286 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 287 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 287 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 288 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 288 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 289 } | 289 } |
| 290 | 290 |
| 291 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 291 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 292 RegisterFailureNotificationsBlocked) { | 292 RegisterFailureNotificationsBlocked) { |
| 293 std::string script_result; | 293 std::string script_result; |
| 294 | 294 |
| 295 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 295 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 296 ASSERT_EQ("ok - service worker registered", script_result); | 296 ASSERT_EQ("ok - service worker registered", script_result); |
| 297 | 297 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 327 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { | 327 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { |
| 328 std::string script_result; | 328 std::string script_result; |
| 329 | 329 |
| 330 // First, test that Service Worker registration IDs are assigned in order of | 330 // First, test that Service Worker registration IDs are assigned in order of |
| 331 // registering the Service Workers, and the (fake) push registration ids are | 331 // registering the Service Workers, and the (fake) push registration ids are |
| 332 // assigned in order of push registration (even when these orders are | 332 // assigned in order of push registration (even when these orders are |
| 333 // different). | 333 // different). |
| 334 | 334 |
| 335 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 335 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 336 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL); | 336 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL); |
| 337 EXPECT_EQ(app_id_sw0.app_id_guid, gcm_service()->last_registered_app_id()); | 337 EXPECT_EQ(app_id_sw0.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 338 | 338 |
| 339 LoadTestPage("files/push_messaging/subscope1/test.html"); | 339 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 340 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 340 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 341 ASSERT_EQ("ok - service worker registered", script_result); | 341 ASSERT_EQ("ok - service worker registered", script_result); |
| 342 | 342 |
| 343 LoadTestPage("files/push_messaging/subscope2/test.html"); | 343 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 344 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 344 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 345 ASSERT_EQ("ok - service worker registered", script_result); | 345 ASSERT_EQ("ok - service worker registered", script_result); |
| 346 | 346 |
| 347 // Note that we need to reload the page after registering, otherwise | 347 // Note that we need to reload the page after registering, otherwise |
| 348 // navigator.serviceWorker.ready is going to be resolved with the parent | 348 // navigator.serviceWorker.ready is going to be resolved with the parent |
| 349 // Service Worker which still controls the page. | 349 // Service Worker which still controls the page. |
| 350 LoadTestPage("files/push_messaging/subscope2/test.html"); | 350 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 351 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); | 351 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); |
| 352 PushMessagingApplicationId app_id_sw2 = GetServiceWorkerAppId(2LL); | 352 PushMessagingApplicationId app_id_sw2 = GetServiceWorkerAppId(2LL); |
| 353 EXPECT_EQ(app_id_sw2.app_id_guid, gcm_service()->last_registered_app_id()); | 353 EXPECT_EQ(app_id_sw2.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 354 | 354 |
| 355 LoadTestPage("files/push_messaging/subscope1/test.html"); | 355 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 356 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); | 356 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); |
| 357 PushMessagingApplicationId app_id_sw1 = GetServiceWorkerAppId(1LL); | 357 PushMessagingApplicationId app_id_sw1 = GetServiceWorkerAppId(1LL); |
| 358 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 358 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 359 | 359 |
| 360 // Now test that the Service Worker registration IDs and push registration IDs | 360 // Now test that the Service Worker registration IDs and push registration IDs |
| 361 // generated above were persisted to SW storage, by checking that they are | 361 // generated above were persisted to SW storage, by checking that they are |
| 362 // unchanged despite requesting them in a different order. | 362 // unchanged despite requesting them in a different order. |
| 363 // TODO(johnme): Ideally we would restart the browser at this point to check | 363 // TODO(johnme): Ideally we would restart the browser at this point to check |
| 364 // they were persisted to disk, but that's not currently possible since the | 364 // they were persisted to disk, but that's not currently possible since the |
| 365 // test server uses random port numbers for each test (even PRE_Foo and Foo), | 365 // test server uses random port numbers for each test (even PRE_Foo and Foo), |
| 366 // so we wouldn't be able to load the test pages with the same origin. | 366 // so we wouldn't be able to load the test pages with the same origin. |
| 367 | 367 |
| 368 LoadTestPage("files/push_messaging/subscope1/test.html"); | 368 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 369 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); | 369 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); |
| 370 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 370 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 371 | 371 |
| 372 LoadTestPage("files/push_messaging/subscope2/test.html"); | 372 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 373 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); | 373 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); |
| 374 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 374 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 375 | 375 |
| 376 LoadTestPage(); | 376 LoadTestPage(); |
| 377 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 377 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 378 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 378 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 379 } | 379 } |
| 380 | 380 |
| 381 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 381 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| 382 std::string script_result; | 382 std::string script_result; |
| 383 | 383 |
| 384 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 384 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 385 | 385 |
| 386 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 386 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 387 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 387 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 388 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 388 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 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.data["data"] = "testdata"; | 399 message.data["data"] = "testdata"; |
| 400 push_service()->OnMessage(app_id.app_id_guid, message); | 400 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 401 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 401 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 402 EXPECT_EQ("testdata", script_result); | 402 EXPECT_EQ("testdata", script_result); |
| 403 } | 403 } |
| 404 | 404 |
| 405 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 405 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| 406 std::string script_result; | 406 std::string script_result; |
| 407 | 407 |
| 408 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 408 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 409 | 409 |
| 410 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 410 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 411 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 411 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 412 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 412 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 413 | 413 |
| 414 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 414 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 415 ASSERT_EQ("false - is not controlled", script_result); | 415 ASSERT_EQ("false - is not controlled", script_result); |
| 416 | 416 |
| 417 LoadTestPage(); // Reload to become controlled. | 417 LoadTestPage(); // Reload to become controlled. |
| 418 | 418 |
| 419 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 419 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 420 ASSERT_EQ("true - is controlled", script_result); | 420 ASSERT_EQ("true - is controlled", script_result); |
| 421 | 421 |
| 422 // Unregister service worker. Sending a message should now fail. | 422 // Unregister service worker. Sending a message should now fail. |
| 423 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 423 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 424 ASSERT_EQ("service worker unregistration status: true", script_result); | 424 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 425 | 425 |
| 426 // When the push service will receive it next message, given that there is no | 426 // When the push service will receive it next message, given that there is no |
| 427 // SW available, it should unregister |app_id|. | 427 // SW available, it should unregister |app_id|. |
| 428 UnregistrationCallback callback; | 428 UnregistrationCallback callback; |
| 429 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 429 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 430 base::Unretained(&callback))); | 430 base::Unretained(&callback))); |
| 431 | 431 |
| 432 GCMClient::IncomingMessage message; | 432 GCMClient::IncomingMessage message; |
| 433 message.data["data"] = "testdata"; | 433 message.data["data"] = "testdata"; |
| 434 push_service()->OnMessage(app_id.app_id_guid, message); | 434 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 435 | 435 |
| 436 callback.WaitUntilSatisfied(); | 436 callback.WaitUntilSatisfied(); |
| 437 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 437 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
| 438 | 438 |
| 439 // No push data should have been received. | 439 // No push data should have been received. |
| 440 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 440 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 441 EXPECT_EQ("null", script_result); | 441 EXPECT_EQ("null", script_result); |
| 442 } | 442 } |
| 443 | 443 |
| 444 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { | 444 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { |
| 445 std::string script_result; | 445 std::string script_result; |
| 446 | 446 |
| 447 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 447 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 448 | 448 |
| 449 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 449 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 450 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 450 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 451 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 451 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 452 | 452 |
| 453 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 453 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 454 ASSERT_EQ("false - is not controlled", script_result); | 454 ASSERT_EQ("false - is not controlled", script_result); |
| 455 | 455 |
| 456 LoadTestPage(); // Reload to become controlled. | 456 LoadTestPage(); // Reload to become controlled. |
| 457 | 457 |
| 458 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 458 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 459 ASSERT_EQ("true - is controlled", script_result); | 459 ASSERT_EQ("true - is controlled", script_result); |
| 460 | 460 |
| 461 // Revoke Push permission. | 461 // Revoke Push permission. |
| 462 browser()->profile()->GetHostContentSettingsMap()-> | 462 browser()->profile()->GetHostContentSettingsMap()-> |
| 463 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 463 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 464 | 464 |
| 465 // When the push service will receive its next message, given that there is no | 465 // When the push service will receive its next message, given that there is no |
| 466 // SW available, it should unregister |app_id|. | 466 // SW available, it should unregister |app_id|. |
| 467 UnregistrationCallback callback; | 467 UnregistrationCallback callback; |
| 468 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 468 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 469 base::Unretained(&callback))); | 469 base::Unretained(&callback))); |
| 470 | 470 |
| 471 GCMClient::IncomingMessage message; | 471 GCMClient::IncomingMessage message; |
| 472 message.data["data"] = "testdata"; | 472 message.data["data"] = "testdata"; |
| 473 push_service()->OnMessage(app_id.app_id_guid, message); | 473 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 474 | 474 |
| 475 callback.WaitUntilSatisfied(); | 475 callback.WaitUntilSatisfied(); |
| 476 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 476 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
| 477 | 477 |
| 478 // No push data should have been received. | 478 // No push data should have been received. |
| 479 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 479 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 480 EXPECT_EQ("null", script_result); | 480 EXPECT_EQ("null", script_result); |
| 481 } | 481 } |
| 482 | 482 |
| 483 #if defined(ENABLE_NOTIFICATIONS) | 483 #if defined(ENABLE_NOTIFICATIONS) |
| 484 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 484 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 485 PushEventEnforcesUserVisibleNotification) { | 485 PushEventEnforcesUserVisibleNotification) { |
| 486 std::string script_result; | 486 std::string script_result; |
| 487 | 487 |
| 488 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 488 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 489 | 489 |
| 490 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 490 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 491 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 491 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 492 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 492 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 493 | 493 |
| 494 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 494 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 495 ASSERT_EQ("false - is not controlled", script_result); | 495 ASSERT_EQ("false - is not controlled", script_result); |
| 496 | 496 |
| 497 LoadTestPage(); // Reload to become controlled. | 497 LoadTestPage(); // Reload to become controlled. |
| 498 | 498 |
| 499 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 499 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 500 ASSERT_EQ("true - is controlled", script_result); | 500 ASSERT_EQ("true - is controlled", script_result); |
| 501 | 501 |
| 502 notification_manager()->CancelAll(); | 502 notification_manager()->CancelAll(); |
| 503 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 503 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 504 | 504 |
| 505 // We'll need to specify the web_contents in which to eval script, since we're | 505 // 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. | 506 // going to run script in a background tab. |
| 507 content::WebContents* web_contents = | 507 content::WebContents* web_contents = |
| 508 browser()->tab_strip_model()->GetActiveWebContents(); | 508 browser()->tab_strip_model()->GetActiveWebContents(); |
| 509 | 509 |
| 510 // If the site is visible in an active tab, we should not force a notification | 510 // 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. | 511 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
| 512 GCMClient::IncomingMessage message; | 512 GCMClient::IncomingMessage message; |
| 513 for (int n = 0; n < 2; n++) { | 513 for (int n = 0; n < 2; n++) { |
| 514 message.data["data"] = "testdata"; | 514 message.data["data"] = "testdata"; |
| 515 push_service()->OnMessage(app_id.app_id_guid, message); | 515 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 516 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 516 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 517 EXPECT_EQ("testdata", script_result); | 517 EXPECT_EQ("testdata", script_result); |
| 518 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 518 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 // Open a blank foreground tab so site is no longer visible. | 521 // Open a blank foreground tab so site is no longer visible. |
| 522 ui_test_utils::NavigateToURLWithDisposition( | 522 ui_test_utils::NavigateToURLWithDisposition( |
| 523 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, | 523 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, |
| 524 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 524 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 525 | 525 |
| 526 // If the Service Worker push event handler does not show a notification, we | 526 // If the Service Worker push event handler does not show a notification, we |
| 527 // should show a forced one, but only on the 2nd occurrence since we allow one | 527 // should show a forced one, but only on the 2nd occurrence since we allow one |
| 528 // mistake per 10 push events. | 528 // mistake per 10 push events. |
| 529 message.data["data"] = "testdata"; | 529 message.data["data"] = "testdata"; |
| 530 push_service()->OnMessage(app_id.app_id_guid, message); | 530 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 531 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 531 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 532 EXPECT_EQ("testdata", script_result); | 532 EXPECT_EQ("testdata", script_result); |
| 533 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 533 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 534 message.data["data"] = "testdata"; | 534 message.data["data"] = "testdata"; |
| 535 push_service()->OnMessage(app_id.app_id_guid, message); | 535 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 536 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 536 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 537 EXPECT_EQ("testdata", script_result); | 537 EXPECT_EQ("testdata", script_result); |
| 538 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); | 538 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 539 EXPECT_EQ(base::ASCIIToUTF16(kPushMessagingForcedNotificationTag), | 539 EXPECT_EQ(base::ASCIIToUTF16(kPushMessagingForcedNotificationTag), |
| 540 notification_manager()->GetNotificationAt(0).replace_id()); | 540 notification_manager()->GetNotificationAt(0).replace_id()); |
| 541 | 541 |
| 542 // Currently, this notification will stick around until the user or webapp | 542 // Currently, this notification will stick around until the user or webapp |
| 543 // explicitly dismisses it (though we may change this later). | 543 // explicitly dismisses it (though we may change this later). |
| 544 message.data["data"] = "shownotification"; | 544 message.data["data"] = "shownotification"; |
| 545 push_service()->OnMessage(app_id.app_id_guid, message); | 545 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 546 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 546 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 547 EXPECT_EQ("shownotification", script_result); | 547 EXPECT_EQ("shownotification", script_result); |
| 548 EXPECT_EQ(2u, notification_manager()->GetNotificationCount()); | 548 EXPECT_EQ(2u, notification_manager()->GetNotificationCount()); |
| 549 | 549 |
| 550 notification_manager()->CancelAll(); | 550 notification_manager()->CancelAll(); |
| 551 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 551 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 552 | 552 |
| 553 // However if the Service Worker push event handler shows a notification, we | 553 // However if the Service Worker push event handler shows a notification, we |
| 554 // should not show a forced one. | 554 // should not show a forced one. |
| 555 message.data["data"] = "shownotification"; | 555 message.data["data"] = "shownotification"; |
| 556 for (int n = 0; n < 9; n++) { | 556 for (int n = 0; n < 9; n++) { |
| 557 push_service()->OnMessage(app_id.app_id_guid, message); | 557 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 558 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 558 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 559 EXPECT_EQ("shownotification", script_result); | 559 EXPECT_EQ("shownotification", script_result); |
| 560 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); | 560 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 561 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), | 561 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), |
| 562 notification_manager()->GetNotificationAt(0).replace_id()); | 562 notification_manager()->GetNotificationAt(0).replace_id()); |
| 563 notification_manager()->CancelAll(); | 563 notification_manager()->CancelAll(); |
| 564 } | 564 } |
| 565 | 565 |
| 566 // Now that 10 push messages in a row have shown notifications, we should | 566 // Now that 10 push messages in a row have shown notifications, we should |
| 567 // allow the next one to mistakenly not show a notification. | 567 // allow the next one to mistakenly not show a notification. |
| 568 message.data["data"] = "testdata"; | 568 message.data["data"] = "testdata"; |
| 569 push_service()->OnMessage(app_id.app_id_guid, message); | 569 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 570 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 570 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 571 EXPECT_EQ("testdata", script_result); | 571 EXPECT_EQ("testdata", script_result); |
| 572 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 572 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 573 } | 573 } |
| 574 #endif | 574 #endif |
| 575 | 575 |
| 576 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { | 576 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { |
| 577 std::string script_result; | 577 std::string script_result; |
| 578 | 578 |
| 579 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 579 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 | 649 |
| 650 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 650 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
| 651 | 651 |
| 652 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 652 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
| 653 EXPECT_EQ("unregister error: " | 653 EXPECT_EQ("unregister error: " |
| 654 "UnknownError: Unexpected error while trying to unregister from the" | 654 "UnknownError: Unexpected error while trying to unregister from the" |
| 655 " push server.", script_result); | 655 " push server.", script_result); |
| 656 } | 656 } |
| 657 | 657 |
| 658 } // namespace gcm | 658 } // namespace gcm |
| OLD | NEW |