Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_service_test_with_install.h" | 5 #include "chrome/browser/extensions/extension_service_test_with_install.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
| 10 #include "chrome/browser/extensions/extension_creator.h" | 10 #include "chrome/browser/extensions/extension_creator.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 pem_output_path, | 94 pem_output_path, |
| 95 ExtensionCreator::kOverwriteCRX)); | 95 ExtensionCreator::kOverwriteCRX)); |
| 96 | 96 |
| 97 ASSERT_TRUE(base::PathExists(crx_path)); | 97 ASSERT_TRUE(base::PathExists(crx_path)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( | 100 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( |
| 101 const base::FilePath& dir_path, | 101 const base::FilePath& dir_path, |
| 102 const base::FilePath& pem_path, | 102 const base::FilePath& pem_path, |
| 103 InstallState install_state, | 103 InstallState install_state, |
| 104 int creation_flags) { | 104 int creation_flags, |
| 105 Manifest::Location install_location) { | |
| 105 base::FilePath crx_path; | 106 base::FilePath crx_path; |
| 106 base::ScopedTempDir temp_dir; | 107 base::ScopedTempDir temp_dir; |
| 107 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 108 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 108 crx_path = temp_dir.GetPath().AppendASCII("temp.crx"); | 109 crx_path = temp_dir.GetPath().AppendASCII("temp.crx"); |
| 110 PackCRX(dir_path, pem_path, crx_path); | |
| 109 | 111 |
| 110 PackCRX(dir_path, pem_path, crx_path); | 112 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service())); |
| 111 return InstallCRX(crx_path, install_state, creation_flags); | 113 installer->set_install_source(install_location); |
| 114 | |
| 115 content::WindowedNotificationObserver observer( | |
| 116 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | |
| 117 content::NotificationService::AllSources()); | |
| 118 installer->InstallCrx(crx_path); | |
|
catmullings
2016/10/12 18:58:58
This line replaces:
return InstallCRX(crx_path,
Devlin
2016/10/12 20:16:53
Instead, we should just be adding a new parameter
catmullings
2016/10/14 23:16:46
Done.
| |
| 119 observer.Wait(); | |
| 120 | |
| 121 return VerifyCrxInstall(crx_path, install_state); | |
| 112 } | 122 } |
| 113 | 123 |
| 114 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( | 124 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( |
| 115 const base::FilePath& dir_path, | 125 const base::FilePath& dir_path, |
| 116 const base::FilePath& pem_path, | 126 const base::FilePath& pem_path, |
| 117 InstallState install_state) { | 127 InstallState install_state) { |
| 118 return PackAndInstallCRX(dir_path, pem_path, install_state, | 128 return PackAndInstallCRX(dir_path, pem_path, install_state, |
| 119 Extension::NO_FLAGS); | 129 Extension::NO_FLAGS, Manifest::Location::INTERNAL); |
|
catmullings
2016/10/12 18:58:58
What is the default for Manifest::Location among t
Devlin
2016/10/12 20:16:53
INTERNAL is the default value (you can see it in C
catmullings
2016/10/14 23:16:46
Done.
catmullings
2016/10/14 23:16:46
In addressing your other CL comment above, refacto
| |
| 120 } | 130 } |
| 121 | 131 |
| 122 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( | 132 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( |
| 123 const base::FilePath& dir_path, | 133 const base::FilePath& dir_path, |
| 124 InstallState install_state) { | 134 InstallState install_state) { |
| 125 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, | 135 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, |
| 126 Extension::NO_FLAGS); | 136 Extension::NO_FLAGS, Manifest::Location::INTERNAL); |
| 137 } | |
| 138 | |
| 139 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( | |
| 140 const base::FilePath& dir_path, | |
| 141 Manifest::Location install_location, | |
| 142 InstallState install_state) { | |
| 143 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, | |
| 144 Extension::NO_FLAGS, install_location); | |
| 127 } | 145 } |
| 128 | 146 |
| 129 // Attempts to install an extension. Use INSTALL_FAILED if the installation | 147 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 130 // is expected to fail. | 148 // is expected to fail. |
| 131 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is | 149 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 132 // non-empty, expects that the existing extension's title was | 150 // non-empty, expects that the existing extension's title was |
| 133 // |expected_old_name|. | 151 // |expected_old_name|. |
| 134 const Extension* ExtensionServiceTestWithInstall::InstallCRX( | 152 const Extension* ExtensionServiceTestWithInstall::InstallCRX( |
| 135 const base::FilePath& path, | 153 const base::FilePath& path, |
| 136 InstallState install_state, | 154 InstallState install_state, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 const std::string& id, | 341 const std::string& id, |
| 324 bool use_helper, | 342 bool use_helper, |
| 325 Extension::State expected_state) { | 343 Extension::State expected_state) { |
| 326 // Verify that the extension is installed. | 344 // Verify that the extension is installed. |
| 327 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); | 345 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); |
| 328 EXPECT_TRUE(base::PathExists(extension_path)); | 346 EXPECT_TRUE(base::PathExists(extension_path)); |
| 329 size_t pref_key_count = GetPrefKeyCount(); | 347 size_t pref_key_count = GetPrefKeyCount(); |
| 330 EXPECT_GT(pref_key_count, 0u); | 348 EXPECT_GT(pref_key_count, 0u); |
| 331 ValidateIntegerPref(id, "state", expected_state); | 349 ValidateIntegerPref(id, "state", expected_state); |
| 332 | 350 |
| 351 // We make a copy of the extension's id since the extension can be deleted | |
| 352 // once it's uninstalled. | |
| 353 std::string extension_id = id; | |
| 333 // Uninstall it. | 354 // Uninstall it. |
| 334 if (use_helper) { | 355 if (use_helper) { |
| 335 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( | 356 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( |
| 336 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); | 357 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); |
| 337 } else { | 358 } else { |
| 338 EXPECT_TRUE(service()->UninstallExtension( | 359 EXPECT_TRUE(service()->UninstallExtension( |
| 339 id, extensions::UNINSTALL_REASON_FOR_TESTING, | 360 id, extensions::UNINSTALL_REASON_FOR_TESTING, |
| 340 base::Bind(&base::DoNothing), nullptr)); | 361 base::Bind(&base::DoNothing), nullptr)); |
| 341 } | 362 } |
| 342 --expected_extensions_count_; | 363 --expected_extensions_count_; |
| 343 | 364 |
| 344 // We should get an unload notification. | 365 // We should get an unload notification. |
| 345 EXPECT_FALSE(unloaded_id_.empty()); | 366 EXPECT_FALSE(unloaded_id_.empty()); |
| 346 EXPECT_EQ(id, unloaded_id_); | 367 EXPECT_EQ(extension_id, unloaded_id_); |
| 347 | 368 |
| 348 // Verify uninstalled state. | 369 // Verify uninstalled state. |
| 349 size_t new_pref_key_count = GetPrefKeyCount(); | 370 size_t new_pref_key_count = GetPrefKeyCount(); |
| 350 if (new_pref_key_count == pref_key_count) { | 371 if (new_pref_key_count == pref_key_count) { |
| 351 ValidateIntegerPref(id, "state", | 372 ValidateIntegerPref(id, "state", |
| 352 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 373 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 353 } else { | 374 } else { |
| 354 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); | 375 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); |
| 355 } | 376 } |
| 356 | 377 |
| 357 // The extension should not be in the service anymore. | 378 // The extension should not be in the service anymore. |
| 358 EXPECT_FALSE(service()->GetInstalledExtension(id)); | 379 EXPECT_FALSE(service()->GetInstalledExtension(extension_id)); |
| 359 base::RunLoop().RunUntilIdle(); | 380 base::RunLoop().RunUntilIdle(); |
| 360 | 381 |
| 361 // The directory should be gone. | 382 // The directory should be gone. |
| 362 EXPECT_FALSE(base::PathExists(extension_path)); | 383 EXPECT_FALSE(base::PathExists(extension_path)); |
| 363 } | 384 } |
| 364 | 385 |
| 365 void ExtensionServiceTestWithInstall::TerminateExtension( | 386 void ExtensionServiceTestWithInstall::TerminateExtension( |
| 366 const std::string& id) { | 387 const std::string& id) { |
| 367 const Extension* extension = service()->GetInstalledExtension(id); | 388 const Extension* extension = service()->GetInstalledExtension(id); |
| 368 if (!extension) { | 389 if (!extension) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 content::WindowedNotificationObserver observer( | 444 content::WindowedNotificationObserver observer( |
| 424 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 445 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 425 content::Source<extensions::CrxInstaller>(installer.get())); | 446 content::Source<extensions::CrxInstaller>(installer.get())); |
| 426 | 447 |
| 427 installer->InstallCrx(crx_path); | 448 installer->InstallCrx(crx_path); |
| 428 | 449 |
| 429 observer.Wait(); | 450 observer.Wait(); |
| 430 } | 451 } |
| 431 | 452 |
| 432 } // namespace extensions | 453 } // namespace extensions |
| OLD | NEW |