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

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

Issue 250443002: Remove NOTIFICATION_EXTENSION_LOADED_DEPRECATED from MenuManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/extensions/extension_system_factory.h" 16 #include "chrome/browser/extensions/extension_system_factory.h"
17 #include "chrome/browser/extensions/menu_manager.h" 17 #include "chrome/browser/extensions/menu_manager.h"
18 #include "chrome/browser/extensions/test_extension_prefs.h" 18 #include "chrome/browser/extensions/test_extension_prefs.h"
19 #include "chrome/browser/extensions/test_extension_system.h" 19 #include "chrome/browser/extensions/test_extension_system.h"
20 #include "chrome/browser/prefs/pref_service_syncable.h" 20 #include "chrome/browser/prefs/pref_service_syncable.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/api/context_menus.h" 22 #include "chrome/common/extensions/api/context_menus.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/common/context_menu_params.h" 25 #include "content/public/common/context_menu_params.h"
26 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
27 #include "extensions/browser/event_router.h" 27 #include "extensions/browser/event_router.h"
28 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/extension_system.h" 29 #include "extensions/browser/extension_system.h"
29 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
30 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 33
33 using content::BrowserThread; 34 using content::BrowserThread;
34 using testing::_; 35 using testing::_;
35 using testing::AtLeast; 36 using testing::AtLeast;
36 using testing::DeleteArg; 37 using testing::DeleteArg;
37 using testing::InSequence; 38 using testing::InSequence;
38 using testing::Return; 39 using testing::Return;
39 using testing::SaveArg; 40 using testing::SaveArg;
40 41
41 namespace extensions { 42 namespace extensions {
42 43
43 namespace context_menus = api::context_menus; 44 namespace context_menus = api::context_menus;
44 45
45 // Base class for tests. 46 // Base class for tests.
46 class MenuManagerTest : public testing::Test { 47 class MenuManagerTest : public testing::Test {
47 public: 48 public:
48 MenuManagerTest() 49 MenuManagerTest()
49 : ui_thread_(BrowserThread::UI, &message_loop_), 50 : ui_thread_(BrowserThread::UI, &message_loop_),
50 file_thread_(BrowserThread::FILE, &message_loop_), 51 file_thread_(BrowserThread::FILE, &message_loop_),
51 manager_(&profile_, ExtensionSystem::Get(&profile_)->state_store()), 52 profile_(new TestingProfile()),
53 manager_(profile_.get(),
54 ExtensionSystem::Get(profile_.get())->state_store()),
52 prefs_(message_loop_.message_loop_proxy().get()), 55 prefs_(message_loop_.message_loop_proxy().get()),
53 next_id_(1) {} 56 next_id_(1) {}
54 57
55 virtual void TearDown() OVERRIDE { 58 virtual void TearDown() OVERRIDE {
56 prefs_.pref_service()->CommitPendingWrite(); 59 prefs_.pref_service()->CommitPendingWrite();
57 message_loop_.RunUntilIdle(); 60 message_loop_.RunUntilIdle();
58 } 61 }
59 62
60 // Returns a test item. 63 // Returns a test item.
61 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) { 64 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) {
(...skipping 21 matching lines...) Expand all
83 Extension* AddExtension(std::string name) { 86 Extension* AddExtension(std::string name) {
84 scoped_refptr<Extension> extension = prefs_.AddExtension(name); 87 scoped_refptr<Extension> extension = prefs_.AddExtension(name);
85 extensions_.push_back(extension); 88 extensions_.push_back(extension);
86 return extension.get(); 89 return extension.get();
87 } 90 }
88 91
89 protected: 92 protected:
90 base::MessageLoopForUI message_loop_; 93 base::MessageLoopForUI message_loop_;
91 content::TestBrowserThread ui_thread_; 94 content::TestBrowserThread ui_thread_;
92 content::TestBrowserThread file_thread_; 95 content::TestBrowserThread file_thread_;
93 TestingProfile profile_; 96 scoped_ptr<TestingProfile> profile_;
94 97
95 MenuManager manager_; 98 MenuManager manager_;
96 ExtensionList extensions_; 99 ExtensionList extensions_;
97 TestExtensionPrefs prefs_; 100 TestExtensionPrefs prefs_;
98 int next_id_; 101 int next_id_;
99 102
100 private: 103 private:
101 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); 104 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest);
102 }; 105 };
103 106
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id()))->size()); 435 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id()))->size());
433 436
434 // Create a menu item with a different extension id and add it to the manager. 437 // Create a menu item with a different extension id and add it to the manager.
435 Extension* extension2 = AddExtension("2222"); 438 Extension* extension2 = AddExtension("2222");
436 MenuItem* item2 = CreateTestItem(extension2); 439 MenuItem* item2 = CreateTestItem(extension2);
437 ASSERT_NE(item1->extension_id(), item2->extension_id()); 440 ASSERT_NE(item1->extension_id(), item2->extension_id());
438 ASSERT_TRUE(manager_.AddContextItem(extension2, item2)); 441 ASSERT_TRUE(manager_.AddContextItem(extension2, item2));
439 442
440 // Notify that the extension was unloaded, and make sure the right item is 443 // Notify that the extension was unloaded, and make sure the right item is
441 // gone. 444 // gone.
442 UnloadedExtensionInfo details( 445 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get());
443 extension1, UnloadedExtensionInfo::REASON_DISABLE); 446 registry->TriggerOnUnloaded(extension1,
444 notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 447 UnloadedExtensionInfo::REASON_DISABLE);
445 content::Source<Profile>(&profile_), 448
446 content::Details<UnloadedExtensionInfo>(
447 &details));
448 ASSERT_EQ(NULL, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id()))); 449 ASSERT_EQ(NULL, manager_.MenuItems(MenuItem::ExtensionKey(extension1->id())));
449 ASSERT_EQ( 450 ASSERT_EQ(
450 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension2->id()))->size()); 451 1u, manager_.MenuItems(MenuItem::ExtensionKey(extension2->id()))->size());
451 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); 452 ASSERT_TRUE(manager_.GetItemById(id1) == NULL);
452 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); 453 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL);
453 } 454 }
454 455
455 // A mock message service for tests of MenuManager::ExecuteCommand. 456 // A mock message service for tests of MenuManager::ExecuteCommand.
456 class MockEventRouter : public EventRouter { 457 class MockEventRouter : public EventRouter {
457 public: 458 public:
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 EXPECT_EQ(4u, manager_.MenuItems(key1)->size()); 759 EXPECT_EQ(4u, manager_.MenuItems(key1)->size());
759 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); 760 EXPECT_EQ(1u, manager_.MenuItems(key2)->size());
760 761
761 // Remove all context menu items with incognito true. 762 // Remove all context menu items with incognito true.
762 manager_.RemoveAllIncognitoContextItems(); 763 manager_.RemoveAllIncognitoContextItems();
763 EXPECT_EQ(2u, manager_.MenuItems(key1)->size()); 764 EXPECT_EQ(2u, manager_.MenuItems(key1)->size());
764 EXPECT_EQ(1u, manager_.MenuItems(key2)->size()); 765 EXPECT_EQ(1u, manager_.MenuItems(key2)->size());
765 } 766 }
766 767
767 } // namespace extensions 768 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698