-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fetch: fragments in responses #7261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const expectedURL = new URL("/common/blank.html#test", location).href; | ||
function fragment_test(url, desc) { | ||
promise_test(() => { | ||
return fetch(url).then(res => { | ||
assert_equals(res.url, expectedURL); | ||
}); | ||
}, "Fetch: " + desc); | ||
async_test(t => { | ||
const client = new XMLHttpRequest(); | ||
client.open("GET", url); | ||
client.send(); | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.responseURL, expectedURL); | ||
}) | ||
}, "XMLHttpRequest: " + desc); | ||
} | ||
|
||
fragment_test("/common/blank.html#test", | ||
"fragment in request copied over to response"); | ||
fragment_test("../resources/redirect.py?omit_parameters&location=/common/blank.html#test", | ||
"fragment in request copied over during redirect to response"); | ||
fragment_test("../resources/redirect.py?omit_parameters&location=/%23test", | ||
"fragment in redirect copied over to response"); | ||
fragment_test("../resources/redirect.py?omit_parameters&location=/%23test#notit", | ||
"fragment in request overridden by fragment in redirect for response"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>Subresources and fragment preservation</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id=log></div> | ||
<!-- | ||
The source image is 50h x 100w lime green. However, if the viewBox 25,25,50,50 is correctly | ||
applied it becomes 25h x 100w. (All images are expected to have this applied per HTTP fragment | ||
rules.) | ||
|
||
This image is then drawn on a 50h x 100w transparent black canvas. | ||
|
||
We then test if the top half of the canvas is lime green and the bottom half is transparent black. | ||
--> | ||
<img data-desc="Control" | ||
src="/images/green.svg#svgView(viewBox(25,25,50,50))"> | ||
<img data-desc="Redirect with the original URL containing a fragment" | ||
src=../api/resources/redirect.py?location=/images/green.svg#svgView(viewBox(25,25,50,50))> | ||
<img data-desc="Redirect with the response Location header containing a fragment" | ||
src=../api/resources/redirect.py?location=/images/green.svg%23svgView(viewBox(25,25,50,50))> | ||
<img data-desc="Redirect with both the original URL and response Location header containing a fragment" | ||
src=../api/resources/redirect.py?location=/images/green.svg%23svgView(viewBox(25,25,50,50))#svgView(viewBox(0,0,50,50))> | ||
<canvas width=100 height=50></canvas> | ||
<script> | ||
const ctx = document.querySelector("canvas").getContext("2d"), | ||
isColor = (data, r, g, b, a) => { | ||
for(let i = 0; i < data.length; i += 4) { | ||
if(data[i] !== r || data[i+1] !== g || data[i+2] !== b || data[i+3] !== a) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
document.querySelectorAll("img").forEach(img => { | ||
async_test(t => { | ||
t.add_cleanup(() => { | ||
img.remove(); | ||
ctx.clearRect(0, 0, 100, 50); | ||
}); | ||
self.addEventListener("load", t.step_func_done(() => { | ||
ctx.drawImage(img, 0, 0); | ||
assert_true(isColor(ctx.getImageData(0, 0, 100, 25).data, 0, 255, 0, 255)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this bit could use a comment to explain what the structure of the image is and why these asserts would fail if something were wrong with how fragments are handled on subresource redirects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an explanation. |
||
assert_true(isColor(ctx.getImageData(0, 25, 100, 25).data, 0, 0, 0, 0)); | ||
})); | ||
}, img.dataset.desc); | ||
}); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Road
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event listener