| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 return scoped_ptr<Value>(megabyte); | 48 return scoped_ptr<Value>(megabyte); |
| 49 } | 49 } |
| 50 | 50 |
| 51 } | 51 } |
| 52 | 52 |
| 53 class ExtensionSettingsFrontendTest : public ExtensionTest { | 53 class ExtensionSettingsFrontendTest : public ExtensionTest { |
| 54 public: | 54 public: |
| 55 ExtensionSettingsFrontendTest() | 55 ExtensionSettingsFrontendTest() |
| 56 : storage_factory_(new util::ScopedSettingsStorageFactory()), | 56 : storage_factory_(new util::ScopedSettingsStorageFactory()), |
| 57 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 57 ui_thread_(BrowserThread::UI, base::MessageLoop::current()), |
| 58 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} | 58 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} |
| 59 | 59 |
| 60 virtual void SetUp() OVERRIDE { | 60 virtual void SetUp() OVERRIDE { |
| 61 ExtensionTest::SetUp(); | 61 ExtensionTest::SetUp(); |
| 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 63 profile_.reset(new util::MockProfile(temp_dir_.path())); | 63 profile_.reset(new util::MockProfile(temp_dir_.path())); |
| 64 ResetFrontend(); | 64 ResetFrontend(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void TearDown() OVERRIDE { | 67 virtual void TearDown() OVERRIDE { |
| 68 frontend_.reset(); | 68 frontend_.reset(); |
| 69 profile_.reset(); | 69 profile_.reset(); |
| 70 // Execute any pending deletion tasks. | 70 // Execute any pending deletion tasks. |
| 71 message_loop_.RunUntilIdle(); | 71 message_loop_.RunUntilIdle(); |
| 72 ExtensionTest::TearDown(); | 72 ExtensionTest::TearDown(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 void ResetFrontend() { | 76 void ResetFrontend() { |
| 77 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); | 77 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); |
| 78 frontend_.reset( | 78 frontend_.reset( |
| 79 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); | 79 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); |
| 80 } | 80 } |
| 81 | 81 |
| 82 base::ScopedTempDir temp_dir_; | 82 base::ScopedTempDir temp_dir_; |
| 83 scoped_ptr<util::MockProfile> profile_; | 83 scoped_ptr<util::MockProfile> profile_; |
| 84 scoped_ptr<SettingsFrontend> frontend_; | 84 scoped_ptr<SettingsFrontend> frontend_; |
| 85 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; | 85 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
| 89 content::TestBrowserThread ui_thread_; | 89 content::TestBrowserThread ui_thread_; |
| 90 content::TestBrowserThread file_thread_; | 90 content::TestBrowserThread file_thread_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // Get a semblance of coverage for both extension and app settings by | 93 // Get a semblance of coverage for both extension and app settings by |
| 94 // alternating in each test. | 94 // alternating in each test. |
| 95 // TODO(kalman): explicitly test the two interact correctly. | 95 // TODO(kalman): explicitly test the two interact correctly. |
| 96 | 96 |
| 97 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { | 97 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { |
| 98 const std::string id = "ext"; | 98 const std::string id = "ext"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ValueStore* storage = util::GetStorage(id, frontend_.get()); | 137 ValueStore* storage = util::GetStorage(id, frontend_.get()); |
| 138 | 138 |
| 139 { | 139 { |
| 140 StringValue bar("bar"); | 140 StringValue bar("bar"); |
| 141 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 141 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
| 142 ASSERT_FALSE(result->HasError()); | 142 ASSERT_FALSE(result->HasError()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // This would be triggered by extension uninstall via a DataDeleter. | 145 // This would be triggered by extension uninstall via a DataDeleter. |
| 146 frontend_->DeleteStorageSoon(id); | 146 frontend_->DeleteStorageSoon(id); |
| 147 MessageLoop::current()->RunUntilIdle(); | 147 base::MessageLoop::current()->RunUntilIdle(); |
| 148 | 148 |
| 149 // The storage area may no longer be valid post-uninstall, so re-request. | 149 // The storage area may no longer be valid post-uninstall, so re-request. |
| 150 storage = util::GetStorage(id, frontend_.get()); | 150 storage = util::GetStorage(id, frontend_.get()); |
| 151 { | 151 { |
| 152 ValueStore::ReadResult result = storage->Get(); | 152 ValueStore::ReadResult result = storage->Get(); |
| 153 ASSERT_FALSE(result->HasError()); | 153 ASSERT_FALSE(result->HasError()); |
| 154 EXPECT_TRUE(result->settings()->empty()); | 154 EXPECT_TRUE(result->settings()->empty()); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 | 173 |
| 174 // Should need to both clear the database and delete the frontend for the | 174 // Should need to both clear the database and delete the frontend for the |
| 175 // leveldb database to be deleted from disk. | 175 // leveldb database to be deleted from disk. |
| 176 { | 176 { |
| 177 ValueStore::WriteResult result = storage->Clear(); | 177 ValueStore::WriteResult result = storage->Clear(); |
| 178 ASSERT_FALSE(result->HasError()); | 178 ASSERT_FALSE(result->HasError()); |
| 179 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); | 179 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); |
| 180 } | 180 } |
| 181 | 181 |
| 182 frontend_.reset(); | 182 frontend_.reset(); |
| 183 MessageLoop::current()->RunUntilIdle(); | 183 base::MessageLoop::current()->RunUntilIdle(); |
| 184 // TODO(kalman): Figure out why this fails, despite appearing to work. | 184 // TODO(kalman): Figure out why this fails, despite appearing to work. |
| 185 // Leaving this commented out rather than disabling the whole test so that the | 185 // Leaving this commented out rather than disabling the whole test so that the |
| 186 // deletion code paths are at least exercised. | 186 // deletion code paths are at least exercised. |
| 187 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); | 187 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(ExtensionSettingsFrontendTest, | 190 TEST_F(ExtensionSettingsFrontendTest, |
| 191 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { | 191 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { |
| 192 const std::string id = "ext"; | 192 const std::string id = "ext"; |
| 193 ExtensionServiceInterface* esi = | 193 ExtensionServiceInterface* esi = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 278 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 279 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | 279 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> |
| 280 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION, | 280 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION, |
| 281 permissions); | 281 permissions); |
| 282 | 282 |
| 283 frontend_->RunWithStorage( | 283 frontend_->RunWithStorage( |
| 284 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); | 284 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); |
| 285 frontend_->RunWithStorage( | 285 frontend_->RunWithStorage( |
| 286 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); | 286 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); |
| 287 | 287 |
| 288 MessageLoop::current()->RunUntilIdle(); | 288 base::MessageLoop::current()->RunUntilIdle(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace extensions | 291 } // namespace extensions |
| OLD | NEW |