| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/run_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/extensions/event_names.h" | 17 #include "chrome/browser/extensions/event_names.h" |
| 17 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
| 18 #include "chrome/browser/extensions/extension_system_factory.h" | 19 #include "chrome/browser/extensions/extension_system_factory.h" |
| 19 #include "chrome/browser/extensions/menu_manager.h" | 20 #include "chrome/browser/extensions/menu_manager.h" |
| 20 #include "chrome/browser/extensions/test_extension_prefs.h" | 21 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 21 #include "chrome/browser/extensions/test_extension_system.h" | 22 #include "chrome/browser/extensions/test_extension_system.h" |
| 22 #include "chrome/browser/prefs/pref_service_syncable.h" | 23 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/common/context_menu_params.h" | 30 #include "content/public/common/context_menu_params.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 34 |
| 33 using content::BrowserThread; | 35 using content::BrowserThread; |
| 34 using testing::_; | 36 using testing::_; |
| 35 using testing::AtLeast; | 37 using testing::AtLeast; |
| 36 using testing::DeleteArg; | 38 using testing::DeleteArg; |
| 37 using testing::InSequence; | 39 using testing::InSequence; |
| 38 using testing::Return; | 40 using testing::Return; |
| 39 using testing::SaveArg; | 41 using testing::SaveArg; |
| 40 | 42 |
| 41 namespace extensions { | 43 namespace extensions { |
| 42 | 44 |
| 43 // Base class for tests. | 45 // Base class for tests. |
| 44 class MenuManagerTest : public testing::Test { | 46 class MenuManagerTest : public testing::Test { |
| 45 public: | 47 public: |
| 46 MenuManagerTest() | 48 MenuManagerTest() |
| 47 : ui_thread_(BrowserThread::UI, &message_loop_), | 49 : manager_(&profile_), |
| 48 file_thread_(BrowserThread::FILE, &message_loop_), | 50 prefs_(base::MessageLoopForUI::current()->message_loop_proxy().get()), |
| 49 manager_(&profile_), | |
| 50 prefs_(message_loop_.message_loop_proxy().get()), | |
| 51 next_id_(1) {} | 51 next_id_(1) {} |
| 52 | 52 |
| 53 virtual void TearDown() OVERRIDE { | 53 virtual void TearDown() OVERRIDE { |
| 54 prefs_.pref_service()->CommitPendingWrite(); | 54 prefs_.pref_service()->CommitPendingWrite(); |
| 55 message_loop_.RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Returns a test item. | 58 // Returns a test item. |
| 59 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) { | 59 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) { |
| 60 MenuItem::Type type = MenuItem::NORMAL; | 60 MenuItem::Type type = MenuItem::NORMAL; |
| 61 MenuItem::ContextList contexts(MenuItem::ALL); | 61 MenuItem::ContextList contexts(MenuItem::ALL); |
| 62 MenuItem::Id id(incognito, extension->id()); | 62 MenuItem::Id id(incognito, extension->id()); |
| 63 id.uid = next_id_++; | 63 id.uid = next_id_++; |
| 64 return new MenuItem(id, "test", false, true, type, contexts); | 64 return new MenuItem(id, "test", false, true, type, contexts); |
| 65 } | 65 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 | 76 |
| 77 // Creates and returns a test Extension. The caller does *not* own the return | 77 // Creates and returns a test Extension. The caller does *not* own the return |
| 78 // value. | 78 // value. |
| 79 Extension* AddExtension(std::string name) { | 79 Extension* AddExtension(std::string name) { |
| 80 scoped_refptr<Extension> extension = prefs_.AddExtension(name); | 80 scoped_refptr<Extension> extension = prefs_.AddExtension(name); |
| 81 extensions_.push_back(extension); | 81 extensions_.push_back(extension); |
| 82 return extension.get(); | 82 return extension.get(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 content::TestBrowserThreadBundle thread_bundle_; |
| 86 TestingProfile profile_; | 87 TestingProfile profile_; |
| 87 base::MessageLoopForUI message_loop_; | |
| 88 content::TestBrowserThread ui_thread_; | |
| 89 content::TestBrowserThread file_thread_; | |
| 90 | 88 |
| 91 MenuManager manager_; | 89 MenuManager manager_; |
| 92 ExtensionList extensions_; | 90 ExtensionList extensions_; |
| 93 TestExtensionPrefs prefs_; | 91 TestExtensionPrefs prefs_; |
| 94 int next_id_; | 92 int next_id_; |
| 95 | 93 |
| 96 private: | 94 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); | 95 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); |
| 98 }; | 96 }; |
| 99 | 97 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 EXPECT_EQ(4u, manager_.MenuItems(extension1->id())->size()); | 746 EXPECT_EQ(4u, manager_.MenuItems(extension1->id())->size()); |
| 749 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 747 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 750 | 748 |
| 751 // Remove all context menu items with incognito true. | 749 // Remove all context menu items with incognito true. |
| 752 manager_.RemoveAllIncognitoContextItems(); | 750 manager_.RemoveAllIncognitoContextItems(); |
| 753 EXPECT_EQ(2u, manager_.MenuItems(extension1->id())->size()); | 751 EXPECT_EQ(2u, manager_.MenuItems(extension1->id())->size()); |
| 754 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 752 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 755 } | 753 } |
| 756 | 754 |
| 757 } // namespace extensions | 755 } // namespace extensions |
| OLD | NEW |