blob: be58d68549fc6e599c8b8b4798e3d16dc05c53fb [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]b44492062011-09-06 12:47:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avib7348942015-12-25 20:57:105#include <stdint.h>
6
[email protected]b44492062011-09-06 12:47:477#include "base/command_line.h"
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
Avi Drissmanadac21992023-01-11 23:46:399#include "base/functional/bind.h"
skyostil95082a62015-06-05 19:53:0710#include "base/location.h"
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
[email protected]b44492062011-09-06 12:47:4712#include "base/memory/ref_counted.h"
Victor Costan827623c2022-01-21 22:08:5613#include "base/run_loop.h"
Patrick Monette643cdf62021-10-15 19:13:4214#include "base/task/single_thread_task_runner.h"
Victor Costan827623c2022-01-21 22:08:5615#include "base/test/bind.h"
[email protected]b44492062011-09-06 12:47:4716#include "base/test/thread_test_helper.h"
[email protected]93ddb3c2012-04-11 21:44:2917#include "content/browser/web_contents/web_contents_impl.h"
[email protected]4cdc9a22012-07-26 03:39:3118#include "content/public/browser/browser_context.h"
Eric Seckler8652dcd52018-09-20 10:42:2819#include "content/public/browser/browser_task_traits.h"
[email protected]4cdc9a22012-07-26 03:39:3120#include "content/public/browser/browser_thread.h"
[email protected]f13b2682012-08-22 00:37:5521#include "content/public/browser/storage_partition.h"
[email protected]c08950d22011-10-13 22:20:2922#include "content/public/common/content_switches.h"
Peter Kasting919ce652020-05-07 10:22:3623#include "content/public/test/browser_test.h"
[email protected]7d478cb2012-07-24 17:19:4224#include "content/public/test/browser_test_utils.h"
[email protected]6e9def12014-03-27 20:23:2825#include "content/public/test/content_browser_test.h"
26#include "content/public/test/content_browser_test_utils.h"
[email protected]de7d61ff2013-08-20 11:30:4127#include "content/shell/browser/shell.h"
pilgrime92c5fcd2014-09-10 23:31:2328#include "storage/browser/quota/quota_manager.h"
[email protected]b44492062011-09-06 12:47:4729
[email protected]cd501a72014-08-22 19:58:3130using storage::QuotaManager;
[email protected]b44492062011-09-06 12:47:4731
[email protected]4cdc9a22012-07-26 03:39:3132namespace content {
33
jsbell14785d902016-10-26 21:37:2634// This browser test is aimed towards exercising the File System API bindings
35// and the actual implementation that lives in the browser side.
Ramin Halavatie24c8b22019-04-11 15:03:1236class FileSystemBrowserTest : public ContentBrowserTest,
37 public testing::WithParamInterface<bool> {
[email protected]b44492062011-09-06 12:47:4738 public:
DongJun Kim47743f42019-10-28 03:05:5139 FileSystemBrowserTest() { is_incognito_ = GetParam(); }
[email protected]b44492062011-09-06 12:47:4740
Lukasz Anforowicz292a1d462020-04-30 19:33:2341 void SetUpOnMainThread() override {
42 ASSERT_TRUE(embedded_test_server()->Start());
Jagadesh P19618272023-10-30 19:11:5243 browser_ = is_incognito() ? CreateOffTheRecordBrowser() : shell();
Lukasz Anforowicz292a1d462020-04-30 19:33:2344 }
45
Jagadesh P19618272023-10-30 19:11:5246 void TearDownOnMainThread() override { browser_ = nullptr; }
47
Ramin Halavatie24c8b22019-04-11 15:03:1248 void SimpleTest(const GURL& test_url) {
[email protected]b44492062011-09-06 12:47:4749 // The test page will perform tests on FileAPI, then navigate to either
50 // a #pass or #fail ref.
[email protected]efde84b02013-11-23 04:18:2051 VLOG(0) << "Navigating to URL and blocking.";
Ramin Halavati9bf18b222019-04-16 18:08:3652 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
[email protected]efde84b02013-11-23 04:18:2053 VLOG(0) << "Navigation done.";
Ramin Halavati9bf18b222019-04-16 18:08:3654 std::string result = browser()->web_contents()->GetLastCommittedURL().ref();
[email protected]b44492062011-09-06 12:47:4755 if (result != "pass") {
Avi Drissmanc91bd8e2021-04-19 23:58:4456 std::string js_result = EvalJs(browser(), "getLog()").ExtractString();
[email protected]b44492062011-09-06 12:47:4757 FAIL() << "Failed: " << js_result;
58 }
59 }
Ramin Halavatie24c8b22019-04-11 15:03:1260
Jagadesh P19618272023-10-30 19:11:5261 Shell* browser() { return browser_; }
Ramin Halavati9bf18b222019-04-16 18:08:3662
63 bool is_incognito() { return is_incognito_; }
64
Ramin Halavatie24c8b22019-04-11 15:03:1265 protected:
Ramin Halavati9bf18b222019-04-16 18:08:3666 bool is_incognito_;
Jagadesh P19618272023-10-30 19:11:5267 raw_ptr<Shell> browser_ = nullptr;
[email protected]b44492062011-09-06 12:47:4768};
69
Ilia Samsonov6d142572019-11-21 02:34:0670INSTANTIATE_TEST_SUITE_P(All, FileSystemBrowserTest, ::testing::Bool());
Ramin Halavatie24c8b22019-04-11 15:03:1271
[email protected]b44492062011-09-06 12:47:4772class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
73 public:
dchengc2282aa2014-10-21 12:07:5874 void SetUpOnMainThread() override {
Lukasz Anforowicz292a1d462020-04-30 19:33:2375 FileSystemBrowserTest::SetUpOnMainThread();
Lukasz Anforowiczb9a969a2021-04-29 15:26:2576 SetLowQuota(browser()
77 ->web_contents()
78 ->GetBrowserContext()
79 ->GetDefaultStoragePartition()
michaeln10e5fc352017-02-07 02:07:5880 ->GetQuotaManager());
[email protected]b44492062011-09-06 12:47:4781 }
82
michaeln10e5fc352017-02-07 02:07:5883 static void SetLowQuota(scoped_refptr<QuotaManager> qm) {
Victor Costan827623c2022-01-21 22:08:5684 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
85
86 base::RunLoop run_loop;
87 GetIOThreadTaskRunner({})->PostTaskAndReply(
88 FROM_HERE, base::BindLambdaForTesting([&]() {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 // These sizes must correspond with expectations in html and js.
91 const int kMeg = 1000 * 1024;
92 storage::QuotaSettings settings;
93 settings.pool_size = 25 * kMeg;
Ayu Ishii802a1ee2022-11-30 17:40:1994 settings.per_storage_key_quota = 5 * kMeg;
Victor Costan827623c2022-01-21 22:08:5695 settings.must_remain_available = 10 * kMeg;
96 settings.refresh_interval = base::TimeDelta::Max();
97 qm->SetQuotaSettings(settings);
98 }),
99 run_loop.QuitClosure());
100 run_loop.Run();
[email protected]b44492062011-09-06 12:47:47101 }
102};
103
Ilia Samsonov6d142572019-11-21 02:34:06104INSTANTIATE_TEST_SUITE_P(All,
Ramin Halavatie24c8b22019-04-11 15:03:12105 FileSystemBrowserTestWithLowQuota,
Ramin Halavati9bf18b222019-04-16 18:08:36106 ::testing::Bool());
Ramin Halavatie24c8b22019-04-11 15:03:12107
108IN_PROC_BROWSER_TEST_P(FileSystemBrowserTest, RequestTest) {
Lukasz Anforowicz292a1d462020-04-30 19:33:23109 SimpleTest(embedded_test_server()->GetURL("/fileapi/request_test.html"));
[email protected]b44492062011-09-06 12:47:47110}
111
Ramin Halavatie24c8b22019-04-11 15:03:12112IN_PROC_BROWSER_TEST_P(FileSystemBrowserTest, CreateTest) {
Lukasz Anforowicz292a1d462020-04-30 19:33:23113 SimpleTest(embedded_test_server()->GetURL("/fileapi/create_test.html"));
[email protected]b44492062011-09-06 12:47:47114}
115
Ramin Halavatie24c8b22019-04-11 15:03:12116IN_PROC_BROWSER_TEST_P(FileSystemBrowserTestWithLowQuota, QuotaTest) {
Lukasz Anforowicz292a1d462020-04-30 19:33:23117 SimpleTest(embedded_test_server()->GetURL("/fileapi/quota_test.html"));
[email protected]b44492062011-09-06 12:47:47118}
[email protected]4cdc9a22012-07-26 03:39:31119
120} // namespace content