| Index: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
|
| index 43b9f205850b76bb16ff7f88fccd53292bb5c0af..b7d90d2bbe8c9bcbad8ca68c35c888ef20ce02c6 100644
|
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
|
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
|
| @@ -9,21 +9,32 @@
|
| #include "chrome/browser/extensions/extension_service_test_base.h"
|
| #include "chrome/browser/extensions/extension_util.h"
|
| #include "chrome/browser/extensions/test_extension_dir.h"
|
| +#include "chrome/browser/extensions/test_extension_system.h"
|
| #include "chrome/browser/extensions/unpacked_installer.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/host_desktop.h"
|
| #include "chrome/common/extensions/api/developer_private.h"
|
| #include "chrome/test/base/test_browser_window.h"
|
| +#include "content/public/test/test_web_contents_factory.h"
|
| #include "extensions/browser/extension_prefs.h"
|
| #include "extensions/browser/extension_registry.h"
|
| #include "extensions/browser/extension_system.h"
|
| #include "extensions/browser/test_extension_registry_observer.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_set.h"
|
| +#include "extensions/common/manifest_constants.h"
|
| #include "extensions/common/test_util.h"
|
|
|
| namespace extensions {
|
|
|
| +namespace {
|
| +
|
| +KeyedService* BuildAPI(content::BrowserContext* context) {
|
| + return new DeveloperPrivateAPI(context);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase {
|
| protected:
|
| DeveloperPrivateApiUnitTest() {}
|
| @@ -180,6 +191,13 @@ void DeveloperPrivateApiUnitTest::SetUp() {
|
| params.type = Browser::TYPE_TABBED;
|
| params.window = browser_window_.get();
|
| browser_.reset(new Browser(params));
|
| +
|
| + // Allow the API to be created.
|
| + static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))->
|
| + SetEventRouter(make_scoped_ptr(
|
| + new EventRouter(profile(), ExtensionPrefs::Get(profile()))));
|
| + DeveloperPrivateAPI::GetFactoryInstance()->SetTestingFactory(
|
| + profile(), &BuildAPI);
|
| }
|
|
|
| void DeveloperPrivateApiUnitTest::TearDown() {
|
| @@ -264,4 +282,94 @@ TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivatePackFunction) {
|
| base::DeleteFile(pem_path, false);
|
| }
|
|
|
| +// Test developerPrivate.choosePath.
|
| +TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateChoosePath) {
|
| + ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT);
|
| + content::TestWebContentsFactory web_contents_factory;
|
| + content::WebContents* web_contents =
|
| + web_contents_factory.CreateWebContents(profile());
|
| +
|
| + base::FilePath expected_dir_path = data_dir().AppendASCII("good_unpacked");
|
| + api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&expected_dir_path);
|
| +
|
| + // Try selecting a directory.
|
| + base::ListValue choose_args;
|
| + choose_args.AppendString("FOLDER");
|
| + choose_args.AppendString("LOAD");
|
| + scoped_refptr<UIThreadExtensionFunction> function(
|
| + new api::DeveloperPrivateChoosePathFunction());
|
| + function->SetRenderViewHost(web_contents->GetRenderViewHost());
|
| + EXPECT_TRUE(RunFunction(function, choose_args)) << function->GetError();
|
| + std::string path;
|
| + EXPECT_TRUE(function->GetResultList() &&
|
| + function->GetResultList()->GetString(0, &path));
|
| + EXPECT_EQ(path, expected_dir_path.AsUTF8Unsafe());
|
| +
|
| + // Try selecting a pem file.
|
| + base::FilePath expected_file_path =
|
| + data_dir().AppendASCII("good_unpacked.pem");
|
| + api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&expected_file_path);
|
| + choose_args.Clear();
|
| + choose_args.AppendString("FILE");
|
| + choose_args.AppendString("PEM");
|
| + function = new api::DeveloperPrivateChoosePathFunction();
|
| + function->SetRenderViewHost(web_contents->GetRenderViewHost());
|
| + EXPECT_TRUE(RunFunction(function, choose_args)) << function->GetError();
|
| + EXPECT_TRUE(function->GetResultList() &&
|
| + function->GetResultList()->GetString(0, &path));
|
| + EXPECT_EQ(path, expected_file_path.AsUTF8Unsafe());
|
| +
|
| + // Try canceling the file dialog.
|
| + api::EntryPicker::SkipPickerAndAlwaysCancelForTest();
|
| + function = new api::DeveloperPrivateChoosePathFunction();
|
| + function->SetRenderViewHost(web_contents->GetRenderViewHost());
|
| + EXPECT_FALSE(RunFunction(function, choose_args));
|
| + EXPECT_EQ(std::string("File selection was canceled."), function->GetError());
|
| +}
|
| +
|
| +// Test developerPrivate.loadUnpacked.
|
| +TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateLoadUnpacked) {
|
| + ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT);
|
| + content::TestWebContentsFactory web_contents_factory;
|
| + content::WebContents* web_contents =
|
| + web_contents_factory.CreateWebContents(profile());
|
| +
|
| + base::FilePath path = data_dir().AppendASCII("good_unpacked");
|
| + api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path);
|
| +
|
| + // Try loading a good extension (it should succeed, and the extension should
|
| + // be added).
|
| + scoped_refptr<UIThreadExtensionFunction> function(
|
| + new api::DeveloperPrivateLoadUnpackedFunction());
|
| + function->SetRenderViewHost(web_contents->GetRenderViewHost());
|
| + ExtensionIdSet current_ids = registry()->enabled_extensions().GetIDs();
|
| + EXPECT_TRUE(RunFunction(function, base::ListValue())) << function->GetError();
|
| + // We should have added one new extension.
|
| + ExtensionIdSet id_difference = base::STLSetDifference<ExtensionIdSet>(
|
| + registry()->enabled_extensions().GetIDs(), current_ids);
|
| + ASSERT_EQ(1u, id_difference.size());
|
| + // The new extension should have the same path.
|
| + EXPECT_EQ(
|
| + path,
|
| + registry()->enabled_extensions().GetByID(*id_difference.begin())->path());
|
| +
|
| + path = data_dir().AppendASCII("empty_manifest");
|
| + api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path);
|
| +
|
| + // Try loading a bad extension (it should fail, and we should get an error).
|
| + function = new api::DeveloperPrivateLoadUnpackedFunction();
|
| + function->SetRenderViewHost(web_contents->GetRenderViewHost());
|
| + base::ListValue unpacked_args;
|
| + scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue());
|
| + options->SetBoolean("failQuietly", true);
|
| + unpacked_args.Append(options.release());
|
| + current_ids = registry()->enabled_extensions().GetIDs();
|
| + EXPECT_FALSE(RunFunction(function, unpacked_args));
|
| + EXPECT_EQ(manifest_errors::kManifestUnreadable, function->GetError());
|
| + // We should have no new extensions installed.
|
| + EXPECT_EQ(0u, base::STLSetDifference<ExtensionIdSet>(
|
| + registry()->enabled_extensions().GetIDs(),
|
| + current_ids).size());
|
| +}
|
| +
|
| } // namespace extensions
|
|
|