Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: chrome/browser/extensions/menu_manager_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/extensions/menu_manager.h"
6
7 #include <memory>
5 #include <vector> 8 #include <vector>
6 9
7 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
9 #include "base/macros.h" 12 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 15 #include "base/values.h"
13 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/extension_system_factory.h" 17 #include "chrome/browser/extensions/extension_system_factory.h"
15 #include "chrome/browser/extensions/menu_manager.h"
16 #include "chrome/browser/extensions/test_extension_prefs.h" 18 #include "chrome/browser/extensions/test_extension_prefs.h"
17 #include "chrome/browser/extensions/test_extension_system.h" 19 #include "chrome/browser/extensions/test_extension_system.h"
18 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/api/context_menus.h" 21 #include "chrome/common/extensions/api/context_menus.h"
20 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
21 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
22 #include "components/syncable_prefs/pref_service_syncable.h" 24 #include "components/syncable_prefs/pref_service_syncable.h"
23 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
24 #include "content/public/common/context_menu_params.h" 26 #include "content/public/common/context_menu_params.h"
25 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Extension* AddExtension(const std::string& name) { 88 Extension* AddExtension(const std::string& name) {
87 scoped_refptr<Extension> extension = prefs_.AddExtension(name); 89 scoped_refptr<Extension> extension = prefs_.AddExtension(name);
88 extensions_.push_back(extension); 90 extensions_.push_back(extension);
89 return extension.get(); 91 return extension.get();
90 } 92 }
91 93
92 protected: 94 protected:
93 base::MessageLoopForUI message_loop_; 95 base::MessageLoopForUI message_loop_;
94 content::TestBrowserThread ui_thread_; 96 content::TestBrowserThread ui_thread_;
95 content::TestBrowserThread file_thread_; 97 content::TestBrowserThread file_thread_;
96 scoped_ptr<TestingProfile> profile_; 98 std::unique_ptr<TestingProfile> profile_;
97 99
98 MenuManager manager_; 100 MenuManager manager_;
99 ExtensionList extensions_; 101 ExtensionList extensions_;
100 TestExtensionPrefs prefs_; 102 TestExtensionPrefs prefs_;
101 int next_id_; 103 int next_id_;
102 104
103 private: 105 private:
104 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); 106 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest);
105 }; 107 };
106 108
(...skipping 30 matching lines...) Expand all
137 ASSERT_EQ(NULL, manager_.GetItemById(id3)); 139 ASSERT_EQ(NULL, manager_.GetItemById(id3));
138 ASSERT_EQ(2u, manager_.MenuItems(extension_key3)->size()); 140 ASSERT_EQ(2u, manager_.MenuItems(extension_key3)->size());
139 141
140 // Make sure removing a non-existent item returns false. 142 // Make sure removing a non-existent item returns false.
141 const MenuItem::ExtensionKey key(extension->id()); 143 const MenuItem::ExtensionKey key(extension->id());
142 MenuItem::Id id(false, key); 144 MenuItem::Id id(false, key);
143 id.uid = id3.uid + 50; 145 id.uid = id3.uid + 50;
144 ASSERT_FALSE(manager_.RemoveContextMenuItem(id)); 146 ASSERT_FALSE(manager_.RemoveContextMenuItem(id));
145 147
146 // Make sure adding an item with the same string ID returns false. 148 // Make sure adding an item with the same string ID returns false.
147 scoped_ptr<MenuItem> item2too(CreateTestItemWithID(extension, "id2")); 149 std::unique_ptr<MenuItem> item2too(CreateTestItemWithID(extension, "id2"));
148 ASSERT_FALSE(manager_.AddContextItem(extension, item2too.get())); 150 ASSERT_FALSE(manager_.AddContextItem(extension, item2too.get()));
149 151
150 // But the same string ID should not collide with another extension. 152 // But the same string ID should not collide with another extension.
151 Extension* extension2 = AddExtension("test2"); 153 Extension* extension2 = AddExtension("test2");
152 MenuItem* item2other = CreateTestItemWithID(extension2, "id2"); 154 MenuItem* item2other = CreateTestItemWithID(extension2, "id2");
153 ASSERT_TRUE(manager_.AddContextItem(extension2, item2other)); 155 ASSERT_TRUE(manager_.AddContextItem(extension2, item2other));
154 } 156 }
155 157
156 // Test adding/removing child items. 158 // Test adding/removing child items.
157 TEST_F(MenuManagerTest, ChildFunctions) { 159 TEST_F(MenuManagerTest, ChildFunctions) {
158 Extension* extension1 = AddExtension("1111"); 160 Extension* extension1 = AddExtension("1111");
159 Extension* extension2 = AddExtension("2222"); 161 Extension* extension2 = AddExtension("2222");
160 Extension* extension3 = AddExtension("3333"); 162 Extension* extension3 = AddExtension("3333");
161 163
162 MenuItem* item1 = CreateTestItem(extension1); 164 MenuItem* item1 = CreateTestItem(extension1);
163 MenuItem* item2 = CreateTestItem(extension2); 165 MenuItem* item2 = CreateTestItem(extension2);
164 MenuItem* item2_child = CreateTestItemWithID(extension2, "2child"); 166 MenuItem* item2_child = CreateTestItemWithID(extension2, "2child");
165 MenuItem* item2_grandchild = CreateTestItem(extension2); 167 MenuItem* item2_grandchild = CreateTestItem(extension2);
166 168
167 // This third item we expect to fail inserting, so we use a scoped_ptr to make 169 // This third item we expect to fail inserting, so we use a scoped_ptr to make
168 // sure it gets deleted. 170 // sure it gets deleted.
169 scoped_ptr<MenuItem> item3(CreateTestItem(extension3)); 171 std::unique_ptr<MenuItem> item3(CreateTestItem(extension3));
170 172
171 // Add in the first two items. 173 // Add in the first two items.
172 ASSERT_TRUE(manager_.AddContextItem(extension1, item1)); 174 ASSERT_TRUE(manager_.AddContextItem(extension1, item1));
173 ASSERT_TRUE(manager_.AddContextItem(extension2, item2)); 175 ASSERT_TRUE(manager_.AddContextItem(extension2, item2));
174 176
175 MenuItem::Id id1 = item1->id(); 177 MenuItem::Id id1 = item1->id();
176 MenuItem::Id id2 = item2->id(); 178 MenuItem::Id id2 = item2->id();
177 179
178 // Try adding item3 as a child of item2 - this should fail because item3 has 180 // Try adding item3 as a child of item2 - this should fail because item3 has
179 // a different extension id. 181 // a different extension id.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 value.SetString("string_uid", std::string()); 241 value.SetString("string_uid", std::string());
240 value.SetInteger("type", type); 242 value.SetInteger("type", type);
241 value.SetString("title", title); 243 value.SetString("title", title);
242 value.SetBoolean("checked", checked); 244 value.SetBoolean("checked", checked);
243 value.SetBoolean("enabled", enabled); 245 value.SetBoolean("enabled", enabled);
244 value.SetInteger("contexts", contexts_value); 246 value.SetInteger("contexts", contexts_value);
245 value.Set("document_url_patterns", document_url_patterns); 247 value.Set("document_url_patterns", document_url_patterns);
246 value.Set("target_url_patterns", target_url_patterns); 248 value.Set("target_url_patterns", target_url_patterns);
247 249
248 std::string error; 250 std::string error;
249 scoped_ptr<MenuItem> item(MenuItem::Populate(extension->id(), value, &error)); 251 std::unique_ptr<MenuItem> item(
252 MenuItem::Populate(extension->id(), value, &error));
250 ASSERT_TRUE(item.get()); 253 ASSERT_TRUE(item.get());
251 254
252 EXPECT_EQ(extension->id(), item->extension_id()); 255 EXPECT_EQ(extension->id(), item->extension_id());
253 EXPECT_EQ(incognito, item->incognito()); 256 EXPECT_EQ(incognito, item->incognito());
254 EXPECT_EQ(title, item->title()); 257 EXPECT_EQ(title, item->title());
255 EXPECT_EQ(checked, item->checked()); 258 EXPECT_EQ(checked, item->checked());
256 EXPECT_EQ(item->checked(), item->checked()); 259 EXPECT_EQ(item->checked(), item->checked());
257 EXPECT_EQ(enabled, item->enabled()); 260 EXPECT_EQ(enabled, item->enabled());
258 EXPECT_EQ(contexts, item->contexts()); 261 EXPECT_EQ(contexts, item->contexts());
259 262
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 465
463 MOCK_METHOD6(DispatchEventToExtensionMock, 466 MOCK_METHOD6(DispatchEventToExtensionMock,
464 void(const std::string& extension_id, 467 void(const std::string& extension_id,
465 const std::string& event_name, 468 const std::string& event_name,
466 base::ListValue* event_args, 469 base::ListValue* event_args,
467 content::BrowserContext* source_context, 470 content::BrowserContext* source_context,
468 const GURL& event_url, 471 const GURL& event_url,
469 EventRouter::UserGestureState state)); 472 EventRouter::UserGestureState state));
470 473
471 virtual void DispatchEventToExtension(const std::string& extension_id, 474 virtual void DispatchEventToExtension(const std::string& extension_id,
472 scoped_ptr<Event> event) { 475 std::unique_ptr<Event> event) {
473 DispatchEventToExtensionMock(extension_id, 476 DispatchEventToExtensionMock(extension_id,
474 event->event_name, 477 event->event_name,
475 event->event_args.release(), 478 event->event_args.release(),
476 event->restrict_to_browser_context, 479 event->restrict_to_browser_context,
477 event->event_url, 480 event->event_url,
478 event->user_gesture); 481 event->user_gesture);
479 } 482 }
480 483
481 private: 484 private:
482 DISALLOW_COPY_AND_ASSIGN(MockEventRouter); 485 DISALLOW_COPY_AND_ASSIGN(MockEventRouter);
483 }; 486 };
484 487
485 // MockEventRouter factory function 488 // MockEventRouter factory function
486 scoped_ptr<KeyedService> MockEventRouterFactoryFunction( 489 std::unique_ptr<KeyedService> MockEventRouterFactoryFunction(
487 content::BrowserContext* context) { 490 content::BrowserContext* context) {
488 return make_scoped_ptr(new MockEventRouter(static_cast<Profile*>(context))); 491 return base::WrapUnique(new MockEventRouter(static_cast<Profile*>(context)));
489 } 492 }
490 493
491 } // namespace 494 } // namespace
492 495
493 // Tests the RemoveAll functionality. 496 // Tests the RemoveAll functionality.
494 TEST_F(MenuManagerTest, RemoveAll) { 497 TEST_F(MenuManagerTest, RemoveAll) {
495 // Try removing all items for an extension id that doesn't have any items. 498 // Try removing all items for an extension id that doesn't have any items.
496 manager_.RemoveAllContextItems(MenuItem::ExtensionKey("CCCC")); 499 manager_.RemoveAllContextItems(MenuItem::ExtensionKey("CCCC"));
497 500
498 // Add 2 top-level and one child item for extension 1. 501 // Add 2 top-level and one child item for extension 1.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 EXPECT_EQ(4u, manager_.MenuItems(key1)->size()); 748 EXPECT_EQ(4u, manager_.MenuItems(key1)->size());
746 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); 749 EXPECT_EQ(1u, manager_.MenuItems(key2)->size());
747 750
748 // Remove all context menu items with incognito true. 751 // Remove all context menu items with incognito true.
749 manager_.RemoveAllIncognitoContextItems(); 752 manager_.RemoveAllIncognitoContextItems();
750 EXPECT_EQ(2u, manager_.MenuItems(key1)->size()); 753 EXPECT_EQ(2u, manager_.MenuItems(key1)->size());
751 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); 754 EXPECT_EQ(1u, manager_.MenuItems(key2)->size());
752 } 755 }
753 756
754 } // namespace extensions 757 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager_factory.cc ('k') | chrome/browser/extensions/navigation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698