Chromium Code Reviews| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 const gcm::GCMClient::IncomingMessage& message) override {} | 141 const gcm::GCMClient::IncomingMessage& message) override {} |
| 142 | 142 |
| 143 void OnMessagesDeleted(const std::string& app_id) override {} | 143 void OnMessagesDeleted(const std::string& app_id) override {} |
| 144 | 144 |
| 145 void OnSendError( | 145 void OnSendError( |
| 146 const std::string& app_id, | 146 const std::string& app_id, |
| 147 const gcm::GCMClient::SendErrorDetails& send_error_details) override {} | 147 const gcm::GCMClient::SendErrorDetails& send_error_details) override {} |
| 148 | 148 |
| 149 void OnUnregisterCompleted(const std::string& app_id, | 149 void OnUnregisterCompleted(const std::string& app_id, |
| 150 gcm::GCMClient::Result result) override { | 150 gcm::GCMClient::Result result) override { |
| 151 ExtensionGCMAppHandler::OnUnregisterCompleted(app_id,result); | |
|
fgorski
2015/02/10 23:10:01
nit: space after a comma. (run git cl format)
| |
| 151 unregistration_result_ = result; | 152 unregistration_result_ = result; |
| 152 waiter_->SignalCompleted(); | 153 waiter_->SignalCompleted(); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void RemoveAppHandler(const std::string& app_id) override { | 156 void RemoveAppHandler(const std::string& app_id) override { |
| 156 ExtensionGCMAppHandler::RemoveAppHandler(app_id); | 157 ExtensionGCMAppHandler::RemoveAppHandler(app_id); |
| 157 if (!GetGCMDriver()->app_handlers().size()) | 158 if (!GetGCMDriver()->app_handlers().size()) |
| 158 app_handler_count_drop_to_zero_ = true; | 159 app_handler_count_drop_to_zero_ = true; |
| 159 } | 160 } |
| 160 | 161 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 scoped_refptr<Extension> extension(CreateExtension()); | 411 scoped_refptr<Extension> extension(CreateExtension()); |
| 411 LoadExtension(extension.get()); | 412 LoadExtension(extension.get()); |
| 412 | 413 |
| 413 // Kick off registration. | 414 // Kick off registration. |
| 414 std::vector<std::string> sender_ids; | 415 std::vector<std::string> sender_ids; |
| 415 sender_ids.push_back("sender1"); | 416 sender_ids.push_back("sender1"); |
| 416 Register(extension->id(), sender_ids); | 417 Register(extension->id(), sender_ids); |
| 417 waiter()->WaitUntilCompleted(); | 418 waiter()->WaitUntilCompleted(); |
| 418 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); | 419 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); |
| 419 | 420 |
| 420 // Add another app handler in order to prevent the GCM service from being | |
| 421 // stopped when the extension is uninstalled. This is needed because otherwise | |
| 422 // we are not able to receive the unregistration result. | |
| 423 GetGCMDriver()->AddAppHandler("Foo", gcm_app_handler()); | |
| 424 | |
| 425 // Unregistration should be triggered when the extension is uninstalled. | 421 // Unregistration should be triggered when the extension is uninstalled. |
| 426 UninstallExtension(extension.get()); | 422 UninstallExtension(extension.get()); |
| 427 waiter()->WaitUntilCompleted(); | 423 waiter()->WaitUntilCompleted(); |
| 428 EXPECT_EQ(gcm::GCMClient::SUCCESS, | 424 EXPECT_EQ(gcm::GCMClient::SUCCESS, |
| 429 gcm_app_handler()->unregistration_result()); | 425 gcm_app_handler()->unregistration_result()); |
| 430 | |
| 431 // Clean up. | |
| 432 GetGCMDriver()->RemoveAppHandler("Foo"); | |
| 433 } | 426 } |
| 434 | 427 |
| 435 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) { | 428 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) { |
| 436 scoped_refptr<Extension> extension(CreateExtension()); | 429 scoped_refptr<Extension> extension(CreateExtension()); |
| 437 | 430 |
| 438 // App handler is added when the extension is loaded. | 431 // App handler is added when the extension is loaded. |
| 439 LoadExtension(extension.get()); | 432 LoadExtension(extension.get()); |
| 440 waiter()->PumpUILoop(); | 433 waiter()->PumpUILoop(); |
| 441 EXPECT_TRUE(HasAppHandlers(extension->id())); | 434 EXPECT_TRUE(HasAppHandlers(extension->id())); |
| 442 | 435 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 457 | 450 |
| 458 // App handler is removed when the extension is updated to the version that | 451 // App handler is removed when the extension is updated to the version that |
| 459 // has GCM permission removed. | 452 // has GCM permission removed. |
| 460 UpdateExtension(extension.get(), "good2.crx"); | 453 UpdateExtension(extension.get(), "good2.crx"); |
| 461 waiter()->PumpUILoop(); | 454 waiter()->PumpUILoop(); |
| 462 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 455 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
| 463 EXPECT_FALSE(HasAppHandlers(extension->id())); | 456 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 464 } | 457 } |
| 465 | 458 |
| 466 } // namespace extensions | 459 } // namespace extensions |
| OLD | NEW |