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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 void SetQuota(int per_host_quota_kilobytes) { | 125 void SetQuota(int per_host_quota_kilobytes) { |
126 SetTempQuota(per_host_quota_kilobytes, | 126 SetTempQuota(per_host_quota_kilobytes, |
127 BrowserContext::GetDefaultStoragePartition( | 127 BrowserContext::GetDefaultStoragePartition( |
128 shell()->web_contents()->GetBrowserContext()) | 128 shell()->web_contents()->GetBrowserContext()) |
129 ->GetQuotaManager()); | 129 ->GetQuotaManager()); |
130 } | 130 } |
131 | 131 |
132 static void SetTempQuota(int per_host_quota_kilobytes, | 132 static void SetTempQuota(int per_host_quota_kilobytes, |
133 scoped_refptr<QuotaManager> qm) { | 133 scoped_refptr<QuotaManager> qm) { |
134 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 134 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
135 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 135 BrowserThread::PostTask( |
136 base::Bind(&IndexedDBBrowserTest::SetTempQuota, | 136 BrowserThread::IO, FROM_HERE, |
137 per_host_quota_kilobytes, qm)); | 137 base::BindOnce(&IndexedDBBrowserTest::SetTempQuota, |
| 138 per_host_quota_kilobytes, qm)); |
138 return; | 139 return; |
139 } | 140 } |
140 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 141 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
141 const int KB = 1024; | 142 const int KB = 1024; |
142 qm->SetQuotaSettings( | 143 qm->SetQuotaSettings( |
143 storage::GetHardCodedSettings(per_host_quota_kilobytes * KB)); | 144 storage::GetHardCodedSettings(per_host_quota_kilobytes * KB)); |
144 } | 145 } |
145 | 146 |
146 virtual int64_t RequestDiskUsage() { | 147 virtual int64_t RequestDiskUsage() { |
147 PostTaskAndReplyWithResult( | 148 PostTaskAndReplyWithResult( |
148 GetContext()->TaskRunner(), | 149 GetContext()->TaskRunner(), FROM_HERE, |
149 FROM_HERE, | 150 base::BindOnce(&IndexedDBContext::GetOriginDiskUsage, GetContext(), |
150 base::Bind(&IndexedDBContext::GetOriginDiskUsage, | 151 GURL("file:///")), |
151 GetContext(), | 152 base::BindOnce(&IndexedDBBrowserTest::DidGetDiskUsage, |
152 GURL("file:///")), | 153 base::Unretained(this))); |
153 base::Bind(&IndexedDBBrowserTest::DidGetDiskUsage, | |
154 base::Unretained(this))); | |
155 scoped_refptr<base::ThreadTestHelper> helper( | 154 scoped_refptr<base::ThreadTestHelper> helper( |
156 new base::ThreadTestHelper(GetContext()->TaskRunner())); | 155 new base::ThreadTestHelper(GetContext()->TaskRunner())); |
157 EXPECT_TRUE(helper->Run()); | 156 EXPECT_TRUE(helper->Run()); |
158 // Wait for DidGetDiskUsage to be called. | 157 // Wait for DidGetDiskUsage to be called. |
159 base::RunLoop().RunUntilIdle(); | 158 base::RunLoop().RunUntilIdle(); |
160 return disk_usage_; | 159 return disk_usage_; |
161 } | 160 } |
162 | 161 |
163 virtual int RequestBlobFileCount() { | 162 virtual int RequestBlobFileCount() { |
164 PostTaskAndReplyWithResult( | 163 PostTaskAndReplyWithResult( |
165 GetContext()->TaskRunner(), FROM_HERE, | 164 GetContext()->TaskRunner(), FROM_HERE, |
166 base::Bind(&IndexedDBContextImpl::GetOriginBlobFileCount, GetContext(), | 165 base::BindOnce(&IndexedDBContextImpl::GetOriginBlobFileCount, |
167 Origin(GURL("file:///"))), | 166 GetContext(), Origin(GURL("file:///"))), |
168 base::Bind(&IndexedDBBrowserTest::DidGetBlobFileCount, | 167 base::BindOnce(&IndexedDBBrowserTest::DidGetBlobFileCount, |
169 base::Unretained(this))); | 168 base::Unretained(this))); |
170 scoped_refptr<base::ThreadTestHelper> helper( | 169 scoped_refptr<base::ThreadTestHelper> helper( |
171 new base::ThreadTestHelper(GetContext()->TaskRunner())); | 170 new base::ThreadTestHelper(GetContext()->TaskRunner())); |
172 EXPECT_TRUE(helper->Run()); | 171 EXPECT_TRUE(helper->Run()); |
173 // Wait for DidGetBlobFileCount to be called. | 172 // Wait for DidGetBlobFileCount to be called. |
174 base::RunLoop().RunUntilIdle(); | 173 base::RunLoop().RunUntilIdle(); |
175 return blob_file_count_; | 174 return blob_file_count_; |
176 } | 175 } |
177 | 176 |
178 private: | 177 private: |
179 static MockBrowserTestIndexedDBClassFactory* GetTestClassFactory() { | 178 static MockBrowserTestIndexedDBClassFactory* GetTestClassFactory() { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 context->data_path(), | 322 context->data_path(), |
324 kRecursive)); | 323 kRecursive)); |
325 } | 324 } |
326 | 325 |
327 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { | 326 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { |
328 public: | 327 public: |
329 IndexedDBBrowserTestWithPreexistingLevelDB() {} | 328 IndexedDBBrowserTestWithPreexistingLevelDB() {} |
330 void SetUpOnMainThread() override { | 329 void SetUpOnMainThread() override { |
331 scoped_refptr<IndexedDBContextImpl> context = GetContext(); | 330 scoped_refptr<IndexedDBContextImpl> context = GetContext(); |
332 context->TaskRunner()->PostTask( | 331 context->TaskRunner()->PostTask( |
333 FROM_HERE, | 332 FROM_HERE, base::BindOnce(&CopyLevelDBToProfile, shell(), context, |
334 base::Bind( | 333 EnclosingLevelDBDir())); |
335 &CopyLevelDBToProfile, shell(), context, EnclosingLevelDBDir())); | |
336 scoped_refptr<base::ThreadTestHelper> helper( | 334 scoped_refptr<base::ThreadTestHelper> helper( |
337 new base::ThreadTestHelper(GetContext()->TaskRunner())); | 335 new base::ThreadTestHelper(GetContext()->TaskRunner())); |
338 ASSERT_TRUE(helper->Run()); | 336 ASSERT_TRUE(helper->Run()); |
339 } | 337 } |
340 | 338 |
341 virtual std::string EnclosingLevelDBDir() = 0; | 339 virtual std::string EnclosingLevelDBDir() = 0; |
342 | 340 |
343 private: | 341 private: |
344 DISALLOW_COPY_AND_ASSIGN(IndexedDBBrowserTestWithPreexistingLevelDB); | 342 DISALLOW_COPY_AND_ASSIGN(IndexedDBBrowserTestWithPreexistingLevelDB); |
345 }; | 343 }; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 EXPECT_GT(size, kQuotaKilobytes * 1024); | 433 EXPECT_GT(size, kQuotaKilobytes * 1024); |
436 SetQuota(kQuotaKilobytes); | 434 SetQuota(kQuotaKilobytes); |
437 SimpleTest(GetTestUrl("indexeddb", "delete_over_quota.html")); | 435 SimpleTest(GetTestUrl("indexeddb", "delete_over_quota.html")); |
438 } | 436 } |
439 | 437 |
440 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, EmptyBlob) { | 438 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, EmptyBlob) { |
441 // First delete all IDB's for the test origin | 439 // First delete all IDB's for the test origin |
442 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 440 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
443 GetContext()->TaskRunner()->PostTask( | 441 GetContext()->TaskRunner()->PostTask( |
444 FROM_HERE, | 442 FROM_HERE, |
445 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( | 443 base::BindOnce(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( |
446 &IndexedDBContextImpl::DeleteForOrigin), | 444 &IndexedDBContextImpl::DeleteForOrigin), |
447 GetContext(), GURL("file:///"))); | 445 GetContext(), GURL("file:///"))); |
448 EXPECT_EQ(0, RequestBlobFileCount()); // Start with no blob files. | 446 EXPECT_EQ(0, RequestBlobFileCount()); // Start with no blob files. |
449 const GURL test_url = GetTestUrl("indexeddb", "empty_blob.html"); | 447 const GURL test_url = GetTestUrl("indexeddb", "empty_blob.html"); |
450 // For some reason Android's futimes fails (EPERM) in this test. Do not assert | 448 // For some reason Android's futimes fails (EPERM) in this test. Do not assert |
451 // file times on Android, but do so on other platforms. crbug.com/467247 | 449 // file times on Android, but do so on other platforms. crbug.com/467247 |
452 // TODO(cmumford): Figure out why this is the case and fix if possible. | 450 // TODO(cmumford): Figure out why this is the case and fix if possible. |
453 #if defined(OS_ANDROID) | 451 #if defined(OS_ANDROID) |
454 SimpleTest(GURL(test_url.spec() + "#ignoreTimes")); | 452 SimpleTest(GURL(test_url.spec() + "#ignoreTimes")); |
455 #else | 453 #else |
456 SimpleTest(GURL(test_url.spec())); | 454 SimpleTest(GURL(test_url.spec())); |
457 #endif | 455 #endif |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 } | 487 } |
490 | 488 |
491 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DeleteForOriginDeletesBlobs) { | 489 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DeleteForOriginDeletesBlobs) { |
492 SimpleTest(GetTestUrl("indexeddb", "write_4mb_blob.html")); | 490 SimpleTest(GetTestUrl("indexeddb", "write_4mb_blob.html")); |
493 int64_t size = RequestDiskUsage(); | 491 int64_t size = RequestDiskUsage(); |
494 // This assertion assumes that we do not compress blobs. | 492 // This assertion assumes that we do not compress blobs. |
495 EXPECT_GT(size, 4 << 20 /* 4 MB */); | 493 EXPECT_GT(size, 4 << 20 /* 4 MB */); |
496 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 494 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
497 GetContext()->TaskRunner()->PostTask( | 495 GetContext()->TaskRunner()->PostTask( |
498 FROM_HERE, | 496 FROM_HERE, |
499 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( | 497 base::BindOnce(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( |
500 &IndexedDBContextImpl::DeleteForOrigin), | 498 &IndexedDBContextImpl::DeleteForOrigin), |
501 GetContext(), GURL("file:///"))); | 499 GetContext(), GURL("file:///"))); |
502 scoped_refptr<base::ThreadTestHelper> helper( | 500 scoped_refptr<base::ThreadTestHelper> helper( |
503 new base::ThreadTestHelper(GetContext()->TaskRunner())); | 501 new base::ThreadTestHelper(GetContext()->TaskRunner())); |
504 ASSERT_TRUE(helper->Run()); | 502 ASSERT_TRUE(helper->Run()); |
505 EXPECT_EQ(0, RequestDiskUsage()); | 503 EXPECT_EQ(0, RequestDiskUsage()); |
506 } | 504 } |
507 | 505 |
508 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DiskFullOnCommit) { | 506 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DiskFullOnCommit) { |
509 // Ignore several preceding transactions: | 507 // Ignore several preceding transactions: |
510 // * The test calls deleteDatabase() which opens the backing store: | 508 // * The test calls deleteDatabase() which opens the backing store: |
511 // #1: IndexedDBBackingStore::OpenBackingStore | 509 // #1: IndexedDBBackingStore::OpenBackingStore |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 request_path = request_path.substr(0, query_pos); | 604 request_path = request_path.substr(0, query_pos); |
607 } | 605 } |
608 | 606 |
609 if (request_path == "corruptdb" && !request_query.empty()) { | 607 if (request_path == "corruptdb" && !request_query.empty()) { |
610 VLOG(0) << "Requested to corrupt IndexedDB: " << request_query; | 608 VLOG(0) << "Requested to corrupt IndexedDB: " << request_query; |
611 base::WaitableEvent signal_when_finished( | 609 base::WaitableEvent signal_when_finished( |
612 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 610 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
613 base::WaitableEvent::InitialState::NOT_SIGNALED); | 611 base::WaitableEvent::InitialState::NOT_SIGNALED); |
614 context->TaskRunner()->PostTask( | 612 context->TaskRunner()->PostTask( |
615 FROM_HERE, | 613 FROM_HERE, |
616 base::Bind(&CorruptIndexedDBDatabase, base::ConstRef(context), origin, | 614 base::BindOnce(&CorruptIndexedDBDatabase, base::ConstRef(context), |
617 &signal_when_finished)); | 615 origin, &signal_when_finished)); |
618 signal_when_finished.Wait(); | 616 signal_when_finished.Wait(); |
619 | 617 |
620 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( | 618 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
621 new net::test_server::BasicHttpResponse); | 619 new net::test_server::BasicHttpResponse); |
622 http_response->set_code(net::HTTP_OK); | 620 http_response->set_code(net::HTTP_OK); |
623 return std::move(http_response); | 621 return std::move(http_response); |
624 } else if (request_path == "fail" && !request_query.empty()) { | 622 } else if (request_path == "fail" && !request_query.empty()) { |
625 FailClass failure_class = FAIL_CLASS_NOTHING; | 623 FailClass failure_class = FAIL_CLASS_NOTHING; |
626 FailMethod failure_method = FAIL_METHOD_NOTHING; | 624 FailMethod failure_method = FAIL_METHOD_NOTHING; |
627 int instance_num = 1; | 625 int instance_num = 1; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 } | 827 } |
830 | 828 |
831 // Verify that a "close" event is fired at database connections when | 829 // Verify that a "close" event is fired at database connections when |
832 // the backing store is deleted. | 830 // the backing store is deleted. |
833 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ForceCloseEventTest) { | 831 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ForceCloseEventTest) { |
834 NavigateAndWaitForTitle(shell(), "force_close_event.html", NULL, | 832 NavigateAndWaitForTitle(shell(), "force_close_event.html", NULL, |
835 "connection ready"); | 833 "connection ready"); |
836 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 834 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
837 GetContext()->TaskRunner()->PostTask( | 835 GetContext()->TaskRunner()->PostTask( |
838 FROM_HERE, | 836 FROM_HERE, |
839 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( | 837 base::BindOnce(static_cast<void (IndexedDBContextImpl::*)(const GURL&)>( |
840 &IndexedDBContextImpl::DeleteForOrigin), | 838 &IndexedDBContextImpl::DeleteForOrigin), |
841 GetContext(), GURL("file:///"))); | 839 GetContext(), GURL("file:///"))); |
842 | 840 |
843 base::string16 expected_title16(ASCIIToUTF16("connection closed")); | 841 base::string16 expected_title16(ASCIIToUTF16("connection closed")); |
844 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 842 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
845 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("connection closed with error")); | 843 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("connection closed with error")); |
846 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 844 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
847 } | 845 } |
848 | 846 |
849 class IndexedDBBrowserTestSingleProcess : public IndexedDBBrowserTest { | 847 class IndexedDBBrowserTestSingleProcess : public IndexedDBBrowserTest { |
850 public: | 848 public: |
851 void SetUpCommandLine(base::CommandLine* command_line) override { | 849 void SetUpCommandLine(base::CommandLine* command_line) override { |
852 command_line->AppendSwitch(switches::kSingleProcess); | 850 command_line->AppendSwitch(switches::kSingleProcess); |
853 } | 851 } |
854 }; | 852 }; |
855 | 853 |
856 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestSingleProcess, | 854 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestSingleProcess, |
857 RenderThreadShutdownTest) { | 855 RenderThreadShutdownTest) { |
858 SimpleTest(GetTestUrl("indexeddb", "shutdown_with_requests.html")); | 856 SimpleTest(GetTestUrl("indexeddb", "shutdown_with_requests.html")); |
859 } | 857 } |
860 | 858 |
861 } // namespace content | 859 } // namespace content |
OLD | NEW |