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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 // A simple callback for AddPendingTask. | 76 // A simple callback for AddPendingTask. |
77 void RunPendingTask(ExtensionHost* host) { | 77 void RunPendingTask(ExtensionHost* host) { |
78 task_run_count_++; | 78 task_run_count_++; |
79 } | 79 } |
80 | 80 |
81 // Creates and registers an extension without a background page. | 81 // Creates and registers an extension without a background page. |
82 scoped_refptr<Extension> CreateSimpleExtension() { | 82 scoped_refptr<Extension> CreateSimpleExtension() { |
83 scoped_refptr<Extension> extension = | 83 scoped_refptr<Extension> extension = |
84 ExtensionBuilder() | 84 ExtensionBuilder() |
85 .SetManifest(std::move(DictionaryBuilder() | 85 .SetManifest(DictionaryBuilder() |
86 .Set("name", "No background") | 86 .Set("name", "No background") |
87 .Set("version", "1") | 87 .Set("version", "1") |
88 .Set("manifest_version", 2))) | 88 .Set("manifest_version", 2) |
| 89 .Build()) |
89 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | 90 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") |
90 .Build(); | 91 .Build(); |
91 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); | 92 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); |
92 return extension; | 93 return extension; |
93 } | 94 } |
94 | 95 |
95 // Creates and registers an extension with a lazy background page. | 96 // Creates and registers an extension with a lazy background page. |
96 scoped_refptr<Extension> CreateLazyBackgroundExtension() { | 97 scoped_refptr<Extension> CreateLazyBackgroundExtension() { |
97 scoped_refptr<Extension> extension = | 98 scoped_refptr<Extension> extension = |
98 ExtensionBuilder() | 99 ExtensionBuilder() |
99 .SetManifest(std::move( | 100 .SetManifest( |
100 DictionaryBuilder() | 101 DictionaryBuilder() |
101 .Set("name", "Lazy background") | 102 .Set("name", "Lazy background") |
102 .Set("version", "1") | 103 .Set("version", "1") |
103 .Set("manifest_version", 2) | 104 .Set("manifest_version", 2) |
104 .Set("background", | 105 .Set("background", DictionaryBuilder() |
105 std::move(DictionaryBuilder() | 106 .Set("page", "background.html") |
106 .Set("page", "background.html") | 107 .SetBoolean("persistent", false) |
107 .SetBoolean("persistent", false))))) | 108 .Build()) |
| 109 .Build()) |
108 .SetID("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") | 110 .SetID("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") |
109 .Build(); | 111 .Build(); |
110 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); | 112 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); |
111 return extension; | 113 return extension; |
112 } | 114 } |
113 | 115 |
114 protected: | 116 protected: |
115 void SetUp() override { | 117 void SetUp() override { |
116 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); | 118 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); |
117 } | 119 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 EXPECT_EQ(1u, queue.extensions_with_pending_tasks()); | 212 EXPECT_EQ(1u, queue.extensions_with_pending_tasks()); |
211 | 213 |
212 // Processing tasks when there is one pending runs the task and removes the | 214 // Processing tasks when there is one pending runs the task and removes the |
213 // extension from the list of extensions with pending tasks. | 215 // extension from the list of extensions with pending tasks. |
214 queue.ProcessPendingTasks(NULL, browser_context(), extension.get()); | 216 queue.ProcessPendingTasks(NULL, browser_context(), extension.get()); |
215 EXPECT_EQ(1, task_run_count()); | 217 EXPECT_EQ(1, task_run_count()); |
216 EXPECT_EQ(0u, queue.extensions_with_pending_tasks()); | 218 EXPECT_EQ(0u, queue.extensions_with_pending_tasks()); |
217 } | 219 } |
218 | 220 |
219 } // namespace extensions | 221 } // namespace extensions |
OLD | NEW |