| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 waiter_(waiter), | 138 waiter_(waiter), |
| 139 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR), | 139 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR), |
| 140 app_handler_count_drop_to_zero_(false) { | 140 app_handler_count_drop_to_zero_(false) { |
| 141 } | 141 } |
| 142 | 142 |
| 143 virtual ~FakeExtensionGCMAppHandler() { | 143 virtual ~FakeExtensionGCMAppHandler() { |
| 144 } | 144 } |
| 145 | 145 |
| 146 virtual void OnMessage( | 146 virtual void OnMessage( |
| 147 const std::string& app_id, | 147 const std::string& app_id, |
| 148 const gcm::GCMClient::IncomingMessage& message) OVERRIDE { | 148 const gcm::GCMClient::IncomingMessage& message) override { |
| 149 } | 149 } |
| 150 | 150 |
| 151 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE { | 151 virtual void OnMessagesDeleted(const std::string& app_id) override { |
| 152 } | 152 } |
| 153 | 153 |
| 154 virtual void OnSendError( | 154 virtual void OnSendError( |
| 155 const std::string& app_id, | 155 const std::string& app_id, |
| 156 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE { | 156 const gcm::GCMClient::SendErrorDetails& send_error_details) override { |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual void OnUnregisterCompleted(const std::string& app_id, | 159 virtual void OnUnregisterCompleted(const std::string& app_id, |
| 160 gcm::GCMClient::Result result) OVERRIDE { | 160 gcm::GCMClient::Result result) override { |
| 161 unregistration_result_ = result; | 161 unregistration_result_ = result; |
| 162 waiter_->SignalCompleted(); | 162 waiter_->SignalCompleted(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE{ | 165 virtual void RemoveAppHandler(const std::string& app_id) override{ |
| 166 ExtensionGCMAppHandler::RemoveAppHandler(app_id); | 166 ExtensionGCMAppHandler::RemoveAppHandler(app_id); |
| 167 if (!GetGCMDriver()->app_handlers().size()) | 167 if (!GetGCMDriver()->app_handlers().size()) |
| 168 app_handler_count_drop_to_zero_ = true; | 168 app_handler_count_drop_to_zero_ = true; |
| 169 } | 169 } |
| 170 | 170 |
| 171 gcm::GCMClient::Result unregistration_result() const { | 171 gcm::GCMClient::Result unregistration_result() const { |
| 172 return unregistration_result_; | 172 return unregistration_result_; |
| 173 } | 173 } |
| 174 bool app_handler_count_drop_to_zero() const { | 174 bool app_handler_count_drop_to_zero() const { |
| 175 return app_handler_count_drop_to_zero_; | 175 return app_handler_count_drop_to_zero_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 200 ExtensionGCMAppHandlerTest() | 200 ExtensionGCMAppHandlerTest() |
| 201 : extension_service_(NULL), | 201 : extension_service_(NULL), |
| 202 registration_result_(gcm::GCMClient::UNKNOWN_ERROR), | 202 registration_result_(gcm::GCMClient::UNKNOWN_ERROR), |
| 203 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR) { | 203 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR) { |
| 204 } | 204 } |
| 205 | 205 |
| 206 virtual ~ExtensionGCMAppHandlerTest() { | 206 virtual ~ExtensionGCMAppHandlerTest() { |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Overridden from test::Test: | 209 // Overridden from test::Test: |
| 210 virtual void SetUp() OVERRIDE { | 210 virtual void SetUp() override { |
| 211 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 211 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 212 | 212 |
| 213 // Make BrowserThread work in unittest. | 213 // Make BrowserThread work in unittest. |
| 214 thread_bundle_.reset(new content::TestBrowserThreadBundle( | 214 thread_bundle_.reset(new content::TestBrowserThreadBundle( |
| 215 content::TestBrowserThreadBundle::REAL_IO_THREAD)); | 215 content::TestBrowserThreadBundle::REAL_IO_THREAD)); |
| 216 | 216 |
| 217 // Allow extension update to unpack crx in process. | 217 // Allow extension update to unpack crx in process. |
| 218 in_process_utility_thread_helper_.reset( | 218 in_process_utility_thread_helper_.reset( |
| 219 new content::InProcessUtilityThreadHelper); | 219 new content::InProcessUtilityThreadHelper); |
| 220 | 220 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 251 profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | 251 profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); |
| 252 | 252 |
| 253 // Create GCMProfileService that talks with fake GCMClient. | 253 // Create GCMProfileService that talks with fake GCMClient. |
| 254 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 254 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 255 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); | 255 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); |
| 256 | 256 |
| 257 // Create a fake version of ExtensionGCMAppHandler. | 257 // Create a fake version of ExtensionGCMAppHandler. |
| 258 gcm_app_handler_.reset(new FakeExtensionGCMAppHandler(profile(), &waiter_)); | 258 gcm_app_handler_.reset(new FakeExtensionGCMAppHandler(profile(), &waiter_)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 virtual void TearDown() OVERRIDE { | 261 virtual void TearDown() override { |
| 262 #if defined(OS_CHROMEOS) | 262 #if defined(OS_CHROMEOS) |
| 263 test_user_manager_.reset(); | 263 test_user_manager_.reset(); |
| 264 #endif | 264 #endif |
| 265 | 265 |
| 266 waiter_.PumpUILoop(); | 266 waiter_.PumpUILoop(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Returns a barebones test extension. | 269 // Returns a barebones test extension. |
| 270 scoped_refptr<Extension> CreateExtension() { | 270 scoped_refptr<Extension> CreateExtension() { |
| 271 base::DictionaryValue manifest; | 271 base::DictionaryValue manifest; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 // App handler is removed when the extension is updated to the version that | 491 // App handler is removed when the extension is updated to the version that |
| 492 // has GCM permission removed. | 492 // has GCM permission removed. |
| 493 UpdateExtension(extension.get(), "good2.crx"); | 493 UpdateExtension(extension.get(), "good2.crx"); |
| 494 waiter()->PumpUILoop(); | 494 waiter()->PumpUILoop(); |
| 495 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 495 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
| 496 EXPECT_FALSE(HasAppHandlers(extension->id())); | 496 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 497 } | 497 } |
| 498 | 498 |
| 499 } // namespace extensions | 499 } // namespace extensions |
| OLD | NEW |