Chromium Code Reviews| 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/threading/sequenced_worker_pool.h" | |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/event_names.h" | 15 #include "chrome/browser/extensions/event_names.h" |
| 15 #include "chrome/browser/extensions/event_router.h" | 16 #include "chrome/browser/extensions/event_router.h" |
| 16 #include "chrome/browser/extensions/menu_manager.h" | 17 #include "chrome/browser/extensions/menu_manager.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | |
| 17 #include "chrome/browser/extensions/test_extension_prefs.h" | 19 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.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" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 30 |
| 29 using content::BrowserThread; | 31 using content::BrowserThread; |
| 30 using testing::_; | 32 using testing::_; |
| 31 using testing::AtLeast; | 33 using testing::AtLeast; |
| 32 using testing::DeleteArg; | 34 using testing::DeleteArg; |
| 33 using testing::InSequence; | 35 using testing::InSequence; |
| 34 using testing::Return; | 36 using testing::Return; |
| 35 using testing::SaveArg; | 37 using testing::SaveArg; |
| 36 | 38 |
| 37 namespace extensions { | 39 namespace extensions { |
| 38 | 40 |
| 39 // Base class for tests. | 41 // Base class for tests. |
| 40 class MenuManagerTest : public testing::Test { | 42 class MenuManagerTest : public testing::Test { |
| 41 public: | 43 public: |
| 42 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), | 44 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
| 43 file_thread_(BrowserThread::FILE, &message_loop_), | 45 file_thread_(BrowserThread::FILE, &message_loop_), |
| 44 manager_(&profile_), | 46 manager_(&profile_), |
| 45 next_id_(1) { | 47 next_id_(1) { |
| 48 blocking_pool_ = new base::SequencedWorkerPool(1, "ExtensionTestBlocking"); | |
|
akalin
2012/10/18 23:52:24
use current loop, etc.
| |
| 49 prefs_.reset(new TestExtensionPrefs(blocking_pool_)); | |
| 50 } | |
| 51 | |
| 52 ~MenuManagerTest() { | |
| 53 blocking_pool_->Shutdown(); | |
| 54 } | |
| 55 | |
| 56 virtual void TearDown() OVERRIDE { | |
| 57 prefs_->pref_service()->CommitPendingWrite(); | |
| 58 blocking_pool_->FlushForTesting(); | |
| 59 MessageLoop::current()->RunAllPending(); | |
| 46 } | 60 } |
| 47 | 61 |
| 48 // Returns a test item. | 62 // Returns a test item. |
| 49 MenuItem* CreateTestItem(Extension* extension) { | 63 MenuItem* CreateTestItem(Extension* extension) { |
| 50 MenuItem::Type type = MenuItem::NORMAL; | 64 MenuItem::Type type = MenuItem::NORMAL; |
| 51 MenuItem::ContextList contexts(MenuItem::ALL); | 65 MenuItem::ContextList contexts(MenuItem::ALL); |
| 52 MenuItem::Id id(false, extension->id()); | 66 MenuItem::Id id(false, extension->id()); |
| 53 id.uid = next_id_++; | 67 id.uid = next_id_++; |
| 54 return new MenuItem(id, "test", false, true, type, contexts); | 68 return new MenuItem(id, "test", false, true, type, contexts); |
| 55 } | 69 } |
| 56 | 70 |
| 57 // Returns a test item with the given string ID. | 71 // Returns a test item with the given string ID. |
| 58 MenuItem* CreateTestItemWithID(Extension* extension, | 72 MenuItem* CreateTestItemWithID(Extension* extension, |
| 59 const std::string& string_id) { | 73 const std::string& string_id) { |
| 60 MenuItem::Type type = MenuItem::NORMAL; | 74 MenuItem::Type type = MenuItem::NORMAL; |
| 61 MenuItem::ContextList contexts(MenuItem::ALL); | 75 MenuItem::ContextList contexts(MenuItem::ALL); |
| 62 MenuItem::Id id(false, extension->id()); | 76 MenuItem::Id id(false, extension->id()); |
| 63 id.string_uid = string_id; | 77 id.string_uid = string_id; |
| 64 return new MenuItem(id, "test", false, true, type, contexts); | 78 return new MenuItem(id, "test", false, true, type, contexts); |
| 65 } | 79 } |
| 66 | 80 |
| 67 // Creates and returns a test Extension. The caller does *not* own the return | 81 // Creates and returns a test Extension. The caller does *not* own the return |
| 68 // value. | 82 // value. |
| 69 Extension* AddExtension(std::string name) { | 83 Extension* AddExtension(std::string name) { |
| 70 scoped_refptr<Extension> extension = prefs_.AddExtension(name); | 84 scoped_refptr<Extension> extension = prefs_->AddExtension(name); |
| 71 extensions_.push_back(extension); | 85 extensions_.push_back(extension); |
| 72 return extension; | 86 return extension; |
| 73 } | 87 } |
| 74 | 88 |
| 75 protected: | 89 protected: |
| 76 TestingProfile profile_; | 90 TestingProfile profile_; |
| 77 MessageLoopForUI message_loop_; | 91 MessageLoopForUI message_loop_; |
| 78 content::TestBrowserThread ui_thread_; | 92 content::TestBrowserThread ui_thread_; |
| 79 content::TestBrowserThread file_thread_; | 93 content::TestBrowserThread file_thread_; |
| 80 | 94 |
| 81 MenuManager manager_; | 95 MenuManager manager_; |
| 82 ExtensionList extensions_; | 96 ExtensionList extensions_; |
| 83 TestExtensionPrefs prefs_; | 97 scoped_ptr<TestExtensionPrefs> prefs_; |
| 98 // A blocking pool that we can use for file operations. | |
| 99 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | |
| 84 int next_id_; | 100 int next_id_; |
| 85 | 101 |
| 86 private: | 102 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); | 103 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); |
| 88 }; | 104 }; |
| 89 | 105 |
| 90 // Tests adding, getting, and removing items. | 106 // Tests adding, getting, and removing items. |
| 91 TEST_F(MenuManagerTest, AddGetRemoveItems) { | 107 TEST_F(MenuManagerTest, AddGetRemoveItems) { |
| 92 Extension* extension = AddExtension("test"); | 108 Extension* extension = AddExtension("test"); |
| 93 | 109 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 ASSERT_TRUE(child1->checked()); | 701 ASSERT_TRUE(child1->checked()); |
| 686 | 702 |
| 687 // Removing |parent| should cause only |child1| to be selected. | 703 // Removing |parent| should cause only |child1| to be selected. |
| 688 manager_.RemoveContextMenuItem(parent->id()); | 704 manager_.RemoveContextMenuItem(parent->id()); |
| 689 parent = NULL; | 705 parent = NULL; |
| 690 ASSERT_FALSE(new_item->checked()); | 706 ASSERT_FALSE(new_item->checked()); |
| 691 ASSERT_TRUE(child1->checked()); | 707 ASSERT_TRUE(child1->checked()); |
| 692 } | 708 } |
| 693 | 709 |
| 694 } // namespace extensions | 710 } // namespace extensions |
| OLD | NEW |