Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1958)

Unified Diff: chrome/browser/extensions/menu_manager_unittest.cc

Issue 11232066: Remove GetExtensionEventRouter from Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/menu_manager_unittest.cc
diff --git a/chrome/browser/extensions/menu_manager_unittest.cc b/chrome/browser/extensions/menu_manager_unittest.cc
index fc6049da9564bd4745f44664bde84d9d1f01b964..984dd30db3caa49d1a7e29cbff41a1fe21f327f7 100644
--- a/chrome/browser/extensions/menu_manager_unittest.cc
+++ b/chrome/browser/extensions/menu_manager_unittest.cc
@@ -13,8 +13,10 @@
#include "base/values.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/menu_manager.h"
#include "chrome/browser/extensions/test_extension_prefs.h"
+#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
@@ -461,16 +463,28 @@ class MockEventRouter : public EventRouter {
DISALLOW_COPY_AND_ASSIGN(MockEventRouter);
};
-// A mock profile for tests of MenuManager::ExecuteCommand.
-class MockTestingProfile : public TestingProfile {
+// A mock ExtensionSystem to serve our MockEventRouter.
+class MockExtensionSystem : public TestExtensionSystem {
public:
- MockTestingProfile() {}
- MOCK_METHOD0(GetExtensionEventRouter, EventRouter*());
+ explicit MockExtensionSystem(Profile* profile)
+ : TestExtensionSystem(profile) {}
+
+ virtual EventRouter* event_router() {
+ if (!mock_event_router_.get())
+ mock_event_router_.reset(new MockEventRouter(profile_));
+ return mock_event_router_.get();
+ }
private:
- DISALLOW_COPY_AND_ASSIGN(MockTestingProfile);
+ scoped_ptr<MockEventRouter> mock_event_router_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
};
+ProfileKeyedService* BuildMockExtensionSystem(Profile* profile) {
+ return new MockExtensionSystem(profile);
+}
+
// Tests the RemoveAll functionality.
TEST_F(MenuManagerTest, RemoveAll) {
// Try removing all items for an extension id that doesn't have any items.
@@ -524,9 +538,13 @@ TEST_F(MenuManagerTest, RemoveOneByOne) {
}
TEST_F(MenuManagerTest, ExecuteCommand) {
- MockTestingProfile profile;
+ TestingProfile profile;
- scoped_ptr<MockEventRouter> mock_event_router(new MockEventRouter(&profile));
+ MockExtensionSystem* mock_extension_system =
+ static_cast<MockExtensionSystem*>(ExtensionSystemFactory::GetInstance()->
+ SetTestingFactoryAndUse(&profile, &BuildMockExtensionSystem));
+ MockEventRouter* mock_event_router =
+ static_cast<MockEventRouter*>(mock_extension_system->event_router());
content::ContextMenuParams params;
params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
@@ -540,16 +558,12 @@ TEST_F(MenuManagerTest, ExecuteCommand) {
MenuItem::Id id = item->id();
ASSERT_TRUE(manager_.AddContextItem(extension, item));
- EXPECT_CALL(profile, GetExtensionEventRouter())
- .Times(1)
- .WillOnce(Return(mock_event_router.get()));
-
// Use the magic of googlemock to save a parameter to our mock's
// DispatchEventToExtension method into event_args.
base::ListValue* list = NULL;
{
InSequence s;
- EXPECT_CALL(*mock_event_router.get(),
+ EXPECT_CALL(*mock_event_router,
DispatchEventToExtensionMock(
item->extension_id(),
extensions::event_names::kOnContextMenus,
@@ -559,7 +573,7 @@ TEST_F(MenuManagerTest, ExecuteCommand) {
EventRouter::USER_GESTURE_ENABLED))
.Times(1)
.WillOnce(SaveArg<2>(&list));
- EXPECT_CALL(*mock_event_router.get(),
+ EXPECT_CALL(*mock_event_router,
DispatchEventToExtensionMock(
item->extension_id(),
extensions::event_names::kOnContextMenuClicked,
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698