Changeset 57237 in webkit
- Timestamp:
- Apr 7, 2010 3:43:29 PM (14 years ago)
- Location:
- trunk/LayoutTests
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r57234 r57237 1 2010-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 1 19 2010-04-07 Zhenyao Mo <zmo@google.com> 2 20 -
trunk/LayoutTests/http/tests/xmlhttprequest/cookies.html
r18549 r57237 6 6 7 7 <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 { 13 16 req = new XMLHttpRequest; 14 17 req.open("POST", "resources/get-set-cookie.cgi", false); 15 18 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!"); 18 33 } 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"); 25 39 else 26 document.getElementById("result").firstChild.data = "FAIL: the cookie was not set";40 setResult("FAIL: the cookie was not set"); 27 41 } 28 42 } catch (ex) { 29 document.getElementById("result").firstChild.data = ex; 43 setResult(ex); 44 } finally { 45 clearCookies(); 30 46 } 31 47 </script> -
trunk/LayoutTests/http/tests/xmlhttprequest/cross-origin-cookie-storage.html
r47792 r57237 11 11 function log(message) 12 12 { 13 document.getElementById('console').appendChild(document.createTextNode(message + '\n')); 13 var consoleDiv = document.getElementById('console'); 14 consoleDiv.appendChild(document.createTextNode(message + '\n')); 15 } 16 17 function resourceURL(resourceName) 18 { 19 return "http://localhost:8000/xmlhttprequest/resources/" + resourceName; 20 } 21 22 function 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 30 function endTesting() 31 { 32 clearCookies(); 33 if (window.layoutTestController) 34 layoutTestController.notifyDone(); 35 } 36 37 function 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 } 14 48 } 15 49 … … 18 52 log("Cross-origin XMLHttpRequest (sync), testing that cookies are not set when not sending credentials."); 19 53 54 clearCookies(); 55 20 56 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); 22 58 req.withCredentials = false; 23 59 req.send(); 24 60 log("PASS: Finished sync xhr."); 25 61 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 35 65 testAsyncCookiesNoCredentials(); 36 66 } … … 40 70 log("Cross-origin XMLHttpRequest (async), testing that cookies are not set when not sending credentials."); 41 71 72 clearCookies(); 73 42 74 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); 44 76 req.withCredentials = false; 45 77 req.send(); 46 78 req.onerror = function() { 47 79 log("FAIL: Async xhr to set cookies."); 48 if (window.layoutTestController) 49 layoutTestController.notifyDone(); 80 endTesting(); 50 81 } 51 82 req.onload = function() { 52 83 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)); 63 86 testSyncCookiesWithCredentials(); 64 87 } … … 69 92 log("Cross-origin XMLHttpRequest (sync), testing that cookies are set when sending credentials."); 70 93 94 clearCookies(); 95 71 96 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); 73 98 req.withCredentials = true; 74 99 req.send(); 75 100 log("PASS: Finished sync xhr."); 76 101 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."); 86 104 log("DONE"); 87 if (window.layoutTestController) 88 layoutTestController.notifyDone(); 105 endTesting(); 89 106 } 90 107 -
trunk/LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-set-cookies.php
r47792 r57237 1 1 <?php 2 header("Set-Cookie: WK-xhr-cookie-storage=MySpecialValue"); 2 $age_string = ""; 3 if ($_GET['clear']) { 4 $age_string = "max-age=-1"; 5 } 6 header("Set-Cookie: WK-xhr-cookie-storage=MySpecialValue;$age_string"); 3 7 header("Cache-Control: no-store"); 4 8 header("Last-Modified: Thu, 19 Mar 2009 11:22:11 GMT"); -
trunk/LayoutTests/http/tests/xmlhttprequest/resources/get-set-cookie.cgi
r41577 r57237 1 1 #!/usr/bin/perl -w 2 2 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"; 3 print "Content-type: text/plain\n"; 4 my $AGE_STRING = ""; 5 if ($ENV{"QUERY_STRING"}) { # Assume any query string means "?clear=1" 6 $AGE_STRING = "max-age=-1"; 7 } 8 print "Set-Cookie: WK-test=1;$AGE_STRING\n"; 9 print "Set-Cookie: WK-test-secure=1; secure;$AGE_STRING\n"; 10 print "Set-Cookie2: WK-test-2=1;$AGE_STRING\n\n"; 7 11 print "$ENV{\"HTTP_COOKIE\"}\n" if $ENV{"HTTP_COOKIE"};
Note: See TracChangeset
for help on using the changeset viewer.