Skip to main content

FakeFileSystem

Struct FakeFileSystem 

Source
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

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub async fn seed_on_navigation( &self, name: &str, bytes: &[u8], permission: &str, ) -> Result<()>

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

Source§

fn clone(&self) -> FakeFileSystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FakeFileSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more