Changeset 263595 in webkit
- Timestamp:
- Jun 26, 2020 4:07:38 PM (4 years ago)
- Location:
- trunk/LayoutTests/imported/w3c
- Files:
-
- 5 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r263451 r263595 1 2020-06-26 Chris Dumez <cdumez@apple.com> 2 3 Update web-platform-tests/beacon from upstream 4 https://bugs.webkit.org/show_bug.cgi?id=213663 5 6 Reviewed by Darin Adler. 7 8 Update web-platform-tests/beacon from upstream b076c305a256e7fb7. 9 10 * web-platform-tests/beacon/*: Updated. 11 1 12 2020-06-24 Sergio Villar Senin <svillar@igalia.com> 2 13 -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-common.sub.js
r253760 r263595 17 17 18 18 // Test case definitions. 19 // id: String containing the unique name of the test case.19 // name: String containing the unique name of the test case. 20 20 // data: Payload object to send through sendbeacon. 21 var noDataTest = { id: "NoData" };22 var nullDataTest = { id: "NullData", data: null };23 var undefinedDataTest = { id: "UndefinedData", data: undefined };24 var smallStringTest = { id: "SmallString", data: smallPayload };25 var mediumStringTest = { id: "MediumString", data: mediumPayload };26 var largeStringTest = { id: "LargeString", data: largePayload };27 var maxStringTest = { id: "MaxString", data: maxPayload };28 var emptyBlobTest = { id: "EmptyBlob", data: new Blob() };29 var smallBlobTest = { id: "SmallBlob", data: new Blob([smallPayload]) };30 var mediumBlobTest = { id: "MediumBlob", data: new Blob([mediumPayload]) };31 var largeBlobTest = { id: "LargeBlob", data: new Blob([largePayload]) };32 var maxBlobTest = { id: "MaxBlob", data: new Blob([maxPayload]) };33 var emptyBufferSourceTest = { id: "EmptyBufferSource", data: new Uint8Array() };34 var smallBufferSourceTest = { id: "SmallBufferSource", data: CreateArrayBufferFromPayload(smallPayload) };35 var mediumBufferSourceTest = { id: "MediumBufferSource", data: CreateArrayBufferFromPayload(mediumPayload) };36 var largeBufferSourceTest = { id: "LargeBufferSource", data: CreateArrayBufferFromPayload(largePayload) };37 var maxBufferSourceTest = { id: "MaxBufferSource", data: CreateArrayBufferFromPayload(maxPayload) };38 var emptyFormDataTest = { id: "EmptyFormData", data: CreateEmptyFormDataPayload() };39 var smallFormDataTest = { id: "SmallFormData", data: CreateFormDataFromPayload(smallPayload) };40 var mediumFormDataTest = { id: "MediumFormData", data: CreateFormDataFromPayload(mediumPayload) };41 var largeFormDataTest = { id: "LargeFormData", data: CreateFormDataFromPayload(largePayload) };42 var smallSafeContentTypeEncodedTest = { id: "SmallSafeContentTypeEncoded", data: new Blob([smallPayload], { type: 'application/x-www-form-urlencoded' }) };43 var smallSafeContentTypeFormTest = { id: "SmallSafeContentTypeForm", data: new FormData() };44 var smallSafeContentTypeTextTest = { id: "SmallSafeContentTypeText", data: new Blob([smallPayload], { type: 'text/plain' }) };45 var smallCORSContentTypeTextTest = { id: "SmallCORSContentTypeText", data: new Blob([smallPayload], { type: 'text/html' }) };21 var noDataTest = { name: "NoData" }; 22 var nullDataTest = { name: "NullData", data: null }; 23 var undefinedDataTest = { name: "UndefinedData", data: undefined }; 24 var smallStringTest = { name: "SmallString", data: smallPayload }; 25 var mediumStringTest = { name: "MediumString", data: mediumPayload }; 26 var largeStringTest = { name: "LargeString", data: largePayload }; 27 var maxStringTest = { name: "MaxString", data: maxPayload }; 28 var emptyBlobTest = { name: "EmptyBlob", data: new Blob() }; 29 var smallBlobTest = { name: "SmallBlob", data: new Blob([smallPayload]) }; 30 var mediumBlobTest = { name: "MediumBlob", data: new Blob([mediumPayload]) }; 31 var largeBlobTest = { name: "LargeBlob", data: new Blob([largePayload]) }; 32 var maxBlobTest = { name: "MaxBlob", data: new Blob([maxPayload]) }; 33 var emptyBufferSourceTest = { name: "EmptyBufferSource", data: new Uint8Array() }; 34 var smallBufferSourceTest = { name: "SmallBufferSource", data: CreateArrayBufferFromPayload(smallPayload) }; 35 var mediumBufferSourceTest = { name: "MediumBufferSource", data: CreateArrayBufferFromPayload(mediumPayload) }; 36 var largeBufferSourceTest = { name: "LargeBufferSource", data: CreateArrayBufferFromPayload(largePayload) }; 37 var maxBufferSourceTest = { name: "MaxBufferSource", data: CreateArrayBufferFromPayload(maxPayload) }; 38 var emptyFormDataTest = { name: "EmptyFormData", data: CreateEmptyFormDataPayload() }; 39 var smallFormDataTest = { name: "SmallFormData", data: CreateFormDataFromPayload(smallPayload) }; 40 var mediumFormDataTest = { name: "MediumFormData", data: CreateFormDataFromPayload(mediumPayload) }; 41 var largeFormDataTest = { name: "LargeFormData", data: CreateFormDataFromPayload(largePayload) }; 42 var smallSafeContentTypeEncodedTest = { name: "SmallSafeContentTypeEncoded", data: new Blob([smallPayload], { type: 'application/x-www-form-urlencoded' }) }; 43 var smallSafeContentTypeFormTest = { name: "SmallSafeContentTypeForm", data: new FormData() }; 44 var smallSafeContentTypeTextTest = { name: "SmallSafeContentTypeText", data: new Blob([smallPayload], { type: 'text/plain' }) }; 45 var smallCORSContentTypeTextTest = { name: "SmallCORSContentTypeText", data: new Blob([smallPayload], { type: 'text/html' }) }; 46 46 // We don't test maxFormData because the extra multipart separators make it difficult to 47 47 // calculate a maxPayload. … … 66 66 67 67 var preflightTests = [smallCORSContentTypeTextTest]; 68 69 // Build a test lookup table, which is useful when instructing a web worker or an iframe70 // to run a test, so that we don't have to marshal the entire test case across a process boundary.71 var testLookup = {};72 allTests.forEach(function(testCase) {73 testLookup[testCase.id] = testCase;74 });75 68 76 69 // Helper function to create an ArrayBuffer representation of a string. … … 106 99 } 107 100 108 // Initializes a session with a client-generated SID. 109 // A "session" is a run of one or more tests. It is used to batch several beacon 110 // tests in a way that isolates the server-side session state and makes it easy 111 // to poll the results of the tests in one request. 112 // testCases: The array of test cases participating in the session. 113 function initSession(testCases) { 114 return { 115 // Provides a unique session identifier to prevent mixing server-side data 116 // with other sessions. 117 id: self.token(), 118 // Dictionary of test name to live testCase object. 119 testCaseLookup: {}, 120 // Array of testCase objects for iteration. 121 testCases: [], 122 // Tracks the total number of tests in the session. 123 totalCount: testCases.length, 124 // Tracks the number of tests for which we have sent the beacon. 125 // When it reaches totalCount, we will start polling for results. 126 sentCount: 0, 127 // Tracks the number of tests for which we have verified the results. 128 // When it reaches sentCount, we will stop polling for results. 129 doneCount: 0, 130 // Helper to add a testCase to the session. 131 add: function add(testCase) { 132 this.testCases.push(testCase); 133 this.testCaseLookup[testCase.id] = testCase; 134 } 101 // Schedules async_test's for each of the test cases, treating them as a single session, 102 // and wires up the continueAfterSendingBeacon() and waitForResults() calls. 103 // Parameters: 104 // testCases: An array of test cases. 105 // suffix [optional]: A string used for the suffix for each test case name. 106 // buildUrl [optional]: A function that returns a beacon URL given an id. 107 // sendData [optional]: A function that sends the beacon with given a URL and payload. 108 function runTests(testCases, suffix = '', buildUrl = self.buildUrl, sendData = self.sendData) { 109 for (const testCase of testCases) { 110 const id = token(); 111 async_test((test) => { 112 const url = buildUrl(id); 113 assert_true(sendData(url, testCase.data), 'sendBeacon should succeed'); 114 waitForResult(id).then(() => test.done(), test.step_func((e) => {throw e;})); 115 }, `Verify 'navigator.sendbeacon()' successfully sends for variant: ${testCase.name}${suffix}`); 135 116 }; 136 117 } 137 118 138 // Schedules async_test's for each of the test cases, treating them as a single session, 139 // and wires up the continueAfterSendingBeacon() and waitForResults() calls. 140 // The method looks for several "extension" functions in the global scope: 141 // - self.buildBaseUrl: if present, can change the base URL of a beacon target URL (this 142 // is the scheme, hostname, and port). 143 // - self.buildTargetUrl: if present, can modify a beacon target URL (for example wrap it). 144 // Parameters: 145 // testCases: An array of test cases. 146 // sendData [optional]: A function that sends the beacon. 147 function runTests(testCases, sendData = self.sendData) { 148 const session = initSession(testCases); 149 150 testCases.forEach(function(testCase, testIndex) { 151 // Make a copy of the test case as we'll be storing some metadata on it, 152 // such as which session it belongs to. 153 const testCaseCopy = Object.assign({ session: session }, testCase); 154 155 testCaseCopy.index = testIndex; 156 157 async_test((test) => { 158 // Save the testharness.js 'test' object, so that we only have one object 159 // to pass around. 160 testCaseCopy.test = test; 161 162 // Extension point: generate the beacon URL. 163 var baseUrl = "http://{{host}}:{{ports[http][0]}}"; 164 if (self.buildBaseUrl) { 165 baseUrl = self.buildBaseUrl(baseUrl); 166 } 167 var targetUrl = `${baseUrl}/beacon/resources/beacon.py?cmd=store&sid=${session.id}&tid=${testCaseCopy.id}&tidx=${testIndex}`; 168 if (self.buildTargetUrl) { 169 targetUrl = self.buildTargetUrl(targetUrl); 170 } 171 // Attach the URL to the test object for debugging purposes. 172 testCaseCopy.url = targetUrl; 173 174 assert_true(sendData(testCaseCopy), 'sendBeacon should succeed'); 175 waitForResult(testCaseCopy).then(() => test.done(), test.step_func((e) => {throw e;})); 176 }, `Verify 'navigator.sendbeacon()' successfully sends for variant: ${testCaseCopy.id}`); 177 }); 119 function buildUrl(id) { 120 const baseUrl = "http://{{host}}:{{ports[http][0]}}"; 121 return `${baseUrl}/beacon/resources/beacon.py?cmd=store&id=${id}`; 178 122 } 179 123 … … 184 128 // the test. 185 129 // Returns the result of the 'sendbeacon()' function call, true or false. 186 function sendData( testCase) {187 return self.navigator.sendBeacon( testCase.url, testCase.data);130 function sendData(url, payload) { 131 return self.navigator.sendBeacon(url, payload); 188 132 } 189 133 190 134 // Poll the server for the test result. 191 async function waitForResult(testCase) { 192 const session = testCase.session; 193 const index = testCase.index; 194 const url = `resources/beacon.py?cmd=stat&sid=${session.id}&tidx_min=${index}&tidx_max=${index}`; 135 async function waitForResult(id) { 136 const url = `resources/beacon.py?cmd=stat&id=${id}`; 195 137 for (let i = 0; i < 30; ++i) { 196 138 const response = await fetch(url); … … 219 161 // Clear our onload handler to prevent re-running the tests as we navigate away. 220 162 iframe.onload = null; 221 function sendData( testCase) {222 return iframe.contentWindow.navigator.sendBeacon( testCase.url, testCase.data);163 function sendData(url, payload) { 164 return iframe.contentWindow.navigator.sendBeacon(url, payload); 223 165 } 224 const tests = []; 225 for (const test of sampleTests) { 226 const copy = Object.assign({}, test); 227 copy.id = `${test.id}-NAVIGATE`; 228 tests.push(copy); 229 } 230 runTests(tests, sendData); 166 runTests(sampleTests, '-NAVIGATE', self.buildUrl, sendData); 231 167 // Now navigate ourselves. 232 168 iframe.contentWindow.location = "http://{{host}}:{{ports[http][0]}}/"; -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-cors.sub.window.js
r253760 r263595 9 9 // sendBeacon() succeeds in either case. 10 10 [true, false].forEach(function(allowCors) { 11 // Implement the self.buildBaseUrl and self.buildTargetUrl extensions 12 // to change the target URL to use a cross-origin domain name. 13 self.buildBaseUrl = function(baseUrl) { 14 return "http://{{hosts[alt][]}}:{{ports[http][0]}}"; 15 }; 16 // Implement the self.buildTargetUrl extension to append a directive 17 // to the handler, that it should return CORS headers, if 'allowCors' 18 // is true. 19 self.buildTargetUrl = function(targetUrl) { 11 function buildUrl(id) { 12 const baseUrl = "http://{{hosts[alt][]}}:{{ports[http][0]}}"; 20 13 // Note that 'allowCors=true' is not necessary for the sendBeacon() to reach 21 14 // the server. Beacons use the HTTP POST method, which is a CORS-safelisted … … 28 21 // The "Beacon CORS" tests are merely testing that sendBeacon() to a cross- 29 22 // origin URL *will* work regardless. 30 return allowCors ? `${targetUrl}&origin=http://{{host}}:{{ports[http][0]}}&credentials=true` : targetUrl; 23 const additionalQuery = allowCors ? "&origin=http://{{host}}:{{ports[http][0]}}&credentials=true" : ""; 24 return `${baseUrl}/beacon/resources/beacon.py?cmd=store&id=${id}${additionalQuery}` 31 25 } 32 33 const tests = []; 34 for (const test of sampleTests) { 35 const copy = Object.assign({}, test); 36 copy.id = `${test.id}-${allowCors ? "CORS-ALLOW" : "CORS-FORBID"}`; 37 tests.push(copy); 38 } 39 runTests(tests); 26 runTests(sampleTests, allowCors ? "-CORS-ALLOW" : "-CORS-FORBID", buildUrl); 40 27 }); 41 28 … … 45 32 // send the payload if the proper CORS headers are used. 46 33 { 47 // Implement the self.buildBaseUrl and self.buildTargetUrl extensions 48 // to change the target URL to use a cross-origin domain name. 49 self.buildBaseUrl = function (baseUrl) { 50 return "http://{{hosts[alt][]}}:{{ports[http][0]}}"; 51 }; 52 53 // Implement the self.buildTargetUrl extension to append a directive 54 // to the handler, that it should return CORS headers for the preflight we expect. 55 self.buildTargetUrl = function (targetUrl) { 56 return `${targetUrl}&origin=http://{{host}}:{{ports[http][0]}}&credentials=true&preflightExpected=true`; 34 function buildUrl(id) { 35 const baseUrl = "http://{{hosts[alt][]}}:{{ports[http][0]}}"; 36 const additionalQuery = "&origin=http://{{host}}:{{ports[http][0]}}&credentials=true&preflightExpected=true"; 37 return `${baseUrl}/beacon/resources/beacon.py?cmd=store&id=${id}${additionalQuery}` 57 38 } 58 const tests = []; 59 for (const test of preflightTests) { 60 const copy = Object.assign({}, test); 61 copy.id = `${test.id}-PREFLIGHT-ALLOW`; 62 tests.push(copy); 63 } 64 runTests(tests); 39 runTests(preflightTests, "-PREFLIGHT-ALLOW", buildUrl); 65 40 } 66 41 -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-error.sub.window.js
r253760 r263595 14 14 test(function() { 15 15 var invalidUrl = "http://invalid:url"; 16 assert_throws (new TypeError(), function() { navigator.sendBeacon(invalidUrl, smallPayload); },16 assert_throws_js(TypeError, function() { navigator.sendBeacon(invalidUrl, smallPayload); }, 17 17 `calling 'navigator.sendBeacon()' with an invalid URL '${invalidUrl}' must throw a TypeError`); 18 18 }, "Verify calling 'navigator.sendBeacon()' with an invalid URL throws an exception."); … … 20 20 test(function() { 21 21 var invalidUrl = "nothttp://invalid.url"; 22 assert_throws (new TypeError(), function() { navigator.sendBeacon(invalidUrl, smallPayload); },22 assert_throws_js(TypeError, function() { navigator.sendBeacon(invalidUrl, smallPayload); }, 23 23 `calling 'navigator.sendBeacon()' with a non-http(s) URL '${invalidUrl}' must throw a TypeError`); 24 24 }, "Verify calling 'navigator.sendBeacon()' with a URL that is not a http(s) scheme throws an exception."); -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-readablestream.window.js
r253760 r263595 1 1 test(() => { 2 assert_throws (new TypeError(), () => navigator.sendBeacon("...", new ReadableStream()));2 assert_throws_js(TypeError, () => navigator.sendBeacon("...", new ReadableStream())); 3 3 }, "sendBeacon() with a stream does not work due to the keepalive flag being set"); -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect.sub.window.js
r263594 r263595 9 9 // through a redirect. 10 10 [307, 308].forEach(function(status) { 11 // Implement the self.buildTargetUrl extension to inject a redirect to 12 // the sendBeacon target. 13 self.buildTargetUrl = function(targetUrl) { 11 function buildUrl(id) { 12 const baseUrl = "http://{{host}}:{{ports[http][0]}}"; 13 const targetUrl = `${baseUrl}/beacon/resources/beacon.py?cmd=store&id=${id}`; 14 14 15 return `/common/redirect.py?status=${status}&location=${encodeURIComponent(targetUrl)}`; 15 };16 const tests = [];17 for (const test of sampleTests) {18 const copy = Object.assign({}, test);19 copy.id = `${test.id}-${status}`;20 tests.push(copy);21 16 } 22 runTests( tests);17 runTests(sampleTests, `-${status}`, buildUrl); 23 18 }); 24 19 -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html
r215164 r263595 16 16 testReferrerHeader(testBase, referrerUrl); 17 17 testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR; 18 testReferrerHeader(testBase, "" );18 testReferrerHeader(testBase, "", true); 19 19 </script> 20 20 </body> -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/resources/beacon.py
r232641 r263595 1 1 import json 2 2 3 def build_stash_key(session_id, test_num): 4 return "%s_%s" % (session_id, test_num) 3 from wptserve.utils import isomorphic_decode 5 4 6 5 def main(request, response): … … 10 9 11 10 STORE: 12 A URL with a query string of the form 'cmd=store& sid=<token>&tidx=<test_index>&tid=<test_name>'.11 A URL with a query string of the form 'cmd=store&id=<token>'. 13 12 14 Stores the receipt of a sendBeacon() request along with its validation result, returning HTTP 200 OK. 13 Stores the receipt of a sendBeacon() request along with its validation 14 result, returning HTTP 200 OK. 15 15 16 Parameters: 17 tidx - the integer index of the test. 18 tid - a friendly identifier or name for the test, used when returning results. 16 if "preflightExpected" exists in the query, this handler responds to 17 CORS preflights. 19 18 20 19 STAT: 21 A URL with a query string of the form 'cmd=stat& sid=<token>&tidx_min=<min_test_index>&tidx_max=<max_test_index>'.20 A URL with a query string of the form 'cmd=stat&id=<token>'. 22 21 23 Retrieves the results of test with indices [min_test_index, max_test_index] and returns them as 24 a JSON array and HTTP 200 OK status code. Due to the eventual read-once nature of the stash, results for a given test 25 are only guaranteed to be returned once, though they may be returned multiple times. 22 Retrieves the results of test for the given id and returns them as a 23 JSON array and HTTP 200 OK status code. Due to the eventual read-once 24 nature of the stash, results for a given test are only guaranteed to be 25 returned once, though they may be returned multiple times. 26 26 27 Parameters: 28 tidx_min - the lower-bounding integer test index. 29 tidx_max - the upper-bounding integer test index. 30 31 Example response body: 32 [{"id": "Test1", error: null}, {"id": "Test2", error: "some validation details"}] 27 Example response bodies: 28 - [{error: null}] 29 - [{error: "some validation details"}] 30 - [] 33 31 34 32 Common parameters: 35 33 cmd - the command, 'store' or 'stat'. 36 sid - session id used to provide isolation to a test run comprising multiple sendBeacon() 37 tests. 34 id - the unique identifier of the test. 38 35 """ 39 36 40 session_id = request.GET.first("sid"); 41 command = request.GET.first("cmd").lower(); 42 43 # Workaround to circumvent the limitation that cache keys 44 # can only be UUID's. 45 def wrap_key(key, path): 46 return (str(path), str(key)) 47 request.server.stash._wrap_key = wrap_key 37 id = request.GET.first(b"id") 38 command = request.GET.first(b"cmd").lower() 48 39 49 40 # Append CORS headers if needed. 50 if "origin" in request.GET: 51 response.headers.set("Access-Control-Allow-Origin", request.GET.first("origin")) 52 if "credentials" in request.GET: 53 response.headers.set("Access-Control-Allow-Credentials", request.GET.first("credentials")) 41 if b"origin" in request.GET: 42 response.headers.set(b"Access-Control-Allow-Origin", 43 request.GET.first(b"origin")) 44 if b"credentials" in request.GET: 45 response.headers.set(b"Access-Control-Allow-Credentials", 46 request.GET.first(b"credentials")) 54 47 55 48 # Handle the 'store' and 'stat' commands. 56 if command == "store": 57 # The test id is just used to make the results more human-readable. 58 test_id = request.GET.first("tid") 59 # The test index is used to build a predictable stash key, together 60 # with the unique session id, in order to retrieve a range of results 61 # later knowing the index range. 62 test_idx = request.GET.first("tidx") 63 test_data = { "id": test_id, "error": None } 49 if command == b"store": 50 error = None 64 51 65 # Only store the actual POST requests, not any preflight/OPTIONS requests we may get. 66 if request.method == "POST": 67 test_data_key = build_stash_key(session_id, test_idx) 68 69 payload = "" 70 if "Content-Type" in request.headers and \ 71 "form-data" in request.headers["Content-Type"]: 72 if "payload" in request.POST: 52 # Only store the actual POST requests, not any preflight/OPTIONS 53 # requests we may get. 54 if request.method == u"POST": 55 payload = b"" 56 if b"Content-Type" in request.headers and \ 57 b"form-data" in request.headers[b"Content-Type"]: 58 if b"payload" in request.POST: 73 59 # The payload was sent as a FormData. 74 payload = request.POST.first( "payload")60 payload = request.POST.first(b"payload") 75 61 else: 76 62 # A FormData was sent with an empty payload. … … 80 66 payload = request.body 81 67 82 payload_parts = filter(None, payload.split(":"))68 payload_parts = list(filter(None, payload.split(b":"))) 83 69 if len(payload_parts) > 0: 84 70 payload_size = int(payload_parts[0]) 85 71 86 # Confirm the payload size sent matches with the number of characters sent. 72 # Confirm the payload size sent matches with the number of 73 # characters sent. 87 74 if payload_size != len(payload_parts[1]): 88 test_data["error"] = "expected %d characters but got %d" % (payload_size, len(payload_parts[1])) 75 error = u"expected %d characters but got %d" % ( 76 payload_size, len(payload_parts[1])) 89 77 else: 90 78 # Confirm the payload contains the correct characters. 91 79 for i in range(0, payload_size): 92 if payload_parts[1][i] != "*": 93 test_data["error"] = "expected '*' at index %d but got '%s''" % (i, payload_parts[1][i]) 80 if payload_parts[1][i:i+1] != b"*": 81 error = u"expected '*' at index %d but got '%s''" % ( 82 i, isomorphic_decode(payload_parts[1][i:i+1])) 94 83 break 95 84 96 85 # Store the result in the stash so that it can be retrieved 97 86 # later with a 'stat' command. 98 request.server.stash.put(test_data_key, test_data) 99 elif request.method == "OPTIONS": 100 # If we expect a preflight, then add the cors headers we expect, otherwise log an error as we shouldn't 101 # send a preflight for all requests. 102 if "preflightExpected" in request.GET: 103 response.headers.set("Access-Control-Allow-Headers", "content-type") 104 response.headers.set("Access-Control-Allow-Methods", "POST") 87 request.server.stash.put(id, {u"error": error}) 88 elif request.method == u"OPTIONS": 89 # If we expect a preflight, then add the cors headers we expect, 90 # otherwise log an error as we shouldn't send a preflight for all 91 # requests. 92 if b"preflightExpected" in request.GET: 93 response.headers.set(b"Access-Control-Allow-Headers", 94 b"content-type") 95 response.headers.set(b"Access-Control-Allow-Methods", b"POST") 105 96 else: 106 test_data_key = build_stash_key(session_id, test_idx) 107 test_data["error"] = "Preflight not expected." 108 request.server.stash.put(test_data_key, test_data) 109 elif command == "stat": 110 test_idx_min = int(request.GET.first("tidx_min")) 111 test_idx_max = int(request.GET.first("tidx_max")) 97 error = u"Preflight not expected." 98 request.server.stash.put(id, {u"error": error}) 99 elif command == b"stat": 100 test_data = request.server.stash.take(id) 101 results = [test_data] if test_data else [] 112 102 113 # For each result that has come in, append it to the response. 114 results = [] 115 for test_idx in range(test_idx_min, test_idx_max+1): # +1 because end is exclusive 116 test_data_key = build_stash_key(session_id, test_idx) 117 test_data = request.server.stash.take(test_data_key) 118 if test_data: 119 results.append(test_data) 120 121 response.headers.set("Content-Type", "text/plain") 103 response.headers.set(b"Content-Type", b"text/plain") 122 104 response.content = json.dumps(results) 123 105 else: 124 response.status = 400 # BadRequest106 response.status = 400 # BadRequest -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/resources/content-type.py
r217225 r263595 1 1 def main(request, response): 2 command = request.GET.first("cmd").lower();3 test_id = request.GET.first("id")4 if command =="put":5 request.server.stash.put(test_id, request.headers.get("Content-Type",""))6 return [("Content-Type", "text/plain")],""2 command = request.GET.first(b"cmd").lower() 3 test_id = request.GET.first(b"id") 4 if command == b"put": 5 request.server.stash.put(test_id, request.headers.get(b"Content-Type", b"")) 6 return [(b"Content-Type", b"text/plain")], u"" 7 7 8 if command =="get":9 stashed_header = request.server.stash.take(test_id)10 if stashed_header is not None:11 return [("Content-Type","text/plain")], stashed_header8 if command == b"get": 9 stashed_header = request.server.stash.take(test_id) 10 if stashed_header is not None: 11 return [(b"Content-Type", b"text/plain")], stashed_header 12 12 13 response.set_error(400,"Bad Command")14 return"ERROR: Bad Command!"13 response.set_error(400, u"Bad Command") 14 return u"ERROR: Bad Command!" -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/resources/inspect-header.py
r215164 r263595 1 1 def main(request, response): 2 headers = [( "Content-Type","text/plain")]3 command = request.GET.first( "cmd").lower();4 test_id = request.GET.first( "id")5 header = request.GET.first( "header")6 if command == "put":7 request.server.stash.put(test_id, request.headers.get(header, ""))2 headers = [(b"Content-Type", b"text/plain")] 3 command = request.GET.first(b"cmd").lower() 4 test_id = request.GET.first(b"id") 5 header = request.GET.first(b"header") 6 if command == b"put": 7 request.server.stash.put(test_id, request.headers.get(header, b"")) 8 8 9 elif command == "get":9 elif command == b"get": 10 10 stashed_header = request.server.stash.take(test_id) 11 11 if stashed_header is not None: 12 headers.append(( "x-request-" + header, stashed_header))12 headers.append((b"x-request-" + header, stashed_header)) 13 13 14 14 else: 15 response.set_error(400, "Bad Command")16 return "ERROR: Bad Command!"15 response.set_error(400, u"Bad Command") 16 return u"ERROR: Bad Command!" 17 17 18 return headers, ""18 return headers, u"" -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/w3c-import.log
r253760 r263595 28 28 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-error.sub.window.js 29 29 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-navigate.html 30 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-preflight-failure.sub.window.js 30 31 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-readablestream.window.js 31 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect. window.js32 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect.sub.window.js 32 33 /LayoutTests/imported/w3c/web-platform-tests/beacon/idlharness.any.js
Note: See TracChangeset
for help on using the changeset viewer.