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