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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | |
11 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory
.h" | 12 #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory
.h" |
14 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 13 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
15 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 14 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
16 #include "chrome/browser/extensions/api/storage/settings_test_util.h" | 15 #include "chrome/browser/extensions/api/storage/settings_test_util.h" |
17 #include "chrome/browser/value_store/value_store.h" | 16 #include "chrome/browser/value_store/value_store.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
21 | 19 |
22 using content::BrowserThread; | 20 using content::BrowserThread; |
23 | 21 |
24 namespace extensions { | 22 namespace extensions { |
25 | 23 |
26 namespace settings = settings_namespace; | 24 namespace settings = settings_namespace; |
27 namespace util = settings_test_util; | 25 namespace util = settings_test_util; |
28 | 26 |
29 namespace { | 27 namespace { |
(...skipping 17 matching lines...) Expand all Loading... |
47 megabyte->Append(CreateKilobyte().release()); | 45 megabyte->Append(CreateKilobyte().release()); |
48 } | 46 } |
49 return scoped_ptr<Value>(megabyte); | 47 return scoped_ptr<Value>(megabyte); |
50 } | 48 } |
51 | 49 |
52 } // namespace | 50 } // namespace |
53 | 51 |
54 class ExtensionSettingsFrontendTest : public testing::Test { | 52 class ExtensionSettingsFrontendTest : public testing::Test { |
55 public: | 53 public: |
56 ExtensionSettingsFrontendTest() | 54 ExtensionSettingsFrontendTest() |
57 : storage_factory_(new util::ScopedSettingsStorageFactory()) {} | 55 : storage_factory_(new util::ScopedSettingsStorageFactory()), |
| 56 ui_thread_(BrowserThread::UI, base::MessageLoop::current()), |
| 57 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} |
58 | 58 |
59 virtual void SetUp() OVERRIDE { | 59 virtual void SetUp() OVERRIDE { |
60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
61 profile_.reset(new util::MockProfile(temp_dir_.path())); | 61 profile_.reset(new util::MockProfile(temp_dir_.path())); |
62 ResetFrontend(); | 62 ResetFrontend(); |
63 } | 63 } |
64 | 64 |
65 virtual void TearDown() OVERRIDE { | 65 virtual void TearDown() OVERRIDE { |
66 frontend_.reset(); | 66 frontend_.reset(); |
67 profile_.reset(); | 67 profile_.reset(); |
68 // Execute any pending deletion tasks. | 68 // Execute any pending deletion tasks. |
69 base::RunLoop().RunUntilIdle(); | 69 message_loop_.RunUntilIdle(); |
70 } | 70 } |
71 | 71 |
72 protected: | 72 protected: |
73 void ResetFrontend() { | 73 void ResetFrontend() { |
74 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); | 74 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); |
75 frontend_.reset( | 75 frontend_.reset( |
76 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); | 76 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); |
77 } | 77 } |
78 | 78 |
79 content::TestBrowserThreadBundle thread_bundle_; | |
80 base::ScopedTempDir temp_dir_; | 79 base::ScopedTempDir temp_dir_; |
81 scoped_ptr<util::MockProfile> profile_; | 80 scoped_ptr<util::MockProfile> profile_; |
82 scoped_ptr<SettingsFrontend> frontend_; | 81 scoped_ptr<SettingsFrontend> frontend_; |
83 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; | 82 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; |
| 83 |
| 84 private: |
| 85 base::MessageLoop message_loop_; |
| 86 content::TestBrowserThread ui_thread_; |
| 87 content::TestBrowserThread file_thread_; |
84 }; | 88 }; |
85 | 89 |
86 // Get a semblance of coverage for both extension and app settings by | 90 // Get a semblance of coverage for both extension and app settings by |
87 // alternating in each test. | 91 // alternating in each test. |
88 // TODO(kalman): explicitly test the two interact correctly. | 92 // TODO(kalman): explicitly test the two interact correctly. |
89 | 93 |
90 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { | 94 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { |
91 const std::string id = "ext"; | 95 const std::string id = "ext"; |
92 ExtensionServiceInterface* esi = | 96 ExtensionServiceInterface* esi = |
93 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 97 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ValueStore* storage = util::GetStorage(id, frontend_.get()); | 134 ValueStore* storage = util::GetStorage(id, frontend_.get()); |
131 | 135 |
132 { | 136 { |
133 StringValue bar("bar"); | 137 StringValue bar("bar"); |
134 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 138 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
135 ASSERT_FALSE(result->HasError()); | 139 ASSERT_FALSE(result->HasError()); |
136 } | 140 } |
137 | 141 |
138 // This would be triggered by extension uninstall via a DataDeleter. | 142 // This would be triggered by extension uninstall via a DataDeleter. |
139 frontend_->DeleteStorageSoon(id); | 143 frontend_->DeleteStorageSoon(id); |
140 base::RunLoop().RunUntilIdle(); | 144 base::MessageLoop::current()->RunUntilIdle(); |
141 | 145 |
142 // The storage area may no longer be valid post-uninstall, so re-request. | 146 // The storage area may no longer be valid post-uninstall, so re-request. |
143 storage = util::GetStorage(id, frontend_.get()); | 147 storage = util::GetStorage(id, frontend_.get()); |
144 { | 148 { |
145 ValueStore::ReadResult result = storage->Get(); | 149 ValueStore::ReadResult result = storage->Get(); |
146 ASSERT_FALSE(result->HasError()); | 150 ASSERT_FALSE(result->HasError()); |
147 EXPECT_TRUE(result->settings()->empty()); | 151 EXPECT_TRUE(result->settings()->empty()); |
148 } | 152 } |
149 } | 153 } |
150 | 154 |
(...skipping 15 matching lines...) Expand all Loading... |
166 | 170 |
167 // Should need to both clear the database and delete the frontend for the | 171 // Should need to both clear the database and delete the frontend for the |
168 // leveldb database to be deleted from disk. | 172 // leveldb database to be deleted from disk. |
169 { | 173 { |
170 ValueStore::WriteResult result = storage->Clear(); | 174 ValueStore::WriteResult result = storage->Clear(); |
171 ASSERT_FALSE(result->HasError()); | 175 ASSERT_FALSE(result->HasError()); |
172 EXPECT_TRUE(base::PathExists(temp_dir_.path())); | 176 EXPECT_TRUE(base::PathExists(temp_dir_.path())); |
173 } | 177 } |
174 | 178 |
175 frontend_.reset(); | 179 frontend_.reset(); |
176 base::RunLoop().RunUntilIdle(); | 180 base::MessageLoop::current()->RunUntilIdle(); |
177 // TODO(kalman): Figure out why this fails, despite appearing to work. | 181 // TODO(kalman): Figure out why this fails, despite appearing to work. |
178 // Leaving this commented out rather than disabling the whole test so that the | 182 // Leaving this commented out rather than disabling the whole test so that the |
179 // deletion code paths are at least exercised. | 183 // deletion code paths are at least exercised. |
180 //EXPECT_FALSE(base::PathExists(temp_dir_.path())); | 184 //EXPECT_FALSE(base::PathExists(temp_dir_.path())); |
181 } | 185 } |
182 | 186 |
183 TEST_F(ExtensionSettingsFrontendTest, | 187 TEST_F(ExtensionSettingsFrontendTest, |
184 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { | 188 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { |
185 const std::string id = "ext"; | 189 const std::string id = "ext"; |
186 ExtensionServiceInterface* esi = | 190 ExtensionServiceInterface* esi = |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 275 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
272 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | 276 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> |
273 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION, | 277 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION, |
274 permissions); | 278 permissions); |
275 | 279 |
276 frontend_->RunWithStorage( | 280 frontend_->RunWithStorage( |
277 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); | 281 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); |
278 frontend_->RunWithStorage( | 282 frontend_->RunWithStorage( |
279 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); | 283 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); |
280 | 284 |
281 base::RunLoop().RunUntilIdle(); | 285 base::MessageLoop::current()->RunUntilIdle(); |
282 } | 286 } |
283 | 287 |
284 } // namespace extensions | 288 } // namespace extensions |
OLD | NEW |