viewpoint_core/wait/
load_state.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
8pub enum DocumentLoadState {
9 Commit,
12
13 DomContentLoaded,
16
17 #[default]
21 Load,
22
23 NetworkIdle,
26}
27
28impl DocumentLoadState {
29 pub fn is_reached(&self, current: Self) -> bool {
33 current >= *self
34 }
35
36 pub fn cdp_event_name(&self) -> Option<&'static str> {
38 match self {
39 Self::Commit | Self::NetworkIdle => None,
41 Self::DomContentLoaded => Some("Page.domContentEventFired"),
42 Self::Load => Some("Page.loadEventFired"),
43 }
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_load_state_ordering() {
53 assert!(DocumentLoadState::Commit < DocumentLoadState::DomContentLoaded);
54 assert!(DocumentLoadState::DomContentLoaded < DocumentLoadState::Load);
55 assert!(DocumentLoadState::Load < DocumentLoadState::NetworkIdle);
56 }
57
58 #[test]
59 fn test_is_reached() {
60 let current = DocumentLoadState::Load;
61
62 assert!(DocumentLoadState::Commit.is_reached(current));
63 assert!(DocumentLoadState::DomContentLoaded.is_reached(current));
64 assert!(DocumentLoadState::Load.is_reached(current));
65 assert!(!DocumentLoadState::NetworkIdle.is_reached(current));
66 }
67
68 #[test]
69 fn test_default_is_load() {
70 assert_eq!(DocumentLoadState::default(), DocumentLoadState::Load);
71 }
72}