#include <memory>
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/values_util.h"
#include "base/test/test_timeouts.h"
#include "build/buildflag.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/back_forward_cache_util.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/content_browser_test_utils.h"
#include "content/public/test/file_system_chooser_test_helpers.h"
#include "content/shell/browser/shell.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_FUCHSIA) && \
!BUILDFLAG(IS_MAC)
constexpr int kBFCacheTestTimeoutMs = …;
#endif
enum class TestFileSystemType { … };
}
#define CREATE_PROMISE_AND_RESOLVERS …
#define GET_LOCAL_FILE …
#define GET_BUCKET_FILE …
#define GET_LOCAL_DIRECTORY …
#define GET_BUCKET_DIRECTORY …
#define GET_FILE(file_system_type) …
#define GET_DIRECTORY(file_system_type) …
#define START_OBSERVING_FILE(file_system_type) …
#define START_OBSERVING_DIRECTORY(file_system_type, recursive) …
#define WRITE_TO_FILE …
#define SET_CHANGE_TIMEOUT …
class FileSystemAccessObserverBrowserTestBase : public ContentBrowserTest { … };
class FileSystemAccessObserverDefaultBrowserTest
: public FileSystemAccessObserverBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserverDefaultBrowserTest,
DisabledByDefault) { … }
class FileSystemAccessObserveWithFlagBrowserTest
: public FileSystemAccessObserverBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
UnobserveDisabledByDefault) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
CreateObserver) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
NothingToDisconnect) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
DisconnectIsIdempotent) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
ObserveSyncAccessHandleWrite) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
ObserveSyncAccessHandleMultipleWrites) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
ObserveSyncAccessHandleTruncate) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
DoNotObserveSyncAccessHandleWithNoChanges) { … }
class FileSystemAccessObserveWithUnobserveFlagBrowserTest
: public FileSystemAccessObserveWithFlagBrowserTest { … };
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithUnobserveFlagBrowserTest,
NothingToUnobserve) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithUnobserveFlagBrowserTest,
UnobserveIsIdempotent) { … }
class FileSystemAccessObserverBrowserTest
: public FileSystemAccessObserverBrowserTestBase,
public testing::WithParamInterface<TestFileSystemType> { … };
#if BUILDFLAG(IS_FUCHSIA)
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserveWithFlagBrowserTest,
ObservingLocalFileIsNotSupportedOnFuchsia) {
base::FilePath file_path = CreateFileToBePicked();
const std::string script =
"(async () => {"
CREATE_PROMISE_AND_RESOLVERS
START_OBSERVING_FILE(TestFileSystemType::kLocal)
WRITE_TO_FILE
SET_CHANGE_TIMEOUT
"})()";
auto result = EvalJs(shell(), script);
EXPECT_TRUE(result.error.find("did not support") != std::string::npos)
<< result.error;
}
#endif
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest, CreateObserver) { … }
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest, ObserveFile) { … }
#endif
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest, ObserveFileRename) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest, ObserveDirectory) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveFailsWhenFileDoesNotExist) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveFailsWhenDirectoryDoesNotExist) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryRecursively) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveThenUnobserve) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveThenUnobserveUnrelated) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
NoChangesAfterUnobserve) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveThenDisconnect) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
NoChangesAfterDisconnect) { … }
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ReObserveAfterDisconnect) { … }
#endif
#if !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveFileReportsType) { … }
#endif
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveFileReportsCorrectHandle) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveFileReportsCorrectRelativePathComponents) { … }
#endif
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsCorrectHandle) { … }
#if !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsCorrectHandleType) { … }
#endif
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsCorrectRelativePathComponents) { … }
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsMoveChangeInfo) { … }
#endif
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsAppearedOnMoveIntoScope) { … }
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
ObserveDirectoryReportsDisappearedOnMoveOutsideScope) { … }
IN_PROC_BROWSER_TEST_P(
FileSystemAccessObserverBrowserTest,
NonRecursiveWatchReportsDisappearedWhenDirectDescendentMovedToNonDirectDescendent) { … }
#endif
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(
FileSystemAccessObserverBrowserTest,
NonRecursiveWatchReportsAppearedWhenDirectDescendentMovedFromNonDirectDescendent) { … }
#endif
#if !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FileSystemAccessObserverBrowserTest,
WritableReportsSingleModifiedEventOnClose) { … }
#endif
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_FUCHSIA)
class FileSystemAccessObserverWithBFCacheBrowserTest
: public FileSystemAccessObserverBrowserTestBase { … };
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserverWithBFCacheBrowserTest,
ReceivesFileUpdatesAfterReturningFromBFCache) { … }
#endif
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserverWithBFCacheBrowserTest,
NotifyOnReturnFromBFCacheWhenFileUpdates) { … }
IN_PROC_BROWSER_TEST_F(FileSystemAccessObserverWithBFCacheBrowserTest,
DoNotNotifyOnReturnFromBFCacheWhenNoFileUpdates) { … }
#endif
}