Support stable insertion and managed tab placement
Verify Tessera GUI / verify (push) Failing after 7m40s
Verify Tessera GUI / verify (push) Failing after 7m40s
This commit is contained in:
+246
-1
@@ -670,6 +670,10 @@ impl ReplSession {
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)
|
||||
}
|
||||
|
||||
pub fn accepts_tab_drop(&self, input: &crate::events::Input) -> bool {
|
||||
self.bridge.accepts_tab_drop(&self.candidate.vm, input)
|
||||
}
|
||||
|
||||
pub fn accepts_window(&self, id: u64) -> bool {
|
||||
self.bridge.accepts_window(id)
|
||||
}
|
||||
@@ -685,6 +689,9 @@ impl ReplSession {
|
||||
if input.session != self.id {
|
||||
bail!("event belongs to another runtime session");
|
||||
}
|
||||
if !self.accepts_tab_drop(input) {
|
||||
bail!("drop targets an obsolete presentation");
|
||||
}
|
||||
self.bridge.select_window(input.window)?;
|
||||
let result = (|| {
|
||||
self.bridge.dispatch(&mut self.candidate.vm, input)?;
|
||||
@@ -986,6 +993,226 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn positional_insert_preserves_existing_slots_and_mounts_and_rejects_invalid_graphs() {
|
||||
let source = r#"head=TextBlock("head")
|
||||
tail=TextBlock("tail")
|
||||
list=Column(24,8,head,tail)
|
||||
page=Page()
|
||||
page.render(list)"#;
|
||||
let (mut session, initial) = ReplSession::load(source, "app.main", 1, 200).unwrap();
|
||||
session
|
||||
.execute("held=tail.mounts().at(0)", "app.main")
|
||||
.unwrap();
|
||||
let id = session
|
||||
.execute("held.id", "app.main")
|
||||
.unwrap()
|
||||
.value
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
let old = initial
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.find(|mount| mount.id == id)
|
||||
.unwrap();
|
||||
let inserted = session
|
||||
.execute("slot=list.insert(1,TextBlock(\"middle\"))", "app.main")
|
||||
.unwrap();
|
||||
assert_eq!(inserted.value, "2");
|
||||
let document = inserted.document.unwrap();
|
||||
let new = document
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.find(|mount| mount.id == id)
|
||||
.unwrap();
|
||||
assert!(new.y > old.y);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("tail.mounts().at(0).id", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
id.to_string()
|
||||
);
|
||||
for invalid in [
|
||||
"list.insert(4,head)",
|
||||
"list.insert(0,list)",
|
||||
"list.insert(-1,head)",
|
||||
] {
|
||||
assert!(session.execute(invalid, "app.main").is_err());
|
||||
assert!(!session.is_faulted());
|
||||
}
|
||||
assert_eq!(
|
||||
session.execute("held.mounted", "app.main").unwrap().value,
|
||||
"true"
|
||||
);
|
||||
session.execute("list.remove(slot)", "app.main").unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("tail.mounts().at(0).id", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
id.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_drop_preserves_page_identity_calls_source_methods_and_rejects_stale_targets() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../examples/tab-placement.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
201,
|
||||
)
|
||||
.unwrap();
|
||||
session.take_window_commands().unwrap();
|
||||
let page = initial.frame.tabs[0].id;
|
||||
let input = crate::events::Input {
|
||||
window: 1,
|
||||
session: 201,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: page,
|
||||
kind: "tab-drop".into(),
|
||||
point: None,
|
||||
press_point: None,
|
||||
delta: None,
|
||||
screen_position: None,
|
||||
tab_drop: Some(crate::events::TabDrop {
|
||||
window: 1,
|
||||
layout_version: initial.frame.layout_version,
|
||||
index: 3,
|
||||
}),
|
||||
};
|
||||
session
|
||||
.execute("held=list.mounts().at(0)", "app.main")
|
||||
.unwrap();
|
||||
let mount = session.execute("held.id", "app.main").unwrap().value;
|
||||
session.dispatch(&input).unwrap();
|
||||
assert_eq!(
|
||||
session.execute("calls.value", "app.main").unwrap().value,
|
||||
"1"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("list.mounts().at(0).id", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
mount
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("ui.window().pages().at(2)", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
session.execute("first", "app.main").unwrap().value
|
||||
);
|
||||
let input = crate::events::Input {
|
||||
layout_version: session.documents[&1].frame.layout_version,
|
||||
tab_drop: Some(crate::events::TabDrop {
|
||||
window: 2,
|
||||
layout_version: session.documents[&2].frame.layout_version,
|
||||
index: 0,
|
||||
}),
|
||||
..input
|
||||
};
|
||||
let mut stale = input.clone();
|
||||
stale.tab_drop.as_mut().unwrap().layout_version += 1;
|
||||
assert!(!session.accepts_tab_drop(&stale));
|
||||
assert!(session.dispatch(&stale).is_err());
|
||||
assert!(!session.is_faulted());
|
||||
session.dispatch(&input).unwrap();
|
||||
assert_eq!(
|
||||
session.execute("calls.value", "app.main").unwrap().value,
|
||||
"3"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("first.window().id()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("other.pages().at(0)", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
session.execute("first", "app.main").unwrap().value
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("held.mounted", "app.main").unwrap().value,
|
||||
"false"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_respects_declined_source_moves_and_detach_queues_signed_desktop_position() {
|
||||
let source = r#"class Declining: Page {
|
||||
calls: Object
|
||||
function moveToWindow(self: Declining, window: Window): Page { self.calls.increment() return self }
|
||||
}
|
||||
calls=ui.state(0)
|
||||
page=Declining(calls)
|
||||
page.render(TextBlock("source"))
|
||||
other=Window()
|
||||
target=Page()
|
||||
target.render(TextBlock("target"))
|
||||
target.open(other)"#;
|
||||
let (mut session, initial) = ReplSession::load(source, "app.main", 1, 202).unwrap();
|
||||
session.take_window_commands().unwrap();
|
||||
let mut input = crate::events::Input {
|
||||
window: 1,
|
||||
session: 202,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: initial.frame.tabs[0].id,
|
||||
kind: "tab-drop".into(),
|
||||
point: None,
|
||||
press_point: None,
|
||||
delta: None,
|
||||
screen_position: None,
|
||||
tab_drop: Some(crate::events::TabDrop {
|
||||
window: 2,
|
||||
layout_version: initial.windows[&2].frame.layout_version,
|
||||
index: 0,
|
||||
}),
|
||||
};
|
||||
session.dispatch(&input).unwrap();
|
||||
assert_eq!(
|
||||
session.execute("calls.value", "app.main").unwrap().value,
|
||||
"1"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("page.window().id()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"1"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("other.pages().count", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"1"
|
||||
);
|
||||
input.kind = "tab-detach".into();
|
||||
input.tab_drop = None;
|
||||
input.screen_position = Some([-400, 120]);
|
||||
input.layout_version = session.documents[&1].frame.layout_version;
|
||||
session.dispatch(&input).unwrap();
|
||||
let commands = session.take_window_commands().unwrap();
|
||||
assert!(commands.iter().any(|command| command.window == 3
|
||||
&& command.action == crate::window::Action::MoveTo { x: -400, y: 120 }));
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("page.window().id()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"3"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn owned_tasks_replace_cancel_and_update_unmounted_objects() {
|
||||
let source = r#"class Action {
|
||||
@@ -1305,7 +1532,9 @@ mod tests {
|
||||
kind: "click".into(),
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.is_err()
|
||||
);
|
||||
@@ -1489,6 +1718,8 @@ mod tests {
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
};
|
||||
let selected = session.dispatch(&input).unwrap().document.unwrap();
|
||||
assert!(selected.frame.tabs[0].active);
|
||||
@@ -1517,6 +1748,8 @@ mod tests {
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.unwrap()
|
||||
.document
|
||||
@@ -1732,6 +1965,8 @@ mod tests {
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.unwrap()
|
||||
.document
|
||||
@@ -2059,6 +2294,8 @@ mod tests {
|
||||
point: Some(release),
|
||||
delta: None,
|
||||
press_point: Some(press),
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -2103,6 +2340,8 @@ mod tests {
|
||||
point: Some([64.0, 64.0]),
|
||||
delta: None,
|
||||
press_point: Some([64.0, 64.0]),
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.err()
|
||||
.unwrap();
|
||||
@@ -2569,6 +2808,8 @@ mod tests {
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
})
|
||||
.unwrap()
|
||||
.document
|
||||
@@ -2849,6 +3090,8 @@ mod tests {
|
||||
point: None,
|
||||
delta: None,
|
||||
press_point: None,
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
};
|
||||
let updated = session.dispatch(&event).unwrap().document.unwrap();
|
||||
updated.validate().unwrap();
|
||||
@@ -2901,6 +3144,8 @@ mod tests {
|
||||
kind: "click".into(),
|
||||
point: Some(point),
|
||||
press_point: Some(point),
|
||||
tab_drop: None,
|
||||
screen_position: None,
|
||||
delta: None,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user