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