| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/test_simple_task_runner.h" | 16 #include "base/test/scoped_task_environment.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/sequenced_task_runner_handle.h" |
| 18 #include "content/browser/indexed_db/indexed_db_connection.h" | 18 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 20 #include "content/browser/indexed_db/indexed_db_data_format_version.h" | 20 #include "content/browser/indexed_db/indexed_db_data_format_version.h" |
| 21 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 21 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 22 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 22 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
| 23 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 23 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "storage/browser/test/mock_quota_manager_proxy.h" | 25 #include "storage/browser/test/mock_quota_manager_proxy.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 private: | 65 private: |
| 66 ~MockIDBFactory() override {} | 66 ~MockIDBFactory() override {} |
| 67 | 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); | 68 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 class IndexedDBFactoryTest : public testing::Test { | 73 class IndexedDBFactoryTest : public testing::Test { |
| 74 public: | 74 public: |
| 75 IndexedDBFactoryTest() |
| 76 : scoped_task_environment_( |
| 77 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 78 quota_manager_proxy_(new MockQuotaManagerProxy(nullptr, nullptr)) {} |
| 79 |
| 75 void SetUp() override { | 80 void SetUp() override { |
| 76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 81 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 77 task_runner_ = new base::TestSimpleTaskRunner(); | 82 context_ = new IndexedDBContextImpl(temp_dir_.GetPath(), |
| 78 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr); | 83 nullptr /* special_storage_policy */, |
| 79 context_ = new IndexedDBContextImpl( | 84 quota_manager_proxy_.get()); |
| 80 temp_dir_.GetPath(), nullptr /* special_storage_policy */, | 85 // Assign current task runner so that methods on factory can be invoked |
| 81 quota_manager_proxy_.get(), task_runner_.get()); | 86 // directly from test bodies. |
| 87 context_->SetTaskRunnerForTesting(base::SequencedTaskRunnerHandle::Get()); |
| 82 idb_factory_ = new MockIDBFactory(context_.get()); | 88 idb_factory_ = new MockIDBFactory(context_.get()); |
| 83 } | 89 } |
| 84 | 90 |
| 85 void TearDown() override { | 91 void TearDown() override { |
| 86 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 92 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 87 } | 93 } |
| 88 | 94 |
| 89 protected: | 95 protected: |
| 90 IndexedDBFactoryTest() {} | |
| 91 MockIDBFactory* factory() const { return idb_factory_.get(); } | 96 MockIDBFactory* factory() const { return idb_factory_.get(); } |
| 92 void clear_factory() { idb_factory_ = nullptr; } | 97 void clear_factory() { idb_factory_ = nullptr; } |
| 93 IndexedDBContextImpl* context() const { return context_.get(); } | 98 IndexedDBContextImpl* context() const { return context_.get(); } |
| 94 | 99 |
| 95 private: | 100 private: |
| 96 base::ScopedTempDir temp_dir_; | 101 base::ScopedTempDir temp_dir_; |
| 97 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 102 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 103 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
| 98 scoped_refptr<IndexedDBContextImpl> context_; | 104 scoped_refptr<IndexedDBContextImpl> context_; |
| 99 scoped_refptr<MockIDBFactory> idb_factory_; | 105 scoped_refptr<MockIDBFactory> idb_factory_; |
| 100 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | |
| 101 TestBrowserThreadBundle thread_bundle_; | 106 TestBrowserThreadBundle thread_bundle_; |
| 102 | 107 |
| 103 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest); | 108 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest); |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 TEST_F(IndexedDBFactoryTest, BackingStoreLifetime) { | 111 TEST_F(IndexedDBFactoryTest, BackingStoreLifetime) { |
| 107 const Origin origin1(GURL("http://localhost:81")); | 112 const Origin origin1(GURL("http://localhost:81")); |
| 108 const Origin origin2(GURL("http://localhost:82")); | 113 const Origin origin2(GURL("http://localhost:82")); |
| 109 | 114 |
| 110 base::ScopedTempDir temp_directory; | 115 base::ScopedTempDir temp_directory; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 236 |
| 232 DISALLOW_COPY_AND_ASSIGN(DiskFullFactory); | 237 DISALLOW_COPY_AND_ASSIGN(DiskFullFactory); |
| 233 }; | 238 }; |
| 234 | 239 |
| 235 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { | 240 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { |
| 236 public: | 241 public: |
| 237 LookingForQuotaErrorMockCallbacks() | 242 LookingForQuotaErrorMockCallbacks() |
| 238 : IndexedDBCallbacks(nullptr, | 243 : IndexedDBCallbacks(nullptr, |
| 239 url::Origin(), | 244 url::Origin(), |
| 240 nullptr, | 245 nullptr, |
| 241 base::ThreadTaskRunnerHandle::Get()), | 246 base::SequencedTaskRunnerHandle::Get()), |
| 242 error_called_(false) {} | 247 error_called_(false) {} |
| 243 void OnError(const IndexedDBDatabaseError& error) override { | 248 void OnError(const IndexedDBDatabaseError& error) override { |
| 244 error_called_ = true; | 249 error_called_ = true; |
| 245 EXPECT_EQ(blink::kWebIDBDatabaseExceptionQuotaError, error.code()); | 250 EXPECT_EQ(blink::kWebIDBDatabaseExceptionQuotaError, error.code()); |
| 246 } | 251 } |
| 247 bool error_called() const { return error_called_; } | 252 bool error_called() const { return error_called_; } |
| 248 | 253 |
| 249 private: | 254 private: |
| 250 ~LookingForQuotaErrorMockCallbacks() override {} | 255 ~LookingForQuotaErrorMockCallbacks() override {} |
| 251 bool error_called_; | 256 bool error_called_; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 SCOPED_TRACE(test.origin); | 597 SCOPED_TRACE(test.origin); |
| 593 const Origin origin(GURL(test.origin)); | 598 const Origin origin(GURL(test.origin)); |
| 594 ASSERT_EQ(kWebIDBDataLossNone, try_open(origin, test.open_version_1)); | 599 ASSERT_EQ(kWebIDBDataLossNone, try_open(origin, test.open_version_1)); |
| 595 EXPECT_EQ(test.expected_data_loss, try_open(origin, test.open_version_2)); | 600 EXPECT_EQ(test.expected_data_loss, try_open(origin, test.open_version_2)); |
| 596 } | 601 } |
| 597 } | 602 } |
| 598 | 603 |
| 599 } // namespace | 604 } // namespace |
| 600 | 605 |
| 601 } // namespace content | 606 } // namespace content |
| OLD | NEW |