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

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: rebase 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
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..6985ca0fe55dfcd458c4578b1e76e1dd4c996d80 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,11 +463,32 @@ class MockEventRouter : public EventRouter {
DISALLOW_COPY_AND_ASSIGN(MockEventRouter);
};
+// A mock ExtensionSystem to serve our MockEventRouter.
+class MockExtensionSystem : public TestExtensionSystem {
+ public:
+ 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:
+ scoped_ptr<MockEventRouter> mock_event_router_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
+};
+
+ProfileKeyedService* BuildMockExtensionSystem(Profile* profile) {
+ return new MockExtensionSystem(profile);
+}
+
// A mock profile for tests of MenuManager::ExecuteCommand.
class MockTestingProfile : public TestingProfile {
Yoyo Zhou 2012/10/25 22:24:47 Since this is no longer interesting, you can repla
Miranda Callahan 2012/10/26 19:23:01 Done.
public:
MockTestingProfile() {}
- MOCK_METHOD0(GetExtensionEventRouter, EventRouter*());
private:
DISALLOW_COPY_AND_ASSIGN(MockTestingProfile);
@@ -526,7 +549,11 @@ TEST_F(MenuManagerTest, RemoveOneByOne) {
TEST_F(MenuManagerTest, ExecuteCommand) {
MockTestingProfile 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 +567,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.
+ // DispatchEventToExtension method into event_)args.
Yoyo Zhou 2012/10/25 22:24:47 spurious
Miranda Callahan 2012/10/26 19:23:01 Done.
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 +582,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,

Powered by Google App Engine
This is Rietveld 408576698