Add profile history clear confirmation

This commit is contained in:
2026-05-08 04:10:04 -04:00
parent 177399dd1c
commit 02279f8984
6 changed files with 189 additions and 1 deletions
+2
View File
@@ -55,6 +55,7 @@ pub struct BrowserSnapshot {
pub site_permission_audit_events: Vec<SitePermissionAuditEvent>,
pub download_entries: Vec<DownloadEntry>,
pub history_entries: Vec<HistoryEntry>,
pub active_profile_history_entry_count: usize,
pub split_layouts: Vec<SplitLayout>,
pub installed_plugins: Vec<InstalledPlugin>,
pub plugin_audit_events: Vec<PluginAuditEvent>,
@@ -291,6 +292,7 @@ impl BrowserCore {
site_permission_audit_events: self.visible_site_permission_audit_events(),
download_entries: self.visible_downloads(),
history_entries: self.visible_history(),
active_profile_history_entry_count: self.active_profile_history_count(),
split_layouts: self.visible_split_layouts(),
installed_plugins: self.installed_plugins.clone(),
plugin_audit_events: self.plugin_audit_events.clone(),
@@ -7,6 +7,11 @@ use crate::navigation::records_history;
use super::BrowserCore;
impl BrowserCore {
pub fn clear_active_profile_history(&mut self) -> Result<usize, crate::CoreError> {
let profile_id = self.active_profile_id.clone();
self.clear_profile_history(&profile_id)
}
pub(super) fn record_history_entry(&mut self, tab: &BrowserTab) {
if !self.history_recording_policy.records_history()
|| !records_history(tab.url())
@@ -50,6 +55,23 @@ impl BrowserCore {
.collect()
}
pub(super) fn active_profile_history_count(&self) -> usize {
self.history_entries
.iter()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.count()
}
fn clear_profile_history(&mut self, profile_id: &ProfileId) -> Result<usize, crate::CoreError> {
if !self.profiles.iter().any(|profile| profile.id() == profile_id) {
return Err(crate::CoreError::ProfileNotFound { id: profile_id.clone() });
}
let original_count = self.history_entries.len();
self.history_entries.retain(|entry| entry.profile_id() != profile_id);
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,
+40
View File
@@ -45,6 +45,46 @@ fn paused_history_recording_skips_new_history_entries() -> Result<(), Box<dyn Er
Ok(())
}
#[test]
fn clear_active_profile_history_removes_every_space_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let default_profile_id = core.snapshot()?.active_profile_id;
core.open_tab(UrlText::parse("https://example.com/work")?);
core.create_space("Research", "R", 0xf54e00)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
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_profile_history()?;
let default_snapshot = core.snapshot()?;
assert_eq!(removed_count, 2);
assert_eq!(default_snapshot.active_profile_history_entry_count, 0);
assert!(default_snapshot.history_entries.is_empty());
core.select_profile(&personal_profile_id)?;
let personal_snapshot = core.snapshot()?;
assert_eq!(personal_snapshot.active_profile_history_entry_count, 1);
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_profile_history_without_entries_is_empty_change() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let removed_count = core.clear_active_profile_history()?;
let snapshot = core.snapshot()?;
assert_eq!(removed_count, 0);
assert_eq!(snapshot.active_profile_history_entry_count, 0);
assert!(snapshot.history_entries.is_empty());
Ok(())
}
#[test]
fn history_scoped_search_opens_recent_matching_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;