diff options
author | tessamac@google.com <tessamac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 21:24:08 +0000 |
---|---|---|
committer | tessamac@google.com <tessamac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 21:24:08 +0000 |
commit | 59e0336042579bf25ee44ba1029ad469df7fa1bf (patch) | |
tree | 3f6edc0b7bc8b518284b9dac611245efe6cb0b4f | |
parent | 2df1b3656f9442f617966f733dbf66751aa85686 (diff) | |
download | chromium_src-59e0336042579bf25ee44ba1029ad469df7fa1bf.zip chromium_src-59e0336042579bf25ee44ba1029ad469df7fa1bf.tar.gz chromium_src-59e0336042579bf25ee44ba1029ad469df7fa1bf.tar.bz2 |
Tests for incognito app install, plus some cleanup.
BUG=62752
TEST=browser_tests
Review URL: http://codereview.chromium.org/5543001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72192 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 73 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.h | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui_browsertest.cc | 39 |
3 files changed, 124 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 8178848..fca41d9 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,40 @@ bool ExtensionBrowserTest::LoadExtensionIncognito(const FilePath& path) { return LoadExtensionImpl(path, true); } +FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) { + FilePath crx_path; + if (!PathService::Get(base::DIR_TEMP, &crx_path)) { + ADD_FAILURE() << "Failed to get DIR_TEMP from PathService."; + return FilePath(); + } + crx_path = crx_path.AppendASCII("temp.crx"); + if (!file_util::Delete(crx_path, false)) { + ADD_FAILURE() << "Failed to delete crx: " << crx_path.value(); + return FilePath(); + } + + FilePath pem_path = crx_path.DirName().AppendASCII("temp.pem"); + if (!file_util::Delete(pem_path, false)) { + ADD_FAILURE() << "Failed to delete pem: " << pem_path.value(); + return FilePath(); + } + + scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); + if (!creator->Run(dir_path, + crx_path, + FilePath(), // no existing pem, use empty path + pem_path)) { + ADD_FAILURE() << "ExtensionCreator::Run() failed."; + return FilePath(); + } + + if (!file_util::PathExists(crx_path)) { + ADD_FAILURE() << crx_path.value() << " was not created."; + return FilePath(); + } + return crx_path; +} + // This class is used to simulate an installation abort by the user. class MockAbortExtensionInstallUI : public ExtensionInstallUI { public: @@ -120,11 +156,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 +197,23 @@ 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); + + // TODO(tessamac): Update callers to always pass an unpacked extension + // and then always pack the extension here. + FilePath crx_path = path; + if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) { + crx_path = PackExtension(path); + } + if (crx_path.empty()) + return false; 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(); } diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h index 9b7f5f0..82d37f1 100644 --- a/chrome/browser/extensions/extension_browsertest.h +++ b/chrome/browser/extensions/extension_browsertest.h @@ -29,6 +29,10 @@ class ExtensionBrowserTest // Same as above, but enables the extension in incognito mode first. bool LoadExtensionIncognito(const FilePath& path); + // Pack the extension in |dir_path| into a crx file and return its path. + // Return an empty FilePath if there were errors. + FilePath PackExtension(const FilePath& dir_path); + // |expected_change| indicates how many extensions should be installed (or // disabled, if negative). // 1 means you expect a new install, 0 means you expect an upgrade, -1 means @@ -52,6 +56,12 @@ class ExtensionBrowserTest return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, expected_change); } + bool InstallExtensionWithUIAutoConfirm(const FilePath& path, + int expected_change, + Profile* profile) { + return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM, + expected_change, profile); + } // Begins install process but simulates a user cancel. bool StartInstallButCancel(const FilePath& path) { @@ -109,11 +119,16 @@ class ExtensionBrowserTest INSTALL_UI_TYPE_NONE, INSTALL_UI_TYPE_CANCEL, INSTALL_UI_TYPE_NORMAL, + INSTALL_UI_TYPE_AUTO_CONFIRM, }; bool InstallOrUpdateExtension(const std::string& id, const FilePath& path, InstallUIType ui_type, int expected_change); + bool InstallOrUpdateExtension(const std::string& id, const FilePath& path, + InstallUIType ui_type, + int expected_change, + Profile* profile); bool LoadExtensionImpl(const FilePath& path, bool incognito_enabled); bool WaitForExtensionHostsToLoad(); diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index 57c9bc8..a643be9 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/string_util.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" @@ -60,3 +61,41 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, VerifyThemeInfoBarAndUndoInstall(); ASSERT_EQ(NULL, browser()->profile()->GetTheme()); } + +IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, + AppInstallConfirmation) { + int num_tabs = browser()->tab_count(); + + FilePath app_dir = test_data_dir_.AppendASCII("app"); + ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1, + browser()->profile())); + + EXPECT_EQ(num_tabs + 1, browser()->tab_count()); + TabContents* tab_contents = browser()->GetSelectedTabContents(); + ASSERT_TRUE(tab_contents); + EXPECT_TRUE(StartsWithASCII(tab_contents->GetURL().spec(), + "chrome://newtab/#app-id=", // id changes + false)); +} + +IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, + AppInstallConfirmation_Incognito) { + Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); + Browser* incognito_browser = Browser::GetOrCreateTabbedBrowser( + incognito_profile); + + int num_incognito_tabs = incognito_browser->tab_count(); + int num_normal_tabs = browser()->tab_count(); + + FilePath app_dir = test_data_dir_.AppendASCII("app"); + ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1, + incognito_profile)); + + EXPECT_EQ(num_incognito_tabs, incognito_browser->tab_count()); + EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); + TabContents* tab_contents = browser()->GetSelectedTabContents(); + ASSERT_TRUE(tab_contents); + EXPECT_TRUE(StartsWithASCII(tab_contents->GetURL().spec(), + "chrome://newtab/#app-id=", // id changes + false)); +} |