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