| OLD | NEW |
| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 &details)); | 430 &details)); |
| 431 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); | 431 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); |
| 432 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 432 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 433 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); | 433 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); |
| 434 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); | 434 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); |
| 435 } | 435 } |
| 436 | 436 |
| 437 // A mock message service for tests of MenuManager::ExecuteCommand. | 437 // A mock message service for tests of MenuManager::ExecuteCommand. |
| 438 class MockEventRouter : public EventRouter { | 438 class MockEventRouter : public EventRouter { |
| 439 public: | 439 public: |
| 440 explicit MockEventRouter(Profile* profile) : | 440 explicit MockEventRouter(Profile* profile) : EventRouter(profile, NULL) {} |
| 441 EventRouter(profile) {} | |
| 442 | 441 |
| 443 MOCK_METHOD6(DispatchEventToExtensionMock, | 442 MOCK_METHOD6(DispatchEventToExtensionMock, |
| 444 void(const std::string& extension_id, | 443 void(const std::string& extension_id, |
| 445 const std::string& event_name, | 444 const std::string& event_name, |
| 446 base::ListValue* event_args, | 445 base::ListValue* event_args, |
| 447 Profile* source_profile, | 446 Profile* source_profile, |
| 448 const GURL& event_url, | 447 const GURL& event_url, |
| 449 EventRouter::UserGestureState state)); | 448 EventRouter::UserGestureState state)); |
| 450 | 449 |
| 451 virtual void DispatchEventToExtension(const std::string& extension_id, | 450 virtual void DispatchEventToExtension(const std::string& extension_id, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 manager_.RemoveContextMenuItem(item3->id()); | 519 manager_.RemoveContextMenuItem(item3->id()); |
| 521 manager_.RemoveContextMenuItem(item1->id()); | 520 manager_.RemoveContextMenuItem(item1->id()); |
| 522 manager_.RemoveContextMenuItem(item2->id()); | 521 manager_.RemoveContextMenuItem(item2->id()); |
| 523 | 522 |
| 524 ASSERT_TRUE(manager_.context_items_.empty()); | 523 ASSERT_TRUE(manager_.context_items_.empty()); |
| 525 } | 524 } |
| 526 | 525 |
| 527 TEST_F(MenuManagerTest, ExecuteCommand) { | 526 TEST_F(MenuManagerTest, ExecuteCommand) { |
| 528 MockTestingProfile profile; | 527 MockTestingProfile profile; |
| 529 | 528 |
| 530 scoped_ptr<MockEventRouter> mock_event_router( | 529 scoped_ptr<MockEventRouter> mock_event_router(new MockEventRouter(&profile)); |
| 531 new MockEventRouter(&profile)); | |
| 532 | 530 |
| 533 content::ContextMenuParams params; | 531 content::ContextMenuParams params; |
| 534 params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 532 params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 535 params.src_url = GURL("http://foo.bar/image.png"); | 533 params.src_url = GURL("http://foo.bar/image.png"); |
| 536 params.page_url = GURL("http://foo.bar"); | 534 params.page_url = GURL("http://foo.bar"); |
| 537 params.selection_text = ASCIIToUTF16("Hello World"); | 535 params.selection_text = ASCIIToUTF16("Hello World"); |
| 538 params.is_editable = false; | 536 params.is_editable = false; |
| 539 | 537 |
| 540 Extension* extension = AddExtension("test"); | 538 Extension* extension = AddExtension("test"); |
| 541 MenuItem* item = CreateTestItem(extension); | 539 MenuItem* item = CreateTestItem(extension); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 ASSERT_TRUE(child1->checked()); | 685 ASSERT_TRUE(child1->checked()); |
| 688 | 686 |
| 689 // Removing |parent| should cause only |child1| to be selected. | 687 // Removing |parent| should cause only |child1| to be selected. |
| 690 manager_.RemoveContextMenuItem(parent->id()); | 688 manager_.RemoveContextMenuItem(parent->id()); |
| 691 parent = NULL; | 689 parent = NULL; |
| 692 ASSERT_FALSE(new_item->checked()); | 690 ASSERT_FALSE(new_item->checked()); |
| 693 ASSERT_TRUE(child1->checked()); | 691 ASSERT_TRUE(child1->checked()); |
| 694 } | 692 } |
| 695 | 693 |
| 696 } // namespace extensions | 694 } // namespace extensions |
| OLD | NEW |