| 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 "chrome/browser/extensions/extension_gcm_app_handler.h" | 5 #include "chrome/browser/extensions/extension_gcm_app_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 gcm::GCMClient::Result registration_result_; | 404 gcm::GCMClient::Result registration_result_; |
| 405 gcm::GCMClient::Result unregistration_result_; | 405 gcm::GCMClient::Result unregistration_result_; |
| 406 | 406 |
| 407 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandlerTest); | 407 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandlerTest); |
| 408 }; | 408 }; |
| 409 | 409 |
| 410 TEST_F(ExtensionGCMAppHandlerTest, AddAndRemoveAppHandler) { | 410 TEST_F(ExtensionGCMAppHandlerTest, AddAndRemoveAppHandler) { |
| 411 scoped_refptr<Extension> extension(CreateExtension()); | 411 scoped_refptr<Extension> extension(CreateExtension()); |
| 412 | 412 |
| 413 // App handler is added when extension is loaded. | 413 // App handler is added when extension is loaded. |
| 414 LoadExtension(extension); | 414 LoadExtension(extension.get()); |
| 415 waiter()->PumpUILoop(); | 415 waiter()->PumpUILoop(); |
| 416 EXPECT_TRUE(HasAppHandlers(extension->id())); | 416 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 417 | 417 |
| 418 // App handler is removed when extension is unloaded. | 418 // App handler is removed when extension is unloaded. |
| 419 DisableExtension(extension); | 419 DisableExtension(extension.get()); |
| 420 waiter()->PumpUILoop(); | 420 waiter()->PumpUILoop(); |
| 421 EXPECT_FALSE(HasAppHandlers(extension->id())); | 421 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 422 | 422 |
| 423 // App handler is added when extension is reloaded. | 423 // App handler is added when extension is reloaded. |
| 424 EnableExtension(extension); | 424 EnableExtension(extension.get()); |
| 425 waiter()->PumpUILoop(); | 425 waiter()->PumpUILoop(); |
| 426 EXPECT_TRUE(HasAppHandlers(extension->id())); | 426 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 427 | 427 |
| 428 // App handler is removed when extension is uninstalled. | 428 // App handler is removed when extension is uninstalled. |
| 429 UninstallExtension(extension); | 429 UninstallExtension(extension.get()); |
| 430 waiter()->PumpUILoop(); | 430 waiter()->PumpUILoop(); |
| 431 EXPECT_FALSE(HasAppHandlers(extension->id())); | 431 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 432 } | 432 } |
| 433 | 433 |
| 434 TEST_F(ExtensionGCMAppHandlerTest, UnregisterOnExtensionUninstall) { | 434 TEST_F(ExtensionGCMAppHandlerTest, UnregisterOnExtensionUninstall) { |
| 435 scoped_refptr<Extension> extension(CreateExtension()); | 435 scoped_refptr<Extension> extension(CreateExtension()); |
| 436 LoadExtension(extension); | 436 LoadExtension(extension.get()); |
| 437 | 437 |
| 438 // Sign-in is needed for registration. | 438 // Sign-in is needed for registration. |
| 439 SignIn(kTestingUsername); | 439 SignIn(kTestingUsername); |
| 440 | 440 |
| 441 // Kick off registration. | 441 // Kick off registration. |
| 442 std::vector<std::string> sender_ids; | 442 std::vector<std::string> sender_ids; |
| 443 sender_ids.push_back("sender1"); | 443 sender_ids.push_back("sender1"); |
| 444 Register(extension->id(), sender_ids); | 444 Register(extension->id(), sender_ids); |
| 445 waiter()->WaitUntilCompleted(); | 445 waiter()->WaitUntilCompleted(); |
| 446 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); | 446 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); |
| 447 | 447 |
| 448 // Add another app handler in order to prevent the GCM service from being | 448 // Add another app handler in order to prevent the GCM service from being |
| 449 // stopped when the extension is uninstalled. This is needed because otherwise | 449 // stopped when the extension is uninstalled. This is needed because otherwise |
| 450 // we are not able to receive the unregistration result. | 450 // we are not able to receive the unregistration result. |
| 451 GetGCMDriver()->AddAppHandler("Foo", gcm_app_handler()); | 451 GetGCMDriver()->AddAppHandler("Foo", gcm_app_handler()); |
| 452 | 452 |
| 453 // Unregistration should be triggered when the extension is uninstalled. | 453 // Unregistration should be triggered when the extension is uninstalled. |
| 454 UninstallExtension(extension); | 454 UninstallExtension(extension.get()); |
| 455 waiter()->WaitUntilCompleted(); | 455 waiter()->WaitUntilCompleted(); |
| 456 EXPECT_EQ(gcm::GCMClient::SUCCESS, | 456 EXPECT_EQ(gcm::GCMClient::SUCCESS, |
| 457 gcm_app_handler()->unregistration_result()); | 457 gcm_app_handler()->unregistration_result()); |
| 458 | 458 |
| 459 // Clean up. | 459 // Clean up. |
| 460 GetGCMDriver()->RemoveAppHandler("Foo"); | 460 GetGCMDriver()->RemoveAppHandler("Foo"); |
| 461 } | 461 } |
| 462 | 462 |
| 463 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) { | 463 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) { |
| 464 scoped_refptr<Extension> extension(CreateExtension()); | 464 scoped_refptr<Extension> extension(CreateExtension()); |
| 465 | 465 |
| 466 // App handler is added when the extension is loaded. | 466 // App handler is added when the extension is loaded. |
| 467 LoadExtension(extension); | 467 LoadExtension(extension.get()); |
| 468 waiter()->PumpUILoop(); | 468 waiter()->PumpUILoop(); |
| 469 EXPECT_TRUE(HasAppHandlers(extension->id())); | 469 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 470 | 470 |
| 471 // App handler count should not drop to zero when the extension is updated. | 471 // App handler count should not drop to zero when the extension is updated. |
| 472 UpdateExtension(extension, "gcm2.crx"); | 472 UpdateExtension(extension.get(), "gcm2.crx"); |
| 473 waiter()->PumpUILoop(); | 473 waiter()->PumpUILoop(); |
| 474 EXPECT_FALSE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 474 EXPECT_FALSE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
| 475 EXPECT_TRUE(HasAppHandlers(extension->id())); | 475 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 476 } | 476 } |
| 477 | 477 |
| 478 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionRemoved) { | 478 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionRemoved) { |
| 479 scoped_refptr<Extension> extension(CreateExtension()); | 479 scoped_refptr<Extension> extension(CreateExtension()); |
| 480 | 480 |
| 481 // App handler is added when the extension is loaded. | 481 // App handler is added when the extension is loaded. |
| 482 LoadExtension(extension); | 482 LoadExtension(extension.get()); |
| 483 waiter()->PumpUILoop(); | 483 waiter()->PumpUILoop(); |
| 484 EXPECT_TRUE(HasAppHandlers(extension->id())); | 484 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 485 | 485 |
| 486 // App handler is removed when the extension is updated to the version that | 486 // App handler is removed when the extension is updated to the version that |
| 487 // has GCM permission removed. | 487 // has GCM permission removed. |
| 488 UpdateExtension(extension, "good2.crx"); | 488 UpdateExtension(extension.get(), "good2.crx"); |
| 489 waiter()->PumpUILoop(); | 489 waiter()->PumpUILoop(); |
| 490 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 490 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
| 491 EXPECT_FALSE(HasAppHandlers(extension->id())); | 491 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 492 } | 492 } |
| 493 | 493 |
| 494 } // namespace extensions | 494 } // namespace extensions |
| OLD | NEW |