| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 kOriginOther("http://other"), | 40 kOriginOther("http://other"), |
| 41 usage_(0), | 41 usage_(0), |
| 42 task_runner_(new base::TestSimpleTaskRunner), | 42 task_runner_(new base::TestSimpleTaskRunner), |
| 43 weak_factory_(this) { | 43 weak_factory_(this) { |
| 44 browser_context_.reset(new TestBrowserContext()); | 44 browser_context_.reset(new TestBrowserContext()); |
| 45 | 45 |
| 46 scoped_refptr<quota::QuotaManager> quota_manager = | 46 scoped_refptr<quota::QuotaManager> quota_manager = |
| 47 new quota::MockQuotaManager( | 47 new quota::MockQuotaManager( |
| 48 false /*in_memory*/, | 48 false /*in_memory*/, |
| 49 browser_context_->GetPath(), | 49 browser_context_->GetPath(), |
| 50 base::MessageLoop::current()->message_loop_proxy().get(), | 50 base::MessageLoop::current()->message_loop_proxy(), |
| 51 base::MessageLoop::current()->message_loop_proxy().get(), | 51 base::MessageLoop::current()->message_loop_proxy(), |
| 52 browser_context_->GetSpecialStoragePolicy()); | 52 browser_context_->GetSpecialStoragePolicy()); |
| 53 | 53 |
| 54 idb_context_ = | 54 idb_context_ = |
| 55 new IndexedDBContextImpl(browser_context_->GetPath(), | 55 new IndexedDBContextImpl(browser_context_->GetPath(), |
| 56 browser_context_->GetSpecialStoragePolicy(), | 56 browser_context_->GetSpecialStoragePolicy(), |
| 57 quota_manager->proxy(), | 57 quota_manager->proxy(), |
| 58 task_runner_.get()); | 58 task_runner_); |
| 59 base::MessageLoop::current()->RunUntilIdle(); | 59 base::MessageLoop::current()->RunUntilIdle(); |
| 60 setup_temp_dir(); | 60 setup_temp_dir(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void FlushIndexedDBTaskRunner() { | 63 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } |
| 64 task_runner_->RunUntilIdle(); | |
| 65 } | |
| 66 | 64 |
| 67 void setup_temp_dir() { | 65 void setup_temp_dir() { |
| 68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 69 base::FilePath indexeddb_dir = | 67 base::FilePath indexeddb_dir = |
| 70 temp_dir_.path().Append(IndexedDBContextImpl::kIndexedDBDirectory); | 68 temp_dir_.path().Append(IndexedDBContextImpl::kIndexedDBDirectory); |
| 71 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | 69 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); |
| 72 idb_context()->set_data_path_for_testing(indexeddb_dir); | 70 idb_context()->set_data_path_for_testing(indexeddb_dir); |
| 73 } | 71 } |
| 74 | 72 |
| 75 virtual ~IndexedDBQuotaClientTest() { | 73 virtual ~IndexedDBQuotaClientTest() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 client->DeleteOriginData( | 124 client->DeleteOriginData( |
| 127 origin_url, | 125 origin_url, |
| 128 kTemp, | 126 kTemp, |
| 129 base::Bind(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, | 127 base::Bind(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, |
| 130 weak_factory_.GetWeakPtr())); | 128 weak_factory_.GetWeakPtr())); |
| 131 FlushIndexedDBTaskRunner(); | 129 FlushIndexedDBTaskRunner(); |
| 132 base::MessageLoop::current()->RunUntilIdle(); | 130 base::MessageLoop::current()->RunUntilIdle(); |
| 133 return delete_status_; | 131 return delete_status_; |
| 134 } | 132 } |
| 135 | 133 |
| 136 IndexedDBContextImpl* idb_context() { return idb_context_.get(); } | 134 IndexedDBContextImpl* idb_context() { return idb_context_; } |
| 137 | 135 |
| 138 void SetFileSizeTo(const base::FilePath& path, int size) { | 136 void SetFileSizeTo(const base::FilePath& path, int size) { |
| 139 std::string junk(size, 'a'); | 137 std::string junk(size, 'a'); |
| 140 ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size)); | 138 ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size)); |
| 141 } | 139 } |
| 142 | 140 |
| 143 void AddFakeIndexedDB(const GURL& origin, int size) { | 141 void AddFakeIndexedDB(const GURL& origin, int size) { |
| 144 base::FilePath file_path_origin = idb_context()->GetFilePathForTesting( | 142 base::FilePath file_path_origin = idb_context()->GetFilePathForTesting( |
| 145 webkit_database::GetIdentifierFromOrigin(origin)); | 143 webkit_database::GetIdentifierFromOrigin(origin)); |
| 146 if (!file_util::CreateDirectory(file_path_origin)) { | 144 if (!file_util::CreateDirectory(file_path_origin)) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); | 235 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); |
| 238 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 236 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 239 | 237 |
| 240 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); | 238 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); |
| 241 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); | 239 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); |
| 242 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); | 240 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); |
| 243 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 241 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace content | 244 } // namespace content |
| OLD | NEW |