| 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_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
| 15 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" | 15 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" |
| 16 #include "content/test/test_browser_context.h" | 16 #include "content/public/test/test_browser_context.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/database/database_util.h" | 18 #include "webkit/database/database_util.h" |
| 19 | 19 |
| 20 using content::BrowserContext; | 20 using content::BrowserContext; |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 | 22 |
| 23 // Declared to shorten the line lengths. | 23 // Declared to shorten the line lengths. |
| 24 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; | 24 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; |
| 25 static const quota::StorageType kPerm = quota::kStorageTypePersistent; | 25 static const quota::StorageType kPerm = quota::kStorageTypePersistent; |
| 26 | 26 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 kOriginOther("http://other"), | 40 kOriginOther("http://other"), |
| 41 usage_(0), | 41 usage_(0), |
| 42 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 42 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 43 message_loop_(MessageLoop::TYPE_IO), | 43 message_loop_(MessageLoop::TYPE_IO), |
| 44 db_thread_(BrowserThread::DB, &message_loop_), | 44 db_thread_(BrowserThread::DB, &message_loop_), |
| 45 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), | 45 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
| 46 file_thread_(BrowserThread::FILE, &message_loop_), | 46 file_thread_(BrowserThread::FILE, &message_loop_), |
| 47 file_user_blocking_thread_( | 47 file_user_blocking_thread_( |
| 48 BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 48 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 49 io_thread_(BrowserThread::IO, &message_loop_) { | 49 io_thread_(BrowserThread::IO, &message_loop_) { |
| 50 browser_context_.reset(new TestBrowserContext()); | 50 browser_context_.reset(new content::TestBrowserContext()); |
| 51 idb_context_ = static_cast<IndexedDBContextImpl*>( | 51 idb_context_ = static_cast<IndexedDBContextImpl*>( |
| 52 BrowserContext::GetIndexedDBContext(browser_context_.get())); | 52 BrowserContext::GetIndexedDBContext(browser_context_.get())); |
| 53 message_loop_.RunAllPending(); | 53 message_loop_.RunAllPending(); |
| 54 setup_temp_dir(); | 54 setup_temp_dir(); |
| 55 } | 55 } |
| 56 void setup_temp_dir() { | 56 void setup_temp_dir() { |
| 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 58 FilePath indexeddb_dir = temp_dir_.path().Append( | 58 FilePath indexeddb_dir = temp_dir_.path().Append( |
| 59 IndexedDBContextImpl::kIndexedDBDirectory); | 59 IndexedDBContextImpl::kIndexedDBDirectory); |
| 60 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | 60 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 std::set<GURL> origins_; | 162 std::set<GURL> origins_; |
| 163 quota::StorageType type_; | 163 quota::StorageType type_; |
| 164 scoped_refptr<IndexedDBContextImpl> idb_context_; | 164 scoped_refptr<IndexedDBContextImpl> idb_context_; |
| 165 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; | 165 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; |
| 166 MessageLoop message_loop_; | 166 MessageLoop message_loop_; |
| 167 BrowserThreadImpl db_thread_; | 167 BrowserThreadImpl db_thread_; |
| 168 BrowserThreadImpl webkit_thread_; | 168 BrowserThreadImpl webkit_thread_; |
| 169 BrowserThreadImpl file_thread_; | 169 BrowserThreadImpl file_thread_; |
| 170 BrowserThreadImpl file_user_blocking_thread_; | 170 BrowserThreadImpl file_user_blocking_thread_; |
| 171 BrowserThreadImpl io_thread_; | 171 BrowserThreadImpl io_thread_; |
| 172 scoped_ptr<TestBrowserContext> browser_context_; | 172 scoped_ptr<content::TestBrowserContext> browser_context_; |
| 173 quota::QuotaStatusCode delete_status_; | 173 quota::QuotaStatusCode delete_status_; |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 | 176 |
| 177 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { | 177 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { |
| 178 IndexedDBQuotaClient client( | 178 IndexedDBQuotaClient client( |
| 179 base::MessageLoopProxy::current(), | 179 base::MessageLoopProxy::current(), |
| 180 idb_context()); | 180 idb_context()); |
| 181 | 181 |
| 182 AddFakeIndexedDB(kOriginA, 6); | 182 AddFakeIndexedDB(kOriginA, 6); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 AddFakeIndexedDB(kOriginA, 1000); | 243 AddFakeIndexedDB(kOriginA, 1000); |
| 244 AddFakeIndexedDB(kOriginB, 50); | 244 AddFakeIndexedDB(kOriginB, 50); |
| 245 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); | 245 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); |
| 246 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 246 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 247 | 247 |
| 248 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); | 248 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); |
| 249 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); | 249 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); |
| 250 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); | 250 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); |
| 251 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 251 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 252 } | 252 } |
| OLD | NEW |