#include "content/browser/file_system/file_system_url_loader_factory.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/i18n/unicodestring.h"
#include "base/memory/raw_ptr.h"
#include "base/rand_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
#include "components/file_access/scoped_file_access.h"
#include "components/file_access/test/mock_scoped_file_access_delegate.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/mime_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/test/test_url_loader_client.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_file_util.h"
#include "storage/browser/file_system/file_system_operation_context.h"
#include "storage/browser/file_system/file_system_operation_runner.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/browser/file_system/sandbox_file_system_backend_delegate.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/test/async_file_test_helper.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "storage/browser/test/test_file_system_backend.h"
#include "storage/browser/test/test_file_system_context.h"
#include "storage/browser/test/test_file_system_options.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/icu/source/i18n/unicode/datefmt.h"
#include "third_party/icu/source/i18n/unicode/regex.h"
#include "url/gurl.h"
#include "url/origin.h"
BindLambdaForTesting;
URLLoaderFactory;
AsyncFileTestHelper;
FileSystemContext;
FileSystemOperationContext;
FileSystemURL;
namespace content {
namespace {
enum class TestMode { … };
constexpr char kFileSystemURLPrefix[] = …;
constexpr char kValidExternalMountPoint[] = …;
constexpr char kTestFileData[] = …;
void FillBuffer(base::span<uint8_t> buffer) { … }
bool TestAutoMountForURLRequest(
const storage::FileSystemRequestInfo& request_info,
const storage::FileSystemURL& filesystem_url,
base::OnceCallback<void(base::File::Error result)> callback) { … }
void ReadDataPipeInternal(mojo::DataPipeConsumerHandle handle,
std::string* result,
base::OnceClosure quit_closure) { … }
std::string ReadDataPipe(mojo::ScopedDataPipeConsumerHandle handle) { … }
bool IsDirectoryListingLine(const std::string& line) { … }
bool IsDirectoryListingTitle(const std::string& line) { … }
}
class FileSystemURLLoaderFactoryTest
: public ContentBrowserTest,
public ::testing::WithParamInterface<TestMode> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, DirectoryListing) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, InvalidURL) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, NoSuchRoot) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, NoSuchDirectory) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, Cancel) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, Incognito) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
AutoMountDirectoryListing) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, AutoMountInvalidRoot) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, AutoMountNoHandler) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileTest) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileTestDlp) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, CrossOriginFileBlocked) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
FileTestFullSpecifiedRange) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
FileTestHalfSpecifiedRange) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
FileTestMultipleRangesNotSupported) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileRangeOutOfBounds) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
DISABLED_FileDirRedirect) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileNoSuchRoot) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, NoSuchFile) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileCancel) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileGetMimeType) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileIncognito) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileAutoMountFileTest) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest,
FileAutoMountInvalidRoot) { … }
IN_PROC_BROWSER_TEST_P(FileSystemURLLoaderFactoryTest, FileAutoMountNoHandler) { … }
}