Track history favicon keys
This commit is contained in:
@@ -44,7 +44,7 @@ impl BrowserCore {
|
||||
&& entry.space_id() == tab.space_id()
|
||||
&& entry.url() == tab.url()
|
||||
}) {
|
||||
entry.record_visit(tab.id().clone(), tab.title(), visited_at);
|
||||
entry.record_visit(tab.id().clone(), tab.title(), tab.favicon_key(), visited_at);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,10 +54,36 @@ impl BrowserCore {
|
||||
tab.id().clone(),
|
||||
tab.title(),
|
||||
tab.url().clone(),
|
||||
tab.favicon_key().map(ToOwned::to_owned),
|
||||
visited_at,
|
||||
));
|
||||
}
|
||||
|
||||
pub(super) fn set_history_favicon_key_for_tab(
|
||||
&mut self,
|
||||
tab: &BrowserTab,
|
||||
favicon_key: impl Into<String>,
|
||||
) {
|
||||
let favicon_key = favicon_key.into();
|
||||
if let Some(entry) = self.history_entries.iter_mut().find(|entry| {
|
||||
entry.profile_id() == tab.profile_id()
|
||||
&& entry.space_id() == tab.space_id()
|
||||
&& entry.url() == tab.url()
|
||||
}) {
|
||||
entry.set_favicon_key(favicon_key);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn clear_history_favicon_key_for_tab(&mut self, tab: &BrowserTab) {
|
||||
if let Some(entry) = self.history_entries.iter_mut().find(|entry| {
|
||||
entry.profile_id() == tab.profile_id()
|
||||
&& entry.space_id() == tab.space_id()
|
||||
&& entry.url() == tab.url()
|
||||
}) {
|
||||
entry.clear_favicon_key();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn find_history_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
|
||||
@@ -279,22 +279,27 @@ impl BrowserCore {
|
||||
tab_id: &TabId,
|
||||
favicon_key: impl Into<String>,
|
||||
) -> Result<(), CoreError> {
|
||||
let tab = self
|
||||
let favicon_key = favicon_key.into();
|
||||
let tab_index = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id() == tab_id)
|
||||
.iter()
|
||||
.position(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
tab.set_favicon_key(favicon_key)?;
|
||||
self.tabs[tab_index].set_favicon_key(favicon_key.clone())?;
|
||||
let tab = self.tabs[tab_index].clone();
|
||||
self.set_history_favicon_key_for_tab(&tab, favicon_key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn clear_tab_favicon_key(&mut self, tab_id: &TabId) -> Result<(), CoreError> {
|
||||
let tab = self
|
||||
let tab_index = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id() == tab_id)
|
||||
.iter()
|
||||
.position(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
tab.clear_favicon_key();
|
||||
self.tabs[tab_index].clear_favicon_key();
|
||||
let tab = self.tabs[tab_index].clone();
|
||||
self.clear_history_favicon_key_for_tab(&tab);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,31 @@ fn navigation_records_profile_and_space_history() -> Result<(), Box<dyn Error>>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_entry_updates_favicon_key_after_navigation() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
|
||||
core.set_tab_favicon_key(&tab_id, "favicons/example.ico")?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(snapshot.history_entries[0].favicon_key(), Some("favicons/example.ico"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_entry_clears_favicon_key_with_source_tab() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
|
||||
core.set_tab_favicon_key(&tab_id, "favicons/example.ico")?;
|
||||
core.clear_tab_favicon_key(&tab_id)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(snapshot.history_entries[0].favicon_key(), None);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_history_visits_increment_count_in_active_context() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user