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

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

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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/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/menu_manager.h" 16 #include "chrome/browser/extensions/menu_manager.h"
17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/extensions/test_extension_prefs.h" 18 #include "chrome/browser/extensions/test_extension_prefs.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_constants.h" 22 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
24 #include "content/public/common/context_menu_params.h" 25 #include "content/public/common/context_menu_params.h"
25 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 using content::BrowserThread; 30 using content::BrowserThread;
30 using testing::_; 31 using testing::_;
31 using testing::AtLeast; 32 using testing::AtLeast;
32 using testing::DeleteArg; 33 using testing::DeleteArg;
33 using testing::InSequence; 34 using testing::InSequence;
34 using testing::Return; 35 using testing::Return;
35 using testing::SaveArg; 36 using testing::SaveArg;
36 37
37 namespace extensions { 38 namespace extensions {
38 39
39 // Base class for tests. 40 // Base class for tests.
40 class MenuManagerTest : public testing::Test { 41 class MenuManagerTest : public testing::Test {
41 public: 42 public:
42 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_), 43 MenuManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_),
43 file_thread_(BrowserThread::FILE, &message_loop_), 44 file_thread_(BrowserThread::FILE, &message_loop_),
44 manager_(&profile_), 45 manager_(&profile_),
45 next_id_(1) { 46 next_id_(1) {
47 prefs_.reset(new TestExtensionPrefs(message_loop_.message_loop_proxy()));
48 }
49
50 ~MenuManagerTest() {
akalin 2012/10/19 02:00:51 destructor should be virtual
zel 2012/10/19 18:45:07 Removed.
51 }
52
53 virtual void TearDown() OVERRIDE {
54 prefs_->pref_service()->CommitPendingWrite();
55 MessageLoop::current()->RunAllPending();
46 } 56 }
47 57
48 // Returns a test item. 58 // Returns a test item.
49 MenuItem* CreateTestItem(Extension* extension) { 59 MenuItem* CreateTestItem(Extension* extension) {
50 MenuItem::Type type = MenuItem::NORMAL; 60 MenuItem::Type type = MenuItem::NORMAL;
51 MenuItem::ContextList contexts(MenuItem::ALL); 61 MenuItem::ContextList contexts(MenuItem::ALL);
52 MenuItem::Id id(false, extension->id()); 62 MenuItem::Id id(false, extension->id());
53 id.uid = next_id_++; 63 id.uid = next_id_++;
54 return new MenuItem(id, "test", false, true, type, contexts); 64 return new MenuItem(id, "test", false, true, type, contexts);
55 } 65 }
56 66
57 // Returns a test item with the given string ID. 67 // Returns a test item with the given string ID.
58 MenuItem* CreateTestItemWithID(Extension* extension, 68 MenuItem* CreateTestItemWithID(Extension* extension,
59 const std::string& string_id) { 69 const std::string& string_id) {
60 MenuItem::Type type = MenuItem::NORMAL; 70 MenuItem::Type type = MenuItem::NORMAL;
61 MenuItem::ContextList contexts(MenuItem::ALL); 71 MenuItem::ContextList contexts(MenuItem::ALL);
62 MenuItem::Id id(false, extension->id()); 72 MenuItem::Id id(false, extension->id());
63 id.string_uid = string_id; 73 id.string_uid = string_id;
64 return new MenuItem(id, "test", false, true, type, contexts); 74 return new MenuItem(id, "test", false, true, type, contexts);
65 } 75 }
66 76
67 // Creates and returns a test Extension. The caller does *not* own the return 77 // Creates and returns a test Extension. The caller does *not* own the return
68 // value. 78 // value.
69 Extension* AddExtension(std::string name) { 79 Extension* AddExtension(std::string name) {
70 scoped_refptr<Extension> extension = prefs_.AddExtension(name); 80 scoped_refptr<Extension> extension = prefs_->AddExtension(name);
71 extensions_.push_back(extension); 81 extensions_.push_back(extension);
72 return extension; 82 return extension;
73 } 83 }
74 84
75 protected: 85 protected:
76 TestingProfile profile_; 86 TestingProfile profile_;
77 MessageLoopForUI message_loop_; 87 MessageLoopForUI message_loop_;
78 content::TestBrowserThread ui_thread_; 88 content::TestBrowserThread ui_thread_;
79 content::TestBrowserThread file_thread_; 89 content::TestBrowserThread file_thread_;
80 90
81 MenuManager manager_; 91 MenuManager manager_;
82 ExtensionList extensions_; 92 ExtensionList extensions_;
83 TestExtensionPrefs prefs_; 93 scoped_ptr<TestExtensionPrefs> prefs_;
akalin 2012/10/19 02:00:51 as above, don't think this needs to be a scoped_pt
zel 2012/10/19 18:45:07 Done.
84 int next_id_; 94 int next_id_;
85 95
86 private: 96 private:
87 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest); 97 DISALLOW_COPY_AND_ASSIGN(MenuManagerTest);
88 }; 98 };
89 99
90 // Tests adding, getting, and removing items. 100 // Tests adding, getting, and removing items.
91 TEST_F(MenuManagerTest, AddGetRemoveItems) { 101 TEST_F(MenuManagerTest, AddGetRemoveItems) {
92 Extension* extension = AddExtension("test"); 102 Extension* extension = AddExtension("test");
93 103
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 ASSERT_TRUE(child1->checked()); 695 ASSERT_TRUE(child1->checked());
686 696
687 // Removing |parent| should cause only |child1| to be selected. 697 // Removing |parent| should cause only |child1| to be selected.
688 manager_.RemoveContextMenuItem(parent->id()); 698 manager_.RemoveContextMenuItem(parent->id());
689 parent = NULL; 699 parent = NULL;
690 ASSERT_FALSE(new_item->checked()); 700 ASSERT_FALSE(new_item->checked());
691 ASSERT_TRUE(child1->checked()); 701 ASSERT_TRUE(child1->checked());
692 } 702 }
693 703
694 } // namespace extensions 704 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698