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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 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 546e5214df24abd6dcd5ccba397c2b7a1286510c..8e6522f0fe26b60dffe60375ec4a9a51e661d33f 100644
--- a/chrome/browser/extensions/menu_manager_unittest.cc
+++ b/chrome/browser/extensions/menu_manager_unittest.cc
@@ -29,6 +29,7 @@
using content::BrowserThread;
using testing::_;
using testing::AtLeast;
+using testing::DeleteArg;
using testing::InSequence;
using testing::Return;
using testing::SaveArg;
@@ -375,14 +376,23 @@ class MockEventRouter : public EventRouter {
explicit MockEventRouter(Profile* profile) :
EventRouter(profile) {}
- MOCK_METHOD6(DispatchEventToExtension,
+ MOCK_METHOD6(DispatchEventToExtensionMock,
void(const std::string& extension_id,
const std::string& event_name,
- const std::string& event_args,
+ base::ListValue* event_args,
Profile* source_profile,
const GURL& event_url,
EventRouter::UserGestureState state));
+ virtual void DispatchEventToExtension(const std::string& extension_id,
+ const std::string& event_name,
+ scoped_ptr<base::ListValue> event_args,
+ Profile* source_profile,
+ const GURL& event_url,
+ EventRouter::UserGestureState state) {
+ DispatchEventToExtensionMock(extension_id, event_name, event_args.release(),
+ source_profile, event_url, state);
+ }
private:
DISALLOW_COPY_AND_ASSIGN(MockEventRouter);
@@ -474,40 +484,32 @@ TEST_F(MenuManagerTest, ExecuteCommand) {
// Use the magic of googlemock to save a parameter to our mock's
// DispatchEventToExtension method into event_args.
- std::string event_args;
+ base::ListValue* list = NULL;
{
InSequence s;
EXPECT_CALL(*mock_event_router.get(),
- DispatchEventToExtension(
+ DispatchEventToExtensionMock(
item->extension_id(),
- extensions::event_names::kOnContextMenus,
- _,
- &profile,
- GURL(),
- EventRouter::USER_GESTURE_ENABLED))
+ extensions::event_names::kOnContextMenus,
+ _,
+ &profile,
+ GURL(),
+ EventRouter::USER_GESTURE_ENABLED))
.Times(1)
- .WillOnce(SaveArg<2>(&event_args));
+ .WillOnce(SaveArg<2>(&list));
EXPECT_CALL(*mock_event_router.get(),
- DispatchEventToExtension(
+ DispatchEventToExtensionMock(
item->extension_id(),
extensions::event_names::kOnContextMenuClicked,
_,
&profile,
GURL(),
EventRouter::USER_GESTURE_ENABLED))
- .Times(1);
+ .Times(1)
+ .WillOnce(DeleteArg<2>());
}
manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id);
- // Parse the json event_args, which should turn into a 2-element list where
- // the first element is a dictionary we want to inspect for the correct
- // values.
- scoped_ptr<Value> result(
- base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS));
- Value* value = result.get();
- ASSERT_TRUE(result.get() != NULL);
- ASSERT_EQ(Value::TYPE_LIST, value->GetType());
- ListValue* list = static_cast<ListValue*>(value);
ASSERT_EQ(2u, list->GetSize());
DictionaryValue* info;
@@ -532,6 +534,8 @@ TEST_F(MenuManagerTest, ExecuteCommand) {
bool bool_tmp = true;
ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp));
ASSERT_EQ(params.is_editable, bool_tmp);
+
+ delete list;
}
// Test that there is always only one radio item selected.
« 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