Chromium Code Reviews| Index: chrome/browser/extensions/extension_browsertest.cc |
| diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc |
| index 6f29447014552125c8fdd211806e1b20f85de69d..d6b4968903fac196c64653bdb7f779586cf76b45 100644 |
| --- a/chrome/browser/extensions/extension_browsertest.cc |
| +++ b/chrome/browser/extensions/extension_browsertest.cc |
| @@ -8,10 +8,12 @@ |
| #include "base/command_line.h" |
| #include "base/file_path.h" |
| +#include "base/file_util.h" |
| #include "base/path_service.h" |
| #include "base/string_number_conversions.h" |
| #include "chrome/browser/browser_window.h" |
| #include "chrome/browser/extensions/crx_installer.h" |
| +#include "chrome/browser/extensions/extension_creator.h" |
| #include "chrome/browser/extensions/extension_error_reporter.h" |
| #include "chrome/browser/extensions/extension_host.h" |
| #include "chrome/browser/extensions/extension_install_ui.h" |
| @@ -101,6 +103,24 @@ bool ExtensionBrowserTest::LoadExtensionIncognito(const FilePath& path) { |
| return LoadExtensionImpl(path, true); |
| } |
| +void ExtensionBrowserTest::PackExtension(const FilePath& dir_path, |
| + FilePath* crx_path) { |
| + // Init paths to output files and ensure files do not already exist. |
| + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, crx_path)); |
| + *crx_path = crx_path->AppendASCII("temp.crx"); |
| + ASSERT_TRUE(file_util::Delete(*crx_path, false)); |
|
Aaron Boodman
2010/12/15 22:29:18
You should double-check that this returns true in
Tessa MacDuff
2010/12/16 00:08:04
Done.
There is even a test that checks this: http
|
| + FilePath pem_path = crx_path->DirName().AppendASCII("temp.pem"); |
| + ASSERT_TRUE(file_util::Delete(pem_path, false)); |
| + |
| + scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| + ASSERT_TRUE(creator->Run(dir_path, |
| + *crx_path, |
| + FilePath(), // no existing pem, use empty path |
| + pem_path)); |
| + |
| + ASSERT_TRUE(file_util::PathExists(*crx_path)); |
| +} |
| + |
| // This class is used to simulate an installation abort by the user. |
| class MockAbortExtensionInstallUI : public ExtensionInstallUI { |
| public: |
| @@ -120,11 +140,31 @@ class MockAbortExtensionInstallUI : public ExtensionInstallUI { |
| virtual void OnInstallFailure(const std::string& error) {} |
| }; |
| +class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI { |
| + public: |
| + MockAutoConfirmExtensionInstallUI(Profile* profile) : |
| + ExtensionInstallUI(profile) {} |
| + |
| + // Proceed without confirmation prompt. |
| + virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
| + delegate->InstallUIProceed(); |
| + } |
| +}; |
| + |
| bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, |
| const FilePath& path, |
| InstallUIType ui_type, |
| int expected_change) { |
| - ExtensionService* service = browser()->profile()->GetExtensionService(); |
| + return InstallOrUpdateExtension(id, path, ui_type, expected_change, |
| + browser()->profile()); |
| +} |
| + |
| +bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, |
| + const FilePath& path, |
| + InstallUIType ui_type, |
| + int expected_change, |
| + Profile* profile) { |
| + ExtensionService* service = profile->GetExtensionService(); |
| service->set_show_extensions_prompts(false); |
| size_t num_before = service->extensions()->size(); |
| @@ -141,12 +181,20 @@ bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, |
| if (ui_type == INSTALL_UI_TYPE_CANCEL) |
| install_ui = new MockAbortExtensionInstallUI(); |
| else if (ui_type == INSTALL_UI_TYPE_NORMAL) |
| - install_ui = new ExtensionInstallUI(browser()->profile()); |
| + install_ui = new ExtensionInstallUI(profile); |
| + else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) |
| + install_ui = new MockAutoConfirmExtensionInstallUI(profile); |
| + FilePath crx_path; |
| + if (path.Extension() == FILE_PATH_LITERAL(".crx")) { |
|
Aaron Boodman
2010/12/15 22:29:18
Can you fix all the callers so that we don't need
Tessa MacDuff
2010/12/16 00:08:04
Do you mind if I do it in a separate CL? I'll lea
Aaron Boodman
2011/01/14 20:58:43
No that is fine.
|
| + crx_path = path; |
| + } else { |
| + PackExtension(path, &crx_path); |
| + } |
| scoped_refptr<CrxInstaller> installer( |
| new CrxInstaller(service, install_ui)); |
| installer->set_expected_id(id); |
| - installer->InstallCrx(path); |
| + installer->InstallCrx(crx_path); |
| ui_test_utils::RunMessageLoop(); |
| } |