Skip to content

Commit

Permalink
Fix wpt/beacon/headers/header-content-type.html slowness
Browse files Browse the repository at this point in the history
This CL uses ResourceTiming API to speed up the test cases while
avoiding flakiness.

Bug: 779965
Change-Id: I40dc2fae470df296c87c12e432fc7fc7644cc40a
  • Loading branch information
yutakahirano authored and chromium-wpt-export-bot committed Feb 19, 2018
1 parent 63a5a6d commit 2724855
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions beacon/headers/header-content-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,30 @@
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
var RESOURCES_DIR = "/beacon/resources/";

function pollResult(test, id) {
var checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;

return new Promise(resolve => {
step_timeout(test.step_func(() => {
fetch(checkUrl).then(response => {
response.text().then(body => {
resolve(body);
});
});
}), 1000);
});
}
const RESOURCES_DIR = "/beacon/resources/";

function testContentTypeHeader(what, contentType, title) {
var testBase = RESOURCES_DIR;
var id = self.token();
var testUrl = testBase + "content-type.py?cmd=put&id=" + id;

promise_test(function(test) {
function wait(ms) {
return new Promise(resolve => step_timeout(resolve, ms));
}
promise_test(async t => {
const id = self.token();
const testUrl = new Request(RESOURCES_DIR + "content-type.py?cmd=put&id=" + id).url;
assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
return pollResult(test, id) .then(result => {
if (contentType == "multipart/form-data") {
assert_true(result.startsWith(contentType), "Correct Content-Type header result");
} else {
assert_equals(result, contentType, "Correct Content-Type header result");
}
});
assert_equals(performance.getEntriesByName(testUrl).length, 0);

do {
await wait(50);
} while (performance.getEntriesByName(testUrl).length === 0);
assert_equals(performance.getEntriesByName(testUrl).length, 1);
const checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
const response = await fetch(checkUrl);
const text = await response.text();
if (contentType == "multipart/form-data") {
assert_true(text.startsWith(contentType), "Correct Content-Type header result");
} else {
assert_equals(text, contentType, "Correct Content-Type header result");
};
}, "Test content-type header for a body " + title);
}

Expand Down

0 comments on commit 2724855

Please sign in to comment.