0

[Extensions] Clean up test classes in FileSystemChooseEntryFunction.

This function had a series of classes to manage setting and resetting
testing options that relied on global variables and obscured what was
actually happening.

This CL changes this to use an explicit test struct with options
that can be initialized in the test. It then uses base::AutoReset
to set and reset the static pointer to the test struct. This is
much cleaner and clearer than the current code.

Bug: n/a
Change-Id: I6311aec3fa5bb43de82549a66700a00129dbc5f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4609708
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Tim <tjudkins@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Auto-Submit: David Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1159057}
This commit is contained in:
David Bertoni
2023-06-16 20:58:11 +00:00
committed by Chromium LUCI CQ
parent 5462f8970c
commit e44b7e009a
8 changed files with 273 additions and 233 deletions

@ -120,8 +120,10 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsSavedToPrefs) {
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file));
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
temp_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &temp_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
"temp", temp_directory.GetPath());
@ -158,8 +160,10 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_FileAccessIsRestored) {
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file));
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
temp_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &temp_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
"temp", temp_directory.GetPath());

@ -155,8 +155,10 @@ class FileSystemApiTest : public PlatformAppBrowserTest {
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/get_display_path",
{.launch_as_platform_app = true}))
<< message_;
@ -171,8 +173,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
}
base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/get_display_path_prettify",
{.launch_as_platform_app = true}))
<< message_;
@ -194,8 +198,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
EXPECT_TRUE(base::CopyFile(source, test_file));
}
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/get_display_path_prettify_mac",
{.launch_as_platform_app = true}))
@ -206,8 +212,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -218,7 +226,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenExistingFileUsingPreviousPathTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
AppLoadObserver observer(
profile(),
@ -240,7 +251,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
}
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
AppLoadObserver observer(
profile(),
@ -265,7 +279,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
}
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -277,8 +294,10 @@ IN_PROC_BROWSER_TEST_F(
FileSystemApiOpenExistingFileSuggestedNameFilteringTest) {
base::FilePath test_file = TempFilePath("_.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest(
"api_test/file_system/open_existing_suggested_name_filtering",
{.launch_as_platform_app = true}))
@ -294,7 +313,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) {
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
}
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_multiple_with_suggested_name",
{.launch_as_platform_app = true}))
@ -309,8 +331,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
names.push_back("open_existing2.txt");
std::vector<base::FilePath> test_files = TempFilePaths(names, true);
ASSERT_EQ(2u, test_files.size());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest picker(
test_files);
const FileSystemChooseEntryFunction::TestOptions test_options{
.paths_to_be_picked = &test_files};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_multiple_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -320,8 +344,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_directory",
{.launch_as_platform_app = true}))
<< message_;
@ -333,8 +359,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_directory_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -346,8 +374,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_directory_without_permission",
{.launch_as_platform_app = true}))
@ -360,8 +390,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_directory_with_only_write",
{.launch_as_platform_app = true}))
@ -375,9 +407,11 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory, /*skip_dir_confirmation=*/true,
/*allow_directory_access=*/true);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory,
.skip_directory_confirmation = true};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
@ -396,8 +430,12 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath test_directory = test_file.DirName();
// If a dialog is erroneously displayed, auto cancel it, so that the test
// fails.
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory, /*skip_dir_confirmation=*/true);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory,
.skip_directory_confirmation = true,
.allow_directory_access = false};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
@ -417,8 +455,12 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath parent_directory = test_directory.DirName();
// If a dialog is erroneously displayed, auto cancel it, so that the test
// fails.
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
parent_directory, /*skip_dir_confirmation=*/true);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &parent_directory,
.skip_directory_confirmation = true,
.allow_directory_access = false};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
@ -439,8 +481,12 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
base::FilePath parent_directory = test_directory.DirName();
// If a dialog is erroneously displayed, auto cancel it, so that the test
// fails.
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory, /*skip_dir_confirmation=*/true);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory,
.skip_directory_confirmation = true,
.allow_directory_access = false};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
@ -457,8 +503,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiInvalidChooseEntryTypeTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/invalid_choose_file_type",
{.launch_as_platform_app = true}))
<< message_;
@ -469,8 +517,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenExistingFileWithWriteTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_existing_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -481,8 +531,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenWritableExistingFileTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_writable_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -493,8 +545,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenWritableExistingFileWithWriteTest) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_writable_existing_with_write",
{.launch_as_platform_app = true}))
@ -509,8 +563,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
names.push_back("open_existing2.txt");
std::vector<base::FilePath> test_files = TempFilePaths(names, true);
ASSERT_EQ(2u, test_files.size());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest picker(
test_files);
const FileSystemChooseEntryFunction::TestOptions test_options{
.paths_to_be_picked = &test_files};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest(
"api_test/file_system/open_multiple_writable_existing_with_write",
{.launch_as_platform_app = true}))
@ -518,7 +574,9 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
}
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options;
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_cancel",
{.launch_as_platform_app = true}))
<< message_;
@ -534,8 +592,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) {
base::FilePath test_file = TempFilePath("save_new.txt", false);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_new",
{.launch_as_platform_app = true}))
<< message_;
@ -545,8 +605,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) {
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) {
base::FilePath test_file = TempFilePath("save_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -557,8 +619,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiSaveNewFileWithWriteTest) {
base::FilePath test_file = TempFilePath("save_new.txt", false);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_new_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -569,8 +633,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiSaveExistingFileWithWriteTest) {
base::FilePath test_file = TempFilePath("save_existing.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_existing_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -592,15 +658,19 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
names.push_back("save2.txt");
std::vector<base::FilePath> test_files = TempFilePaths(names, false);
ASSERT_EQ(2u, test_files.size());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest picker(
test_files);
const FileSystemChooseEntryFunction::TestOptions test_options{
.paths_to_be_picked = &test_files};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_multiple",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options;
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_cancel",
{.launch_as_platform_app = true}))
<< message_;
@ -615,8 +685,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/get_writable_file_entry",
{.launch_as_platform_app = true}))
<< message_;
@ -626,8 +698,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiGetWritableWithWriteTest) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest(
"api_test/file_system/get_writable_file_entry_with_write",
{.launch_as_platform_app = true}))
@ -638,8 +712,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiGetWritableRootEntryTest) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/get_writable_root_entry",
{.launch_as_platform_app = true}))
<< message_;
@ -648,8 +724,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/is_writable_file_entry",
{.launch_as_platform_app = true}))
<< message_;
@ -659,8 +737,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiIsWritableWithWritePermissionTest) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/is_writable_file_entry_with_write",
{.launch_as_platform_app = true}))
@ -670,8 +750,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/retain_entry",
{.launch_as_platform_app = true}))
<< message_;
@ -688,8 +770,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) {
base::FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/retain_directory",
{.launch_as_platform_app = true}))
<< message_;
@ -705,8 +789,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) {
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
AppLoadObserver observer(
profile(), base::BindRepeating(AddSavedEntry, test_file, false,
apps::SavedFilesService::Get(profile())));
@ -719,8 +805,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) {
base::FilePath test_file = TempFilePath("writable.txt", true);
ASSERT_FALSE(test_file.empty());
base::FilePath test_directory = test_file.DirName();
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
AppLoadObserver observer(
profile(), base::BindRepeating(AddSavedEntry, test_directory, true,
apps::SavedFilesService::Get(profile())));

@ -310,8 +310,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenExistingFileTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/open_existing.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -321,8 +323,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenExistingFileWithWriteTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/open_existing.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_existing_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -334,7 +338,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
GetDriveMountPoint().AppendASCII("root/open_existing.txt");
ASSERT_TRUE(base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_DOCUMENTS, test_file.DirName(), true, false));
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest picker;
const FileSystemChooseEntryFunction::TestOptions test_options{
.use_suggested_path = true};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_multiple_with_suggested_name",
{.launch_as_platform_app = true}))
@ -350,8 +357,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
std::vector<base::FilePath> test_files;
test_files.push_back(test_file1);
test_files.push_back(test_file2);
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest picker(
test_files);
const FileSystemChooseEntryFunction::TestOptions test_options{
.paths_to_be_picked = &test_files};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_multiple_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -361,8 +370,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenDirectoryTest) {
base::FilePath test_directory =
GetDriveMountPoint().AppendASCII("root/subdir");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_directory",
{.launch_as_platform_app = true}))
<< message_;
@ -372,8 +383,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenDirectoryWithWriteTest) {
base::FilePath test_directory =
GetDriveMountPoint().AppendASCII("root/subdir");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/open_directory_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -383,8 +396,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenDirectoryWithoutPermissionTest) {
base::FilePath test_directory =
GetDriveMountPoint().AppendASCII("root/subdir");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_directory_without_permission",
{.launch_as_platform_app = true}))
@ -395,8 +410,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
base::FilePath test_directory =
GetDriveMountPoint().AppendASCII("root/subdir");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_directory);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_directory};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(
RunExtensionTest("api_test/file_system/open_directory_with_only_write",
{.launch_as_platform_app = true}))
@ -407,8 +424,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiSaveNewFileTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/save_new.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_new",
{.launch_as_platform_app = true}))
<< message_;
@ -418,8 +437,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiSaveExistingFileTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/save_existing.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_existing",
{.launch_as_platform_app = true}))
<< message_;
@ -429,8 +450,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiSaveNewFileWithWriteTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/save_new.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_new_with_write",
{.launch_as_platform_app = true}))
<< message_;
@ -440,8 +463,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
FileSystemApiSaveExistingFileWithWriteTest) {
base::FilePath test_file =
GetDriveMountPoint().AppendASCII("root/save_existing.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("api_test/file_system/save_existing_with_write",
{.launch_as_platform_app = true}))
<< message_;

