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

Side by Side Diff: chrome/browser/extensions/menu_manager_unittest.cc

Issue 10696208: Move ExtensionEventRouter and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed bug + latest master 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
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"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/extension_event_names.h" 14 #include "chrome/browser/extensions/event_names.h"
15 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/event_router.h"
16 #include "chrome/browser/extensions/menu_manager.h" 16 #include "chrome/browser/extensions/menu_manager.h"
17 #include "chrome/browser/extensions/test_extension_prefs.h" 17 #include "chrome/browser/extensions/test_extension_prefs.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/common/context_menu_params.h" 24 #include "content/public/common/context_menu_params.h"
25 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 content::Source<Profile>(&profile_), 363 content::Source<Profile>(&profile_),
364 content::Details<UnloadedExtensionInfo>( 364 content::Details<UnloadedExtensionInfo>(
365 &details)); 365 &details));
366 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); 366 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id()));
367 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); 367 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size());
368 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); 368 ASSERT_TRUE(manager_.GetItemById(id1) == NULL);
369 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); 369 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL);
370 } 370 }
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 MockEventRouter : public EventRouter {
374 public: 374 public:
375 explicit MockExtensionEventRouter(Profile* profile) : 375 explicit MockEventRouter(Profile* profile) :
376 ExtensionEventRouter(profile) {} 376 EventRouter(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 const std::string& 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 EventRouter::UserGestureState state));
385 385
386 386
387 private: 387 private:
388 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); 388 DISALLOW_COPY_AND_ASSIGN(MockEventRouter);
389 }; 389 };
390 390
391 // A mock profile for tests of MenuManager::ExecuteCommand. 391 // A mock profile for tests of MenuManager::ExecuteCommand.
392 class MockTestingProfile : public TestingProfile { 392 class MockTestingProfile : public TestingProfile {
393 public: 393 public:
394 MockTestingProfile() {} 394 MockTestingProfile() {}
395 MOCK_METHOD0(GetExtensionEventRouter, ExtensionEventRouter*()); 395 MOCK_METHOD0(GetExtensionEventRouter, EventRouter*());
396 396
397 private: 397 private:
398 DISALLOW_COPY_AND_ASSIGN(MockTestingProfile); 398 DISALLOW_COPY_AND_ASSIGN(MockTestingProfile);
399 }; 399 };
400 400
401 // Tests the RemoveAll functionality. 401 // Tests the RemoveAll functionality.
402 TEST_F(MenuManagerTest, RemoveAll) { 402 TEST_F(MenuManagerTest, RemoveAll) {
403 // Try removing all items for an extension id that doesn't have any items. 403 // Try removing all items for an extension id that doesn't have any items.
404 manager_.RemoveAllContextItems("CCCC"); 404 manager_.RemoveAllContextItems("CCCC");
405 405
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 manager_.RemoveContextMenuItem(item3->id()); 446 manager_.RemoveContextMenuItem(item3->id());
447 manager_.RemoveContextMenuItem(item1->id()); 447 manager_.RemoveContextMenuItem(item1->id());
448 manager_.RemoveContextMenuItem(item2->id()); 448 manager_.RemoveContextMenuItem(item2->id());
449 449
450 ASSERT_TRUE(manager_.context_items_.empty()); 450 ASSERT_TRUE(manager_.context_items_.empty());
451 } 451 }
452 452
453 TEST_F(MenuManagerTest, ExecuteCommand) { 453 TEST_F(MenuManagerTest, ExecuteCommand) {
454 MockTestingProfile profile; 454 MockTestingProfile profile;
455 455
456 scoped_ptr<MockExtensionEventRouter> mock_event_router( 456 scoped_ptr<MockEventRouter> mock_event_router(
457 new MockExtensionEventRouter(&profile)); 457 new MockEventRouter(&profile));
458 458
459 content::ContextMenuParams params; 459 content::ContextMenuParams params;
460 params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 460 params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
461 params.src_url = GURL("http://foo.bar/image.png"); 461 params.src_url = GURL("http://foo.bar/image.png");
462 params.page_url = GURL("http://foo.bar"); 462 params.page_url = GURL("http://foo.bar");
463 params.selection_text = ASCIIToUTF16("Hello World"); 463 params.selection_text = ASCIIToUTF16("Hello World");
464 params.is_editable = false; 464 params.is_editable = false;
465 465
466 Extension* extension = AddExtension("test"); 466 Extension* extension = AddExtension("test");
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 std::string event_args;
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 extensions::event_names::kOnContextMenus,
484 _, 484 _,
485 &profile, 485 &profile,
486 GURL(), 486 GURL(),
487 ExtensionEventRouter::USER_GESTURE_ENABLED)) 487 EventRouter::USER_GESTURE_ENABLED))
488 .Times(1) 488 .Times(1)
489 .WillOnce(SaveArg<2>(&event_args)); 489 .WillOnce(SaveArg<2>(&event_args));
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 extensions::event_names::kOnContextMenuClicked,
494 _, 494 _,
495 &profile, 495 &profile,
496 GURL(), 496 GURL(),
497 ExtensionEventRouter::USER_GESTURE_ENABLED)) 497 EventRouter::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 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 503 // the first element is a dictionary we want to inspect for the correct
504 // values. 504 // values.
505 scoped_ptr<Value> result( 505 scoped_ptr<Value> result(
506 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS)); 506 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS));
507 Value* value = result.get(); 507 Value* value = result.get();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 ASSERT_TRUE(child1->checked()); 619 ASSERT_TRUE(child1->checked());
620 620
621 // Removing |parent| should cause only |child1| to be selected. 621 // Removing |parent| should cause only |child1| to be selected.
622 manager_.RemoveContextMenuItem(parent->id()); 622 manager_.RemoveContextMenuItem(parent->id());
623 parent = NULL; 623 parent = NULL;
624 ASSERT_FALSE(new_item->checked()); 624 ASSERT_FALSE(new_item->checked());
625 ASSERT_TRUE(child1->checked()); 625 ASSERT_TRUE(child1->checked());
626 } 626 }
627 627
628 } // namespace extensions 628 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | chrome/browser/extensions/page_action_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698