| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "content/browser/browser_thread_impl.h" | 7 #include "content/browser/browser_thread_impl.h" |
| 8 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 8 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
| 9 #include "content/public/browser/storage_partition.h" |
| 9 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
| 10 #include "content/public/test/test_browser_context.h" | 11 #include "content/public/test/test_browser_context.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" |
| 13 #include "webkit/database/database_util.h" | 14 #include "webkit/database/database_util.h" |
| 14 #include "webkit/quota/mock_special_storage_policy.h" | 15 #include "webkit/quota/mock_special_storage_policy.h" |
| 15 #include "webkit/quota/quota_manager.h" | 16 #include "webkit/quota/quota_manager.h" |
| 16 #include "webkit/quota/special_storage_policy.h" | 17 #include "webkit/quota/special_storage_policy.h" |
| 17 | 18 |
| 18 using content::BrowserContext; | 19 using content::BrowserContext; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 const GURL kNormalOrigin("http://normal/"); | 54 const GURL kNormalOrigin("http://normal/"); |
| 54 const GURL kSessionOnlyOrigin("http://session-only/"); | 55 const GURL kSessionOnlyOrigin("http://session-only/"); |
| 55 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 56 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 56 new quota::MockSpecialStoragePolicy; | 57 new quota::MockSpecialStoragePolicy; |
| 57 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 58 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
| 58 | 59 |
| 59 // Create some indexedDB paths. | 60 // Create some indexedDB paths. |
| 60 // With the levelDB backend, these are directories. | 61 // With the levelDB backend, these are directories. |
| 61 IndexedDBContextImpl* idb_context = | 62 IndexedDBContextImpl* idb_context = |
| 62 static_cast<IndexedDBContextImpl*>( | 63 static_cast<IndexedDBContextImpl*>( |
| 63 BrowserContext::GetIndexedDBContext(&browser_context)); | 64 BrowserContext::GetDefaultStoragePartition(&browser_context)-> |
| 65 GetIndexedDBContext()); |
| 64 | 66 |
| 65 // Override the storage policy with our own. | 67 // Override the storage policy with our own. |
| 66 idb_context->special_storage_policy_ = special_storage_policy; | 68 idb_context->special_storage_policy_ = special_storage_policy; |
| 67 idb_context->set_data_path_for_testing(temp_dir.path()); | 69 idb_context->set_data_path_for_testing(temp_dir.path()); |
| 68 | 70 |
| 69 normal_path = idb_context->GetFilePathForTesting( | 71 normal_path = idb_context->GetFilePathForTesting( |
| 70 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); | 72 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); |
| 71 session_only_path = idb_context->GetFilePathForTesting( | 73 session_only_path = idb_context->GetFilePathForTesting( |
| 72 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); | 74 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); |
| 73 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 75 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 const GURL kNormalOrigin("http://normal/"); | 98 const GURL kNormalOrigin("http://normal/"); |
| 97 const GURL kSessionOnlyOrigin("http://session-only/"); | 99 const GURL kSessionOnlyOrigin("http://session-only/"); |
| 98 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 100 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 99 new quota::MockSpecialStoragePolicy; | 101 new quota::MockSpecialStoragePolicy; |
| 100 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 102 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
| 101 | 103 |
| 102 // Create some indexedDB paths. | 104 // Create some indexedDB paths. |
| 103 // With the levelDB backend, these are directories. | 105 // With the levelDB backend, these are directories. |
| 104 IndexedDBContextImpl* idb_context = | 106 IndexedDBContextImpl* idb_context = |
| 105 static_cast<IndexedDBContextImpl*>( | 107 static_cast<IndexedDBContextImpl*>( |
| 106 BrowserContext::GetIndexedDBContext(&browser_context)); | 108 BrowserContext::GetDefaultStoragePartition(&browser_context)-> |
| 109 GetIndexedDBContext()); |
| 107 | 110 |
| 108 // Override the storage policy with our own. | 111 // Override the storage policy with our own. |
| 109 idb_context->special_storage_policy_ = special_storage_policy; | 112 idb_context->special_storage_policy_ = special_storage_policy; |
| 110 idb_context->set_data_path_for_testing(temp_dir.path()); | 113 idb_context->set_data_path_for_testing(temp_dir.path()); |
| 111 | 114 |
| 112 // Save session state. This should bypass the destruction-time deletion. | 115 // Save session state. This should bypass the destruction-time deletion. |
| 113 idb_context->SetForceKeepSessionState(); | 116 idb_context->SetForceKeepSessionState(); |
| 114 | 117 |
| 115 normal_path = idb_context->GetFilePathForTesting( | 118 normal_path = idb_context->GetFilePathForTesting( |
| 116 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); | 119 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 164 |
| 162 // Create the scope which will ensure we run the destructor of the webkit | 165 // Create the scope which will ensure we run the destructor of the webkit |
| 163 // context. | 166 // context. |
| 164 { | 167 { |
| 165 content::TestBrowserContext browser_context; | 168 content::TestBrowserContext browser_context; |
| 166 | 169 |
| 167 const GURL kTestOrigin("http://test/"); | 170 const GURL kTestOrigin("http://test/"); |
| 168 | 171 |
| 169 IndexedDBContextImpl* idb_context = | 172 IndexedDBContextImpl* idb_context = |
| 170 static_cast<IndexedDBContextImpl*>( | 173 static_cast<IndexedDBContextImpl*>( |
| 171 BrowserContext::GetIndexedDBContext(&browser_context)); | 174 BrowserContext::GetDefaultStoragePartition(&browser_context)-> |
| 175 GetIndexedDBContext()); |
| 172 | 176 |
| 173 idb_context->quota_manager_proxy_ = NULL; | 177 idb_context->quota_manager_proxy_ = NULL; |
| 174 idb_context->set_data_path_for_testing(temp_dir.path()); | 178 idb_context->set_data_path_for_testing(temp_dir.path()); |
| 175 | 179 |
| 176 test_path = idb_context->GetFilePathForTesting( | 180 test_path = idb_context->GetFilePathForTesting( |
| 177 DatabaseUtil::GetOriginIdentifier(kTestOrigin)); | 181 DatabaseUtil::GetOriginIdentifier(kTestOrigin)); |
| 178 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 182 ASSERT_TRUE(file_util::CreateDirectory(test_path)); |
| 179 | 183 |
| 180 const bool kExpectForceClose = true; | 184 const bool kExpectForceClose = true; |
| 181 | 185 |
| 182 MockWebIDBDatabase connection1(kExpectForceClose); | 186 MockWebIDBDatabase connection1(kExpectForceClose); |
| 183 idb_context->ConnectionOpened(kTestOrigin, &connection1); | 187 idb_context->ConnectionOpened(kTestOrigin, &connection1); |
| 184 | 188 |
| 185 MockWebIDBDatabase connection2(!kExpectForceClose); | 189 MockWebIDBDatabase connection2(!kExpectForceClose); |
| 186 idb_context->ConnectionOpened(kTestOrigin, &connection2); | 190 idb_context->ConnectionOpened(kTestOrigin, &connection2); |
| 187 idb_context->ConnectionClosed(kTestOrigin, &connection2); | 191 idb_context->ConnectionClosed(kTestOrigin, &connection2); |
| 188 | 192 |
| 189 idb_context->DeleteForOrigin(kTestOrigin); | 193 idb_context->DeleteForOrigin(kTestOrigin); |
| 190 | 194 |
| 191 message_loop_.RunAllPending(); | 195 message_loop_.RunAllPending(); |
| 192 } | 196 } |
| 193 | 197 |
| 194 // Make sure we wait until the destructor has run. | 198 // Make sure we wait until the destructor has run. |
| 195 message_loop_.RunAllPending(); | 199 message_loop_.RunAllPending(); |
| 196 | 200 |
| 197 EXPECT_FALSE(file_util::DirectoryExists(test_path)); | 201 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
| 198 } | 202 } |
| OLD | NEW |