| 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.h" | 14 #include "content/browser/in_process_webkit/indexed_db_context.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/browser/in_process_webkit/webkit_context.h" | 16 #include "content/browser/in_process_webkit/webkit_context.h" |
| 17 #include "content/test/test_browser_context.h" | 17 #include "content/test/test_browser_context.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webkit/database/database_util.h" | 19 #include "webkit/database/database_util.h" |
| 20 | 20 |
| 21 using content::BrowserContext; |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 // Declared to shorten the line lengths. | 24 // Declared to shorten the line lengths. |
| 24 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; | 25 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; |
| 25 static const quota::StorageType kPerm = quota::kStorageTypePersistent; | 26 static const quota::StorageType kPerm = quota::kStorageTypePersistent; |
| 26 | 27 |
| 27 using namespace webkit_database; | 28 using namespace webkit_database; |
| 28 using content::BrowserThreadImpl; | 29 using content::BrowserThreadImpl; |
| 29 | 30 |
| 30 // Base class for our test fixtures. | 31 // Base class for our test fixtures. |
| 31 class IndexedDBQuotaClientTest : public testing::Test { | 32 class IndexedDBQuotaClientTest : public testing::Test { |
| 32 public: | 33 public: |
| 33 const GURL kOriginA; | 34 const GURL kOriginA; |
| 34 const GURL kOriginB; | 35 const GURL kOriginB; |
| 35 const GURL kOriginOther; | 36 const GURL kOriginOther; |
| 36 | 37 |
| 37 IndexedDBQuotaClientTest() | 38 IndexedDBQuotaClientTest() |
| 38 : kOriginA("http://host"), | 39 : kOriginA("http://host"), |
| 39 kOriginB("http://host:8000"), | 40 kOriginB("http://host:8000"), |
| 40 kOriginOther("http://other"), | 41 kOriginOther("http://other"), |
| 41 usage_(0), | 42 usage_(0), |
| 42 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 43 message_loop_(MessageLoop::TYPE_IO), | 44 message_loop_(MessageLoop::TYPE_IO), |
| 44 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), | 45 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
| 46 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 45 io_thread_(BrowserThread::IO, &message_loop_) { | 47 io_thread_(BrowserThread::IO, &message_loop_) { |
| 46 TestBrowserContext browser_context; | 48 TestBrowserContext browser_context; |
| 47 idb_context_ = browser_context.GetWebKitContext()->indexed_db_context(); | 49 idb_context_ = BrowserContext::GetWebKitContext(&browser_context)-> |
| 50 indexed_db_context(); |
| 48 setup_temp_dir(); | 51 setup_temp_dir(); |
| 49 } | 52 } |
| 50 void setup_temp_dir() { | 53 void setup_temp_dir() { |
| 51 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 52 FilePath indexeddb_dir = temp_dir_.path().Append( | 55 FilePath indexeddb_dir = temp_dir_.path().Append( |
| 53 IndexedDBContext::kIndexedDBDirectory); | 56 IndexedDBContext::kIndexedDBDirectory); |
| 54 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | 57 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); |
| 55 idb_context()->set_data_path_for_testing(indexeddb_dir); | 58 idb_context()->set_data_path_for_testing(indexeddb_dir); |
| 56 } | 59 } |
| 57 | 60 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 154 } |
| 152 | 155 |
| 153 ScopedTempDir temp_dir_; | 156 ScopedTempDir temp_dir_; |
| 154 int64 usage_; | 157 int64 usage_; |
| 155 std::set<GURL> origins_; | 158 std::set<GURL> origins_; |
| 156 quota::StorageType type_; | 159 quota::StorageType type_; |
| 157 scoped_refptr<IndexedDBContext> idb_context_; | 160 scoped_refptr<IndexedDBContext> idb_context_; |
| 158 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; | 161 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; |
| 159 MessageLoop message_loop_; | 162 MessageLoop message_loop_; |
| 160 BrowserThreadImpl webkit_thread_; | 163 BrowserThreadImpl webkit_thread_; |
| 164 BrowserThreadImpl file_thread_; |
| 161 BrowserThreadImpl io_thread_; | 165 BrowserThreadImpl io_thread_; |
| 162 quota::QuotaStatusCode delete_status_; | 166 quota::QuotaStatusCode delete_status_; |
| 163 }; | 167 }; |
| 164 | 168 |
| 165 | 169 |
| 166 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { | 170 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { |
| 167 IndexedDBQuotaClient client( | 171 IndexedDBQuotaClient client( |
| 168 base::MessageLoopProxy::current(), | 172 base::MessageLoopProxy::current(), |
| 169 idb_context()); | 173 idb_context()); |
| 170 | 174 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 AddFakeIndexedDB(kOriginA, 1000); | 236 AddFakeIndexedDB(kOriginA, 1000); |
| 233 AddFakeIndexedDB(kOriginB, 50); | 237 AddFakeIndexedDB(kOriginB, 50); |
| 234 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); | 238 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); |
| 235 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 239 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 236 | 240 |
| 237 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); | 241 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); |
| 238 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); | 242 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); |
| 239 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); | 243 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); |
| 240 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 244 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
| 241 } | 245 } |
| OLD | NEW |