OLD | NEW |
1 // Copyright (c) 2010 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/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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
(...skipping 10 matching lines...) Expand all Loading... |
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 const FilePath& root_dir_, | 31 const FilePath& root_dir_, |
32 ExtensionPrefStore* pref_store) | 32 ExtensionPrefStore* pref_store, |
33 : ExtensionPrefs(prefs, root_dir_, pref_store), | 33 ExtensionPrefStore* incognito_pref_store) |
| 34 : ExtensionPrefs(prefs, root_dir_, pref_store, incognito_pref_store), |
34 currentTime(base::Time::Now()) {} | 35 currentTime(base::Time::Now()) {} |
35 ~MockExtensionPrefs() {} | 36 ~MockExtensionPrefs() {} |
36 | 37 |
37 protected: | 38 protected: |
38 mutable base::Time currentTime; | 39 mutable base::Time currentTime; |
39 | 40 |
40 virtual base::Time GetCurrentTime() const { | 41 virtual base::Time GetCurrentTime() const { |
41 currentTime += base::TimeDelta::FromSeconds(10); | 42 currentTime += base::TimeDelta::FromSeconds(10); |
42 return currentTime; | 43 return currentTime; |
43 } | 44 } |
(...skipping 19 matching lines...) Expand all Loading... |
63 if (pref_service_.get()) { | 64 if (pref_service_.get()) { |
64 // The PrefService writes its persistent file on the file thread, so we | 65 // The PrefService writes its persistent file on the file thread, so we |
65 // need to wait for any pending I/O to complete before creating a new | 66 // need to wait for any pending I/O to complete before creating a new |
66 // PrefService. | 67 // PrefService. |
67 MessageLoop file_loop; | 68 MessageLoop file_loop; |
68 BrowserThread file_thread(BrowserThread::FILE, &file_loop); | 69 BrowserThread file_thread(BrowserThread::FILE, &file_loop); |
69 pref_service_->SavePersistentPrefs(); | 70 pref_service_->SavePersistentPrefs(); |
70 file_loop.RunAllPending(); | 71 file_loop.RunAllPending(); |
71 } | 72 } |
72 | 73 |
73 ExtensionPrefStore* pref_store = new ExtensionPrefStore; | 74 ExtensionPrefStore* pref_store = new ExtensionPrefStore(false); |
74 PrefServiceMockBuilder builder; | 75 PrefServiceMockBuilder builder; |
75 builder.WithUserFilePrefs(preferences_file_); | 76 builder.WithUserFilePrefs(preferences_file_); |
76 builder.WithExtensionPrefs(pref_store); | 77 builder.WithExtensionPrefs(pref_store); |
77 pref_service_.reset(builder.Create()); | 78 pref_service_.reset(builder.Create()); |
78 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); | 79 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); |
79 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path(), | 80 |
80 pref_store)); | 81 ExtensionPrefStore* incognito_pref_store = new ExtensionPrefStore(true); |
| 82 |
| 83 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), |
| 84 temp_dir_.path(), |
| 85 pref_store, |
| 86 incognito_pref_store)); |
81 } | 87 } |
82 | 88 |
83 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { | 89 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { |
84 DictionaryValue dictionary; | 90 DictionaryValue dictionary; |
85 dictionary.SetString(extension_manifest_keys::kName, name); | 91 dictionary.SetString(extension_manifest_keys::kName, name); |
86 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 92 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
87 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); | 93 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); |
88 } | 94 } |
89 | 95 |
90 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( | 96 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( |
(...skipping 12 matching lines...) Expand all Loading... |
103 const bool kInitialIncognitoEnabled = false; | 109 const bool kInitialIncognitoEnabled = false; |
104 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, | 110 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, |
105 kInitialIncognitoEnabled); | 111 kInitialIncognitoEnabled); |
106 return extension; | 112 return extension; |
107 } | 113 } |
108 | 114 |
109 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 115 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
110 scoped_refptr<Extension> extension(AddExtension(name)); | 116 scoped_refptr<Extension> extension(AddExtension(name)); |
111 return extension->id(); | 117 return extension->id(); |
112 } | 118 } |
OLD | NEW |