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