| 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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 registry->TriggerOnUnloaded(extension1, | 446 registry->TriggerOnUnloaded(extension1, |
| 447 UnloadedExtensionInfo::REASON_DISABLE); | 447 UnloadedExtensionInfo::REASON_DISABLE); |
| 448 | 448 |
| 449 ASSERT_EQ(NULL, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id()))); | 449 ASSERT_EQ(NULL, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id()))); |
| 450 ASSERT_EQ( | 450 ASSERT_EQ( |
| 451 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension2->id()))->size()); | 451 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension2->id()))->size()); |
| 452 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); | 452 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); |
| 453 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); | 453 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); |
| 454 } | 454 } |
| 455 | 455 |
| 456 namespace { |
| 457 |
| 456 // A mock message service for tests of MenuManager::ExecuteCommand. | 458 // A mock message service for tests of MenuManager::ExecuteCommand. |
| 457 class MockEventRouter : public EventRouter { | 459 class MockEventRouter : public EventRouter { |
| 458 public: | 460 public: |
| 459 explicit MockEventRouter(Profile* profile) : EventRouter(profile, NULL) {} | 461 explicit MockEventRouter(Profile* profile) : EventRouter(profile, NULL) {} |
| 460 | 462 |
| 461 MOCK_METHOD6(DispatchEventToExtensionMock, | 463 MOCK_METHOD6(DispatchEventToExtensionMock, |
| 462 void(const std::string& extension_id, | 464 void(const std::string& extension_id, |
| 463 const std::string& event_name, | 465 const std::string& event_name, |
| 464 base::ListValue* event_args, | 466 base::ListValue* event_args, |
| 465 content::BrowserContext* source_context, | 467 content::BrowserContext* source_context, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 495 private: | 497 private: |
| 496 scoped_ptr<MockEventRouter> mock_event_router_; | 498 scoped_ptr<MockEventRouter> mock_event_router_; |
| 497 | 499 |
| 498 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); | 500 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); |
| 499 }; | 501 }; |
| 500 | 502 |
| 501 KeyedService* BuildMockExtensionSystem(content::BrowserContext* profile) { | 503 KeyedService* BuildMockExtensionSystem(content::BrowserContext* profile) { |
| 502 return new MockExtensionSystem(static_cast<Profile*>(profile)); | 504 return new MockExtensionSystem(static_cast<Profile*>(profile)); |
| 503 } | 505 } |
| 504 | 506 |
| 507 } // namespace |
| 508 |
| 505 // Tests the RemoveAll functionality. | 509 // Tests the RemoveAll functionality. |
| 506 TEST_F(MenuManagerTest, RemoveAll) { | 510 TEST_F(MenuManagerTest, RemoveAll) { |
| 507 // Try removing all items for an extension id that doesn't have any items. | 511 // Try removing all items for an extension id that doesn't have any items. |
| 508 manager_.RemoveAllContextItems(MenuItem::ExtensionKey("CCCC")); | 512 manager_.RemoveAllContextItems(MenuItem::ExtensionKey("CCCC")); |
| 509 | 513 |
| 510 // Add 2 top-level and one child item for extension 1. | 514 // Add 2 top-level and one child item for extension 1. |
| 511 Extension* extension1 = AddExtension("1111"); | 515 Extension* extension1 = AddExtension("1111"); |
| 512 MenuItem* item1 = CreateTestItem(extension1); | 516 MenuItem* item1 = CreateTestItem(extension1); |
| 513 MenuItem* item2 = CreateTestItem(extension1); | 517 MenuItem* item2 = CreateTestItem(extension1); |
| 514 MenuItem* item3 = CreateTestItem(extension1); | 518 MenuItem* item3 = CreateTestItem(extension1); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 EXPECT_EQ(4u, manager_.MenuItems(key1)->size()); | 763 EXPECT_EQ(4u, manager_.MenuItems(key1)->size()); |
| 760 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); | 764 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); |
| 761 | 765 |
| 762 // Remove all context menu items with incognito true. | 766 // Remove all context menu items with incognito true. |
| 763 manager_.RemoveAllIncognitoContextItems(); | 767 manager_.RemoveAllIncognitoContextItems(); |
| 764 EXPECT_EQ(2u, manager_.MenuItems(key1)->size()); | 768 EXPECT_EQ(2u, manager_.MenuItems(key1)->size()); |
| 765 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); | 769 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); |
| 766 } | 770 } |
| 767 | 771 |
| 768 } // namespace extensions | 772 } // namespace extensions |
| OLD | NEW |