Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/request/request-keepalive-quota.html

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Request Keepalive Quota Tests</title>
6 <meta name="help" href="https://fetch.spec.whatwg.org/#request">
7 <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
8 <meta name="author" title="Microsoft Edge" href="https://www.microsoft.c om">
9 <meta name="timeout" content="long">
10 <script src="/resources/testharness.js"></script>
11 <script src="/resources/testharnessreport.js"></script>
12 </head>
13 <body>
14 <script>
15 "use strict";
16
17 // We want to ensure that our keepalive requests hang slightly befor e completing so we can validate
18 // the effects of a rolling quota. To do this we will utilize trickl e.py with a 1s delay. This should
19 // prevent any of the Fetch's from finishing in this window.
20 var trickleURL = "../resources/trickle.py?count=1&ms=";
21 var standardDelay = 1000;
22
23 // We should expect 64KiB of rolling quota for any type of keep-aliv e request sent.
24 var expectedQuota = 65536;
25
26 function CreateKeepAliveRequest(delay, bodySize) {
27 // Create a body of the specified size that's filled with *'s
28 var requestBody = "*".repeat(bodySize);
29 return new Request(trickleURL+delay, {keepalive: true, body: req uestBody, method: "POST"});
30 }
31
32 // Test 1 Byte
33 promise_test(function(test) {
34 return fetch(CreateKeepAliveRequest(0 /* delay */, 1 /* bodySize */));
35 }, "A Keep-Alive fetch() with a small body should succeed.");
36
37 // Test Quota full limit
38 promise_test(function(test) {
39 return fetch(CreateKeepAliveRequest(0 /* delay */, expectedQuota ));
40 }, "A Keep-Alive fetch() with a body at the Quota Limit should succe ed.");
41
42 // Test Quota + 1 Byte
43 promise_test(function(test) {
44 return promise_rejects(test, new TypeError(), fetch(CreateKeepAl iveRequest(0 /* delay */, expectedQuota + 1)));
45 }, "A Keep-Alive fetch() with a body over the Quota Limit should rej ect.");
46
47 // Test the Quota becomes available upon promise completion.
48 promise_test(function (test) {
49 // Fill our Quota then try to send a second fetch.
50 var firstFetch = fetch(CreateKeepAliveRequest(standardDelay, exp ectedQuota)).then(function(response) {
51 // Now validate that we can send another Keep-Alive fetch fo r the full size of the quota.
52 return fetch(CreateKeepAliveRequest(0 /* delay */, expectedQ uota));
53 });
54
55 return firstFetch;
56 }, "A Keep-Alive fetch() should return it's allocated Quota upon pro mise resolution.");
57
58 // Ensure only the correct amount of Quota becomes available when a fetch completes.
59 promise_test(function(test) {
60 var lastFetchSucceeded = false;
61 // Create a fetch that uses all but 1 Byte of the Quota and runs for 2x as long as the other requests.
62 var firstFetch = fetch(CreateKeepAliveRequest(standardDelay * 2, expectedQuota - 1)).then(function(response) {
63 // This should be our last completing fetch(). We need to va lidate that the last fetch we sent out actually
64 // completed.
65 assert_true(lastFetchSucceeded, "Out last fetch after gainin g Quota back should have succeeded.");
66 });
67
68 // Now create a single Byte request that will complete quicker.
69 fetch(CreateKeepAliveRequest(standardDelay, 1 /* bodySize */)).t hen(function(response) {
70 // We shouldn't be able to create a 2 Byte request right now as only 1 Byte should have freed up.
71 assert_throws(new TypeError(), fetch(CreateKeepAliveRequest( 0 /* delay */, 2 /* bodySize */)), "Only 1 Byte of Quota should be available rig ht now.");
72
73 // Now validate that we can send another Keep-Alive fetch fo r just 1 Byte.
74 fetch(CreateKeepAliveRequest(0 /* delay */, 1 /* bodySize */ )).then(function(response) {
75 // Flag we got a response from this request.
76 lastFetchSucceeded = true;
77 });
78 });
79
80 return firstFetch;
81 }, "A Keep-Alive fetch() should return only it's allocated Quota upo n promise resolution.");
82
83 // Test rejecting a fetch() after the quota is used up.
84 promise_test(function (test) {
85 // Fill our Quota then try to send a second fetch.
86 fetch(CreateKeepAliveRequest(standardDelay, expectedQuota));
87
88 return promise_rejects(test, new TypeError(), fetch(CreateKeepAl iveRequest(0 /* delay */, 1 /* bodySize */)));
89 }, "A Keep-Alive fetch() should not be allowed if the Quota is used up.");
90
91 </script>
92 </body>
93 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698