pub struct FakeFileSystem { /* private fields */ }Expand description
Handle to the fake File System Access API installed on a Page by
Page::fake_file_system.
See the module docs for the pattern and a usage example. Scope of
the fake: showSaveFilePicker, showOpenFilePicker, per-handle
getFile/createWritable/queryPermission/requestPermission, and
persisting a handle to IndexedDB — apps that stash the picker handle in
IndexedDB and re-queryPermission on the next load (the standard
startup-reopen pattern) work, because the fake stores a serializable
placeholder in place of the method-bearing handle and rehydrates it on read
(real FileSystemFileHandle is [Serializable]; the fake is not, so a raw
put would otherwise throw DataCloneError). The in-memory file content
and permission state still live in page JS, so they reset on a full page
reload. To test an app that reads its last file on startup (reading before
any test code could re-seed), use
seed_on_navigation, which re-establishes
content and permission before the app mounts on the next navigation;
set_open_file only takes effect at call time.
showDirectoryPicker is not faked.
IndexedDB access requires a real origin: install the fake, then
goto an http(s):// page rather than using
set_content (opaque origins deny IndexedDB) if the flow under test
persists handles.
Implementations§
Source§impl FakeFileSystem
impl FakeFileSystem
Sourcepub async fn last_saved_name(&self) -> Result<Option<String>>
pub async fn last_saved_name(&self) -> Result<Option<String>>
The file name passed to the most recent completed save, or None if
nothing has been saved.
§Errors
Returns an error if the page is closed or the evaluation fails.
Sourcepub async fn last_saved_bytes(&self) -> Result<Option<Vec<u8>>>
pub async fn last_saved_bytes(&self) -> Result<Option<Vec<u8>>>
The bytes written by the most recent completed save (everything
written between createWritable() and close()), or None if
nothing has been saved.
§Errors
Returns an error if the page is closed, the evaluation fails, or the shim returns malformed base64 (which indicates a bug in the shim, not the caller).
Sourcepub async fn set_open_file(&self, name: &str, bytes: &[u8]) -> Result<()>
pub async fn set_open_file(&self, name: &str, bytes: &[u8]) -> Result<()>
Seed a file that the app’s next showOpenFilePicker() call will
“pick”. Seeding the same name again replaces the content.
§Errors
Returns an error if the page is closed or the evaluation fails.
Sourcepub async fn set_permission(&self, state: &str) -> Result<()>
pub async fn set_permission(&self, state: &str) -> Result<()>
Set the permission state reported by the fake handles’
queryPermission / requestPermission: "granted", "prompt", or
"denied". Defaults to "granted". In the "prompt" state,
requestPermission upgrades to "granted", mirroring the real API’s
user-approval path; in "denied", the pickers throw
NotAllowedError.
§Errors
Returns an error if the page is closed or the evaluation fails.
Sourcepub async fn grant_permission(&self) -> Result<()>
pub async fn grant_permission(&self) -> Result<()>
Shorthand for set_permission("granted").
§Errors
Returns an error if the page is closed or the evaluation fails.
Re-establishes openable-file content and permission state before the app
mounts on the next navigation (including reload).
set_open_file and
set_permission take effect at call time, which
is too late for an app that reads its last file on startup: a full page
reload clears the fake’s in-memory content and resets permission to
"granted", and by the time a test could re-seed, the app has already
mounted and read. This registers an init script (running after the fake’s
own, so window state exists) that re-seeds the given file and
permission on every subsequent navigation — making the “reopen the last
file on startup” flow testable across a reload. The persisted handle
already survives a reload on its own (the fake stores it in IndexedDB and
rehydrates it); only content and permission need re-seeding.
The seed persists for all later navigations in this context, so seed the
state the app should observe on its next load. permission takes the
same values as set_permission.
§Errors
Returns an error if the page is closed or registering the script fails.
Trait Implementations§
Source§impl Clone for FakeFileSystem
impl Clone for FakeFileSystem
Source§fn clone(&self) -> FakeFileSystem
fn clone(&self) -> FakeFileSystem
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more