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