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 "chrome/browser/extensions/test_extension_prefs.h" | 5 #include "chrome/browser/extensions/test_extension_prefs.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/json_pref_store.h" | 12 #include "base/prefs/json_pref_store.h" |
13 #include "base/prefs/pref_value_store.h" | 13 #include "base/prefs/pref_value_store.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/chrome_app_sorting.h" |
19 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 20 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
20 #include "chrome/browser/prefs/pref_service_syncable.h" | 21 #include "chrome/browser/prefs/pref_service_syncable.h" |
21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
22 #include "components/crx_file/id_util.h" | 23 #include "components/crx_file/id_util.h" |
23 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "extensions/browser/extension_pref_store.h" | 26 #include "extensions/browser/extension_pref_store.h" |
26 #include "extensions/browser/extension_pref_value_map.h" | 27 #include "extensions/browser/extension_pref_value_map.h" |
27 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
28 #include "extensions/browser/extensions_browser_client.h" | 29 #include "extensions/browser/extensions_browser_client.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 PrefServiceMockFactory factory; | 110 PrefServiceMockFactory factory; |
110 factory.SetUserPrefsFile(preferences_file_, task_runner_.get()); | 111 factory.SetUserPrefsFile(preferences_file_, task_runner_.get()); |
111 factory.set_extension_prefs( | 112 factory.set_extension_prefs( |
112 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); | 113 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); |
113 pref_service_ = factory.CreateSyncable(pref_registry_.get()).Pass(); | 114 pref_service_ = factory.CreateSyncable(pref_registry_.get()).Pass(); |
114 | 115 |
115 prefs_.reset(ExtensionPrefs::Create( | 116 prefs_.reset(ExtensionPrefs::Create( |
116 pref_service_.get(), | 117 pref_service_.get(), |
117 temp_dir_.path(), | 118 temp_dir_.path(), |
118 extension_pref_value_map_.get(), | 119 extension_pref_value_map_.get(), |
119 ExtensionsBrowserClient::Get()->CreateAppSorting(nullptr).Pass(), | |
120 extensions_disabled_, | 120 extensions_disabled_, |
121 std::vector<ExtensionPrefsObserver*>(), | 121 std::vector<ExtensionPrefsObserver*>(), |
122 // Guarantee that no two extensions get the same installation time | 122 // Guarantee that no two extensions get the same installation time |
123 // stamp and we can reliably assert the installation order in the tests. | 123 // stamp and we can reliably assert the installation order in the tests. |
124 scoped_ptr<ExtensionPrefs::TimeProvider>(new IncrementalTimeProvider()))); | 124 scoped_ptr<ExtensionPrefs::TimeProvider>(new IncrementalTimeProvider()))); |
| 125 ExtensionPrefs::SetInstanceForTesting(prefs_.get()); |
| 126 app_sorting_.reset(new ChromeAppSorting(nullptr)); |
| 127 ExtensionIdList extensions; |
| 128 prefs_->GetExtensions(&extensions); |
| 129 app_sorting_->Initialize(extensions); |
| 130 prefs_->set_app_sorting(app_sorting_.get()); |
125 } | 131 } |
126 | 132 |
127 scoped_refptr<Extension> TestExtensionPrefs::AddExtension( | 133 scoped_refptr<Extension> TestExtensionPrefs::AddExtension( |
128 const std::string& name) { | 134 const std::string& name) { |
129 base::DictionaryValue dictionary; | 135 base::DictionaryValue dictionary; |
130 dictionary.SetString(manifest_keys::kName, name); | 136 dictionary.SetString(manifest_keys::kName, name); |
131 dictionary.SetString(manifest_keys::kVersion, "0.1"); | 137 dictionary.SetString(manifest_keys::kVersion, "0.1"); |
132 return AddExtensionWithManifest(dictionary, Manifest::INTERNAL); | 138 return AddExtensionWithManifest(dictionary, Manifest::INTERNAL); |
133 } | 139 } |
134 | 140 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 192 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
187 return pref_service_->CreateIncognitoPrefService( | 193 return pref_service_->CreateIncognitoPrefService( |
188 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 194 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
189 } | 195 } |
190 | 196 |
191 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 197 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
192 extensions_disabled_ = extensions_disabled; | 198 extensions_disabled_ = extensions_disabled; |
193 } | 199 } |
194 | 200 |
195 } // namespace extensions | 201 } // namespace extensions |
OLD | NEW |