Restore archived tabs from sidebar
This commit is contained in:
@@ -131,6 +131,17 @@ impl BrowserCore {
|
||||
self.restore_tab(tab)
|
||||
}
|
||||
|
||||
pub fn restore_archived_tab(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
let index = self
|
||||
.archived_tabs
|
||||
.iter()
|
||||
.position(|archived| archived.tab().id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
let archived_tab = self.archived_tabs.remove(index);
|
||||
let tab = archived_tab.into_tab();
|
||||
self.restore_tab(tab)
|
||||
}
|
||||
|
||||
pub fn restore_archived_tab_match(&mut self, query: &str) -> Result<Option<TabId>, CoreError> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
|
||||
@@ -73,6 +73,40 @@ fn restores_last_archived_tab() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restores_archived_tab_by_id() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let example_tab_id = core.open_tab(UrlText::parse("https://example.com")?);
|
||||
let servo_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
|
||||
|
||||
core.close_active_tab()?;
|
||||
core.select_tab(&example_tab_id)?;
|
||||
core.close_active_tab()?;
|
||||
|
||||
let restored_tab_id = core.restore_archived_tab(&servo_tab_id)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(restored_tab_id, servo_tab_id);
|
||||
assert_eq!(snapshot.active_tab_id, servo_tab_id);
|
||||
assert_eq!(snapshot.archived_tabs.len(), 1);
|
||||
assert_eq!(snapshot.archived_tabs[0].tab().id(), &example_tab_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_archived_tab_by_id_returns_error_for_open_tab() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let active_tab_id = core.active_tab()?.id().clone();
|
||||
|
||||
let error = match core.restore_archived_tab(&active_tab_id) {
|
||||
Err(error) => error,
|
||||
Ok(_) => return Err("restore should require an archived tab id".into()),
|
||||
};
|
||||
|
||||
assert_eq!(error, CoreError::TabNotFound { id: active_tab_id });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restores_matching_archived_tab() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user