@ -86,8 +86,10 @@ IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestWriteFromFile) {
"test_temp", test_utils_.GetTempDir());
base::FilePath selected_image(test_utils_.GetImagePath());
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
selected_image);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &selected_image};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
#if !BUILDFLAG(IS_CHROMEOS_ASH)
auto set_up_utility_client_callbacks = [](FakeImageWriterClient* client) {

@ -171,8 +171,10 @@ IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, FileSystemApiGetDisplayPath) {
FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
"test_root", test_dir);
base::FilePath test_file = test_dir.AppendASCII("text.txt");
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest picker(
test_file);
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &test_file};
auto reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
ASSERT_TRUE(RunExtensionTest("native_bindings/instance_of",
{.launch_as_platform_app = true}))
<< message_;

@ -1914,8 +1914,11 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionSaveTest, MAYBE_Save) {
base::FilePath save_path = GetDownloadDir().AppendASCII("edited.pdf");
ASSERT_FALSE(base::PathExists(save_path));
using FileChooser = extensions::FileSystemChooseEntryFunction;
FileChooser::SkipPickerAndAlwaysSelectPathForTest file_picker(save_path);
using extensions::FileSystemChooseEntryFunction;
const FileSystemChooseEntryFunction::TestOptions test_options{
.path_to_be_picked = &save_path};
auto auto_reset_options =
FileSystemChooseEntryFunction::SetOptionsForTesting(test_options);
MimeHandlerViewGuest* guest = LoadTestComboBoxPdfGetMimeHandlerView();
ClickLeftSideOfEditableComboBox(guest);

@ -103,22 +103,6 @@ namespace ChooseEntry = file_system::ChooseEntry;
namespace {
bool g_skip_picker_for_test = false;
bool g_use_suggested_path_for_test = false;
const base::FilePath* g_path_to_be_picked_for_test = nullptr;
const std::vector<base::FilePath>* g_paths_to_be_picked_for_test = nullptr;
bool g_skip_directory_confirmation_for_test = false;
bool g_allow_directory_access_for_test = false;
void ResetTestValuesToDefaults() {
g_skip_picker_for_test = false;
g_use_suggested_path_for_test = false;
g_path_to_be_picked_for_test = nullptr;
g_paths_to_be_picked_for_test = nullptr;
g_skip_directory_confirmation_for_test = false;
g_allow_directory_access_for_test = false;
}
// Expand the mime-types and extensions provided in an AcceptOption, returning
// them within the passed extension vector. Returns false if no valid types
// were found.
@ -443,21 +427,32 @@ ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() {
return RespondNow(WithArguments(is_writable));
}
const FileSystemChooseEntryFunction::TestOptions*
FileSystemChooseEntryFunction::g_test_options = nullptr;
base::AutoReset<const FileSystemChooseEntryFunction::TestOptions*>
FileSystemChooseEntryFunction::SetOptionsForTesting(
const TestOptions& options) {
CHECK_EQ(nullptr, g_test_options);
return base::AutoReset<const TestOptions*>(&g_test_options, &options);
}
void FileSystemChooseEntryFunction::ShowPicker(
const ui::SelectFileDialog::FileTypeInfo& file_type_info,
ui::SelectFileDialog::Type picker_type,
const base::FilePath& initial_path) {
// TODO(michaelpg): Use the FileSystemDelegate to override functionality for
// tests instead of using global variables.
if (g_skip_picker_for_test) {
if (g_test_options) {
std::vector<base::FilePath> test_paths;
if (g_use_suggested_path_for_test)
if (g_test_options->use_suggested_path) {
CHECK(!g_test_options->path_to_be_picked &&
!g_test_options->paths_to_be_picked);
test_paths.push_back(initial_path);
else if (g_path_to_be_picked_for_test)
test_paths.push_back(*g_path_to_be_picked_for_test);
else if (g_paths_to_be_picked_for_test)
test_paths = *g_paths_to_be_picked_for_test;
} else if (g_test_options->path_to_be_picked) {
CHECK(!g_test_options->paths_to_be_picked);
test_paths.push_back(*g_test_options->path_to_be_picked);
} else if (g_test_options->paths_to_be_picked) {
test_paths = *g_test_options->paths_to_be_picked;
}
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
test_paths.size() > 0
@ -467,7 +462,6 @@ void FileSystemChooseEntryFunction::ShowPicker(
&FileSystemChooseEntryFunction::FileSelectionCanceled, this));
return;
}
FileSystemDelegate* delegate =
ExtensionsAPIClient::Get()->GetFileSystemDelegate();
DCHECK(delegate);
@ -485,59 +479,6 @@ void FileSystemChooseEntryFunction::ShowPicker(
}
}
FileSystemChooseEntryFunction::SkipPickerBaseForTest*
FileSystemChooseEntryFunction::SkipPickerBaseForTest::g_picker = nullptr;
FileSystemChooseEntryFunction::SkipPickerBaseForTest::SkipPickerBaseForTest() {
CHECK(!g_picker);
g_picker = this;
}
FileSystemChooseEntryFunction::SkipPickerBaseForTest::~SkipPickerBaseForTest() {
DCHECK_EQ(this, g_picker);
ResetTestValuesToDefaults();
g_picker = nullptr;
}
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest::
SkipPickerAndAlwaysSelectPathForTest(const base::FilePath& path,
bool skip_dir_confirmation,
bool allow_directory_access)
: path_(path) {
g_skip_picker_for_test = true;
g_path_to_be_picked_for_test = &path_;
g_skip_directory_confirmation_for_test = skip_dir_confirmation;
g_allow_directory_access_for_test = allow_directory_access;
}
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest::
~SkipPickerAndAlwaysSelectPathForTest() = default;
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest::
SkipPickerAndAlwaysSelectPathsForTest(
const std::vector<base::FilePath>& paths)
: paths_(paths) {
g_skip_picker_for_test = true;
g_paths_to_be_picked_for_test = &paths_;
}
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest::
~SkipPickerAndAlwaysSelectPathsForTest() = default;
FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest::
SkipPickerAndSelectSuggestedPathForTest() {
g_skip_picker_for_test = true;
g_use_suggested_path_for_test = true;
}
FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest::
~SkipPickerAndAlwaysCancelForTest() = default;
FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest::
SkipPickerAndAlwaysCancelForTest() {
g_skip_picker_for_test = true;
}
// static
void FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
const std::string& name,
@ -614,9 +555,10 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync(
if (check_path != graylisted_path && !check_path.IsParent(graylisted_path))
continue;
if (g_skip_directory_confirmation_for_test) {
if (g_allow_directory_access_for_test)
if (g_test_options && g_test_options->skip_directory_confirmation) {
if (g_test_options->allow_directory_access) {
break;
}
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&FileSystemChooseEntryFunction::FileSelectionCanceled,

@ -9,8 +9,10 @@
#include <string>
#include <vector>
#include "base/auto_reset.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
@ -115,54 +117,24 @@ class FileSystemIsWritableEntryFunction : public ExtensionFunction {
class FileSystemChooseEntryFunction : public FileSystemEntryFunction {
public:
class SkipPickerBaseForTest {
protected:
SkipPickerBaseForTest();
~SkipPickerBaseForTest();
private:
// Nested pickers are not allowed, so track the singleton
// instance.
static SkipPickerBaseForTest* g_picker;
};
// Various classes to to allow the picker UI to be skipped in testing.
// Upon destruction, the affected global variables are reset to their
// default values;
class SkipPickerAndAlwaysSelectPathForTest : public SkipPickerBaseForTest {
public:
explicit SkipPickerAndAlwaysSelectPathForTest(
const base::FilePath& path,
bool skip_dir_confirmation = false,
bool allow_directory_access = false);
~SkipPickerAndAlwaysSelectPathForTest();
private:
const base::FilePath path_;
};
class SkipPickerAndAlwaysSelectPathsForTest : public SkipPickerBaseForTest {
public:
explicit SkipPickerAndAlwaysSelectPathsForTest(
const std::vector<base::FilePath>& paths);
~SkipPickerAndAlwaysSelectPathsForTest();
private:
const std::vector<base::FilePath> paths_;
};
class SkipPickerAndSelectSuggestedPathForTest : public SkipPickerBaseForTest {
public:
SkipPickerAndSelectSuggestedPathForTest();
~SkipPickerAndSelectSuggestedPathForTest() = default;
};
class SkipPickerAndAlwaysCancelForTest : public SkipPickerBaseForTest {
public:
SkipPickerAndAlwaysCancelForTest();
~SkipPickerAndAlwaysCancelForTest();
struct TestOptions {
// These first three options are mutually exclusive and are chosen in
// this order.
bool use_suggested_path = false;
const base::raw_ptr<base::FilePath> path_to_be_picked = nullptr;
const base::raw_ptr<std::vector<base::FilePath>> paths_to_be_picked =
nullptr;
bool skip_directory_confirmation = false;
// This option is true and is only set to false in tests that do not
// expect a dialog box to be displayed and want the test to fail if
// it is displayed. See
// FileSystemApiTest.FileSystemApiOpenDirectoryOnGraylistTest as an
// example.
bool allow_directory_access = true;
};
static base::AutoReset<const TestOptions*> SetOptionsForTesting(
const TestOptions& options);
// Call this with the directory for test file paths. On Chrome OS, accessed
// path needs to be explicitly registered for smooth integration with Google
// Drive support.
@ -214,6 +186,8 @@ class FileSystemChooseEntryFunction : public FileSystemEntryFunction {
const std::vector<base::FilePath>& paths);
void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths);
static const TestOptions* g_test_options;
};
class FileSystemRetainEntryFunction : public ExtensionFunction {