| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Mock ExtensionPrefs class with artificial clock to guarantee that no two | 25 // Mock ExtensionPrefs class with artificial clock to guarantee that no two |
| 26 // extensions get the same installation time stamp and we can reliably | 26 // extensions get the same installation time stamp and we can reliably |
| 27 // assert the installation order in the tests below. | 27 // assert the installation order in the tests below. |
| 28 class MockExtensionPrefs : public ExtensionPrefs { | 28 class MockExtensionPrefs : public ExtensionPrefs { |
| 29 public: | 29 public: |
| 30 MockExtensionPrefs(PrefService* prefs, | 30 MockExtensionPrefs(PrefService* prefs, |
| 31 PrefService* incognito_prefs, |
| 31 const FilePath& root_dir_, | 32 const FilePath& root_dir_, |
| 32 ExtensionPrefStore* pref_store) | 33 ExtensionPrefStore* pref_store, |
| 33 : ExtensionPrefs(prefs, root_dir_, pref_store), | 34 ExtensionPrefStore* incognito_pref_store) |
| 35 : ExtensionPrefs(prefs, incognito_prefs, root_dir_, pref_store, |
| 36 incognito_pref_store), |
| 34 currentTime(base::Time::Now()) {} | 37 currentTime(base::Time::Now()) {} |
| 35 ~MockExtensionPrefs() {} | 38 ~MockExtensionPrefs() {} |
| 36 | 39 |
| 37 protected: | 40 protected: |
| 38 mutable base::Time currentTime; | 41 mutable base::Time currentTime; |
| 39 | 42 |
| 40 virtual base::Time GetCurrentTime() const { | 43 virtual base::Time GetCurrentTime() const { |
| 41 currentTime += base::TimeDelta::FromSeconds(10); | 44 currentTime += base::TimeDelta::FromSeconds(10); |
| 42 return currentTime; | 45 return currentTime; |
| 43 } | 46 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 69 pref_service_->SavePersistentPrefs(); | 72 pref_service_->SavePersistentPrefs(); |
| 70 file_loop.RunAllPending(); | 73 file_loop.RunAllPending(); |
| 71 } | 74 } |
| 72 | 75 |
| 73 ExtensionPrefStore* pref_store = new ExtensionPrefStore; | 76 ExtensionPrefStore* pref_store = new ExtensionPrefStore; |
| 74 PrefServiceMockBuilder builder; | 77 PrefServiceMockBuilder builder; |
| 75 builder.WithUserFilePrefs(preferences_file_); | 78 builder.WithUserFilePrefs(preferences_file_); |
| 76 builder.WithExtensionPrefs(pref_store); | 79 builder.WithExtensionPrefs(pref_store); |
| 77 pref_service_.reset(builder.Create()); | 80 pref_service_.reset(builder.Create()); |
| 78 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); | 81 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); |
| 79 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path(), | 82 |
| 80 pref_store)); | 83 ExtensionPrefStore* incognito_pref_store = new ExtensionPrefStore; |
| 84 incognito_pref_service_.reset( |
| 85 pref_service_->CreateIncognitoPrefService(incognito_pref_store)); |
| 86 |
| 87 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), |
| 88 incognito_pref_service_.get(), |
| 89 temp_dir_.path(), |
| 90 pref_store, |
| 91 incognito_pref_store)); |
| 81 } | 92 } |
| 82 | 93 |
| 83 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { | 94 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { |
| 84 DictionaryValue dictionary; | 95 DictionaryValue dictionary; |
| 85 dictionary.SetString(extension_manifest_keys::kName, name); | 96 dictionary.SetString(extension_manifest_keys::kName, name); |
| 86 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 97 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 87 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); | 98 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); |
| 88 } | 99 } |
| 89 | 100 |
| 90 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( | 101 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 const bool kInitialIncognitoEnabled = false; | 114 const bool kInitialIncognitoEnabled = false; |
| 104 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, | 115 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, |
| 105 kInitialIncognitoEnabled); | 116 kInitialIncognitoEnabled); |
| 106 return extension; | 117 return extension; |
| 107 } | 118 } |
| 108 | 119 |
| 109 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 120 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
| 110 scoped_refptr<Extension> extension(AddExtension(name)); | 121 scoped_refptr<Extension> extension(AddExtension(name)); |
| 111 return extension->id(); | 122 return extension->id(); |
| 112 } | 123 } |
| OLD | NEW |