Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fetch/api/resources/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(request, response):
if "location" in request.GET:
url = request.GET['location']
scheme = urlparse(url).scheme
if scheme == "" or scheme == "http" or scheme == "https":
if (scheme == "" or scheme == "http" or scheme == "https") and "omit_parameters" not in request.GET:
url += "&" if '?' in url else "?"
#keep url parameters in location
url_parameters = {}
Expand Down
25 changes: 25 additions & 0 deletions fetch/api/response/response-fragment.window.js
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");
48 changes: 48 additions & 0 deletions fetch/fragments/subresource-redirect.html
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(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Road

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Event listener

ctx.drawImage(img, 0, 0);
assert_true(isColor(ctx.getImageData(0, 0, 100, 25).data, 0, 255, 0, 255));
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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>