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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
11 #include "base/test/thread_test_helper.h" | 11 #include "base/test/thread_test_helper.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 17 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
18 #include "content/browser/in_process_webkit/webkit_context.h" | |
19 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
21 #include "webkit/database/database_util.h" | 20 #include "webkit/database/database_util.h" |
22 #include "webkit/quota/mock_special_storage_policy.h" | 21 #include "webkit/quota/mock_special_storage_policy.h" |
23 #include "webkit/quota/quota_manager.h" | 22 #include "webkit/quota/quota_manager.h" |
24 #include "webkit/quota/special_storage_policy.h" | 23 #include "webkit/quota/special_storage_policy.h" |
25 | 24 |
26 using content::BrowserContext; | 25 using content::BrowserContext; |
27 using content::BrowserThread; | 26 using content::BrowserThread; |
28 using quota::QuotaManager; | 27 using quota::QuotaManager; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 153 |
155 // Test our assumptions about what is protected and what is not. | 154 // Test our assumptions about what is protected and what is not. |
156 const GURL kProtectedOrigin("chrome-extension://foo/"); | 155 const GURL kProtectedOrigin("chrome-extension://foo/"); |
157 const GURL kUnprotectedOrigin("http://foo/"); | 156 const GURL kUnprotectedOrigin("http://foo/"); |
158 quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy(); | 157 quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy(); |
159 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin)); | 158 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin)); |
160 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin)); | 159 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin)); |
161 | 160 |
162 // Create some indexedDB paths. | 161 // Create some indexedDB paths. |
163 // With the levelDB backend, these are directories. | 162 // With the levelDB backend, these are directories. |
164 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); | 163 IndexedDBContextImpl* idb_context = |
165 IndexedDBContextImpl* idb_context = webkit_context->indexed_db_context(); | 164 static_cast<IndexedDBContextImpl*>( |
| 165 BrowserContext::GetIndexedDBContext(&profile)); |
166 idb_context->set_data_path_for_testing(temp_dir.path()); | 166 idb_context->set_data_path_for_testing(temp_dir.path()); |
167 protected_path = idb_context->GetFilePathForTesting( | 167 protected_path = idb_context->GetFilePathForTesting( |
168 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin)); | 168 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin)); |
169 unprotected_path = idb_context->GetFilePathForTesting( | 169 unprotected_path = idb_context->GetFilePathForTesting( |
170 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin)); | 170 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin)); |
171 ASSERT_TRUE(file_util::CreateDirectory(protected_path)); | 171 ASSERT_TRUE(file_util::CreateDirectory(protected_path)); |
172 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path)); | 172 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path)); |
173 | 173 |
174 // Setup to clear all unprotected origins on exit. | 174 // Setup to clear all unprotected origins on exit. |
175 idb_context->set_clear_local_state_on_exit(true); | 175 idb_context->set_clear_local_state_on_exit(true); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 TestingProfile profile; | 207 TestingProfile profile; |
208 | 208 |
209 const GURL kNormalOrigin("http://normal/"); | 209 const GURL kNormalOrigin("http://normal/"); |
210 const GURL kSessionOnlyOrigin("http://session-only/"); | 210 const GURL kSessionOnlyOrigin("http://session-only/"); |
211 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 211 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
212 new quota::MockSpecialStoragePolicy; | 212 new quota::MockSpecialStoragePolicy; |
213 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 213 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
214 | 214 |
215 // Create some indexedDB paths. | 215 // Create some indexedDB paths. |
216 // With the levelDB backend, these are directories. | 216 // With the levelDB backend, these are directories. |
217 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); | 217 IndexedDBContextImpl* idb_context = |
218 IndexedDBContextImpl* idb_context = webkit_context->indexed_db_context(); | 218 static_cast<IndexedDBContextImpl*>( |
| 219 BrowserContext::GetIndexedDBContext(&profile)); |
219 | 220 |
220 // Override the storage policy with our own. | 221 // Override the storage policy with our own. |
221 idb_context->special_storage_policy_ = special_storage_policy; | 222 idb_context->special_storage_policy_ = special_storage_policy; |
222 idb_context->set_data_path_for_testing(temp_dir.path()); | 223 idb_context->set_data_path_for_testing(temp_dir.path()); |
223 | 224 |
224 normal_path = idb_context->GetFilePathForTesting( | 225 normal_path = idb_context->GetFilePathForTesting( |
225 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); | 226 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); |
226 session_only_path = idb_context->GetFilePathForTesting( | 227 session_only_path = idb_context->GetFilePathForTesting( |
227 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); | 228 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); |
228 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 229 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 TestingProfile profile; | 264 TestingProfile profile; |
264 | 265 |
265 const GURL kNormalOrigin("http://normal/"); | 266 const GURL kNormalOrigin("http://normal/"); |
266 const GURL kSessionOnlyOrigin("http://session-only/"); | 267 const GURL kSessionOnlyOrigin("http://session-only/"); |
267 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 268 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
268 new quota::MockSpecialStoragePolicy; | 269 new quota::MockSpecialStoragePolicy; |
269 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 270 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
270 | 271 |
271 // Create some indexedDB paths. | 272 // Create some indexedDB paths. |
272 // With the levelDB backend, these are directories. | 273 // With the levelDB backend, these are directories. |
273 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); | 274 IndexedDBContextImpl* idb_context = |
274 IndexedDBContextImpl* idb_context = webkit_context->indexed_db_context(); | 275 static_cast<IndexedDBContextImpl*>( |
| 276 BrowserContext::GetIndexedDBContext(&profile)); |
275 | 277 |
276 // Override the storage policy with our own. | 278 // Override the storage policy with our own. |
277 idb_context->special_storage_policy_ = special_storage_policy; | 279 idb_context->special_storage_policy_ = special_storage_policy; |
278 idb_context->set_clear_local_state_on_exit(true); | 280 idb_context->set_clear_local_state_on_exit(true); |
279 idb_context->set_data_path_for_testing(temp_dir.path()); | 281 idb_context->set_data_path_for_testing(temp_dir.path()); |
280 | 282 |
281 // Save session state. This should bypass the destruction-time deletion. | 283 // Save session state. This should bypass the destruction-time deletion. |
282 idb_context->SaveSessionState(); | 284 idb_context->SaveSessionState(); |
283 | 285 |
284 normal_path = idb_context->GetFilePathForTesting( | 286 normal_path = idb_context->GetFilePathForTesting( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 virtual void SetUpCommandLine(CommandLine* command_line) { | 343 virtual void SetUpCommandLine(CommandLine* command_line) { |
342 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 344 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
343 } | 345 } |
344 }; | 346 }; |
345 | 347 |
346 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, | 348 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, |
347 DatabaseCallbacksTest) { | 349 DatabaseCallbacksTest) { |
348 SimpleTest( | 350 SimpleTest( |
349 testUrl(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html")))); | 351 testUrl(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html")))); |
350 } | 352 } |
OLD | NEW |