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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return pref_service_.get(); | 77 return pref_service_.get(); |
78 } | 78 } |
79 | 79 |
80 const scoped_refptr<user_prefs::PrefRegistrySyncable>& | 80 const scoped_refptr<user_prefs::PrefRegistrySyncable>& |
81 TestExtensionPrefs::pref_registry() { | 81 TestExtensionPrefs::pref_registry() { |
82 return pref_registry_; | 82 return pref_registry_; |
83 } | 83 } |
84 | 84 |
85 void TestExtensionPrefs::ResetPrefRegistry() { | 85 void TestExtensionPrefs::ResetPrefRegistry() { |
86 pref_registry_ = new user_prefs::PrefRegistrySyncable; | 86 pref_registry_ = new user_prefs::PrefRegistrySyncable; |
87 ExtensionPrefs::RegisterUserPrefs(pref_registry_); | 87 ExtensionPrefs::RegisterUserPrefs(pref_registry_.get()); |
88 } | 88 } |
89 | 89 |
90 void TestExtensionPrefs::RecreateExtensionPrefs() { | 90 void TestExtensionPrefs::RecreateExtensionPrefs() { |
91 // We persist and reload the PrefService's PrefStores because this process | 91 // We persist and reload the PrefService's PrefStores because this process |
92 // deletes all empty dictionaries. The ExtensionPrefs implementation | 92 // deletes all empty dictionaries. The ExtensionPrefs implementation |
93 // needs to be able to handle this situation. | 93 // needs to be able to handle this situation. |
94 if (pref_service_) { | 94 if (pref_service_) { |
95 // Commit a pending write (which posts a task to task_runner_) and wait for | 95 // Commit a pending write (which posts a task to task_runner_) and wait for |
96 // it to finish. | 96 // it to finish. |
97 pref_service_->CommitPendingWrite(); | 97 pref_service_->CommitPendingWrite(); |
98 base::RunLoop run_loop; | 98 base::RunLoop run_loop; |
99 ASSERT_TRUE( | 99 ASSERT_TRUE( |
100 task_runner_->PostTaskAndReply( | 100 task_runner_->PostTaskAndReply( |
101 FROM_HERE, | 101 FROM_HERE, |
102 base::Bind(&base::DoNothing), | 102 base::Bind(&base::DoNothing), |
103 run_loop.QuitClosure())); | 103 run_loop.QuitClosure())); |
104 run_loop.Run(); | 104 run_loop.Run(); |
105 } | 105 } |
106 | 106 |
107 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | 107 extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
108 PrefServiceMockBuilder builder; | 108 PrefServiceMockBuilder builder; |
109 builder.WithUserFilePrefs(preferences_file_, task_runner_); | 109 builder.WithUserFilePrefs(preferences_file_, task_runner_.get()); |
110 builder.WithExtensionPrefs( | 110 builder.WithExtensionPrefs( |
111 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); | 111 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); |
112 pref_service_.reset(builder.CreateSyncable(pref_registry_)); | 112 pref_service_.reset(builder.CreateSyncable(pref_registry_.get())); |
113 | 113 |
114 prefs_.reset(ExtensionPrefs::Create( | 114 prefs_.reset(ExtensionPrefs::Create( |
115 pref_service_.get(), | 115 pref_service_.get(), |
116 temp_dir_.path(), | 116 temp_dir_.path(), |
117 extension_pref_value_map_.get(), | 117 extension_pref_value_map_.get(), |
118 extensions_disabled_, | 118 extensions_disabled_, |
119 // Guarantee that no two extensions get the same installation time | 119 // Guarantee that no two extensions get the same installation time |
120 // stamp and we can reliably assert the installation order in the tests. | 120 // stamp and we can reliably assert the installation order in the tests. |
121 scoped_ptr<ExtensionPrefs::TimeProvider>( | 121 scoped_ptr<ExtensionPrefs::TimeProvider>( |
122 new IncrementalTimeProvider()))); | 122 new IncrementalTimeProvider()))); |
(...skipping 26 matching lines...) Expand all Loading... |
149 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifestAndFlags( | 149 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifestAndFlags( |
150 const DictionaryValue& manifest, | 150 const DictionaryValue& manifest, |
151 Manifest::Location location, | 151 Manifest::Location location, |
152 int extra_flags) { | 152 int extra_flags) { |
153 std::string name; | 153 std::string name; |
154 EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name)); | 154 EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name)); |
155 base::FilePath path = extensions_dir_.AppendASCII(name); | 155 base::FilePath path = extensions_dir_.AppendASCII(name); |
156 std::string errors; | 156 std::string errors; |
157 scoped_refptr<Extension> extension = Extension::Create( | 157 scoped_refptr<Extension> extension = Extension::Create( |
158 path, location, manifest, extra_flags, &errors); | 158 path, location, manifest, extra_flags, &errors); |
159 EXPECT_TRUE(extension) << errors; | 159 EXPECT_TRUE(extension.get()) << errors; |
160 if (!extension) | 160 if (!extension.get()) |
161 return NULL; | 161 return NULL; |
162 | 162 |
163 EXPECT_TRUE(Extension::IdIsValid(extension->id())); | 163 EXPECT_TRUE(Extension::IdIsValid(extension->id())); |
164 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, | 164 prefs_->OnExtensionInstalled(extension.get(), |
| 165 Extension::ENABLED, |
165 syncer::StringOrdinal::CreateInitialOrdinal()); | 166 syncer::StringOrdinal::CreateInitialOrdinal()); |
166 return extension; | 167 return extension; |
167 } | 168 } |
168 | 169 |
169 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 170 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
170 scoped_refptr<Extension> extension(AddExtension(name)); | 171 scoped_refptr<Extension> extension(AddExtension(name)); |
171 return extension->id(); | 172 return extension->id(); |
172 } | 173 } |
173 | 174 |
174 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 175 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
175 return pref_service_->CreateIncognitoPrefService( | 176 return pref_service_->CreateIncognitoPrefService( |
176 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 177 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
177 } | 178 } |
178 | 179 |
179 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 180 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
180 extensions_disabled_ = extensions_disabled; | 181 extensions_disabled_ = extensions_disabled; |
181 } | 182 } |
182 | 183 |
183 } // namespace extensions | 184 } // namespace extensions |
OLD | NEW |