| 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" |
| 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_router.h" | 14 #include "chrome/browser/extensions/extension_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_menu_manager.h" | 15 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 16 #include "chrome/browser/extensions/test_extension_prefs.h" | 16 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/common/context_menu_params.h" | 23 #include "content/public/common/context_menu_params.h" |
| 24 #include "content/test/test_browser_thread.h" | 24 #include "content/test/test_browser_thread.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 using extensions::Extension; |
| 29 using testing::_; | 30 using testing::_; |
| 30 using testing::AtLeast; | 31 using testing::AtLeast; |
| 31 using testing::Return; | 32 using testing::Return; |
| 32 using testing::SaveArg; | 33 using testing::SaveArg; |
| 33 | 34 |
| 34 // Base class for tests. | 35 // Base class for tests. |
| 35 class ExtensionMenuManagerTest : public testing::Test { | 36 class ExtensionMenuManagerTest : public testing::Test { |
| 36 public: | 37 public: |
| 37 ExtensionMenuManagerTest() | 38 ExtensionMenuManagerTest() |
| 38 : ui_thread_(BrowserThread::UI, &message_loop_), | 39 : ui_thread_(BrowserThread::UI, &message_loop_), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 return extension; | 58 return extension; |
| 58 } | 59 } |
| 59 | 60 |
| 60 protected: | 61 protected: |
| 61 TestingProfile profile_; | 62 TestingProfile profile_; |
| 62 MessageLoopForUI message_loop_; | 63 MessageLoopForUI message_loop_; |
| 63 content::TestBrowserThread ui_thread_; | 64 content::TestBrowserThread ui_thread_; |
| 64 content::TestBrowserThread file_thread_; | 65 content::TestBrowserThread file_thread_; |
| 65 | 66 |
| 66 ExtensionMenuManager manager_; | 67 ExtensionMenuManager manager_; |
| 67 ExtensionList extensions_; | 68 extensions::ExtensionList extensions_; |
| 68 TestExtensionPrefs prefs_; | 69 TestExtensionPrefs prefs_; |
| 69 int next_id_; | 70 int next_id_; |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest); | 73 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 // Tests adding, getting, and removing items. | 76 // Tests adding, getting, and removing items. |
| 76 TEST_F(ExtensionMenuManagerTest, AddGetRemoveItems) { | 77 TEST_F(ExtensionMenuManagerTest, AddGetRemoveItems) { |
| 77 Extension* extension = AddExtension("test"); | 78 Extension* extension = AddExtension("test"); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 ASSERT_EQ(1u, manager_.MenuItems(extension1->id())->size()); | 329 ASSERT_EQ(1u, manager_.MenuItems(extension1->id())->size()); |
| 329 | 330 |
| 330 // Create a menu item with a different extension id and add it to the manager. | 331 // Create a menu item with a different extension id and add it to the manager. |
| 331 Extension* extension2 = AddExtension("2222"); | 332 Extension* extension2 = AddExtension("2222"); |
| 332 ExtensionMenuItem* item2 = CreateTestItem(extension2); | 333 ExtensionMenuItem* item2 = CreateTestItem(extension2); |
| 333 ASSERT_NE(item1->extension_id(), item2->extension_id()); | 334 ASSERT_NE(item1->extension_id(), item2->extension_id()); |
| 334 ASSERT_TRUE(manager_.AddContextItem(extension2, item2)); | 335 ASSERT_TRUE(manager_.AddContextItem(extension2, item2)); |
| 335 | 336 |
| 336 // Notify that the extension was unloaded, and make sure the right item is | 337 // Notify that the extension was unloaded, and make sure the right item is |
| 337 // gone. | 338 // gone. |
| 338 UnloadedExtensionInfo details( | 339 extensions::UnloadedExtensionInfo details( |
| 339 extension1, extension_misc::UNLOAD_REASON_DISABLE); | 340 extension1, extension_misc::UNLOAD_REASON_DISABLE); |
| 340 notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED, | 341 notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 341 content::Source<Profile>(&profile_), | 342 content::Source<Profile>(&profile_), |
| 342 content::Details<UnloadedExtensionInfo>(&details)); | 343 content::Details<extensions::UnloadedExtensionInfo>( |
| 344 &details)); |
| 343 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); | 345 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); |
| 344 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 346 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 345 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); | 347 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); |
| 346 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); | 348 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); |
| 347 } | 349 } |
| 348 | 350 |
| 349 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. | 351 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. |
| 350 class MockExtensionEventRouter : public ExtensionEventRouter { | 352 class MockExtensionEventRouter : public ExtensionEventRouter { |
| 351 public: | 353 public: |
| 352 explicit MockExtensionEventRouter(Profile* profile) : | 354 explicit MockExtensionEventRouter(Profile* profile) : |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 manager_.ChangeParent(child1->id(), NULL); | 584 manager_.ChangeParent(child1->id(), NULL); |
| 583 ASSERT_TRUE(new_item->checked()); | 585 ASSERT_TRUE(new_item->checked()); |
| 584 ASSERT_TRUE(child1->checked()); | 586 ASSERT_TRUE(child1->checked()); |
| 585 | 587 |
| 586 // Removing |parent| should cause only |child1| to be selected. | 588 // Removing |parent| should cause only |child1| to be selected. |
| 587 manager_.RemoveContextMenuItem(parent->id()); | 589 manager_.RemoveContextMenuItem(parent->id()); |
| 588 parent = NULL; | 590 parent = NULL; |
| 589 ASSERT_FALSE(new_item->checked()); | 591 ASSERT_FALSE(new_item->checked()); |
| 590 ASSERT_TRUE(child1->checked()); | 592 ASSERT_TRUE(child1->checked()); |
| 591 } | 593 } |
| OLD | NEW |