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

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

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 6 Created 8 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
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/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 29 matching lines...) Expand all
68 return extension; 69 return extension;
69 } 70 }
70 71
71 protected: 72 protected:
72 TestingProfile profile_; 73 TestingProfile profile_;
73 MessageLoopForUI message_loop_; 74 MessageLoopForUI message_loop_;
74 content::TestBrowserThread ui_thread_; 75 content::TestBrowserThread ui_thread_;
75 content::TestBrowserThread file_thread_; 76 content::TestBrowserThread file_thread_;
76 77
77 ExtensionMenuManager manager_; 78 ExtensionMenuManager manager_;
78 ExtensionList extensions_; 79 extensions::ExtensionList extensions_;
79 TestExtensionPrefs prefs_; 80 TestExtensionPrefs prefs_;
80 int next_id_; 81 int next_id_;
81 82
82 private: 83 private:
83 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest); 84 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest);
84 }; 85 };
85 86
86 // Tests adding, getting, and removing items. 87 // Tests adding, getting, and removing items.
87 TEST_F(ExtensionMenuManagerTest, AddGetRemoveItems) { 88 TEST_F(ExtensionMenuManagerTest, AddGetRemoveItems) {
88 Extension* extension = AddExtension("test"); 89 Extension* extension = AddExtension("test");
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ASSERT_EQ(1u, manager_.MenuItems(extension1->id())->size()); 351 ASSERT_EQ(1u, manager_.MenuItems(extension1->id())->size());
351 352
352 // Create a menu item with a different extension id and add it to the manager. 353 // Create a menu item with a different extension id and add it to the manager.
353 Extension* extension2 = AddExtension("2222"); 354 Extension* extension2 = AddExtension("2222");
354 ExtensionMenuItem* item2 = CreateTestItem(extension2); 355 ExtensionMenuItem* item2 = CreateTestItem(extension2);
355 ASSERT_NE(item1->extension_id(), item2->extension_id()); 356 ASSERT_NE(item1->extension_id(), item2->extension_id());
356 ASSERT_TRUE(manager_.AddContextItem(extension2, item2)); 357 ASSERT_TRUE(manager_.AddContextItem(extension2, item2));
357 358
358 // Notify that the extension was unloaded, and make sure the right item is 359 // Notify that the extension was unloaded, and make sure the right item is
359 // gone. 360 // gone.
360 UnloadedExtensionInfo details( 361 extensions::UnloadedExtensionInfo details(
361 extension1, extension_misc::UNLOAD_REASON_DISABLE); 362 extension1, extension_misc::UNLOAD_REASON_DISABLE);
362 notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED, 363 notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED,
363 content::Source<Profile>(&profile_), 364 content::Source<Profile>(&profile_),
364 content::Details<UnloadedExtensionInfo>(&details)); 365 content::Details<extensions::UnloadedExtensionInfo>(
366 &details));
365 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id())); 367 ASSERT_EQ(NULL, manager_.MenuItems(extension1->id()));
366 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size()); 368 ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size());
367 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); 369 ASSERT_TRUE(manager_.GetItemById(id1) == NULL);
368 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); 370 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL);
369 } 371 }
370 372
371 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. 373 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand.
372 class MockExtensionEventRouter : public ExtensionEventRouter { 374 class MockExtensionEventRouter : public ExtensionEventRouter {
373 public: 375 public:
374 explicit MockExtensionEventRouter(Profile* profile) : 376 explicit MockExtensionEventRouter(Profile* profile) :
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 manager_.ChangeParent(child1->id(), NULL); 608 manager_.ChangeParent(child1->id(), NULL);
607 ASSERT_TRUE(new_item->checked()); 609 ASSERT_TRUE(new_item->checked());
608 ASSERT_TRUE(child1->checked()); 610 ASSERT_TRUE(child1->checked());
609 611
610 // Removing |parent| should cause only |child1| to be selected. 612 // Removing |parent| should cause only |child1| to be selected.
611 manager_.RemoveContextMenuItem(parent->id()); 613 manager_.RemoveContextMenuItem(parent->id());
612 parent = NULL; 614 parent = NULL;
613 ASSERT_FALSE(new_item->checked()); 615 ASSERT_FALSE(new_item->checked());
614 ASSERT_TRUE(child1->checked()); 616 ASSERT_TRUE(child1->checked());
615 } 617 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager.cc ('k') | chrome/browser/extensions/extension_message_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698