Chromium Code Reviews| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/prefs/json_pref_store.h" | 13 #include "base/prefs/json_pref_store.h" |
| 14 #include "base/prefs/pref_service.h" | |
| 15 #include "base/prefs/pref_service_factory.h" | |
| 14 #include "base/prefs/pref_value_store.h" | 16 #include "base/prefs/pref_value_store.h" |
| 17 #include "base/prefs/testing_pref_store.h" | |
| 15 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 16 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 17 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/values.h" | 21 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/extension_pref_store.h" | 22 #include "chrome/browser/extensions/extension_pref_store.h" |
| 20 #include "chrome/browser/extensions/extension_pref_value_map.h" | 23 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 21 #include "chrome/browser/extensions/extension_prefs.h" | 24 #include "chrome/browser/extensions/extension_prefs.h" |
| 22 #include "chrome/browser/prefs/pref_service_mock_factory.h" | |
| 23 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 24 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "extensions/browser/extensions_browser_client.h" | 27 #include "extensions/browser/extensions_browser_client.h" |
| 27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/manifest_constants.h" | 29 #include "extensions/common/manifest_constants.h" |
| 29 #include "sync/api/string_ordinal.h" | 30 #include "sync/api/string_ordinal.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 using content::BrowserThread; | 33 using content::BrowserThread; |
| 33 | 34 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 51 } | 52 } |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(IncrementalTimeProvider); | 55 DISALLOW_COPY_AND_ASSIGN(IncrementalTimeProvider); |
| 55 | 56 |
| 56 mutable base::Time current_time_; | 57 mutable base::Time current_time_; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 61 TestExtensionPrefs::TestExtensionPrefs(base::SequencedTaskRunner* task_runner) | 62 TestExtensionPrefs::TestExtensionPrefs( |
| 62 : task_runner_(task_runner), extensions_disabled_(false) { | 63 base::SequencedTaskRunner* task_runner, |
| 64 base::PrefServiceFactory* custom_pref_service_factory) | |
| 65 : pref_service_factory_(custom_pref_service_factory ? | |
| 66 custom_pref_service_factory : | |
| 67 new base::PrefServiceFactory), | |
|
miket_OOO
2013/12/06 20:42:03
After offline discussion: it looks like you've exp
Daniel Erat
2013/12/06 20:47:55
Just to elaborate: PrefServiceMockFactory doesn't
| |
| 68 task_runner_(task_runner), | |
| 69 extensions_disabled_(false) { | |
| 63 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 70 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 64 preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); | 71 preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); |
| 65 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); | 72 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); |
| 66 EXPECT_TRUE(base::CreateDirectory(extensions_dir_)); | 73 EXPECT_TRUE(base::CreateDirectory(extensions_dir_)); |
| 67 | 74 |
| 68 ResetPrefRegistry(); | 75 ResetPrefRegistry(); |
| 69 RecreateExtensionPrefs(); | 76 RecreateExtensionPrefs(); |
| 70 } | 77 } |
| 71 | 78 |
| 72 TestExtensionPrefs::~TestExtensionPrefs() { | 79 TestExtensionPrefs::~TestExtensionPrefs() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 97 base::RunLoop run_loop; | 104 base::RunLoop run_loop; |
| 98 ASSERT_TRUE( | 105 ASSERT_TRUE( |
| 99 task_runner_->PostTaskAndReply( | 106 task_runner_->PostTaskAndReply( |
| 100 FROM_HERE, | 107 FROM_HERE, |
| 101 base::Bind(&base::DoNothing), | 108 base::Bind(&base::DoNothing), |
| 102 run_loop.QuitClosure())); | 109 run_loop.QuitClosure())); |
| 103 run_loop.Run(); | 110 run_loop.Run(); |
| 104 } | 111 } |
| 105 | 112 |
| 106 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | 113 extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
| 107 PrefServiceMockFactory factory; | 114 pref_service_factory_->SetUserPrefsFile(preferences_file_, |
| 108 factory.SetUserPrefsFile(preferences_file_, task_runner_.get()); | 115 task_runner_.get()); |
| 109 factory.set_extension_prefs( | 116 pref_service_factory_->set_user_prefs(new TestingPrefStore); |
| 117 pref_service_factory_->set_extension_prefs( | |
| 110 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); | 118 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); |
| 111 pref_service_ = factory.CreateSyncable(pref_registry_.get()).Pass(); | 119 pref_service_ = pref_service_factory_->Create(pref_registry_.get()).Pass(); |
|
Daniel Erat
2013/12/06 21:01:17
ugh, i think i see the problem. i changed this Cre
Daniel Erat
2013/12/06 21:07:43
worse than i thought: CreateSyncable also takes a
| |
| 112 | 120 |
| 113 prefs_.reset(ExtensionPrefs::Create( | 121 prefs_.reset(ExtensionPrefs::Create( |
| 114 pref_service_.get(), | 122 pref_service_.get(), |
| 115 temp_dir_.path(), | 123 temp_dir_.path(), |
| 116 extension_pref_value_map_.get(), | 124 extension_pref_value_map_.get(), |
| 117 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(), | 125 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(), |
| 118 extensions_disabled_, | 126 extensions_disabled_, |
| 119 // Guarantee that no two extensions get the same installation time | 127 // Guarantee that no two extensions get the same installation time |
| 120 // stamp and we can reliably assert the installation order in the tests. | 128 // stamp and we can reliably assert the installation order in the tests. |
| 121 scoped_ptr<ExtensionPrefs::TimeProvider>( | 129 scoped_ptr<ExtensionPrefs::TimeProvider>( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 false, | 173 false, |
| 166 syncer::StringOrdinal::CreateInitialOrdinal()); | 174 syncer::StringOrdinal::CreateInitialOrdinal()); |
| 167 return extension; | 175 return extension; |
| 168 } | 176 } |
| 169 | 177 |
| 170 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 178 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
| 171 scoped_refptr<Extension> extension(AddExtension(name)); | 179 scoped_refptr<Extension> extension(AddExtension(name)); |
| 172 return extension->id(); | 180 return extension->id(); |
| 173 } | 181 } |
| 174 | 182 |
| 175 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | |
| 176 return pref_service_->CreateIncognitoPrefService( | |
| 177 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | |
| 178 } | |
| 179 | |
| 180 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 183 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
| 181 extensions_disabled_ = extensions_disabled; | 184 extensions_disabled_ = extensions_disabled; |
| 182 } | 185 } |
| 183 | 186 |
| 184 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |