| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two | 28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two |
| 29 // extensions get the same installation time stamp and we can reliably | 29 // extensions get the same installation time stamp and we can reliably |
| 30 // assert the installation order in the tests below. | 30 // assert the installation order in the tests below. |
| 31 class MockExtensionPrefs : public ExtensionPrefs { | 31 class MockExtensionPrefs : public ExtensionPrefs { |
| 32 public: | 32 public: |
| 33 MockExtensionPrefs(PrefService* prefs, | 33 MockExtensionPrefs(PrefService* prefs, |
| 34 const FilePath& root_dir, | 34 const FilePath& root_dir, |
| 35 ExtensionPrefValueMap* extension_pref_value_map) | 35 ExtensionPrefValueMap* extension_pref_value_map, |
| 36 : ExtensionPrefs(prefs, root_dir, extension_pref_value_map), | 36 bool extensions_disabled) |
| 37 : ExtensionPrefs(prefs, root_dir, extension_pref_value_map, |
| 38 extensions_disabled), |
| 37 currentTime(base::Time::Now()) {} | 39 currentTime(base::Time::Now()) {} |
| 38 ~MockExtensionPrefs() {} | 40 ~MockExtensionPrefs() {} |
| 39 | 41 |
| 40 protected: | 42 protected: |
| 41 mutable base::Time currentTime; | 43 mutable base::Time currentTime; |
| 42 | 44 |
| 43 virtual base::Time GetCurrentTime() const { | 45 virtual base::Time GetCurrentTime() const { |
| 44 currentTime += base::TimeDelta::FromSeconds(10); | 46 currentTime += base::TimeDelta::FromSeconds(10); |
| 45 return currentTime; | 47 return currentTime; |
| 46 } | 48 } |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 } // namespace | 51 } // namespace |
| 50 | 52 |
| 51 TestExtensionPrefs::TestExtensionPrefs() : pref_service_(NULL) { | 53 TestExtensionPrefs::TestExtensionPrefs() |
| 54 : pref_service_(NULL), |
| 55 extensions_disabled_(false) { |
| 52 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 56 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 53 preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); | 57 preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); |
| 54 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); | 58 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); |
| 55 EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_)); | 59 EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_)); |
| 56 | 60 |
| 57 RecreateExtensionPrefs(); | 61 RecreateExtensionPrefs(); |
| 58 } | 62 } |
| 59 | 63 |
| 60 TestExtensionPrefs::~TestExtensionPrefs() {} | 64 TestExtensionPrefs::~TestExtensionPrefs() {} |
| 61 | 65 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | 88 extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
| 85 PrefServiceMockBuilder builder; | 89 PrefServiceMockBuilder builder; |
| 86 builder.WithUserFilePrefs(preferences_file_); | 90 builder.WithUserFilePrefs(preferences_file_); |
| 87 builder.WithExtensionPrefs( | 91 builder.WithExtensionPrefs( |
| 88 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); | 92 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); |
| 89 pref_service_.reset(builder.Create()); | 93 pref_service_.reset(builder.Create()); |
| 90 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); | 94 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); |
| 91 | 95 |
| 92 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), | 96 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), |
| 93 temp_dir_.path(), | 97 temp_dir_.path(), |
| 94 extension_pref_value_map_.get())); | 98 extension_pref_value_map_.get(), |
| 99 extensions_disabled_)); |
| 95 } | 100 } |
| 96 | 101 |
| 97 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { | 102 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { |
| 98 DictionaryValue dictionary; | 103 DictionaryValue dictionary; |
| 99 dictionary.SetString(extension_manifest_keys::kName, name); | 104 dictionary.SetString(extension_manifest_keys::kName, name); |
| 100 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 105 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 101 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); | 106 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); |
| 102 } | 107 } |
| 103 | 108 |
| 104 scoped_refptr<Extension> TestExtensionPrefs::AddApp(std::string name) { | 109 scoped_refptr<Extension> TestExtensionPrefs::AddApp(std::string name) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 145 |
| 141 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 146 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
| 142 scoped_refptr<Extension> extension(AddExtension(name)); | 147 scoped_refptr<Extension> extension(AddExtension(name)); |
| 143 return extension->id(); | 148 return extension->id(); |
| 144 } | 149 } |
| 145 | 150 |
| 146 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 151 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
| 147 return pref_service_->CreateIncognitoPrefService( | 152 return pref_service_->CreateIncognitoPrefService( |
| 148 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 153 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
| 149 } | 154 } |
| 155 |
| 156 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
| 157 extensions_disabled_ = extensions_disabled; |
| 158 } |
| OLD | NEW |