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

Side by Side Diff: extensions/browser/lazy_background_task_queue_unittest.cc

Issue 460203002: Extract a MockExtensionSystem to be used with TestExtensionsBrowserClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/browser/lazy_background_task_queue.h" 5 #include "extensions/browser/lazy_background_task_queue.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" 8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
10 #include "content/public/test/test_browser_context.h" 10 #include "content/public/test/test_browser_context.h"
11 #include "extensions/browser/extension_registry.h" 11 #include "extensions/browser/extension_registry.h"
12 #include "extensions/browser/extension_registry_factory.h" 12 #include "extensions/browser/extension_registry_factory.h"
13 #include "extensions/browser/extension_system.h" 13 #include "extensions/browser/extension_system.h"
14 #include "extensions/browser/extension_system_provider.h" 14 #include "extensions/browser/extension_system_provider.h"
15 #include "extensions/browser/extensions_test.h" 15 #include "extensions/browser/extensions_test.h"
16 #include "extensions/browser/mock_extension_system.h"
16 #include "extensions/browser/process_manager.h" 17 #include "extensions/browser/process_manager.h"
17 #include "extensions/browser/test_extensions_browser_client.h" 18 #include "extensions/browser/test_extensions_browser_client.h"
18 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_builder.h" 20 #include "extensions/common/extension_builder.h"
20 #include "extensions/common/one_shot_event.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 using content::BrowserContext; 23 using content::BrowserContext;
24 24
25 namespace extensions { 25 namespace extensions {
26 namespace { 26 namespace {
27 27
28 // A ProcessManager that doesn't create background host pages. 28 // A ProcessManager that doesn't create background host pages.
29 class TestProcessManager : public ProcessManager { 29 class TestProcessManager : public ProcessManager {
30 public: 30 public:
(...skipping 15 matching lines...) Expand all
46 return false; 46 return false;
47 } 47 }
48 48
49 private: 49 private:
50 int create_count_; 50 int create_count_;
51 51
52 DISALLOW_COPY_AND_ASSIGN(TestProcessManager); 52 DISALLOW_COPY_AND_ASSIGN(TestProcessManager);
53 }; 53 };
54 54
55 // A simple ExtensionSystem that returns a TestProcessManager. 55 // A simple ExtensionSystem that returns a TestProcessManager.
56 class MockExtensionSystem : public ExtensionSystem { 56 class MockExtensionSystemWithProcessManager : public MockExtensionSystem {
57 public: 57 public:
58 explicit MockExtensionSystem(BrowserContext* context) 58 explicit MockExtensionSystemWithProcessManager(BrowserContext* context)
59 : test_process_manager_(context) {} 59 : MockExtensionSystem(context), test_process_manager_(context) {}
60 virtual ~MockExtensionSystem() {} 60 virtual ~MockExtensionSystemWithProcessManager() {}
61 61
62 virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE {}
63 virtual ExtensionService* extension_service() OVERRIDE { return NULL; }
64 virtual RuntimeData* runtime_data() OVERRIDE { return NULL; }
65 virtual ManagementPolicy* management_policy() OVERRIDE { return NULL; }
66 virtual UserScriptMaster* user_script_master() OVERRIDE { return NULL; }
67 virtual ProcessManager* process_manager() OVERRIDE { 62 virtual ProcessManager* process_manager() OVERRIDE {
68 return &test_process_manager_; 63 return &test_process_manager_;
69 } 64 }
70 virtual StateStore* state_store() OVERRIDE { return NULL; }
71 virtual StateStore* rules_store() OVERRIDE { return NULL; }
72 virtual InfoMap* info_map() OVERRIDE { return NULL; }
73 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() OVERRIDE {
74 return NULL;
75 }
76 virtual EventRouter* event_router() OVERRIDE { return NULL; }
77 virtual ExtensionWarningService* warning_service() OVERRIDE { return NULL; }
78 virtual Blacklist* blacklist() OVERRIDE { return NULL; }
79 virtual ErrorConsole* error_console() OVERRIDE { return NULL; }
80 virtual InstallVerifier* install_verifier() OVERRIDE { return NULL; }
81 virtual QuotaService* quota_service() OVERRIDE { return NULL; }
82 virtual const OneShotEvent& ready() const OVERRIDE { return ready_; }
83 virtual ContentVerifier* content_verifier() OVERRIDE { return NULL; }
84 virtual scoped_ptr<ExtensionSet> GetDependentExtensions(
85 const Extension* extension) OVERRIDE {
86 return scoped_ptr<ExtensionSet>();
87 }
88 65
89 private: 66 private:
90 TestProcessManager test_process_manager_; 67 TestProcessManager test_process_manager_;
91 OneShotEvent ready_;
92 };
93
94 // A factory to create a MockExtensionSystem.
95 class MockExtensionSystemFactory : public ExtensionSystemProvider {
96 public:
97 MockExtensionSystemFactory()
98 : ExtensionSystemProvider(
99 "MockExtensionSystem",
100 BrowserContextDependencyManager::GetInstance()) {
101 DependsOn(ExtensionRegistryFactory::GetInstance());
102 }
103 virtual ~MockExtensionSystemFactory() {}
104
105 // BrowserContextKeyedServiceFactory overrides:
106 virtual KeyedService* BuildServiceInstanceFor(
107 BrowserContext* context) const OVERRIDE {
108 return new MockExtensionSystem(context);
109 }
110
111 // ExtensionSystemProvider overrides:
112 virtual ExtensionSystem* GetForBrowserContext(
113 BrowserContext* context) OVERRIDE {
114 return static_cast<MockExtensionSystem*>(
115 GetServiceForBrowserContext(context, true));
116 }
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
120 }; 68 };
121 69
122 } // namespace 70 } // namespace
123 71
124 // Derives from ExtensionsTest to provide content module and keyed service 72 // Derives from ExtensionsTest to provide content module and keyed service
125 // initialization. 73 // initialization.
126 class LazyBackgroundTaskQueueTest : public ExtensionsTest { 74 class LazyBackgroundTaskQueueTest : public ExtensionsTest {
127 public: 75 public:
128 LazyBackgroundTaskQueueTest() 76 LazyBackgroundTaskQueueTest()
129 : notification_service_(content::NotificationService::Create()), 77 : notification_service_(content::NotificationService::Create()),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 .Set("page", "background.html") 113 .Set("page", "background.html")
166 .SetBoolean("persistent", false))) 114 .SetBoolean("persistent", false)))
167 .SetID("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") 115 .SetID("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
168 .Build(); 116 .Build();
169 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); 117 ExtensionRegistry::Get(browser_context())->AddEnabled(extension);
170 return extension; 118 return extension;
171 } 119 }
172 120
173 private: 121 private:
174 scoped_ptr<content::NotificationService> notification_service_; 122 scoped_ptr<content::NotificationService> notification_service_;
175 MockExtensionSystemFactory extension_system_factory_; 123 MockExtensionSystemFactory<MockExtensionSystemWithProcessManager>
124 extension_system_factory_;
176 125
177 // The total number of pending tasks that have been executed. 126 // The total number of pending tasks that have been executed.
178 int task_run_count_; 127 int task_run_count_;
179 128
180 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundTaskQueueTest); 129 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundTaskQueueTest);
181 }; 130 };
182 131
183 // Tests that only extensions with background pages should have tasks queued. 132 // Tests that only extensions with background pages should have tasks queued.
184 TEST_F(LazyBackgroundTaskQueueTest, ShouldEnqueueTask) { 133 TEST_F(LazyBackgroundTaskQueueTest, ShouldEnqueueTask) {
185 LazyBackgroundTaskQueue queue(browser_context()); 134 LazyBackgroundTaskQueue queue(browser_context());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 EXPECT_EQ(1u, queue.extensions_with_pending_tasks()); 213 EXPECT_EQ(1u, queue.extensions_with_pending_tasks());
265 214
266 // Processing tasks when there is one pending runs the task and removes the 215 // Processing tasks when there is one pending runs the task and removes the
267 // extension from the list of extensions with pending tasks. 216 // extension from the list of extensions with pending tasks.
268 queue.ProcessPendingTasks(NULL, browser_context(), extension); 217 queue.ProcessPendingTasks(NULL, browser_context(), extension);
269 EXPECT_EQ(1, task_run_count()); 218 EXPECT_EQ(1, task_run_count());
270 EXPECT_EQ(0u, queue.extensions_with_pending_tasks()); 219 EXPECT_EQ(0u, queue.extensions_with_pending_tasks());
271 } 220 }
272 221
273 } // namespace extensions 222 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/mock_extension_system.h » ('j') | extensions/browser/mock_extension_system.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698