OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" |
| 12 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" |
| 15 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/feature_switch.h" |
| 17 |
| 18 namespace extensions { |
| 19 |
| 20 // An enhancement of ExtensionServiceTestBase that provides helpers to install, |
| 21 // update, and uninstall extensions. |
| 22 class ExtensionServiceTestWithInstall : public ExtensionServiceTestBase, |
| 23 public content::NotificationObserver { |
| 24 public: |
| 25 ExtensionServiceTestWithInstall(); |
| 26 ~ExtensionServiceTestWithInstall() override; |
| 27 |
| 28 protected: |
| 29 static std::vector<base::string16> GetErrors(); |
| 30 |
| 31 void PackCRX(const base::FilePath& dir_path, |
| 32 const base::FilePath& pem_path, |
| 33 const base::FilePath& crx_path); |
| 34 |
| 35 enum InstallState { |
| 36 INSTALL_FAILED, |
| 37 INSTALL_UPDATED, |
| 38 INSTALL_NEW, |
| 39 INSTALL_WITHOUT_LOAD, |
| 40 }; |
| 41 |
| 42 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 43 const base::FilePath& pem_path, |
| 44 InstallState install_state, |
| 45 int creation_flags); |
| 46 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 47 const base::FilePath& pem_path, |
| 48 InstallState install_state); |
| 49 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 50 InstallState install_state); |
| 51 |
| 52 const Extension* InstallCRX(const base::FilePath& path, |
| 53 InstallState install_state, |
| 54 int creation_flags, |
| 55 const std::string& expected_old_name); |
| 56 const Extension* InstallCRX(const base::FilePath& path, |
| 57 InstallState install_state, |
| 58 int creation_flags); |
| 59 const Extension* InstallCRX(const base::FilePath& path, |
| 60 InstallState install_state); |
| 61 const Extension* InstallCRXFromWebStore(const base::FilePath& path, |
| 62 InstallState install_state); |
| 63 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, |
| 64 Manifest::Location install_location, |
| 65 InstallState install_state); |
| 66 |
| 67 // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
| 68 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 69 // Returns an Extension pointer if the install succeeded, null otherwise. |
| 70 const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 71 InstallState install_state); |
| 72 |
| 73 // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
| 74 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 75 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 76 // non-empty, expects that the existing extension's title was |
| 77 // |expected_old_name|. |
| 78 // Returns an Extension pointer if the install succeeded, null otherwise. |
| 79 const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 80 InstallState install_state, |
| 81 const std::string& expected_old_name); |
| 82 |
| 83 enum UpdateState { |
| 84 FAILED_SILENTLY, |
| 85 FAILED, |
| 86 UPDATED, |
| 87 INSTALLED, |
| 88 DISABLED, |
| 89 ENABLED |
| 90 }; |
| 91 |
| 92 void PackCRXAndUpdateExtension(const std::string& id, |
| 93 const base::FilePath& dir_path, |
| 94 const base::FilePath& pem_path, |
| 95 UpdateState expected_state); |
| 96 |
| 97 void UpdateExtension(const std::string& id, |
| 98 const base::FilePath& in_path, |
| 99 UpdateState expected_state); |
| 100 |
| 101 void UninstallExtension(const std::string& id, bool use_helper); |
| 102 void UninstallExtension(const std::string& id, |
| 103 bool use_helper, |
| 104 Extension::State expected_state); |
| 105 |
| 106 void TerminateExtension(const std::string& id); |
| 107 |
| 108 // TODO(treib,devlin): Make these private and add accessors as needed. |
| 109 extensions::ExtensionList loaded_; |
| 110 const Extension* installed_; |
| 111 bool was_update_; |
| 112 std::string old_name_; |
| 113 std::string unloaded_id_; |
| 114 UnloadedExtensionInfo::Reason unloaded_reason_; |
| 115 |
| 116 private: |
| 117 void Observe(int type, |
| 118 const content::NotificationSource& source, |
| 119 const content::NotificationDetails& details) override; |
| 120 |
| 121 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags); |
| 122 |
| 123 content::NotificationRegistrar registrar_; |
| 124 size_t expected_extensions_count_; |
| 125 |
| 126 FeatureSwitch::ScopedOverride override_external_install_prompt_; |
| 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(ExtensionServiceTestWithInstall); |
| 129 }; |
| 130 |
| 131 } // namespace extensions |
| 132 |
| 133 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ |
OLD | NEW |