OSSCA Chromium

기여 목록 / 8030244

base: Test no event when non-existent watched file's parent is created

BasetestMerged

존재하지 않는 감시 파일의 부모 디렉터리를 생성해도 파일 감시 이벤트가 발생하지 않는지 검증하도록 테스트를 보완했습니다.

문제 설명

FilePathWatcherTest.MoveParent는 아직 없는 dir/subdir/file 파일과 그 부모인 dir/subdir 디렉터리를 각각 감시합니다. 부모 디렉터리만 생성하면 디렉터리 감시에는 이벤트가 발생하지만, 파일 감시에는 이벤트가 발생하지 않아야 합니다. 기존에는 파일 감시 쪽에 이벤트가 없는지 확인하라는 TODO가 남아 있었습니다.

해결 내용

TODO를 file_delegate.SpinAndExpectNoEvents()로 교체해, 부모 디렉터리 생성 후 파일 감시의 수신 목록이 비어 있는지 확인했습니다. 디렉터리 감시에서 생성 이벤트를 확인하는 기존 검증은 유지했습니다.

전체 코드 diff는 다음과 같습니다.

--- a/base/files/file_path_watcher_unittest.cc
+++ b/base/files/file_path_watcher_unittest.cc
@@ -969,8 +969,7 @@
   // We should only get notified on `subdir_delegate` of its creation.
   ASSERT_TRUE(CreateDirectory(subdir));
   subdir_event_expecter.AddExpectedEventForPath(subdir);
-  // TODO(crbug.com/40263777): Expect that no events are fired on the
-  // file delegate.
+  file_delegate.SpinAndExpectNoEvents();
   subdir_delegate.RunUntilEventsMatch(subdir_event_expecter);

   ASSERT_TRUE(WriteFile(file, "content"));

테스트 방법

CL에 기록한 테스트는 다음과 같습니다.

base_unittests --gtest_filter=FilePathWatcherTest.MoveParent

이 테스트는 당시 Windows에서 비활성화되어 있었습니다. CQ를 거쳐 2026년 7월 7일(한국 시간) Chromium main에 병합되었습니다.

배운 점

  • 부모 디렉터리를 생성했을 때, 디렉터리 감시에는 이벤트가 오고 아직 없는 파일의 감시에는 이벤트가 오지 않는지 각각 확인해야 합니다.
  • 비동기 알림은 나중에 도착할 수 있으므로, 이벤트 루프를 잠시 실행한 뒤 수신 목록이 비어 있는지 확인해야 합니다.

참고 자료