mirror of
https://github.com/lexmount/moli.git
synced 2026-11-23 16:02:35 +00:00
fix(streams): disturb source synchronously when piping starts
This commit is contained in:
@@ -13,9 +13,6 @@ mod font_queries;
|
||||
#[path = "web_apis/indexed_db_transaction.rs"]
|
||||
mod indexed_db_transaction;
|
||||
|
||||
#[path = "web_apis/pipe_disturbed.rs"]
|
||||
mod pipe_disturbed;
|
||||
|
||||
use moli_test_support as support;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -40,6 +37,8 @@ mod event_dispatch;
|
||||
mod fetch_body_native;
|
||||
#[path = "web_apis/fetch_body_realm.rs"]
|
||||
mod fetch_body_realm;
|
||||
#[path = "web_apis/pipe_disturbed.rs"]
|
||||
mod pipe_disturbed;
|
||||
#[path = "web_apis/request_init.rs"]
|
||||
mod request_init;
|
||||
#[path = "web_apis/request_stream.rs"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::pipe_disturbed::run_probe;
|
||||
use super::event_dispatch::run_probe;
|
||||
use super::*;
|
||||
|
||||
async fn assert_multi_entry_keys(scenario: &str) -> Result<()> {
|
||||
|
||||
@@ -11,7 +11,7 @@ async fn assert_pipe_disturbed(scenario: &str) -> Result<()> {
|
||||
for target in ["window", "child", "worker"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
@@ -33,59 +33,3 @@ async fn piping_disturbs_fetch_bodies_before_reads_and_abort_handling() -> Resul
|
||||
async fn rejected_piping_preserves_undisturbed_fetch_bodies() -> Result<()> {
|
||||
assert_pipe_disturbed("reject").await
|
||||
}
|
||||
|
||||
fn markup_url(server: &FixtureServer, markup: &str) -> String {
|
||||
let mut url = url::Url::parse(&server.url("/compat/child-dynamic-markup-document")).unwrap();
|
||||
url.query_pairs_mut().append_pair("markup", markup);
|
||||
url.into()
|
||||
}
|
||||
|
||||
pub(super) async fn run_probe(
|
||||
browser: &Browser,
|
||||
server: &FixtureServer,
|
||||
target: &str,
|
||||
source: &str,
|
||||
) -> Result<serde_json::Value> {
|
||||
let markup = if target == "worker" {
|
||||
let source = serde_json::to_string(&format!(
|
||||
"self.finish = value => postMessage(value);\n{source}"
|
||||
))?;
|
||||
format!(
|
||||
r#"<!doctype html><script>
|
||||
const worker = new Worker(URL.createObjectURL(new Blob([{source}], {{type: 'text/javascript'}})));
|
||||
window.done = new Promise(resolve => {{
|
||||
worker.onmessage = event => {{ resolve(event.data); worker.terminate(); }};
|
||||
}});
|
||||
worker.postMessage('go');
|
||||
</script>"#
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"<!doctype html><script>self.done = new Promise(resolve => self.finish = resolve);\n{source}</script>"
|
||||
)
|
||||
};
|
||||
let url = markup_url(server, &markup);
|
||||
let url = if target == "child" {
|
||||
markup_url(
|
||||
server,
|
||||
&format!(
|
||||
"<!doctype html><iframe id=target src=\"{}\"></iframe>",
|
||||
url.replace('&', "&")
|
||||
),
|
||||
)
|
||||
} else {
|
||||
url
|
||||
};
|
||||
let mut page = browser.fetch(&url).await?;
|
||||
let expression = if target == "child" {
|
||||
"document.getElementById('target').contentWindow.done.then(JSON.stringify)"
|
||||
} else {
|
||||
"done.then(JSON.stringify)"
|
||||
};
|
||||
let value = page
|
||||
.evaluate_runtime_expression_with_await_async(expression, true)
|
||||
.await?;
|
||||
Ok(serde_json::from_str(
|
||||
value["value"].as_str().expect("callback probe result"),
|
||||
)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user