| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/storage/storage_frontend.h" | 5 #include "extensions/browser/api/storage/storage_frontend.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/run_loop.h" | |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/test/test_browser_context.h" | 14 #include "content/public/test/test_browser_context.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "content/public/test/test_utils.h" |
| 17 #include "extensions/browser/api/extensions_api_client.h" | 17 #include "extensions/browser/api/extensions_api_client.h" |
| 18 #include "extensions/browser/api/storage/settings_namespace.h" | 18 #include "extensions/browser/api/storage/settings_namespace.h" |
| 19 #include "extensions/browser/api/storage/settings_test_util.h" | 19 #include "extensions/browser/api/storage/settings_test_util.h" |
| 20 #include "extensions/browser/extensions_test.h" | 20 #include "extensions/browser/extensions_test.h" |
| 21 #include "extensions/browser/value_store/value_store.h" | 21 #include "extensions/browser/value_store/value_store.h" |
| 22 #include "extensions/browser/value_store/value_store_factory_impl.h" | 22 #include "extensions/browser/value_store/value_store_factory_impl.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 void SetUp() override { | 45 void SetUp() override { |
| 46 ExtensionsTest::SetUp(); | 46 ExtensionsTest::SetUp(); |
| 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 48 storage_factory_ = new ValueStoreFactoryImpl(temp_dir_.GetPath()); | 48 storage_factory_ = new ValueStoreFactoryImpl(temp_dir_.GetPath()); |
| 49 ResetFrontend(); | 49 ResetFrontend(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TearDown() override { | 52 void TearDown() override { |
| 53 frontend_.reset(); | 53 frontend_.reset(); |
| 54 // Execute any pending deletion tasks. | 54 // Execute any pending deletion tasks. |
| 55 base::RunLoop().RunUntilIdle(); | 55 content::RunAllBlockingPoolTasksUntilIdle(); |
| 56 ExtensionsTest::TearDown(); | 56 ExtensionsTest::TearDown(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 void ResetFrontend() { | 60 void ResetFrontend() { |
| 61 frontend_ = | 61 frontend_ = |
| 62 StorageFrontend::CreateForTesting(storage_factory_, browser_context()); | 62 StorageFrontend::CreateForTesting(storage_factory_, browser_context()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 base::ScopedTempDir temp_dir_; | 65 base::ScopedTempDir temp_dir_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 util::GetStorage(extension, settings::LOCAL, frontend_.get()); | 126 util::GetStorage(extension, settings::LOCAL, frontend_.get()); |
| 127 | 127 |
| 128 { | 128 { |
| 129 base::Value bar("bar"); | 129 base::Value bar("bar"); |
| 130 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 130 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
| 131 ASSERT_TRUE(result->status().ok()); | 131 ASSERT_TRUE(result->status().ok()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // This would be triggered by extension uninstall via a DataDeleter. | 134 // This would be triggered by extension uninstall via a DataDeleter. |
| 135 frontend_->DeleteStorageSoon(id); | 135 frontend_->DeleteStorageSoon(id); |
| 136 base::RunLoop().RunUntilIdle(); | 136 content::RunAllBlockingPoolTasksUntilIdle(); |
| 137 | 137 |
| 138 // The storage area may no longer be valid post-uninstall, so re-request. | 138 // The storage area may no longer be valid post-uninstall, so re-request. |
| 139 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get()); | 139 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get()); |
| 140 { | 140 { |
| 141 ValueStore::ReadResult result = storage->Get(); | 141 ValueStore::ReadResult result = storage->Get(); |
| 142 ASSERT_TRUE(result->status().ok()); | 142 ASSERT_TRUE(result->status().ok()); |
| 143 EXPECT_TRUE(result->settings().empty()); | 143 EXPECT_TRUE(result->settings().empty()); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 161 | 161 |
| 162 // Should need to both clear the database and delete the frontend for the | 162 // Should need to both clear the database and delete the frontend for the |
| 163 // leveldb database to be deleted from disk. | 163 // leveldb database to be deleted from disk. |
| 164 { | 164 { |
| 165 ValueStore::WriteResult result = storage->Clear(); | 165 ValueStore::WriteResult result = storage->Clear(); |
| 166 ASSERT_TRUE(result->status().ok()); | 166 ASSERT_TRUE(result->status().ok()); |
| 167 EXPECT_TRUE(base::PathExists(temp_dir_.GetPath())); | 167 EXPECT_TRUE(base::PathExists(temp_dir_.GetPath())); |
| 168 } | 168 } |
| 169 | 169 |
| 170 frontend_.reset(); | 170 frontend_.reset(); |
| 171 base::RunLoop().RunUntilIdle(); | 171 content::RunAllBlockingPoolTasksUntilIdle(); |
| 172 // TODO(kalman): Figure out why this fails, despite appearing to work. | 172 // TODO(kalman): Figure out why this fails, despite appearing to work. |
| 173 // Leaving this commented out rather than disabling the whole test so that the | 173 // Leaving this commented out rather than disabling the whole test so that the |
| 174 // deletion code paths are at least exercised. | 174 // deletion code paths are at least exercised. |
| 175 // EXPECT_FALSE(base::PathExists(temp_dir_.GetPath())); | 175 // EXPECT_FALSE(base::PathExists(temp_dir_.GetPath())); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Disabled (slow), http://crbug.com/322751 . | 178 // Disabled (slow), http://crbug.com/322751 . |
| 179 TEST_F(ExtensionSettingsFrontendTest, | 179 TEST_F(ExtensionSettingsFrontendTest, |
| 180 DISABLED_QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { | 180 DISABLED_QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { |
| 181 const std::string id = "ext"; | 181 const std::string id = "ext"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 208 std::unique_ptr<base::Value> megabyte = util::CreateMegabyte(); | 208 std::unique_ptr<base::Value> megabyte = util::CreateMegabyte(); |
| 209 for (int i = 0; i < 5; ++i) { | 209 for (int i = 0; i < 5; ++i) { |
| 210 local_storage->Set(DEFAULTS, base::IntToString(i), *megabyte); | 210 local_storage->Set(DEFAULTS, base::IntToString(i), *megabyte); |
| 211 } | 211 } |
| 212 | 212 |
| 213 EXPECT_FALSE( | 213 EXPECT_FALSE( |
| 214 local_storage->Set(DEFAULTS, "WillError", *megabyte)->status().ok()); | 214 local_storage->Set(DEFAULTS, "WillError", *megabyte)->status().ok()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace extensions | 217 } // namespace extensions |
| OLD | NEW |