Changeset 263595 in webkit


Ignore:
Timestamp:
Jun 26, 2020 4:07:38 PM (4 years ago)
Author:
Chris Dumez
Message:

Update web-platform-tests/beacon from upstream
https://bugs.webkit.org/show_bug.cgi?id=213663

Reviewed by Darin Adler.

Update web-platform-tests/beacon from upstream b076c305a256e7fb7.

  • web-platform-tests/beacon/*: Updated.
Location:
trunk/LayoutTests/imported/w3c
Files:
5 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r263451 r263595  
     12020-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
    1122020-06-24  Sergio Villar Senin  <svillar@igalia.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-common.sub.js

    r253760 r263595  
    1717
    1818// 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.
    2020//      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' }) };
     21var noDataTest = { name: "NoData" };
     22var nullDataTest = { name: "NullData", data: null };
     23var undefinedDataTest = { name: "UndefinedData", data: undefined };
     24var smallStringTest = { name: "SmallString", data: smallPayload };
     25var mediumStringTest = { name: "MediumString", data: mediumPayload };
     26var largeStringTest = { name: "LargeString", data: largePayload };
     27var maxStringTest = { name: "MaxString", data: maxPayload };
     28var emptyBlobTest = { name: "EmptyBlob", data: new Blob() };
     29var smallBlobTest = { name: "SmallBlob", data: new Blob([smallPayload]) };
     30var mediumBlobTest = { name: "MediumBlob", data: new Blob([mediumPayload]) };
     31var largeBlobTest = { name: "LargeBlob", data: new Blob([largePayload]) };
     32var maxBlobTest = { name: "MaxBlob", data: new Blob([maxPayload]) };
     33var emptyBufferSourceTest = { name: "EmptyBufferSource", data: new Uint8Array() };
     34var smallBufferSourceTest = { name: "SmallBufferSource", data: CreateArrayBufferFromPayload(smallPayload) };
     35var mediumBufferSourceTest = { name: "MediumBufferSource", data: CreateArrayBufferFromPayload(mediumPayload) };
     36var largeBufferSourceTest = { name: "LargeBufferSource", data: CreateArrayBufferFromPayload(largePayload) };
     37var maxBufferSourceTest = { name: "MaxBufferSource", data: CreateArrayBufferFromPayload(maxPayload) };
     38var emptyFormDataTest = { name: "EmptyFormData", data: CreateEmptyFormDataPayload() };
     39var smallFormDataTest = { name: "SmallFormData", data: CreateFormDataFromPayload(smallPayload) };
     40var mediumFormDataTest = { name: "MediumFormData", data: CreateFormDataFromPayload(mediumPayload) };
     41var largeFormDataTest = { name: "LargeFormData", data: CreateFormDataFromPayload(largePayload) };
     42var smallSafeContentTypeEncodedTest = { name: "SmallSafeContentTypeEncoded", data: new Blob([smallPayload], { type: 'application/x-www-form-urlencoded' }) };
     43var smallSafeContentTypeFormTest = { name: "SmallSafeContentTypeForm", data: new FormData() };
     44var smallSafeContentTypeTextTest = { name: "SmallSafeContentTypeText", data: new Blob([smallPayload], { type: 'text/plain' }) };
     45var smallCORSContentTypeTextTest = { name: "SmallCORSContentTypeText", data: new Blob([smallPayload], { type: 'text/html' }) };
    4646// We don't test maxFormData because the extra multipart separators make it difficult to
    4747// calculate a maxPayload.
     
    6666
    6767var preflightTests = [smallCORSContentTypeTextTest];
    68 
    69 // Build a test lookup table, which is useful when instructing a web worker or an iframe
    70 // 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 });
    7568
    7669// Helper function to create an ArrayBuffer representation of a string.
     
    10699}
    107100
    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.
     108function 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}`);
    135116    };
    136117}
    137118
    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     });
     119function buildUrl(id) {
     120    const baseUrl = "http://{{host}}:{{ports[http][0]}}";
     121    return `${baseUrl}/beacon/resources/beacon.py?cmd=store&id=${id}`;
    178122}
    179123
     
    184128// the test.
    185129// Returns the result of the 'sendbeacon()' function call, true or false.
    186 function sendData(testCase) {
    187     return self.navigator.sendBeacon(testCase.url, testCase.data);
     130function sendData(url, payload) {
     131    return self.navigator.sendBeacon(url, payload);
    188132}
    189133
    190134// 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}`;
     135async function waitForResult(id) {
     136    const url = `resources/beacon.py?cmd=stat&id=${id}`;
    195137    for (let i = 0; i < 30; ++i) {
    196138        const response = await fetch(url);
     
    219161        // Clear our onload handler to prevent re-running the tests as we navigate away.
    220162        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);
    223165        }
    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);
    231167        // Now navigate ourselves.
    232168        iframe.contentWindow.location = "http://{{host}}:{{ports[http][0]}}/";
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-cors.sub.window.js

    r253760 r263595  
    99// sendBeacon() succeeds in either case.
    1010[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]}}";
    2013        // Note that 'allowCors=true' is not necessary for the sendBeacon() to reach
    2114        // the server. Beacons use the HTTP POST method, which is a CORS-safelisted
     
    2821        // The "Beacon CORS" tests are merely testing that sendBeacon() to a cross-
    2922        // 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}`
    3125    }
    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);
    4027});
    4128
     
    4532// send the payload if the proper CORS headers are used.
    4633{
    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}`
    5738    }
    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);
    6540}
    6641
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-error.sub.window.js

    r253760 r263595  
    1414test(function() {
    1515    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); },
    1717        `calling 'navigator.sendBeacon()' with an invalid URL '${invalidUrl}' must throw a TypeError`);
    1818}, "Verify calling 'navigator.sendBeacon()' with an invalid URL throws an exception.");
     
    2020test(function() {
    2121    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); },
    2323         `calling 'navigator.sendBeacon()' with a non-http(s) URL '${invalidUrl}' must throw a TypeError`);
    2424}, "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  
    11test(() => {
    2   assert_throws(new TypeError(), () => navigator.sendBeacon("...", new ReadableStream()));
     2  assert_throws_js(TypeError, () => navigator.sendBeacon("...", new ReadableStream()));
    33}, "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  
    99// through a redirect.
    1010[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
    1415        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);
    2116    }
    22     runTests(tests);
     17    runTests(sampleTests, `-${status}`, buildUrl);
    2318});
    2419
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html

    r215164 r263595  
    1616      testReferrerHeader(testBase, referrerUrl);
    1717      testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR;
    18       testReferrerHeader(testBase, "");
     18      testReferrerHeader(testBase, "", true);
    1919    </script>
    2020  </body>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/resources/beacon.py

    r232641 r263595  
    11import json
    22
    3 def build_stash_key(session_id, test_num):
    4     return "%s_%s" % (session_id, test_num)
     3from wptserve.utils import isomorphic_decode
    54
    65def main(request, response):
     
    109
    1110    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>'.
    1312
    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.
    1515
    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.
    1918
    2019    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>'.
    2221
    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.
    2626
    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            - []
    3331
    3432    Common parameters:
    3533        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.
    3835    """
    3936
    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()
    4839
    4940    # 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"))
    5447
    5548    # 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
    6451
    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:
    7359                    # The payload was sent as a FormData.
    74                     payload = request.POST.first("payload")
     60                    payload = request.POST.first(b"payload")
    7561                else:
    7662                    # A FormData was sent with an empty payload.
     
    8066                payload = request.body
    8167
    82             payload_parts = filter(None, payload.split(":"))
     68            payload_parts = list(filter(None, payload.split(b":")))
    8369            if len(payload_parts) > 0:
    8470                payload_size = int(payload_parts[0])
    8571
    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.
    8774                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]))
    8977                else:
    9078                    # Confirm the payload contains the correct characters.
    9179                    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]))
    9483                            break
    9584
    9685            # Store the result in the stash so that it can be retrieved
    9786            # 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")
    10596            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 []
    112102
    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")
    122104        response.content = json.dumps(results)
    123105    else:
    124         response.status = 400 # BadRequest
     106        response.status = 400  # BadRequest
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/resources/content-type.py

    r217225 r263595  
    11def 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""
    77
    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_header
     8    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
    1212
    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  
    11def 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""))
    88
    9     elif command == "get":
     9    elif command == b"get":
    1010        stashed_header = request.server.stash.take(test_id)
    1111        if stashed_header is not None:
    12             headers.append(("x-request-" + header, stashed_header ))
     12            headers.append((b"x-request-" + header, stashed_header))
    1313
    1414    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!"
    1717
    18     return headers, ""
     18    return headers, u""
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/w3c-import.log

    r253760 r263595  
    2828/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-error.sub.window.js
    2929/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-navigate.html
     30/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-preflight-failure.sub.window.js
    3031/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-readablestream.window.js
    31 /LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect.window.js
     32/LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect.sub.window.js
    3233/LayoutTests/imported/w3c/web-platform-tests/beacon/idlharness.any.js
Note: See TracChangeset for help on using the changeset viewer.