fix(tabs): refresh metadata on navigation

This commit is contained in:
2026-05-15 23:31:12 -04:00
parent ca8f118785
commit 225a998642
2 changed files with 62 additions and 0 deletions
+13
View File
@@ -429,6 +429,7 @@ impl BrowserCore {
TabUrlUpdate::PushHistory => self.tabs[tab_index].navigate_to(url),
TabUrlUpdate::PreserveHistory => self.tabs[tab_index].set_url(url),
}
self.refresh_tab_url_metadata(tab_index)?;
self.tabs[tab_index].mark_ready();
let snapshot_tab = self.tabs[tab_index].clone();
self.record_history_entry(&snapshot_tab);
@@ -450,6 +451,7 @@ impl BrowserCore {
return Ok(false);
};
self.refresh_tab_url_metadata(tab_index)?;
self.tabs[tab_index].mark_ready();
let snapshot_tab = self.tabs[tab_index].clone();
self.record_history_entry(&snapshot_tab);
@@ -457,6 +459,17 @@ impl BrowserCore {
Ok(true)
}
fn refresh_tab_url_metadata(&mut self, tab_index: usize) -> Result<(), CoreError> {
let title = tab_title(self.tabs[tab_index].url());
self.tabs[tab_index].set_title(title);
if let Some(favicon_key) = self.tabs[tab_index].url().favicon_url() {
self.tabs[tab_index].set_favicon_key(favicon_key)?;
} else {
self.tabs[tab_index].clear_favicon_key();
}
Ok(())
}
pub(super) fn build_tab(&self, url: UrlText) -> BrowserTab {
self.build_tab_for(self.active_space_id.clone(), self.active_profile_id.clone(), url)
.with_parent_tab_id(self.active_tab_id.clone())
@@ -53,6 +53,55 @@ fn observed_loaded_url_replaces_active_url_without_back_stack() -> Result<(), Bo
Ok(())
}
#[test]
fn navigation_replaces_new_tab_metadata_with_url_metadata() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.navigate_active_tab(UrlText::parse("https://example.com/research")?)?;
let active_tab = core.active_tab()?;
assert_eq!(active_tab.title(), "example.com");
assert_eq!(
active_tab.favicon_key(),
Some("https://www.google.com/s2/favicons?domain=example.com&sz=64"),
);
Ok(())
}
#[test]
fn internal_navigation_clears_previous_web_favicon() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.navigate_active_tab(UrlText::parse("https://example.com/research")?)?;
core.navigate_active_tab(UrlText::parse("ely://history")?)?;
let active_tab = core.active_tab()?;
assert_eq!(active_tab.title(), "History");
assert_eq!(active_tab.favicon_key(), None);
Ok(())
}
#[test]
fn history_navigation_refreshes_url_metadata() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.navigate_active_tab(UrlText::parse("https://example.com/a")?)?;
let tab_id = core.active_tab()?.id().clone();
core.set_tab_title(&tab_id, "Live Example")?;
core.navigate_active_tab(UrlText::parse("https://servo.org/b")?)?;
assert!(core.navigate_active_tab_back()?);
let active_tab = core.active_tab()?;
assert_eq!(active_tab.url().as_str(), "https://example.com/a");
assert_eq!(active_tab.title(), "example.com");
assert_eq!(
active_tab.favicon_key(),
Some("https://www.google.com/s2/favicons?domain=example.com&sz=64"),
);
Ok(())
}
#[test]
fn user_loaded_url_enters_active_back_stack() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;