OLD | NEW |
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 <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
11 #include "components/pref_registry/testing_pref_service_syncable.h" | 13 #include "components/pref_registry/testing_pref_service_syncable.h" |
12 #include "components/prefs/testing_pref_service.h" | 14 #include "components/prefs/testing_pref_service.h" |
13 #include "components/user_prefs/user_prefs.h" | 15 #include "components/user_prefs/user_prefs.h" |
14 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
15 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
16 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/browser/extension_registry_factory.h" | 19 #include "extensions/browser/extension_registry_factory.h" |
18 #include "extensions/browser/extensions_test.h" | 20 #include "extensions/browser/extensions_test.h" |
19 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
(...skipping 28 matching lines...) Expand all Loading... |
48 create_count_++; | 50 create_count_++; |
49 return false; | 51 return false; |
50 } | 52 } |
51 | 53 |
52 private: | 54 private: |
53 int create_count_; | 55 int create_count_; |
54 | 56 |
55 DISALLOW_COPY_AND_ASSIGN(TestProcessManager); | 57 DISALLOW_COPY_AND_ASSIGN(TestProcessManager); |
56 }; | 58 }; |
57 | 59 |
58 scoped_ptr<KeyedService> CreateTestProcessManager(BrowserContext* context) { | 60 std::unique_ptr<KeyedService> CreateTestProcessManager( |
59 return make_scoped_ptr(new TestProcessManager(context)); | 61 BrowserContext* context) { |
| 62 return base::WrapUnique(new TestProcessManager(context)); |
60 } | 63 } |
61 | 64 |
62 } // namespace | 65 } // namespace |
63 | 66 |
64 // Derives from ExtensionsTest to provide content module and keyed service | 67 // Derives from ExtensionsTest to provide content module and keyed service |
65 // initialization. | 68 // initialization. |
66 class LazyBackgroundTaskQueueTest : public ExtensionsTest { | 69 class LazyBackgroundTaskQueueTest : public ExtensionsTest { |
67 public: | 70 public: |
68 LazyBackgroundTaskQueueTest() | 71 LazyBackgroundTaskQueueTest() |
69 : notification_service_(content::NotificationService::Create()), | 72 : notification_service_(content::NotificationService::Create()), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); | 115 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); |
113 return extension; | 116 return extension; |
114 } | 117 } |
115 | 118 |
116 protected: | 119 protected: |
117 void SetUp() override { | 120 void SetUp() override { |
118 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); | 121 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); |
119 } | 122 } |
120 | 123 |
121 private: | 124 private: |
122 scoped_ptr<content::NotificationService> notification_service_; | 125 std::unique_ptr<content::NotificationService> notification_service_; |
123 | 126 |
124 user_prefs::TestingPrefServiceSyncable testing_pref_service_; | 127 user_prefs::TestingPrefServiceSyncable testing_pref_service_; |
125 | 128 |
126 // The total number of pending tasks that have been executed. | 129 // The total number of pending tasks that have been executed. |
127 int task_run_count_; | 130 int task_run_count_; |
128 | 131 |
129 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundTaskQueueTest); | 132 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundTaskQueueTest); |
130 }; | 133 }; |
131 | 134 |
132 // Tests that only extensions with background pages should have tasks queued. | 135 // Tests that only extensions with background pages should have tasks queued. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 EXPECT_EQ(1u, queue.extensions_with_pending_tasks()); | 215 EXPECT_EQ(1u, queue.extensions_with_pending_tasks()); |
213 | 216 |
214 // Processing tasks when there is one pending runs the task and removes the | 217 // Processing tasks when there is one pending runs the task and removes the |
215 // extension from the list of extensions with pending tasks. | 218 // extension from the list of extensions with pending tasks. |
216 queue.ProcessPendingTasks(NULL, browser_context(), extension.get()); | 219 queue.ProcessPendingTasks(NULL, browser_context(), extension.get()); |
217 EXPECT_EQ(1, task_run_count()); | 220 EXPECT_EQ(1, task_run_count()); |
218 EXPECT_EQ(0u, queue.extensions_with_pending_tasks()); | 221 EXPECT_EQ(0u, queue.extensions_with_pending_tasks()); |
219 } | 222 } |
220 | 223 |
221 } // namespace extensions | 224 } // namespace extensions |
OLD | NEW |