From c5b1d7c5e9b20f588d67184b67f6a87149984340 Mon Sep 17 00:00:00 2001 From: Daniel Pechersky Date: Fri, 6 Dec 2024 15:11:00 -0500 Subject: [PATCH 1/3] Reproduce bug --- src/tests/fixtures/frames.html | 4 + src/tests/functional/frame_tests.js | 109 +++++++++++++++++++++++++++- src/tests/functional/visit_tests.js | 62 ++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index 1749de14b..182161aee 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -111,6 +111,10 @@

Frames: #nested-child

Missing frame Missing page Unvisitable page + Non-HTML + Unknown non-HTML + Redirect to non-HTML + Redirect to unknown non-HTML diff --git a/src/tests/functional/frame_tests.js b/src/tests/functional/frame_tests.js index 264024720..d6293cdbf 100644 --- a/src/tests/functional/frame_tests.js +++ b/src/tests/functional/frame_tests.js @@ -16,7 +16,7 @@ import { readEventLogs, scrollPosition, scrollToSelector, - searchParams + searchParams, visitAction } from "../helpers/page" assert.equalIgnoringWhitespace = function (actual, expected, message) { @@ -169,6 +169,113 @@ test("successfully following a link to a page without a matching frame shows an assert.include(error.message, `The response (200) did not contain the expected `) }) +test("following a link to a non html file changes page src", async ({ page }) => { + await page.goto("/src/tests/fixtures/frames.html") + + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + + await page.click("#non-html") + await nextBeat() + + assert.deepEqual(requestedUrls, [ + ["document", "http://localhost:9000/src/tests/fixtures/svg.svg"] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + +test("following a link to an unknown non html file changes page src", async ({ page }) => { + await page.goto("/src/tests/fixtures/frames.html") + + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + + await page.click("#unknown-non-html") + await nextBeat() + + // Because the file extension is not a known extension, Turbo will request it first to + // determine the content type and only then refresh the full page to the provided location + assert.deepEqual(requestedUrls, [ + ["fetch", "http://localhost:9000/__turbo/file.unknown_svg"], + ["document", "http://localhost:9000/__turbo/file.unknown_svg"] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + +test("following a link that redirects to a non html file changes page src", async ({ page }) => { + await page.goto("/src/tests/fixtures/frames.html") + + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + + await page.click("#redirect-to-non-html") + await nextBeat() // 302 + await nextBeat() // 200 + + assert.deepEqual(requestedUrls, [ + [ + "fetch", "http://localhost:9000/__turbo/redirect?path=%2Fsrc%2Ftests%2Ffixtures%2Fsvg.svg" + ], + [ + "fetch", "http://localhost:9000/src/tests/fixtures/svg.svg" + ], + [ + "document", "http://localhost:9000/__turbo/redirect?path=/src/tests/fixtures/svg.svg" + ], + [ + "document", "http://localhost:9000/src/tests/fixtures/svg.svg" + ] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + +test("following a link that redirects to an unknown non html file changes page src", async ({ page }) => { + await page.goto("/src/tests/fixtures/frames.html") + + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + + await page.click("#redirect-to-unknown-non-html") + await nextBeat() // 302 + await nextBeat() // 200 + + assert.deepEqual(requestedUrls, [ + [ + "fetch", "http://localhost:9000/__turbo/redirect?path=%2F__turbo%2Ffile.unknown_svg" + ], + [ + "fetch", "http://localhost:9000/__turbo/file.unknown_svg" + ], + [ + "document", "http://localhost:9000/__turbo/redirect?path=/__turbo/file.unknown_svg" + ], + [ + "document", "http://localhost:9000/__turbo/file.unknown_svg" + ] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + test("successfully following a link to a page with `turbo-visit-control` `reload` performs a full page reload", async ({ page }) => { diff --git a/src/tests/functional/visit_tests.js b/src/tests/functional/visit_tests.js index 165aef74b..fe35e84b1 100644 --- a/src/tests/functional/visit_tests.js +++ b/src/tests/functional/visit_tests.js @@ -94,6 +94,68 @@ test("visiting a location served with an unknown non-HTML content type", async ( assert.equal(await visitAction(page), "load") }) +test("being redirected to a location served with a known non-HTML content type", async ({ page }) => { + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + await visitLocation(page, "/__turbo/redirect?path=/src/tests/fixtures/svg.svg") + await nextBeat() // 302 + await nextBeat() // 200 + + const url = page.url() + const contentType = await contentTypeOfURL(url) + assert.equal(contentType, "image/svg+xml") + + assert.deepEqual(requestedUrls, [ + [ + "fetch", "http://localhost:9000/__turbo/redirect?path=%2Fsrc%2Ftests%2Ffixtures%2Fsvg.svg" + ], + [ + "fetch", "http://localhost:9000/src/tests/fixtures/svg.svg" + ], + [ + "document", "http://localhost:9000/__turbo/redirect?path=/src/tests/fixtures/svg.svg" + ], + [ + "document", "http://localhost:9000/src/tests/fixtures/svg.svg" + ] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + +test("being redirected to a location served with an unknown non-HTML content type", async ({ page }) => { + const requestedUrls = [] + page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) + + const urlBeforeVisit = page.url() + await visitLocation(page, "/__turbo/redirect?path=/__turbo/file.unknown_svg") + await nextBeat() // 302 + await nextBeat() // 200 + + assert.deepEqual(requestedUrls, [ + [ + "fetch", "http://localhost:9000/__turbo/redirect?path=%2F__turbo%2Ffile.unknown_svg" + ], + [ + "fetch", "http://localhost:9000/__turbo/file.unknown_svg" + ], + [ + "document", "http://localhost:9000/__turbo/redirect?path=/__turbo/file.unknown_svg" + ], + [ + "document", "http://localhost:9000/__turbo/file.unknown_svg" + ] + ]) + + const urlAfterVisit = page.url() + assert.notEqual(urlBeforeVisit, urlAfterVisit) + assert.equal(await visitAction(page), "load") +}) + test("visiting a location served with an unknown non-HTML content type added to the unvisitableExtensions set", async ({ page }) => { const requestedUrls = [] page.on('request', (req) => { requestedUrls.push([req.resourceType(), req.url()]) }) From 881cdd89f47d6b20404935782154a94245eb606c Mon Sep 17 00:00:00 2001 From: Daniel Pechersky Date: Fri, 6 Dec 2024 15:33:21 -0500 Subject: [PATCH 2/3] Fix formatting --- src/tests/functional/frame_tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/functional/frame_tests.js b/src/tests/functional/frame_tests.js index d6293cdbf..dcff9916e 100644 --- a/src/tests/functional/frame_tests.js +++ b/src/tests/functional/frame_tests.js @@ -16,7 +16,8 @@ import { readEventLogs, scrollPosition, scrollToSelector, - searchParams, visitAction + searchParams, + visitAction } from "../helpers/page" assert.equalIgnoringWhitespace = function (actual, expected, message) { From f951c4f99302539dd02e7f41cae1e7a7c9e0fe48 Mon Sep 17 00:00:00 2001 From: Daniel Pechersky Date: Fri, 6 Dec 2024 16:16:07 -0500 Subject: [PATCH 3/3] Fix new tests --- src/tests/fixtures/frames.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index 182161aee..41be41c87 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -113,8 +113,8 @@

Frames: #nested-child

Unvisitable page Non-HTML Unknown non-HTML - Redirect to non-HTML - Redirect to unknown non-HTML + Redirect to non-HTML + Redirect to unknown non-HTML