OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/run_loop.h" |
| 6 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 7 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/browser_test_utils.h" |
| 11 #include "content/public/test/content_browser_test.h" |
| 12 #include "content/public/test/content_browser_test_utils.h" |
| 13 #include "content/shell/browser/shell.h" |
| 14 #include "storage/browser/blob/blob_memory_controller.h" |
| 15 #include "storage/browser/blob/blob_storage_context.h" |
| 16 #include "storage/common/blob_storage/blob_storage_constants.h" |
| 17 |
| 18 namespace content { |
| 19 namespace { |
| 20 const size_t kTestBlobStorageIPCThresholdBytes = 5; |
| 21 const size_t kTestBlobStorageMaxSharedMemoryBytes = 10; |
| 22 |
| 23 const size_t kTestBlobStorageMaxBlobMemorySize = 200; |
| 24 const uint64_t kTestBlobStorageMaxDiskSpace = 3000; |
| 25 const uint64_t kTestBlobStorageMinFileSizeBytes = 20; |
| 26 const uint64_t kTestBlobStorageMaxFileSizeBytes = 50; |
| 27 } // namespace |
| 28 |
| 29 // This browser test is aimed towards exercising the blob storage transportation |
| 30 // strategies and paging memory to disk. |
| 31 class BlobStorageBrowserTest : public ContentBrowserTest { |
| 32 public: |
| 33 BlobStorageBrowserTest() { |
| 34 limits_.max_ipc_memory_size = kTestBlobStorageIPCThresholdBytes; |
| 35 limits_.max_shared_memory_size = kTestBlobStorageMaxSharedMemoryBytes; |
| 36 limits_.max_blob_in_memory_space = kTestBlobStorageMaxBlobMemorySize; |
| 37 limits_.max_blob_disk_space = kTestBlobStorageMaxDiskSpace; |
| 38 limits_.min_page_file_size = kTestBlobStorageMinFileSizeBytes; |
| 39 limits_.max_file_size = kTestBlobStorageMaxFileSizeBytes; |
| 40 } |
| 41 |
| 42 void SetBlobLimits() { |
| 43 GetMemoryController()->set_limits_for_testing(limits_); |
| 44 } |
| 45 |
| 46 storage::BlobMemoryController* GetMemoryController() { |
| 47 content::ChromeBlobStorageContext* blob_context = |
| 48 ChromeBlobStorageContext::GetFor( |
| 49 shell()->web_contents()->GetBrowserContext()); |
| 50 return blob_context->context()->mutable_memory_controller(); |
| 51 } |
| 52 |
| 53 void SimpleTest(const GURL& test_url, bool incognito = false) { |
| 54 // The test page will perform tests on blob storage, then navigate to either |
| 55 // a #pass or #fail ref. |
| 56 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell(); |
| 57 |
| 58 VLOG(0) << "Navigating to URL and blocking. " << test_url.spec(); |
| 59 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2); |
| 60 VLOG(0) << "Navigation done."; |
| 61 std::string result = |
| 62 the_browser->web_contents()->GetLastCommittedURL().ref(); |
| 63 if (result != "pass") { |
| 64 std::string js_result; |
| 65 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 66 the_browser, "window.domAutomationController.send(getLog())", |
| 67 &js_result)); |
| 68 FAIL() << "Failed: " << js_result; |
| 69 } |
| 70 } |
| 71 |
| 72 protected: |
| 73 storage::BlobStorageLimits limits_; |
| 74 |
| 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(BlobStorageBrowserTest); |
| 77 }; |
| 78 |
| 79 IN_PROC_BROWSER_TEST_F(BlobStorageBrowserTest, BlobCombinations) { |
| 80 SetBlobLimits(); |
| 81 SimpleTest(GetTestUrl("blob_storage", "blob_creation_and_slicing.html")); |
| 82 storage::BlobMemoryController* memory_controller = GetMemoryController(); |
| 83 // Our exact usages depend on IPC message ordering & garbage collection. |
| 84 // Since this is basically random, we just check bounds. |
| 85 EXPECT_LT(0u, memory_controller->memory_usage()); |
| 86 EXPECT_LT(0ul, memory_controller->disk_usage()); |
| 87 EXPECT_GT(memory_controller->disk_usage(), |
| 88 static_cast<uint64_t>(memory_controller->memory_usage())); |
| 89 EXPECT_GT(limits_.max_blob_in_memory_space, |
| 90 memory_controller->memory_usage()); |
| 91 EXPECT_GT(limits_.max_blob_disk_space, memory_controller->disk_usage()); |
| 92 shell()->Close(); |
| 93 |
| 94 // Make sure we run all file / io tasks. |
| 95 base::RunLoop().RunUntilIdle(); |
| 96 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 97 base::RunLoop().RunUntilIdle(); |
| 98 } |
| 99 |
| 100 } // namespace content |
OLD | NEW |