Skip to content

Commit

Permalink
Move tests for sendBeacon to a separate dedicated directory for clear…
Browse files Browse the repository at this point in the history
…er ownership

Not only because of the ownership clarification, but it's just good to
have a better home for them since they're closer to XHR and Fetch API.
It's not so reasonable to place them in navigation/ just because they
belongs to window.navigator.

The virtual test virtual/stable/http/tests/navigation/ is kept for a
different reason.

Moved redirection-respond.php to http/tests/resources as it's not
specific to the tests under http/tests/navigation/

BUG=682571,619662,490015,694958

Review-Url: https://codereview.chromium.org/2702113003
Cr-Commit-Position: refs/heads/master@{#452408}
  • Loading branch information
tyoshino authored and Commit bot committed Feb 23, 2017
1 parent 645ad78 commit 8a75af1
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 71 deletions.
10 changes: 5 additions & 5 deletions third_party/WebKit/LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1839,13 +1839,13 @@ crbug.com/638618 inspector/editor/text-editor-search-switch-editor.html [ Skip ]

# This test breaks when the feature introduced in the bug is enabled. We keep
# this tested without the feature by using the virtual test. See
# virtual/stable/http/tests/navigation/beacon-cross-origin-redirect-blob-expected.txt
crbug.com/490015 http/tests/navigation/beacon-cross-origin-redirect-blob.html [ Skip ]
crbug.com/490015 virtual/mojo-loading/http/tests/navigation/beacon-cross-origin-redirect-blob.html [ Skip ]
# virtual/stable/http/tests/sendbeacon/beacon-cross-origin-redirect-blob-expected.txt
crbug.com/490015 http/tests/sendbeacon/beacon-cross-origin-redirect-blob.html [ Skip ]
crbug.com/490015 virtual/mojo-loading/http/tests/sendbeacon/beacon-cross-origin-redirect-blob.html [ Skip ]
# This test doesn't need to be run with the stable release mode.
crbug.com/490015 virtual/stable/http/tests/navigation/beacon-blob-with-non-simple-type.html [ Skip ]
crbug.com/490015 virtual/stable/http/tests/sendbeacon/beacon-blob-with-non-simple-type.html [ Skip ]
# This test fails with the stable release mode.
crbug.com/490015 virtual/stable/http/tests/navigation/same-and-different-back.html [ Skip ]
crbug.com/694958 virtual/stable/http/tests/navigation/same-and-different-back.html [ Skip ]

# These tests have console error messages whose order is not deterministic.
crbug.com/685778 http/tests/dom/promise-rejection-events.html [ Pass Failure ]
Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/LayoutTests/VirtualTestSuites
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"base": "http/tests/navigation",
"args": ["--stable-release-mode"]
},
{
"prefix": "stable",
"base": "http/tests/sendbeacon",
"args": ["--stable-release-mode"]
},
{
"prefix": "stable",
"base": "animations-unprefixed",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
</head>
<body onload="doTest()">
<form id="form1" action="resources/redirection-response.php?status=301&target=redirected-post-request-contents.php?content=false" method="post">
<form id="form1" action="../resources/redirection-response.php?status=301&target=/navigation/resources/redirected-post-request-contents.php?content=false" method="post">
<input type="text" name="text1" value="some text"><br>
</form>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
</head>
<body onload="doTest()">
<form id="form1" action="resources/redirection-response.php?status=302&target=redirected-post-request-contents.php?content=false" method="post">
<form id="form1" action="../resources/redirection-response.php?status=302&target=/navigation/resources/redirected-post-request-contents.php?content=false" method="post">
<input type="text" name="text1" value="some text"><br>
</form>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
</head>
<body onload="doTest()">
<form id="form1" action="resources/redirection-response.php?status=303&target=redirected-post-request-contents.php?content=false" method="post">
<form id="form1" action="../resources/redirection-response.php?status=303&target=/navigation/resources/redirected-post-request-contents.php?content=false" method="post">
<input type="text" name="text1" value="some text"><br>
</form>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
</head>
<body onload="doTest()">
<form id="form1" action="resources/redirection-response.php?status=307&target=redirected-post-request-contents.php?content=true" method="post">
<form id="form1" action="../resources/redirection-response.php?status=307&target=/navigation/resources/redirected-post-request-contents.php?content=true" method="post">
<input type="text" name="text1" value="some text"><br>
</form>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
$status_code = $_GET['status'];

$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/" . $_GET['target'];
$target_path = $_GET['target'];

$host = $_SERVER['HTTP_HOST'];
if (isset($_GET['host']))
Expand All @@ -10,19 +9,19 @@
switch ($status_code) {
case 301:
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $host . $uri);
header("Location: http://" . $host . $target_path);
break;
case 302:
header("HTTP/1.1 302 Found");
header("Location: http://" . $host . $uri);
header("Location: http://" . $host . $target_path);
break;
case 303:
header("HTTP/1.1 303 See Other");
header("Location: http://" . $host . $uri);
header("Location: http://" . $host . $target_path);
break;
case 307:
header("HTTP/1.1 307 Temporary Redirect");
header("Location: http://" . $host . $uri);
header("Location: http://" . $host . $target_path);
break;
default:
header("HTTP/1.1 500 Internal Server Error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</script>
</head>
<body>
<form id="form1" action="/navigation/resources/redirection-response.php?host=localhost:8000&status=302&target=form-target.pl" method="post">
<form id="form1" action="/resources/redirection-response.php?host=localhost:8000&status=302&target=/navigation/resources/form-target.pl" method="post">
<input type='text' name='fieldname' value='fieldvalue'>
<input type='submit' id='submit' value='submit'>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Verify that a CSP connect-src directive blocks redirects.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS navigator.sendBeacon("resources/redir.php?url=http://127.0.0.1:8080/navigation/resources/save-beacon.php%3Fname%3Dcsp-redirect-blocked", "ping"); is true
PASS navigator.sendBeacon("resources/redir.php?url=http://127.0.0.1:8080/sendbeacon/resources/save-beacon.php%3Fname%3Dcsp-redirect-blocked", "ping"); is true
PASS Beacon sent successfully
PASS Content-Type: text/plain;charset=UTF-8
PASS Origin: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
description("Verify that a CSP connect-src directive blocks redirects.");
window.jsTestIsAsync = true;

shouldBeTrue('navigator.sendBeacon("resources/redir.php?url=http://127.0.0.1:8080/navigation/resources/save-beacon.php%3Fname%3Dcsp-redirect-blocked", "ping");');
shouldBeTrue('navigator.sendBeacon("resources/redir.php?url=http://127.0.0.1:8080/sendbeacon/resources/save-beacon.php%3Fname%3Dcsp-redirect-blocked", "ping");');

function checkForBeacon() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://127.0.0.1:8000/navigation/resources/check-beacon.php?name=csp-redirect-blocked&retries=100", true);
xhr.open("GET", "http://127.0.0.1:8000/sendbeacon/resources/check-beacon.php?name=csp-redirect-blocked&retries=100", true);
xhr.onload = function () {
var lines = xhr.responseText.split("\n");
for (var i in lines)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONSOLE WARNING: line 18: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
PingLoader dispatched to 'http://127.0.0.1:8000/navigation/resources/save-beacon.php?name=cookie'.
PingLoader dispatched to 'http://127.0.0.1:8000/sendbeacon/resources/save-beacon.php?name=cookie'.
Checking transmission of Beacons involving cookies.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Expand All @@ -10,7 +10,7 @@ PASS Beacon sent successfully
PASS Content-Type: text/plain;charset=UTF-8
PASS Cookie: hello=world
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-cookie.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-cookie.html
PASS Request-Method: POST
PASS Length: 4
PASS Body: Blip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PingLoader dispatched to 'http://localhost:8000/navigation/resources/save-beacon.php?name=cross-origin'.
PingLoader dispatched to 'http://localhost:8000/sendbeacon/resources/save-beacon.php?name=cross-origin'.
Testing navigator.sendBeacon() cross-origin.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS navigator.sendBeacon("http://localhost:8000/navigation/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is true
PASS navigator.sendBeacon("http://localhost:8000/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is true
PASS Beacon sent successfully
PASS Content-Type: text/plain;charset=UTF-8
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-cross-origin.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-cross-origin.html
PASS Request-Method: POST
PASS Length: 11
PASS Body: CrossOrigin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
}

blob = new Blob(["Cross", "Origin"], {type: "text/plain;from-beacon=true"});
shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/navigation/resources/redirection-response.php?status=302&simple=true&target=non-existent.php", blob);');
// The "simple" parameter is just for differentiating the URLs.
shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=true&target=/non-existent.php", blob);');
// Wait a while for the redirect response handling to happen before finishing up.
setTimeout(function () {
blob = new Blob([new Uint8Array(20)], {type: "application/octet-stream"});
shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/navigation/resources/redirection-response.php?status=302&simple=false&target=non-existent.php", blob);');
shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=false&target=/non-existent.php", blob);');
setTimeout(finishJSTest, 200);
}, 200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

promise_test(() => {
return run_test(
host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php',
host_info['HTTP_REMOTE_ORIGIN'] + '/sendbeacon/resources/save-beacon.php',
301,
{
cookie: 'TestCookie=cross',
Expand All @@ -91,7 +91,7 @@

promise_test(() => {
return run_test(
host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php',
host_info['HTTP_REMOTE_ORIGIN'] + '/sendbeacon/resources/save-beacon.php',
302,
{
cookie: 'TestCookie=cross',
Expand All @@ -101,7 +101,7 @@

promise_test(() => {
return run_test(
host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php',
host_info['HTTP_REMOTE_ORIGIN'] + '/sendbeacon/resources/save-beacon.php',
303,
{
cookie: 'TestCookie=cross',
Expand All @@ -111,7 +111,7 @@

promise_test(() => {
return run_test(
host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php',
host_info['HTTP_REMOTE_ORIGIN'] + '/sendbeacon/resources/save-beacon.php',
307,
{
cookie: 'TestCookie=cross',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PingLoader dispatched to 'http://127.0.0.1:8080/resources/redirection-response.php?status=302&target=/non-existent.php'.
Verifying that navigator.sendBeacon() to non-CORS cross-origin redirect fails.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&target=/non-existent.php", "CrossOrigin"); is true
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
testRunner.dumpPingLoaderCallbacks();
}

shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/navigation/resources/redirection-response.php?status=302&target=non-existent.php", "CrossOrigin");');
shouldBeTrue('navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&target=/non-existent.php", "CrossOrigin");');
// Wait a while for the redirect response handling to happen before finishing up.
setTimeout(finishJSTest, 200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
testRunner.dumpPingLoaderCallbacks();
}

shouldBeTrue('navigator.sendBeacon("http://localhost:8000/navigation/resources/save-beacon.php?name=cross-origin", "CrossOrigin");');
shouldBeTrue('navigator.sendBeacon("http://localhost:8000/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin");');
var xhr = new XMLHttpRequest();
xhr.open("GET", "resources/check-beacon.php?name=cross-origin");
xhr.onload = function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CONSOLE ERROR: line 1: Mixed Content: The page at 'https://127.0.0.1:8443/navigation/beacon-cross-origin.https.html' was loaded over HTTPS, but requested an insecure Beacon endpoint 'http://example.test:8000/navigation/resources/save-beacon.php?name=cross-origin'. This request has been blocked; the content must be served over HTTPS.
CONSOLE ERROR: line 1: Mixed Content: The page at 'https://127.0.0.1:8443/sendbeacon/beacon-cross-origin.https.html' was loaded over HTTPS, but requested an insecure Beacon endpoint 'http://example.test:8000/sendbeacon/resources/save-beacon.php?name=cross-origin'. This request has been blocked; the content must be served over HTTPS.
Verify navigator.sendBeacon() mixed content checking.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS navigator.sendBeacon("http://example.test:8000/navigation/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is false
PASS navigator.sendBeacon("http://example.test:8000/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is false
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
testRunner.waitUntilDone();
}

shouldBeFalse('navigator.sendBeacon("http://example.test:8000/navigation/resources/save-beacon.php?name=cross-origin", "CrossOrigin");');
shouldBeFalse('navigator.sendBeacon("http://example.test:8000/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin");');
finishJSTest();
}
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PingLoader dispatched to 'http://127.0.0.1:8000/navigation/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/navigation/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/navigation/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/navigation/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/sendbeacon/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/sendbeacon/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/sendbeacon/resources/save-beacon.php?name=same-origin'.
PingLoader dispatched to 'http://127.0.0.1:8000/sendbeacon/resources/save-beacon.php?name=same-origin'.
Testing navigator.sendBeacon() within same origin.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Expand All @@ -12,7 +12,7 @@ PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload)
PASS Beacon sent successfully
PASS Content-Type: text/plain;charset=UTF-8
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-same-origin.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-same-origin.html
PASS Request-Method: POST
PASS Length: 10
PASS Body: SameOrigin
Expand All @@ -22,7 +22,7 @@ PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload)
PASS Beacon sent successfully
PASS Content-Type: application/octet-stream
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-same-origin.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-same-origin.html
PASS Request-Method: POST
PASS Length: 40
PASS Body: QAAAAEEAAABCAAAAQwAAAEQAAABFAAAARgAAAEcAAABIAAAASQAAAA==
Expand All @@ -32,7 +32,7 @@ PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload)
PASS Beacon sent successfully
PASS Content-Type: text/plain;from-beacon=true
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-same-origin.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-same-origin.html
PASS Request-Method: POST
PASS Length: 11
PASS Body: hello world
Expand All @@ -42,7 +42,7 @@ PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload)
PASS Beacon sent successfully
PASS Content-Type: multipart/form-data;
PASS Origin: http://127.0.0.1:8000
PASS Referer: http://127.0.0.1:8000/navigation/beacon-same-origin.html
PASS Referer: http://127.0.0.1:8000/sendbeacon/beacon-same-origin.html
PASS Request-Method: POST
PASS Length: 9
PASS Body: key=value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
This directory contains expectations to keep the sendBeacon tested both for
the experimental web platform features flag turned on and off until
http://crbug.com/490015 is resolved.
This directory contains expectations to keep the navigation logic tested both
when the --site-per-proces flag turned on and off. See http://crbug.com/619662.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains expectations to keep the sendBeacon tested both for
the experimental web platform features flag turned on and off until
http://crbug.com/490015 is resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PingLoader dispatched to 'http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=true&target=/non-existent.php'.
PingLoader dispatched to 'http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=false&target=/non-existent.php'.
CONSOLE ERROR: Redirect from 'http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=false&target=/non-existent.php' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8000' is therefore not allowed access.
Verifying navigator.sendBeacon(Blob) non-CORS cross-origin redirect handling.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=true&target=/non-existent.php", blob); is true
PASS navigator.sendBeacon("http://127.0.0.1:8080/resources/redirection-response.php?status=302&simple=false&target=/non-existent.php", blob); is true
PASS successfullyParsed is true

TEST COMPLETE

0 comments on commit 8a75af1

Please sign in to comment.