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/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/location.h" | |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/single_thread_task_runner.h" | 13 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/thread_test_helper.h" | 15 #include "base/test/thread_test_helper.h" |
17 #include "content/browser/browser_main_loop.h" | 16 #include "content/browser/browser_main_loop.h" |
18 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 17 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
19 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 18 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
20 #include "content/browser/indexed_db/mock_browsertest_indexed_db_class_factory.h
" | 19 #include "content/browser/indexed_db/mock_browsertest_indexed_db_class_factory.h
" |
21 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 135 |
137 virtual int64 RequestDiskUsage() { | 136 virtual int64 RequestDiskUsage() { |
138 PostTaskAndReplyWithResult( | 137 PostTaskAndReplyWithResult( |
139 GetContext()->TaskRunner(), | 138 GetContext()->TaskRunner(), |
140 FROM_HERE, | 139 FROM_HERE, |
141 base::Bind(&IndexedDBContext::GetOriginDiskUsage, | 140 base::Bind(&IndexedDBContext::GetOriginDiskUsage, |
142 GetContext(), | 141 GetContext(), |
143 GURL("file:///")), | 142 GURL("file:///")), |
144 base::Bind(&IndexedDBBrowserTest::DidGetDiskUsage, this)); | 143 base::Bind(&IndexedDBBrowserTest::DidGetDiskUsage, this)); |
145 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( | 144 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
146 BrowserMainLoop::GetInstance()->indexed_db_thread()->task_runner())); | 145 BrowserMainLoop::GetInstance()->indexed_db_thread()-> |
| 146 message_loop_proxy())); |
147 EXPECT_TRUE(helper->Run()); | 147 EXPECT_TRUE(helper->Run()); |
148 // Wait for DidGetDiskUsage to be called. | 148 // Wait for DidGetDiskUsage to be called. |
149 base::MessageLoop::current()->RunUntilIdle(); | 149 base::MessageLoop::current()->RunUntilIdle(); |
150 return disk_usage_; | 150 return disk_usage_; |
151 } | 151 } |
152 | 152 |
153 virtual int RequestBlobFileCount() { | 153 virtual int RequestBlobFileCount() { |
154 PostTaskAndReplyWithResult( | 154 PostTaskAndReplyWithResult( |
155 GetContext()->TaskRunner(), FROM_HERE, | 155 GetContext()->TaskRunner(), FROM_HERE, |
156 base::Bind(&IndexedDBContextImpl::GetOriginBlobFileCount, GetContext(), | 156 base::Bind(&IndexedDBContextImpl::GetOriginBlobFileCount, GetContext(), |
157 GURL("file:///")), | 157 GURL("file:///")), |
158 base::Bind(&IndexedDBBrowserTest::DidGetBlobFileCount, this)); | 158 base::Bind(&IndexedDBBrowserTest::DidGetBlobFileCount, this)); |
159 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( | 159 scoped_refptr<base::ThreadTestHelper> helper( |
160 BrowserMainLoop::GetInstance()->indexed_db_thread()->task_runner())); | 160 new base::ThreadTestHelper(BrowserMainLoop::GetInstance() |
| 161 ->indexed_db_thread() |
| 162 ->message_loop_proxy())); |
161 EXPECT_TRUE(helper->Run()); | 163 EXPECT_TRUE(helper->Run()); |
162 // Wait for DidGetBlobFileCount to be called. | 164 // Wait for DidGetBlobFileCount to be called. |
163 base::MessageLoop::current()->RunUntilIdle(); | 165 base::MessageLoop::current()->RunUntilIdle(); |
164 return blob_file_count_; | 166 return blob_file_count_; |
165 } | 167 } |
166 | 168 |
167 private: | 169 private: |
168 static MockBrowserTestIndexedDBClassFactory* GetTestClassFactory() { | 170 static MockBrowserTestIndexedDBClassFactory* GetTestClassFactory() { |
169 static ::base::LazyInstance<MockBrowserTestIndexedDBClassFactory>::Leaky | 171 static ::base::LazyInstance<MockBrowserTestIndexedDBClassFactory>::Leaky |
170 s_factory = LAZY_INSTANCE_INITIALIZER; | 172 s_factory = LAZY_INSTANCE_INITIALIZER; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { | 316 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { |
315 public: | 317 public: |
316 IndexedDBBrowserTestWithPreexistingLevelDB() {} | 318 IndexedDBBrowserTestWithPreexistingLevelDB() {} |
317 void SetUpOnMainThread() override { | 319 void SetUpOnMainThread() override { |
318 scoped_refptr<IndexedDBContextImpl> context = GetContext(); | 320 scoped_refptr<IndexedDBContextImpl> context = GetContext(); |
319 context->TaskRunner()->PostTask( | 321 context->TaskRunner()->PostTask( |
320 FROM_HERE, | 322 FROM_HERE, |
321 base::Bind( | 323 base::Bind( |
322 &CopyLevelDBToProfile, shell(), context, EnclosingLevelDBDir())); | 324 &CopyLevelDBToProfile, shell(), context, EnclosingLevelDBDir())); |
323 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( | 325 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
324 BrowserMainLoop::GetInstance()->indexed_db_thread()->task_runner())); | 326 BrowserMainLoop::GetInstance()->indexed_db_thread()-> |
| 327 message_loop_proxy())); |
325 ASSERT_TRUE(helper->Run()); | 328 ASSERT_TRUE(helper->Run()); |
326 } | 329 } |
327 | 330 |
328 virtual std::string EnclosingLevelDBDir() = 0; | 331 virtual std::string EnclosingLevelDBDir() = 0; |
329 | 332 |
330 private: | 333 private: |
331 DISALLOW_COPY_AND_ASSIGN(IndexedDBBrowserTestWithPreexistingLevelDB); | 334 DISALLOW_COPY_AND_ASSIGN(IndexedDBBrowserTestWithPreexistingLevelDB); |
332 }; | 335 }; |
333 | 336 |
334 class IndexedDBBrowserTestWithVersion0Schema : public | 337 class IndexedDBBrowserTestWithVersion0Schema : public |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 470 } |
468 | 471 |
469 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DeleteForOriginDeletesBlobs) { | 472 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DeleteForOriginDeletesBlobs) { |
470 SimpleTest(GetTestUrl("indexeddb", "write_20mb_blob.html")); | 473 SimpleTest(GetTestUrl("indexeddb", "write_20mb_blob.html")); |
471 int64 size = RequestDiskUsage(); | 474 int64 size = RequestDiskUsage(); |
472 // This assertion assumes that we do not compress blobs. | 475 // This assertion assumes that we do not compress blobs. |
473 EXPECT_GT(size, 20 << 20 /* 20 MB */); | 476 EXPECT_GT(size, 20 << 20 /* 20 MB */); |
474 GetContext()->TaskRunner()->PostTask( | 477 GetContext()->TaskRunner()->PostTask( |
475 FROM_HERE, base::Bind(&IndexedDBContextImpl::DeleteForOrigin, | 478 FROM_HERE, base::Bind(&IndexedDBContextImpl::DeleteForOrigin, |
476 GetContext(), GURL("file:///"))); | 479 GetContext(), GURL("file:///"))); |
477 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( | 480 scoped_refptr<base::ThreadTestHelper> helper( |
478 BrowserMainLoop::GetInstance()->indexed_db_thread()->task_runner())); | 481 new base::ThreadTestHelper(BrowserMainLoop::GetInstance() |
| 482 ->indexed_db_thread() |
| 483 ->message_loop_proxy())); |
479 ASSERT_TRUE(helper->Run()); | 484 ASSERT_TRUE(helper->Run()); |
480 EXPECT_EQ(0, RequestDiskUsage()); | 485 EXPECT_EQ(0, RequestDiskUsage()); |
481 } | 486 } |
482 | 487 |
483 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DiskFullOnCommit) { | 488 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DiskFullOnCommit) { |
484 // Ignore several preceding transactions: | 489 // Ignore several preceding transactions: |
485 // * The test calls deleteDatabase() which opens the backing store: | 490 // * The test calls deleteDatabase() which opens the backing store: |
486 // #1: IndexedDBBackingStore::OpenBackingStore | 491 // #1: IndexedDBBackingStore::OpenBackingStore |
487 // => IndexedDBBackingStore::SetUpMetadata | 492 // => IndexedDBBackingStore::SetUpMetadata |
488 // #2: IndexedDBBackingStore::OpenBackingStore | 493 // #2: IndexedDBBackingStore::OpenBackingStore |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 command_line->AppendSwitch(switches::kSingleProcess); | 847 command_line->AppendSwitch(switches::kSingleProcess); |
843 } | 848 } |
844 }; | 849 }; |
845 | 850 |
846 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestSingleProcess, | 851 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestSingleProcess, |
847 RenderThreadShutdownTest) { | 852 RenderThreadShutdownTest) { |
848 SimpleTest(GetTestUrl("indexeddb", "shutdown_with_requests.html")); | 853 SimpleTest(GetTestUrl("indexeddb", "shutdown_with_requests.html")); |
849 } | 854 } |
850 | 855 |
851 } // namespace content | 856 } // namespace content |
OLD | NEW |