Add recent history clear confirmation

This commit is contained in:
2026-05-08 04:31:19 -04:00
parent 71750114a6
commit 349597d283
5 changed files with 257 additions and 8 deletions
@@ -21,6 +21,15 @@ impl BrowserCore {
self.clear_space_profile_history_for_host(&profile_id, &space_id, host)
}
pub fn clear_active_space_history_since(
&mut self,
cutoff: SystemTime,
) -> Result<usize, crate::CoreError> {
let profile_id = self.active_profile_id.clone();
let space_id = self.active_space_id.clone();
self.clear_space_profile_history_since(&profile_id, &space_id, cutoff)
}
pub(super) fn record_history_entry(&mut self, tab: &BrowserTab) {
if !self.history_recording_policy.records_history()
|| !records_history(tab.url())
@@ -108,6 +117,28 @@ impl BrowserCore {
Ok(original_count - self.history_entries.len())
}
fn clear_space_profile_history_since(
&mut self,
profile_id: &ProfileId,
space_id: &SpaceId,
cutoff: SystemTime,
) -> Result<usize, crate::CoreError> {
if !self.profiles.iter().any(|profile| profile.id() == profile_id) {
return Err(crate::CoreError::ProfileNotFound { id: profile_id.clone() });
}
if !self.spaces.iter().any(|space| space.id() == space_id) {
return Err(crate::CoreError::SpaceNotFound { id: space_id.clone() });
}
let original_count = self.history_entries.len();
self.history_entries.retain(|entry| {
entry.profile_id() != profile_id
|| entry.space_id() != space_id
|| entry.visited_at() < cutoff
});
Ok(original_count - self.history_entries.len())
}
fn profile_records_history(&self, profile_id: &ProfileId) -> bool {
match self.profiles.iter().find(|profile| profile.id() == profile_id) {
Some(profile) => profile.kind() == &ProfileKind::Standard,
+56 -1
View File
@@ -1,4 +1,7 @@
use std::error::Error;
use std::{
error::Error,
time::{Duration, SystemTime},
};
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, CommandScope, HistoryRecordingPolicy, ProfileKind, UrlText};
@@ -137,6 +140,58 @@ fn clear_active_space_history_for_absent_host_is_empty_change() -> Result<(), Bo
Ok(())
}
#[test]
fn clear_active_space_history_since_stays_in_space_and_profile() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let cutoff = SystemTime::now() - Duration::from_secs(3_600);
let work_space_id = core.snapshot()?.active_space_id;
let default_profile_id = core.snapshot()?.active_profile_id;
core.open_tab(UrlText::parse("https://example.com/work-one")?);
core.open_tab(UrlText::parse("https://example.org/work-two")?);
let research_space_id = core.create_space("Research", "R", 0xf54e00)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
core.select_space(&work_space_id)?;
let personal_profile_id = core.create_profile("Personal", 0x26251e, ProfileKind::Standard)?;
core.open_tab(UrlText::parse("https://example.com/personal")?);
core.select_profile(&default_profile_id)?;
let removed_count = core.clear_active_space_history_since(cutoff)?;
let work_snapshot = core.snapshot()?;
assert_eq!(removed_count, 2);
assert!(work_snapshot.history_entries.is_empty());
assert_eq!(work_snapshot.active_profile_history_entry_count, 1);
core.select_space(&research_space_id)?;
let research_snapshot = core.snapshot()?;
assert_eq!(research_snapshot.history_entries.len(), 1);
assert_eq!(research_snapshot.history_entries[0].url().as_str(), "https://example.com/research");
core.select_space(&work_space_id)?;
core.select_profile(&personal_profile_id)?;
let personal_snapshot = core.snapshot()?;
assert_eq!(personal_snapshot.history_entries.len(), 1);
assert_eq!(personal_snapshot.history_entries[0].url().as_str(), "https://example.com/personal");
Ok(())
}
#[test]
fn clear_active_space_history_since_future_cutoff_is_empty_change() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/work")?);
let cutoff = SystemTime::now() + Duration::from_secs(60);
let removed_count = core.clear_active_space_history_since(cutoff)?;
let snapshot = core.snapshot()?;
assert_eq!(removed_count, 0);
assert_eq!(snapshot.history_entries.len(), 1);
assert_eq!(snapshot.active_profile_history_entry_count, 1);
Ok(())
}
#[test]
fn history_scoped_search_opens_recent_matching_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;