| 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 <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 #endif | 252 #endif |
| 253 | 253 |
| 254 // Create a new profile. | 254 // Create a new profile. |
| 255 TestingProfile::Builder builder; | 255 TestingProfile::Builder builder; |
| 256 profile_ = builder.Build(); | 256 profile_ = builder.Build(); |
| 257 | 257 |
| 258 // Create extension service in order to uninstall the extension. | 258 // Create extension service in order to uninstall the extension. |
| 259 TestExtensionSystem* extension_system( | 259 TestExtensionSystem* extension_system( |
| 260 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))); | 260 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))); |
| 261 base::FilePath extensions_install_dir = | 261 base::FilePath extensions_install_dir = |
| 262 temp_dir_.path().Append(FILE_PATH_LITERAL("Extensions")); | 262 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Extensions")); |
| 263 extension_system->CreateExtensionService( | 263 extension_system->CreateExtensionService( |
| 264 base::CommandLine::ForCurrentProcess(), extensions_install_dir, false); | 264 base::CommandLine::ForCurrentProcess(), extensions_install_dir, false); |
| 265 extension_service_ = extension_system->Get(profile())->extension_service(); | 265 extension_service_ = extension_system->Get(profile())->extension_service(); |
| 266 extension_service_->set_extensions_enabled(true); | 266 extension_service_->set_extensions_enabled(true); |
| 267 extension_service_->set_show_extensions_prompts(false); | 267 extension_service_->set_show_extensions_prompts(false); |
| 268 | 268 |
| 269 // Create GCMProfileService that talks with fake GCMClient. | 269 // Create GCMProfileService that talks with fake GCMClient. |
| 270 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 270 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 271 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); | 271 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); |
| 272 | 272 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 scoped_refptr<Extension> CreateExtension() { | 286 scoped_refptr<Extension> CreateExtension() { |
| 287 base::DictionaryValue manifest; | 287 base::DictionaryValue manifest; |
| 288 manifest.SetString(manifest_keys::kVersion, "1.0.0.0"); | 288 manifest.SetString(manifest_keys::kVersion, "1.0.0.0"); |
| 289 manifest.SetString(manifest_keys::kName, kTestExtensionName); | 289 manifest.SetString(manifest_keys::kName, kTestExtensionName); |
| 290 base::ListValue* permission_list = new base::ListValue; | 290 base::ListValue* permission_list = new base::ListValue; |
| 291 permission_list->AppendString("gcm"); | 291 permission_list->AppendString("gcm"); |
| 292 manifest.Set(manifest_keys::kPermissions, permission_list); | 292 manifest.Set(manifest_keys::kPermissions, permission_list); |
| 293 | 293 |
| 294 std::string error; | 294 std::string error; |
| 295 scoped_refptr<Extension> extension = Extension::Create( | 295 scoped_refptr<Extension> extension = Extension::Create( |
| 296 temp_dir_.path(), | 296 temp_dir_.GetPath(), Manifest::UNPACKED, manifest, Extension::NO_FLAGS, |
| 297 Manifest::UNPACKED, | 297 "ldnnhddmnhbkjipkidpdiheffobcpfmf", &error); |
| 298 manifest, | |
| 299 Extension::NO_FLAGS, | |
| 300 "ldnnhddmnhbkjipkidpdiheffobcpfmf", | |
| 301 &error); | |
| 302 EXPECT_TRUE(extension.get()) << error; | 298 EXPECT_TRUE(extension.get()) << error; |
| 303 EXPECT_TRUE( | 299 EXPECT_TRUE( |
| 304 extension->permissions_data()->HasAPIPermission(APIPermission::kGcm)); | 300 extension->permissions_data()->HasAPIPermission(APIPermission::kGcm)); |
| 305 | 301 |
| 306 return extension; | 302 return extension; |
| 307 } | 303 } |
| 308 | 304 |
| 309 void LoadExtension(const Extension* extension) { | 305 void LoadExtension(const Extension* extension) { |
| 310 extension_service_->AddExtension(extension); | 306 extension_service_->AddExtension(extension); |
| 311 } | 307 } |
| 312 | 308 |
| 313 static bool IsCrxInstallerDone(extensions::CrxInstaller** installer, | 309 static bool IsCrxInstallerDone(extensions::CrxInstaller** installer, |
| 314 const content::NotificationSource& source, | 310 const content::NotificationSource& source, |
| 315 const content::NotificationDetails& details) { | 311 const content::NotificationDetails& details) { |
| 316 return content::Source<extensions::CrxInstaller>(source).ptr() == | 312 return content::Source<extensions::CrxInstaller>(source).ptr() == |
| 317 *installer; | 313 *installer; |
| 318 } | 314 } |
| 319 | 315 |
| 320 void UpdateExtension(const Extension* extension, | 316 void UpdateExtension(const Extension* extension, |
| 321 const std::string& update_crx) { | 317 const std::string& update_crx) { |
| 322 base::FilePath data_dir; | 318 base::FilePath data_dir; |
| 323 if (!PathService::Get(chrome::DIR_TEST_DATA, &data_dir)) { | 319 if (!PathService::Get(chrome::DIR_TEST_DATA, &data_dir)) { |
| 324 ADD_FAILURE(); | 320 ADD_FAILURE(); |
| 325 return; | 321 return; |
| 326 } | 322 } |
| 327 data_dir = data_dir.AppendASCII("extensions"); | 323 data_dir = data_dir.AppendASCII("extensions"); |
| 328 data_dir = data_dir.AppendASCII(update_crx); | 324 data_dir = data_dir.AppendASCII(update_crx); |
| 329 | 325 |
| 330 base::FilePath path = temp_dir_.path(); | 326 base::FilePath path = temp_dir_.GetPath(); |
| 331 path = path.Append(data_dir.BaseName()); | 327 path = path.Append(data_dir.BaseName()); |
| 332 ASSERT_TRUE(base::CopyFile(data_dir, path)); | 328 ASSERT_TRUE(base::CopyFile(data_dir, path)); |
| 333 | 329 |
| 334 extensions::CrxInstaller* installer = NULL; | 330 extensions::CrxInstaller* installer = NULL; |
| 335 content::WindowedNotificationObserver observer( | 331 content::WindowedNotificationObserver observer( |
| 336 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 332 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 337 base::Bind(&IsCrxInstallerDone, &installer)); | 333 base::Bind(&IsCrxInstallerDone, &installer)); |
| 338 extension_service_->UpdateExtension( | 334 extension_service_->UpdateExtension( |
| 339 extensions::CRXFileInfo(extension->id(), path), true, &installer); | 335 extensions::CRXFileInfo(extension->id(), path), true, &installer); |
| 340 | 336 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 483 |
| 488 // App handler is removed when the extension is updated to the version that | 484 // App handler is removed when the extension is updated to the version that |
| 489 // has GCM permission removed. | 485 // has GCM permission removed. |
| 490 UpdateExtension(extension.get(), "good2.crx"); | 486 UpdateExtension(extension.get(), "good2.crx"); |
| 491 waiter()->PumpUILoop(); | 487 waiter()->PumpUILoop(); |
| 492 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 488 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
| 493 EXPECT_FALSE(HasAppHandlers(extension->id())); | 489 EXPECT_FALSE(HasAppHandlers(extension->id())); |
| 494 } | 490 } |
| 495 | 491 |
| 496 } // namespace extensions | 492 } // namespace extensions |
| OLD | NEW |