| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "base/threading/sequenced_worker_pool.h" | 6 #include "base/threading/sequenced_worker_pool.h" |
| 7 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 7 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SetBlobLimits() { | 44 void SetBlobLimits() { |
| 45 GetMemoryController()->set_limits_for_testing(limits_); | 45 GetMemoryController()->set_limits_for_testing(limits_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 storage::BlobMemoryController* GetMemoryController() { | 48 storage::BlobMemoryController* GetMemoryController() { |
| 49 content::ChromeBlobStorageContext* blob_context = | 49 content::ChromeBlobStorageContext* blob_context = |
| 50 ChromeBlobStorageContext::GetFor( | 50 ChromeBlobStorageContext::GetFor( |
| 51 shell()->web_contents()->GetBrowserContext()); | 51 shell()->web_contents()->GetBrowserContext()); |
| 52 if (!blob_context->context()) |
| 53 return nullptr; |
| 52 return blob_context->context()->mutable_memory_controller(); | 54 return blob_context->context()->mutable_memory_controller(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void SimpleTest(const GURL& test_url, bool incognito = false) { | 57 void SimpleTest(const GURL& test_url, bool incognito = false) { |
| 56 // The test page will perform tests on blob storage, then navigate to either | 58 // The test page will perform tests on blob storage, then navigate to either |
| 57 // a #pass or #fail ref. | 59 // a #pass or #fail ref. |
| 58 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell(); | 60 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell(); |
| 61 ASSERT_TRUE(the_browser); |
| 59 | 62 |
| 60 VLOG(0) << "Navigating to URL and blocking. " << test_url.spec(); | 63 VLOG(0) << "Navigating to URL and blocking. " << test_url.spec(); |
| 61 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2); | 64 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2); |
| 62 VLOG(0) << "Navigation done."; | 65 VLOG(0) << "Navigation done."; |
| 63 std::string result = | 66 std::string result = |
| 64 the_browser->web_contents()->GetLastCommittedURL().ref(); | 67 the_browser->web_contents()->GetLastCommittedURL().ref(); |
| 65 if (result != "pass") { | 68 if (result != "pass") { |
| 66 std::string js_result; | 69 std::string js_result; |
| 67 ASSERT_TRUE(ExecuteScriptAndExtractString( | 70 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 68 the_browser, "window.domAutomationController.send(getLog())", | 71 the_browser, "window.domAutomationController.send(getLog())", |
| 69 &js_result)); | 72 &js_result)); |
| 70 FAIL() << "Failed: " << js_result; | 73 FAIL() << "Failed: " << js_result; |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 | 76 |
| 74 protected: | 77 protected: |
| 75 storage::BlobStorageLimits limits_; | 78 storage::BlobStorageLimits limits_; |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(BlobStorageBrowserTest); | 81 DISALLOW_COPY_AND_ASSIGN(BlobStorageBrowserTest); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 IN_PROC_BROWSER_TEST_F(BlobStorageBrowserTest, BlobCombinations) { | 84 IN_PROC_BROWSER_TEST_F(BlobStorageBrowserTest, BlobCombinations) { |
| 82 SetBlobLimits(); | 85 SetBlobLimits(); |
| 83 SimpleTest(GetTestUrl("blob_storage", "blob_creation_and_slicing.html")); | 86 SimpleTest(GetTestUrl("blob_storage", "blob_creation_and_slicing.html")); |
| 84 storage::BlobMemoryController* memory_controller = GetMemoryController(); | 87 storage::BlobMemoryController* memory_controller = GetMemoryController(); |
| 88 ASSERT_TRUE(memory_controller); |
| 85 // Our exact usages depend on IPC message ordering & garbage collection. | 89 // Our exact usages depend on IPC message ordering & garbage collection. |
| 86 // Since this is basically random, we just check bounds. | 90 // Since this is basically random, we just check bounds. |
| 87 EXPECT_LT(0u, memory_controller->memory_usage()); | 91 EXPECT_LT(0u, memory_controller->memory_usage()); |
| 88 EXPECT_LT(0ul, memory_controller->disk_usage()); | 92 EXPECT_LT(0ul, memory_controller->disk_usage()); |
| 89 EXPECT_GT(memory_controller->disk_usage(), | 93 EXPECT_GT(memory_controller->disk_usage(), |
| 90 static_cast<uint64_t>(memory_controller->memory_usage())); | 94 static_cast<uint64_t>(memory_controller->memory_usage())); |
| 91 EXPECT_GT(limits_.max_blob_in_memory_space, | 95 EXPECT_GT(limits_.max_blob_in_memory_space, |
| 92 memory_controller->memory_usage()); | 96 memory_controller->memory_usage()); |
| 93 EXPECT_GT(limits_.effective_max_disk_space, memory_controller->disk_usage()); | 97 EXPECT_GT(limits_.effective_max_disk_space, memory_controller->disk_usage()); |
| 94 shell()->Close(); | 98 shell()->Close(); |
| 95 | 99 |
| 96 // Make sure we run all file / io tasks. | 100 // Make sure we run all file / io tasks. |
| 97 base::RunLoop().RunUntilIdle(); | 101 base::RunLoop().RunUntilIdle(); |
| 98 BrowserThread::GetBlockingPool()->FlushForTesting(); | 102 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 99 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
| 100 } | 104 } |
| 101 | 105 |
| 102 } // namespace content | 106 } // namespace content |
| OLD | NEW |