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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 content::TestBrowserThread ui_thread_; | 98 content::TestBrowserThread ui_thread_; |
99 content::TestBrowserThread file_thread_; | 99 content::TestBrowserThread file_thread_; |
100 }; | 100 }; |
101 | 101 |
102 // Get a semblance of coverage for both extension and app settings by | 102 // Get a semblance of coverage for both extension and app settings by |
103 // alternating in each test. | 103 // alternating in each test. |
104 // TODO(kalman): explicitly test the two interact correctly. | 104 // TODO(kalman): explicitly test the two interact correctly. |
105 | 105 |
106 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { | 106 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { |
107 const std::string id = "ext"; | 107 const std::string id = "ext"; |
108 profile_->GetMockExtensionService()->AddExtension( | 108 profile_->GetMockExtensionService()->AddExtensionWithId( |
109 id, Extension::TYPE_EXTENSION); | 109 id, Extension::TYPE_EXTENSION); |
110 | 110 |
111 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 111 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
112 | 112 |
113 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to | 113 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to |
114 // be too rigorous. | 114 // be too rigorous. |
115 { | 115 { |
116 StringValue bar("bar"); | 116 StringValue bar("bar"); |
117 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 117 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
118 ASSERT_FALSE(result.HasError()); | 118 ASSERT_FALSE(result.HasError()); |
(...skipping 10 matching lines...) Expand all Loading... |
129 | 129 |
130 { | 130 { |
131 SettingsStorage::ReadResult result = storage->Get(); | 131 SettingsStorage::ReadResult result = storage->Get(); |
132 ASSERT_FALSE(result.HasError()); | 132 ASSERT_FALSE(result.HasError()); |
133 EXPECT_FALSE(result.settings().empty()); | 133 EXPECT_FALSE(result.settings().empty()); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { | 137 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { |
138 const std::string id = "ext"; | 138 const std::string id = "ext"; |
139 profile_->GetMockExtensionService()->AddExtension( | 139 profile_->GetMockExtensionService()->AddExtensionWithId( |
140 id, Extension::TYPE_PACKAGED_APP); | 140 id, Extension::TYPE_PACKAGED_APP); |
141 | 141 |
142 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 142 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
143 | 143 |
144 { | 144 { |
145 StringValue bar("bar"); | 145 StringValue bar("bar"); |
146 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 146 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
147 ASSERT_FALSE(result.HasError()); | 147 ASSERT_FALSE(result.HasError()); |
148 } | 148 } |
149 | 149 |
150 // This would be triggered by extension uninstall via an ExtensionDataDeleter. | 150 // This would be triggered by extension uninstall via an ExtensionDataDeleter. |
151 frontend_->DeleteStorageSoon(id); | 151 frontend_->DeleteStorageSoon(id); |
152 MessageLoop::current()->RunAllPending(); | 152 MessageLoop::current()->RunAllPending(); |
153 | 153 |
154 // The storage area may no longer be valid post-uninstall, so re-request. | 154 // The storage area may no longer be valid post-uninstall, so re-request. |
155 storage = GetStorage(id, frontend_.get()); | 155 storage = GetStorage(id, frontend_.get()); |
156 { | 156 { |
157 SettingsStorage::ReadResult result = storage->Get(); | 157 SettingsStorage::ReadResult result = storage->Get(); |
158 ASSERT_FALSE(result.HasError()); | 158 ASSERT_FALSE(result.HasError()); |
159 EXPECT_TRUE(result.settings().empty()); | 159 EXPECT_TRUE(result.settings().empty()); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { | 163 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { |
164 const std::string id = "ext"; | 164 const std::string id = "ext"; |
165 profile_->GetMockExtensionService()->AddExtension( | 165 profile_->GetMockExtensionService()->AddExtensionWithId( |
166 id, Extension::TYPE_EXTENSION); | 166 id, Extension::TYPE_EXTENSION); |
167 | 167 |
168 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 168 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
169 | 169 |
170 { | 170 { |
171 StringValue bar("bar"); | 171 StringValue bar("bar"); |
172 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 172 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
173 ASSERT_FALSE(result.HasError()); | 173 ASSERT_FALSE(result.HasError()); |
174 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); | 174 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); |
175 } | 175 } |
(...skipping 11 matching lines...) Expand all Loading... |
187 // TODO(kalman): Figure out why this fails, despite appearing to work. | 187 // TODO(kalman): Figure out why this fails, despite appearing to work. |
188 // Leaving this commented out rather than disabling the whole test so that the | 188 // Leaving this commented out rather than disabling the whole test so that the |
189 // deletion code paths are at least exercised. | 189 // deletion code paths are at least exercised. |
190 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); | 190 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); |
191 } | 191 } |
192 | 192 |
193 TEST_F(ExtensionSettingsFrontendTest, | 193 TEST_F(ExtensionSettingsFrontendTest, |
194 LeveldbCreationFailureFailsAllOperations) { | 194 LeveldbCreationFailureFailsAllOperations) { |
195 const StringValue bar("bar"); | 195 const StringValue bar("bar"); |
196 const std::string id = "ext"; | 196 const std::string id = "ext"; |
197 profile_->GetMockExtensionService()->AddExtension( | 197 profile_->GetMockExtensionService()->AddExtensionWithId( |
198 id, Extension::TYPE_EXTENSION); | 198 id, Extension::TYPE_EXTENSION); |
199 | 199 |
200 storage_factory_->Reset(new NullSettingsStorageFactory()); | 200 storage_factory_->Reset(new NullSettingsStorageFactory()); |
201 | 201 |
202 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 202 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
203 ASSERT_TRUE(storage != NULL); | 203 ASSERT_TRUE(storage != NULL); |
204 | 204 |
205 EXPECT_TRUE(storage->Get().HasError()); | 205 EXPECT_TRUE(storage->Get().HasError()); |
206 EXPECT_TRUE(storage->Clear().HasError()); | 206 EXPECT_TRUE(storage->Clear().HasError()); |
207 EXPECT_TRUE(storage->Set("foo", bar).HasError()); | 207 EXPECT_TRUE(storage->Set("foo", bar).HasError()); |
208 EXPECT_TRUE(storage->Remove("foo").HasError()); | 208 EXPECT_TRUE(storage->Remove("foo").HasError()); |
209 | 209 |
210 // For simplicity: just always fail those requests, even if the leveldb | 210 // For simplicity: just always fail those requests, even if the leveldb |
211 // storage areas start working. | 211 // storage areas start working. |
212 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); | 212 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); |
213 | 213 |
214 storage = GetStorage(id, frontend_.get()); | 214 storage = GetStorage(id, frontend_.get()); |
215 ASSERT_TRUE(storage != NULL); | 215 ASSERT_TRUE(storage != NULL); |
216 | 216 |
217 EXPECT_TRUE(storage->Get().HasError()); | 217 EXPECT_TRUE(storage->Get().HasError()); |
218 EXPECT_TRUE(storage->Clear().HasError()); | 218 EXPECT_TRUE(storage->Clear().HasError()); |
219 EXPECT_TRUE(storage->Set("foo", bar).HasError()); | 219 EXPECT_TRUE(storage->Set("foo", bar).HasError()); |
220 EXPECT_TRUE(storage->Remove("foo").HasError()); | 220 EXPECT_TRUE(storage->Remove("foo").HasError()); |
221 } | 221 } |
222 | 222 |
223 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |