| 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/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/event_names.h" | 14 #include "chrome/browser/extensions/event_names.h" |
| 15 #include "chrome/browser/extensions/event_router.h" | 15 #include "chrome/browser/extensions/event_router.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/prefs/pref_service.h" |
| 18 #include "chrome/browser/extensions/test_extension_prefs.h" | 19 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 19 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/common/context_menu_params.h" | 27 #include "content/public/common/context_menu_params.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 using content::BrowserThread; | 32 using content::BrowserThread; |
| 32 using testing::_; | 33 using testing::_; |
| 33 using testing::AtLeast; | 34 using testing::AtLeast; |
| 34 using testing::DeleteArg; | 35 using testing::DeleteArg; |
| 35 using testing::InSequence; | 36 using testing::InSequence; |
| 36 using testing::Return; | 37 using testing::Return; |
| 37 using testing::SaveArg; | 38 using testing::SaveArg; |
| 38 | 39 |
| 39 namespace extensions { | 40 namespace extensions { |
| 40 | 41 |
| 41 // Base class for tests. | 42 // Base class for tests. |
| 42 class MenuManagerTest : public testing::Test { | 43 class MenuManagerTest : public testing::Test { |
| 43 public: | 44 public: |
| 44 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), | 45 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
| 45 file_thread_(BrowserThread::FILE, &message_loop_), | 46 file_thread_(BrowserThread::FILE, &message_loop_), |
| 46 manager_(&profile_), | 47 manager_(&profile_), |
| 48 prefs_(message_loop_.message_loop_proxy()), |
| 47 next_id_(1) { | 49 next_id_(1) { |
| 48 } | 50 } |
| 49 | 51 |
| 52 virtual void TearDown() OVERRIDE { |
| 53 prefs_.pref_service()->CommitPendingWrite(); |
| 54 message_loop_.RunUntilIdle(); |
| 55 } |
| 56 |
| 50 // Returns a test item. | 57 // Returns a test item. |
| 51 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) { | 58 MenuItem* CreateTestItem(Extension* extension, bool incognito = false) { |
| 52 MenuItem::Type type = MenuItem::NORMAL; | 59 MenuItem::Type type = MenuItem::NORMAL; |
| 53 MenuItem::ContextList contexts(MenuItem::ALL); | 60 MenuItem::ContextList contexts(MenuItem::ALL); |
| 54 MenuItem::Id id(incognito, extension->id()); | 61 MenuItem::Id id(incognito, extension->id()); |
| 55 id.uid = next_id_++; | 62 id.uid = next_id_++; |
| 56 return new MenuItem(id, "test", false, true, type, contexts); | 63 return new MenuItem(id, "test", false, true, type, contexts); |
| 57 } | 64 } |
| 58 | 65 |
| 59 // Returns a test item with the given string ID. | 66 // Returns a test item with the given string ID. |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 EXPECT_EQ(4u, manager_.MenuItems(extension1->id())->size()); | 741 EXPECT_EQ(4u, manager_.MenuItems(extension1->id())->size()); |
| 735 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 742 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 736 | 743 |
| 737 // Remove all context menu items with incognito true. | 744 // Remove all context menu items with incognito true. |
| 738 manager_.RemoveAllIncognitoContextItems(); | 745 manager_.RemoveAllIncognitoContextItems(); |
| 739 EXPECT_EQ(2u, manager_.MenuItems(extension1->id())->size()); | 746 EXPECT_EQ(2u, manager_.MenuItems(extension1->id())->size()); |
| 740 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); | 747 EXPECT_EQ(1u, manager_.MenuItems(extension2->id())->size()); |
| 741 } | 748 } |
| 742 | 749 |
| 743 } // namespace extensions | 750 } // namespace extensions |
| OLD | NEW |