Create extensions_test_support build target

* Create extensions/common/test_util.h for shared test code
* Consolidate duplicated CreateExtensionWithID() functions
* Create extensions_test_support build target because you can't have multiple
  files named test_util.h in a single build target on MSVS, all the other
  names are taken (test_utils.h, extension_test_util.h, etc.), and this gets
  us a step closer to having an extensions-only test suite.
* Fix some missing dependencies for the extensions_common target
* Remove unnecessary includes that create a dependency on themes

BUG=none
TEST=compiles, unit_tests
TBR=thakis@chromium.org for mechanical changes to chrome/browser/ui/cocoa/extensions/

Review URL: https://codereview.chromium.org/110463003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243382 0039d316-1c4b-4281-b951-d872f2087c98
parent af01a3b5
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h" #include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::NiceMock; using ::testing::NiceMock;
...@@ -27,7 +27,7 @@ class MediaGalleriesDialogBrowserTest : public InProcessBrowserTest { ...@@ -27,7 +27,7 @@ class MediaGalleriesDialogBrowserTest : public InProcessBrowserTest {
// the sheet. // the sheet.
IN_PROC_BROWSER_TEST_F(MediaGalleriesDialogBrowserTest, Close) { IN_PROC_BROWSER_TEST_F(MediaGalleriesDialogBrowserTest, Close) {
scoped_refptr<extensions::Extension> dummy_extension = scoped_refptr<extensions::Extension> dummy_extension =
extension_test_util::CreateExtensionWithID("dummy"); extensions::test_util::CreateExtensionWithID("dummy");
NiceMock<MediaGalleriesDialogControllerMock> controller(*dummy_extension); NiceMock<MediaGalleriesDialogControllerMock> controller(*dummy_extension);
content::WebContents* web_contents = content::WebContents* web_contents =
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.h" #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.h"
#include "chrome/browser/storage_monitor/storage_info.h" #include "chrome/browser/storage_monitor/storage_info.h"
#include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::_; using ::testing::_;
...@@ -32,7 +32,7 @@ class MediaGalleriesDialogTest : public testing::Test { ...@@ -32,7 +32,7 @@ class MediaGalleriesDialogTest : public testing::Test {
MediaGalleriesDialogTest() {} MediaGalleriesDialogTest() {}
virtual ~MediaGalleriesDialogTest() {} virtual ~MediaGalleriesDialogTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
dummy_extension_ = extension_test_util::CreateExtensionWithID("dummy"); dummy_extension_ = extensions::test_util::CreateExtensionWithID("dummy");
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
dummy_extension_ = NULL; dummy_extension_ = NULL;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.h" #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.h"
#include "chrome/browser/storage_monitor/storage_info.h" #include "chrome/browser/storage_monitor/storage_info.h"
#include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::_; using ::testing::_;
...@@ -35,7 +35,7 @@ class MediaGalleriesDialogTest : public testing::Test { ...@@ -35,7 +35,7 @@ class MediaGalleriesDialogTest : public testing::Test {
MediaGalleriesDialogTest() {} MediaGalleriesDialogTest() {}
virtual ~MediaGalleriesDialogTest() {} virtual ~MediaGalleriesDialogTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
dummy_extension_ = extension_test_util::CreateExtensionWithID("dummy"); dummy_extension_ = extensions::test_util::CreateExtensionWithID("dummy");
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
dummy_extension_ = NULL; dummy_extension_ = NULL;
......
...@@ -39,12 +39,6 @@ ...@@ -39,12 +39,6 @@
'..', '..',
], ],
'sources': [ 'sources': [
'../extensions/browser/test_management_policy.cc',
'../extensions/browser/test_management_policy.h',
'../extensions/common/extension_builder.cc',
'../extensions/common/extension_builder.h',
'../extensions/common/value_builder.cc',
'../extensions/common/value_builder.h',
'app/chrome_main_delegate.cc', 'app/chrome_main_delegate.cc',
'app/chrome_main_delegate.h', 'app/chrome_main_delegate.h',
'browser/android/bookmarks/partner_bookmarks_shim_unittest.cc', 'browser/android/bookmarks/partner_bookmarks_shim_unittest.cc',
...@@ -300,6 +294,7 @@ ...@@ -300,6 +294,7 @@
'../content/content.gyp:content_worker', '../content/content.gyp:content_worker',
'../components/components.gyp:autofill_core_test_support', '../components/components.gyp:autofill_core_test_support',
'../components/components.gyp:sessions_test_support', '../components/components.gyp:sessions_test_support',
'../extensions/extensions.gyp:extensions_test_support',
'../google_apis/google_apis.gyp:google_apis_test_support', '../google_apis/google_apis.gyp:google_apis_test_support',
'../ipc/ipc.gyp:test_support_ipc', '../ipc/ipc.gyp:test_support_ipc',
'../media/media.gyp:media_test_support', '../media/media.gyp:media_test_support',
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "chrome/common/extensions/features/api_feature.h" #include "chrome/common/extensions/features/api_feature.h"
#include "chrome/common/extensions/features/base_feature_provider.h" #include "chrome/common/extensions/features/base_feature_provider.h"
#include "chrome/common/extensions/features/simple_feature.h" #include "chrome/common/extensions/features/simple_feature.h"
...@@ -25,12 +24,13 @@ ...@@ -25,12 +24,13 @@
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "extensions/common/manifest.h" #include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "extensions/common/test_util.h"
#include "extensions/common/value_builder.h" #include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace extensions { namespace extensions {
using extension_test_util::BuildExtension; using test_util::BuildExtension;
SimpleFeature* CreateAPIFeature() { SimpleFeature* CreateAPIFeature() {
return new APIFeature(); return new APIFeature();
......
...@@ -10,49 +10,14 @@ ...@@ -10,49 +10,14 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using extensions::DictionaryBuilder;
using extensions::Extension; using extensions::Extension;
using extensions::ExtensionBuilder;
using extensions::ListBuilder;
using extensions::Manifest; using extensions::Manifest;
namespace extensions {
namespace extension_test_util { namespace extension_test_util {
ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) {
return builder
.SetManifest(DictionaryBuilder()
.Set("name", "Test extension")
.Set("version", "1.0")
.Set("manifest_version", 2));
}
ExtensionBuilder& BuildExtensionWithPermissions(ExtensionBuilder& builder,
ListBuilder& permissions) {
return
BuildExtension(builder)
.MergeManifest(
DictionaryBuilder().Set("permissions", permissions));
}
} // namespace extension_test_util
} // namespace extensions
namespace extension_test_util {
scoped_refptr<Extension> CreateExtensionWithID(std::string id) {
base::DictionaryValue values;
values.SetString(extensions::manifest_keys::kName, "test");
values.SetString(extensions::manifest_keys::kVersion, "0.1");
std::string error;
return Extension::Create(base::FilePath(), extensions::Manifest::INTERNAL,
values, Extension::NO_FLAGS, id, &error);
}
scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir, scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
const std::string& test_file, const std::string& test_file,
Manifest::Location location, Manifest::Location location,
......
...@@ -8,28 +8,15 @@ ...@@ -8,28 +8,15 @@
#include <string> #include <string>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/manifest.h" #include "extensions/common/manifest.h"
namespace extensions { namespace extensions {
class Extension; class Extension;
}
// Newer functions go here. // Newer functions go in extensions/common/test_util.h.
// TODO(mpcomplete): migrate older functions over.
namespace extension_test_util { namespace extension_test_util {
ExtensionBuilder& BuildExtension(ExtensionBuilder& builder);
ExtensionBuilder& BuildExtensionWithPermissions(ExtensionBuilder& builder,
ListBuilder& permissions);
} // namespace extension_test_util
} // namespace extensions
namespace extension_test_util {
// Return a very simple extension with id |id|.
scoped_refptr<extensions::Extension> CreateExtensionWithID(std::string id);
// Helpers for loading manifests, |dir| is relative to chrome::DIR_TEST_DATA // Helpers for loading manifests, |dir| is relative to chrome::DIR_TEST_DATA
// followed by "extensions". // followed by "extensions".
scoped_refptr<extensions::Extension> LoadManifestUnchecked( scoped_refptr<extensions::Extension> LoadManifestUnchecked(
......
...@@ -6,34 +6,22 @@ ...@@ -6,34 +6,22 @@
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/values.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/test_util.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace extensions { namespace extensions {
namespace { namespace {
// Creates a very simple extension.
scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
return ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "Echo").Set("version", "1.0"))
.SetID(id)
.Build();
}
typedef testing::Test ExtensionRegistryTest; typedef testing::Test ExtensionRegistryTest;
TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { TEST_F(ExtensionRegistryTest, FillAndClearRegistry) {
ExtensionRegistry registry; ExtensionRegistry registry;
scoped_refptr<Extension> extension1 = CreateExtensionWithID("id1"); scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1");
scoped_refptr<Extension> extension2 = CreateExtensionWithID("id2"); scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2");
scoped_refptr<Extension> extension3 = CreateExtensionWithID("id3"); scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3");
scoped_refptr<Extension> extension4 = CreateExtensionWithID("id4"); scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4");
// All the sets start empty. // All the sets start empty.
EXPECT_EQ(0u, registry.enabled_extensions().size()); EXPECT_EQ(0u, registry.enabled_extensions().size());
...@@ -66,7 +54,7 @@ TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) { ...@@ -66,7 +54,7 @@ TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) {
ExtensionRegistry registry; ExtensionRegistry registry;
// Adding an extension works. // Adding an extension works.
scoped_refptr<Extension> extension = CreateExtensionWithID("id"); scoped_refptr<Extension> extension = test_util::CreateExtensionWithID("id");
EXPECT_TRUE(registry.AddEnabled(extension)); EXPECT_TRUE(registry.AddEnabled(extension));
EXPECT_EQ(1u, registry.enabled_extensions().size()); EXPECT_EQ(1u, registry.enabled_extensions().size());
...@@ -85,7 +73,7 @@ TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) { ...@@ -85,7 +73,7 @@ TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) {
TEST_F(ExtensionRegistryTest, AddExtensionToRegistryTwice) { TEST_F(ExtensionRegistryTest, AddExtensionToRegistryTwice) {
ExtensionRegistry registry; ExtensionRegistry registry;
scoped_refptr<Extension> extension = CreateExtensionWithID("id"); scoped_refptr<Extension> extension = test_util::CreateExtensionWithID("id");
// An extension can exist in two sets at once. It would be nice to eliminate // An extension can exist in two sets at once. It would be nice to eliminate
// this functionality, but some users of ExtensionRegistry need it. // this functionality, but some users of ExtensionRegistry need it.
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <string> #include <string>
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/extensions/extension_service.h"
#include "extensions/browser/management_policy.h" #include "extensions/browser/management_policy.h"
namespace extensions { namespace extensions {
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "extensions/common/switches.h" #include "extensions/common/switches.h"
#include "extensions/common/url_pattern_set.h" #include "extensions/common/url_pattern_set.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "url/url_util.h" #include "url/url_util.h"
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/common/test_util.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
namespace extensions {
namespace test_util {
ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) {
return builder
.SetManifest(DictionaryBuilder()
.Set("name", "Test extension")
.Set("version", "1.0")
.Set("manifest_version", 2));
}
scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
return ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
.SetID(id)
.Build();
}
} // namespace test_util
} // namespace extensions
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_COMMON_TEST_UTIL_H_
#define EXTENSIONS_COMMON_TEST_UTIL_H_
#include <string>
#include "base/memory/ref_counted.h"
namespace extensions {
class Extension;
class ExtensionBuilder;
namespace test_util {
// Adds an extension manifest to a builder.
ExtensionBuilder& BuildExtension(ExtensionBuilder& builder);
// Return a very simple extension with a given |id|.
scoped_refptr<Extension> CreateExtensionWithID(const std::string& id);
} // namespace test_util
} // namespace extensions
#endif // EXTENSIONS_COMMON_TEST_UTIL_H_
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# api resources compiled into the chrome resource bundle. # api resources compiled into the chrome resource bundle.
# http://crbug.com/162530 # http://crbug.com/162530
'../chrome/chrome_resources.gyp:chrome_resources', '../chrome/chrome_resources.gyp:chrome_resources',
# TODO(jamescook|derat): Pull strings into extensions module.
'../chrome/chrome_resources.gyp:chrome_strings',
'../chrome/common/extensions/api/api.gyp:api', '../chrome/common/extensions/api/api.gyp:api',
'../components/components.gyp:url_matcher', '../components/components.gyp:url_matcher',
'../content/content.gyp:content_common', '../content/content.gyp:content_common',
...@@ -207,5 +209,29 @@ ...@@ -207,5 +209,29 @@
# Disable c4267 warnings until we fix size_t to int truncations. # Disable c4267 warnings until we fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ], 'msvs_disabled_warnings': [ 4267, ],
}, },
{
'target_name': 'extensions_test_support',
'type': 'static_library',
'dependencies': [
'extensions_browser',
'extensions_common',
'../base/base.gyp:base',
],
'include_dirs': [
'..',
],
'sources': [
'browser/test_management_policy.cc',
'browser/test_management_policy.h',
'common/extension_builder.cc',
'common/extension_builder.h',
'common/test_util.cc',
'common/test_util.h',
'common/value_builder.cc',
'common/value_builder.h',
],
# Disable c4267 warnings until we fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ],
},
] ]
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment