Changeset 57237 in webkit


Ignore:
Timestamp:
Apr 7, 2010 3:43:29 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-07 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Fix two cookie tests to clean up after themselves (so they can be run repeatedly)
https://bugs.webkit.org/show_bug.cgi?id=37235

Added a ?clear=1 query parameter to the two "set cookies" cgi scripts
that these tests use, and call it to clear the cookies before leaving the test.

I could not resist the temptation of cleaning up the ridiculously awful copy/paste
in these tests, so the changes are larger than strictly necessary.

  • http/tests/xmlhttprequest/cookies.html:
  • http/tests/xmlhttprequest/cross-origin-cookie-storage.html:
  • http/tests/xmlhttprequest/resources/cross-origin-set-cookies.php:
  • http/tests/xmlhttprequest/resources/get-set-cookie.cgi:
Location:
trunk/LayoutTests
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57234 r57237  
     12010-04-07  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Fix two cookie tests to clean up after themselves (so they can be run repeatedly)
     6        https://bugs.webkit.org/show_bug.cgi?id=37235
     7
     8        Added a ?clear=1 query parameter to the two "set cookies" cgi scripts
     9        that these tests use, and call it to clear the cookies before leaving the test.
     10
     11        I could not resist the temptation of cleaning up the ridiculously awful copy/paste
     12        in these tests, so the changes are larger than strictly necessary.
     13
     14        * http/tests/xmlhttprequest/cookies.html:
     15        * http/tests/xmlhttprequest/cross-origin-cookie-storage.html:
     16        * http/tests/xmlhttprequest/resources/cross-origin-set-cookies.php:
     17        * http/tests/xmlhttprequest/resources/get-set-cookie.cgi:
     18
    1192010-04-07  Zhenyao Mo  <zmo@google.com>
    220
  • trunk/LayoutTests/http/tests/xmlhttprequest/cookies.html

    r18549 r57237  
    66
    77<script>
    8     if (window.layoutTestController)
    9         layoutTestController.dumpAsText();
    10    
    11     try {
    12    
     8    function clearCookies()
     9    {
     10        req = new XMLHttpRequest;
     11        req.open("POST", "resources/get-set-cookie.cgi?clear=1", false);
     12        req.send("");
     13    }
     14    function getAndSetCookies()
     15    {
    1316        req = new XMLHttpRequest;
    1417        req.open("POST", "resources/get-set-cookie.cgi", false);
    1518        req.send("");
    16         if (req.responseText && req.responseText.match(/.*WK-test=1.*/)) {
    17             document.getElementById("result").firstChild.data = "FAIL: the cookie is already present. Please restart your browser to remove it.";
     19        return req.responseText;
     20    }
     21    function setResult(result)
     22    {
     23        document.getElementById("result").firstChild.data = result;
     24    }
     25
     26    if (window.layoutTestController)
     27        layoutTestController.dumpAsText();
     28    try {
     29        clearCookies();
     30        var response = getAndSetCookies();
     31        if (response && response.match(/.*WK-test=1.*/)) {
     32            setResult("FAIL: The cookie still present after clear. clearCookies() failed.  Must be a bug in the test!");
    1833        } else {
    19             req.open("POST", "resources/get-set-cookie.cgi", false);
    20             req.send("");
    21             if (req.responseText.match(/.*WK-test-secure=1.*/))
    22                 document.getElementById("result").firstChild.data = "FAIL: a secure cookie was sent via HTTP";
    23             else if (req.responseText.match(/.*WK-test=1.*/))
    24                 document.getElementById("result").firstChild.data = "SUCCESS";
     34            var response = getAndSetCookies();
     35            if (response.match(/.*WK-test-secure=1.*/))
     36                 setResult("FAIL: a secure cookie was sent via HTTP");
     37            else if (response.match(/.*WK-test=1.*/))
     38                setResult("SUCCESS");
    2539            else
    26                 document.getElementById("result").firstChild.data = "FAIL: the cookie was not set";
     40                setResult("FAIL: the cookie was not set");
    2741        }
    2842    } catch (ex) {
    29         document.getElementById("result").firstChild.data = ex;
     43        setResult(ex);
     44    } finally {
     45        clearCookies();
    3046    }
    3147</script>
  • trunk/LayoutTests/http/tests/xmlhttprequest/cross-origin-cookie-storage.html

    r47792 r57237  
    1111function log(message)
    1212{
    13     document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
     13    var consoleDiv = document.getElementById('console');
     14    consoleDiv.appendChild(document.createTextNode(message + '\n'));
     15}
     16
     17function resourceURL(resourceName)
     18{
     19    return "http://localhost:8000/xmlhttprequest/resources/" + resourceName;
     20}
     21
     22function clearCookies()
     23{
     24    var xhr = new XMLHttpRequest;
     25    xhr.open("GET", resourceURL("cross-origin-set-cookies.php?clear=1"), false);
     26    xhr.withCredentials = true;
     27    xhr.send("");
     28}
     29
     30function endTesting()
     31{
     32    clearCookies();
     33    if (window.layoutTestController)
     34        layoutTestController.notifyDone();
     35}
     36
     37function checkForCookie()
     38{
     39    var xhr = new XMLHttpRequest;
     40    xhr.open("GET", resourceURL("cross-origin-check-cookies.php?cookie=WK-xhr-cookie-storage"), false);
     41    xhr.withCredentials = true;
     42    try {
     43        xhr.send();
     44        return xhr.responseText
     45    } catch (ex) {
     46        log("FAIL: Got an exception. " + ex);
     47    }
    1448}
    1549
     
    1852    log("Cross-origin XMLHttpRequest (sync), testing that cookies are not set when not sending credentials.");
    1953
     54    clearCookies();
     55
    2056    var req = new XMLHttpRequest;
    21     req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-set-cookies.php", false);
     57    req.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
    2258    req.withCredentials = false;
    2359    req.send();
    2460    log("PASS: Finished sync xhr.");
    2561
    26     req = new XMLHttpRequest;
    27     req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-check-cookies.php?cookie=WK-xhr-cookie-storage", false);
    28     req.withCredentials = true;
    29     try {
    30         req.send();
    31         log(!req.responseText.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + req.responseText));
    32     } catch (ex) {
    33         log("FAIL: Got an exception. " + ex);
    34     }
     62    var response = checkForCookie()
     63    log(!response.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + response));
     64
    3565    testAsyncCookiesNoCredentials();
    3666}
     
    4070    log("Cross-origin XMLHttpRequest (async), testing that cookies are not set when not sending credentials.");
    4171
     72    clearCookies();
     73
    4274    var req = new XMLHttpRequest;
    43     req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-set-cookies.php", true);
     75    req.open("GET", resourceURL("cross-origin-set-cookies.php"), true);
    4476    req.withCredentials = false;
    4577    req.send();
    4678    req.onerror = function() {
    4779        log("FAIL: Async xhr to set cookies.");
    48         if (window.layoutTestController)
    49             layoutTestController.notifyDone();
     80        endTesting();
    5081    }
    5182    req.onload = function() {
    5283        log("PASS: Finished async xhr.");
    53 
    54         var req2 = new XMLHttpRequest;
    55         req2.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-check-cookies.php?cookie=WK-xhr-cookie-storage", false);
    56         req2.withCredentials = true;
    57         try {
    58             req2.send();
    59             log(!req2.responseText.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + req2.responseText));
    60         } catch (ex) {
    61             log("FAIL: Got an exception. " + ex);
    62         }
     84        var response = checkForCookie();
     85        log(!response.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + response));
    6386        testSyncCookiesWithCredentials();
    6487    }
     
    6992    log("Cross-origin XMLHttpRequest (sync), testing that cookies are set when sending credentials.");
    7093
     94    clearCookies();
     95
    7196    var req = new XMLHttpRequest;
    72     req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-set-cookies.php", false);
     97    req.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
    7398    req.withCredentials = true;
    7499    req.send();
    75100    log("PASS: Finished sync xhr.");
    76101
    77     req = new XMLHttpRequest;
    78     req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin-check-cookies.php?cookie=WK-xhr-cookie-storage", false);
    79     req.withCredentials = true;
    80     try {
    81         req.send();
    82         log(req.responseText.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: Cookie set." : "FAIL: no cookie set");
    83     } catch (ex) {
    84         log("FAIL: Got an exception. " + ex);
    85     }
     102    var response = checkForCookie();
     103    log(response.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: Cookie set." : "FAIL: no cookie set.");
    86104    log("DONE");
    87     if (window.layoutTestController)
    88         layoutTestController.notifyDone();
     105    endTesting();
    89106}
    90107
  • trunk/LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-set-cookies.php

    r47792 r57237  
    11<?php
    2 header("Set-Cookie: WK-xhr-cookie-storage=MySpecialValue");
     2$age_string = "";
     3if ($_GET['clear']) {
     4    $age_string = "max-age=-1";
     5}
     6header("Set-Cookie: WK-xhr-cookie-storage=MySpecialValue;$age_string");
    37header("Cache-Control: no-store");
    48header("Last-Modified: Thu, 19 Mar 2009 11:22:11 GMT");
  • trunk/LayoutTests/http/tests/xmlhttprequest/resources/get-set-cookie.cgi

    r41577 r57237  
    11#!/usr/bin/perl -w
    22
    3 print "Content-type: text/plain\n";
    4 print "Set-Cookie: WK-test=1\n";
    5 print "Set-Cookie: WK-test-secure=1; secure\n";
    6 print "Set-Cookie2: WK-test-2=1\n\n";
     3print "Content-type: text/plain\n";
     4my $AGE_STRING = "";
     5if ($ENV{"QUERY_STRING"}) { # Assume any query string means "?clear=1"
     6    $AGE_STRING = "max-age=-1";
     7}
     8print "Set-Cookie: WK-test=1;$AGE_STRING\n";
     9print "Set-Cookie: WK-test-secure=1; secure;$AGE_STRING\n";
     10print "Set-Cookie2: WK-test-2=1;$AGE_STRING\n\n";
    711print "$ENV{\"HTTP_COOKIE\"}\n" if $ENV{"HTTP_COOKIE"};
Note: See TracChangeset for help on using the changeset viewer.