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

Side by Side 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: Rebase and review changes. Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 371
372 // A mock message service for tests of MenuManager::ExecuteCommand. 372 // A mock message service for tests of MenuManager::ExecuteCommand.
373 class MockExtensionEventRouter : public ExtensionEventRouter { 373 class MockExtensionEventRouter : public ExtensionEventRouter {
374 public: 374 public:
375 explicit MockExtensionEventRouter(Profile* profile) : 375 explicit MockExtensionEventRouter(Profile* profile) :
376 ExtensionEventRouter(profile) {} 376 ExtensionEventRouter(profile) {}
377 377
378 MOCK_METHOD6(DispatchEventToExtension, 378 MOCK_METHOD6(DispatchEventToExtension,
379 void(const std::string& extension_id, 379 void(const std::string& extension_id,
380 const std::string& event_name, 380 const std::string& event_name,
381 const std::string& event_args, 381 base::ListValue* event_args,
382 Profile* source_profile, 382 Profile* source_profile,
383 const GURL& event_url, 383 const GURL& event_url,
384 ExtensionEventRouter::UserGestureState state)); 384 ExtensionEventRouter::UserGestureState state));
385 385
386 386
387 private: 387 private:
388 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); 388 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter);
389 }; 389 };
390 390
391 // A mock profile for tests of MenuManager::ExecuteCommand. 391 // A mock profile for tests of MenuManager::ExecuteCommand.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 MenuItem* item = CreateTestItem(extension); 467 MenuItem* item = CreateTestItem(extension);
468 MenuItem::Id id = item->id(); 468 MenuItem::Id id = item->id();
469 ASSERT_TRUE(manager_.AddContextItem(extension, item)); 469 ASSERT_TRUE(manager_.AddContextItem(extension, item));
470 470
471 EXPECT_CALL(profile, GetExtensionEventRouter()) 471 EXPECT_CALL(profile, GetExtensionEventRouter())
472 .Times(1) 472 .Times(1)
473 .WillOnce(Return(mock_event_router.get())); 473 .WillOnce(Return(mock_event_router.get()));
474 474
475 // Use the magic of googlemock to save a parameter to our mock's 475 // Use the magic of googlemock to save a parameter to our mock's
476 // DispatchEventToExtension method into event_args. 476 // DispatchEventToExtension method into event_args.
477 std::string event_args; 477 base::ListValue* list = NULL;
478 { 478 {
479 InSequence s; 479 InSequence s;
480 EXPECT_CALL(*mock_event_router.get(), 480 EXPECT_CALL(*mock_event_router.get(),
481 DispatchEventToExtension( 481 DispatchEventToExtension(
482 item->extension_id(), 482 item->extension_id(),
483 extension_event_names::kOnContextMenus, 483 extension_event_names::kOnContextMenus,
484 _, 484 _,
485 &profile, 485 &profile,
486 GURL(), 486 GURL(),
487 ExtensionEventRouter::USER_GESTURE_ENABLED)) 487 ExtensionEventRouter::USER_GESTURE_ENABLED))
488 .Times(1) 488 .Times(1)
489 .WillOnce(SaveArg<2>(&event_args)); 489 .WillOnce(SaveArg<2>(&list));
490 EXPECT_CALL(*mock_event_router.get(), 490 EXPECT_CALL(*mock_event_router.get(),
491 DispatchEventToExtension( 491 DispatchEventToExtension(
492 item->extension_id(), 492 item->extension_id(),
493 extension_event_names::kOnContextMenuClicked, 493 extension_event_names::kOnContextMenuClicked,
494 _, 494 _,
495 &profile, 495 &profile,
496 GURL(), 496 GURL(),
497 ExtensionEventRouter::USER_GESTURE_ENABLED)) 497 ExtensionEventRouter::USER_GESTURE_ENABLED))
498 .Times(1); 498 .Times(1);
499 } 499 }
500 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); 500 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id);
501 501
502 // Parse the json event_args, which should turn into a 2-element list where
503 // the first element is a dictionary we want to inspect for the correct
504 // values.
505 scoped_ptr<Value> result(
506 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS));
507 Value* value = result.get();
508 ASSERT_TRUE(result.get() != NULL);
509 ASSERT_EQ(Value::TYPE_LIST, value->GetType());
510 ListValue* list = static_cast<ListValue*>(value);
511 ASSERT_EQ(2u, list->GetSize()); 502 ASSERT_EQ(2u, list->GetSize());
512 503
513 DictionaryValue* info; 504 DictionaryValue* info;
514 ASSERT_TRUE(list->GetDictionary(0, &info)); 505 ASSERT_TRUE(list->GetDictionary(0, &info));
515 506
516 int tmp_id = 0; 507 int tmp_id = 0;
517 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id)); 508 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id));
518 ASSERT_EQ(id.uid, tmp_id); 509 ASSERT_EQ(id.uid, tmp_id);
519 510
520 std::string tmp; 511 std::string tmp;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 ASSERT_TRUE(child1->checked()); 610 ASSERT_TRUE(child1->checked());
620 611
621 // Removing |parent| should cause only |child1| to be selected. 612 // Removing |parent| should cause only |child1| to be selected.
622 manager_.RemoveContextMenuItem(parent->id()); 613 manager_.RemoveContextMenuItem(parent->id());
623 parent = NULL; 614 parent = NULL;
624 ASSERT_FALSE(new_item->checked()); 615 ASSERT_FALSE(new_item->checked());
625 ASSERT_TRUE(child1->checked()); 616 ASSERT_TRUE(child1->checked());
626 } 617 }
627 618
628 } // namespace extensions 619 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698