diff options
author | Steve Block <steveblock@google.com> | 2010-08-25 14:36:30 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-08-25 14:36:30 +0100 |
commit | e45c1cdad9627f8b5f50f55c4a9642c1703a616a (patch) | |
tree | b58b96f635e30448a045dfcac3656ae7ddbbb1ad /LayoutTests/http/tests | |
parent | 734a2cd65c426074c10e2d6d01a7cc3b67d1cdaf (diff) | |
download | external_webkit-e45c1cdad9627f8b5f50f55c4a9642c1703a616a.zip external_webkit-e45c1cdad9627f8b5f50f55c4a9642c1703a616a.tar.gz external_webkit-e45c1cdad9627f8b5f50f55c4a9642c1703a616a.tar.bz2 |
Add LayoutTests/http/tests/resources at r65615
These scripts are required to run the http tests, eg
http/tests/appcache/fail-on-update.html
Change-Id: I6173fcb9bc0d77a5cfc94fce45d02b1704ee6306
Diffstat (limited to 'LayoutTests/http/tests')
-rw-r--r-- | LayoutTests/http/tests/resources/network-simulator.php | 143 | ||||
-rw-r--r-- | LayoutTests/http/tests/resources/notify-done.html | 7 | ||||
-rwxr-xr-x | LayoutTests/http/tests/resources/portabilityLayer.php | 35 | ||||
-rwxr-xr-x | LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi | 86 | ||||
-rwxr-xr-x | LayoutTests/http/tests/resources/post-and-verify.cgi | 30 | ||||
-rw-r--r-- | LayoutTests/http/tests/resources/redirect.php | 16 | ||||
-rwxr-xr-x | LayoutTests/http/tests/resources/reset-temp-file.php | 19 | ||||
-rw-r--r-- | LayoutTests/http/tests/resources/silence.mpg | bin | 0 -> 33227 bytes | |||
-rw-r--r-- | LayoutTests/http/tests/resources/touch-temp-file.php | 22 | ||||
-rw-r--r-- | LayoutTests/http/tests/resources/tripmine.php | 63 | ||||
-rw-r--r-- | LayoutTests/http/tests/resources/write-temp-file.php | 17 |
11 files changed, 438 insertions, 0 deletions
diff --git a/LayoutTests/http/tests/resources/network-simulator.php b/LayoutTests/http/tests/resources/network-simulator.php new file mode 100644 index 0000000..3f1201f --- /dev/null +++ b/LayoutTests/http/tests/resources/network-simulator.php @@ -0,0 +1,143 @@ +<?php +require_once 'portabilityLayer.php'; + +// This script acts as a stateful proxy for retrieving files. When the state is set to +// offline, it simulates a network error by redirecting to itself. + +if (!sys_get_temp_dir()) { + echo "FAIL: No temp dir was returned.\n"; + exit(); +} + +function setState($newState, $file) +{ + file_put_contents($file, $newState); +} + +function getState($file) +{ + if (!file_exists($file)) { + return "Uninitialized"; + } + return file_get_contents($file); +} + +function contentType($path) +{ + if (preg_match("/\.html$/", $path)) + return "text/html"; + if (preg_match("/\.manifest$/", $path)) + return "text/cache-manifest"; + if (preg_match("/\.js$/", $path)) + return "text/javascript"; + if (preg_match("/\.xml$/", $path)) + return "application/xml"; + if (preg_match("/\.xhtml$/", $path)) + return "application/xhtml+xml"; + if (preg_match("/\.svg$/", $path)) + return "application/svg+xml"; + if (preg_match("/\.xsl$/", $path)) + return "application/xslt+xml"; + if (preg_match("/\.gif$/", $path)) + return "image/gif"; + if (preg_match("/\.jpg$/", $path)) + return "image/jpeg"; + if (preg_match("/\.png$/", $path)) + return "image/png"; + return "text/plain"; +} + +function generateNoCacheHTTPHeader() +{ + header("Expires: Thu, 01 Dec 2003 16:00:00 GMT"); + header("Cache-Control: no-cache, no-store, must-revalidate"); + header("Pragma: no-cache"); +} + +function generateResponse($path) +{ + global $stateFile; + $state = getState($stateFile); + if ($state == "Offline") { + header('HTTP/1.1 307 Temporary Redirect'); + # Simulate a network error by redirecting to self. + header('Location: ' . $_SERVER['REQUEST_URI']); + } else { + // A little securuty checking can't hurt. + if (strstr($path, "..")) + exit; + + if ($path[0] == '/') + $path = '..' . $path; + + generateNoCacheHTTPHeader(); + + if (file_exists($path)) { + header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path))); + header("Content-Type: " . contentType($path)); + + print file_get_contents($path); + } else { + header('HTTP/1.1 404 Not Found'); + } + } +} + +function handleIncreaseResourceCountCommand($path) +{ + $resourceCountFile = sys_get_temp_dir() . "/resource-count"; + $resourceCount = getState($resourceCountFile); + $pieces = explode(" ", $resourceCount); + $count = 0; + if (count($pieces) == 2 && $pieces[0] == $path) { + $count = 1 + $pieces[1]; + } else { + $count = 1; + } + file_put_contents($resourceCountFile, $path . " " . $count); + generateResponse($path); +} + +function handleResetResourceCountCommand() +{ + $resourceCountFile = sys_get_temp_dir() . "/resource-count"; + file_put_contents($resourceCountFile, 0); + generateNoCacheHTTPHeader(); + header('HTTP/1.1 200 OK'); +} + +function handleGetResourceCountCommand($path) +{ + $resourceCountFile = sys_get_temp_dir() . "/resource-count"; + $resourceCount = getState($resourceCountFile); + $pieces = explode(" ", $resourceCount); + generateNoCacheHTTPHeader(); + header('HTTP/1.1 200 OK'); + if (count($pieces) == 2 && $pieces[0] == $path) { + echo $pieces[1]; + } else { + echo 0; + } +} + +$stateFile = sys_get_temp_dir() . "/network-simulator-state"; +$command = $_GET['command']; +if ($command) { + if ($command == "connect") + setState("Online", $stateFile); + else if ($command == "disconnect") + setState("Offline", $stateFile); + else if ($command == "increase-resource-count") + handleIncreaseResourceCountCommand($_GET['path']); + else if ($command == "reset-resource-count") + handleResetResourceCountCommand(); + else if ($command == "get-resource-count") + handleGetResourceCountCommand($_GET['path']); + else + echo "Unknown command: " . $command . "\n"; + exit(); +} + +$requestedPath = $_GET['path']; +generateResponse($requestedPath); +?> diff --git a/LayoutTests/http/tests/resources/notify-done.html b/LayoutTests/http/tests/resources/notify-done.html new file mode 100644 index 0000000..8d692ed --- /dev/null +++ b/LayoutTests/http/tests/resources/notify-done.html @@ -0,0 +1,7 @@ +<script> +function loaded() { + if (window.layoutTestController) + setTimeout("layoutTestController.notifyDone();", 0); +} +</script> +<body onload="loaded();"></body> diff --git a/LayoutTests/http/tests/resources/portabilityLayer.php b/LayoutTests/http/tests/resources/portabilityLayer.php new file mode 100755 index 0000000..e2fdc2d --- /dev/null +++ b/LayoutTests/http/tests/resources/portabilityLayer.php @@ -0,0 +1,35 @@ +<?php + +if (!function_exists('sys_get_temp_dir')) { + // Based on http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/2/ + // If the builtin PHP sys_get_temp_dir doesn't exist, we replace it with one that will + // try to guess from the environment. Since sys_get_temp_dir() doesn't return a trailing + // slash on all system (see comment at http://us.php.net/sys_get_temp_dir), we don't + // append a trailing slash, and expect callers to append one when needed. + function sys_get_temp_dir() + { + // Try to get from environment variable + if (!empty($_ENV['TMP'])) + return realpath($_ENV['TMP']); + if (!empty($_ENV['TMPDIR'])) + return realpath($_ENV['TMPDIR']); + if (!empty($_ENV['TEMP'])) + return realpath( $_ENV['TEMP']); + return "/tmp"; + } +} + +if (!function_exists('file_put_contents')) { + function file_put_contents($filename, $data) + { + $handle = fopen($filename, "w"); + if (!$handle) + return FALSE; + $bytesWritten = fwrite($handle, $data); + if (!fclose($handle)) + return FALSE; + return $bytesWritten; + } +} + +?> diff --git a/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi b/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi new file mode 100755 index 0000000..2cc826a --- /dev/null +++ b/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w + +use Config; + +print "Content-type: text/plain\n\n"; + +if ($ENV{'REQUEST_METHOD'} eq "POST") { + if ($ENV{'CONTENT_LENGTH'}) { + read(STDIN, $postData, $ENV{'CONTENT_LENGTH'}) || die "Could not get post data\n"; + } else { + $postData = ""; + } + + @list = split(/&/, $ENV{'QUERY_STRING'}); + @values; + $values{'start'} = 0; + $values{'length'} = -1; + $values{'convert_newlines'} = 0; + foreach $element (@list) { + ($key, $value) = split(/=/, $element); + $values{$key} = $value; + } + + # 'items' parameter would look like: + # <items> := <item>(','<item>)* + # <item> := <file> | <data> + # <file> := "file":<file-path> + # <data> := "data":<data-string> + @items = split(/,/, $values{'items'}); + $expectedData = ""; + $readPos = $values{'start'}; + $remainingLength = $values{'length'}; + foreach $item (@items) { + my ($type, $data) = split(/:/, $item); + my $size; + if ($type eq "data") { + $data =~ s/%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg; + $size = length($data); + if ($readPos > 0) { + if ($readPos > $size) { + $readPos -= $size; + next; + } + $data = substr($data, $readPos); + } + $data = substr($data, 0, $remainingLength) if ($remainingLength > 0); + } else { + $path = $data; + open(FILE, $path) || next; + $size = -s $path; + if ($readPos > 0) { + if ($readPos > $size) { + $readPos -= $size; + next; + } + seek(FILE, $readPos, 0); + } + if ($remainingLength > 0) { + read(FILE, $data, $remainingLength); + } else { + local $/ = undef; + $data = <FILE>; + } + close(FILE); + } + $readPos -= $size; + $expectedData .= $data; + if ($remainingLength > 0) { + $remainingLength -= length($data); + last if $remainingLength <= 0; + } + } + + if ($values{'convert_newlines'}) { + $nativeEnding = ($Config{osname} =~ /(MSWin|cygwin)/) ? "\r\n" : "\n"; + $postData =~ s/$nativeEnding/[NL]/g; + } + + if ($postData eq $expectedData) { + print "OK"; + } else { + print "FAILED"; + } +} else { + print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n"; +} diff --git a/LayoutTests/http/tests/resources/post-and-verify.cgi b/LayoutTests/http/tests/resources/post-and-verify.cgi new file mode 100755 index 0000000..2c7aa62 --- /dev/null +++ b/LayoutTests/http/tests/resources/post-and-verify.cgi @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w + +print "Content-type: text/plain\n\n"; + +if ($ENV{'REQUEST_METHOD'} eq "POST") { + if ($ENV{'CONTENT_LENGTH'}) { + read(STDIN, $postData, $ENV{'CONTENT_LENGTH'}) || die "Could not get post data\n"; + } else { + $postData = ""; + } + + @list = split(/&/, $ENV{'QUERY_STRING'}); + foreach $element (@list) { + ($key, $value) = split(/=/, $element); + $values{$key} = $value; + } + + open FILE, $values{'path'} || die("Could not open file\n"); + seek FILE, $values{'start'}, 0; + read FILE, $expectedData, $values{'length'}; + close(FILE); + + if ($postData eq $expectedData) { + print "OK"; + } else { + print "FAILED"; + } +} else { + print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n"; +} diff --git a/LayoutTests/http/tests/resources/redirect.php b/LayoutTests/http/tests/resources/redirect.php new file mode 100644 index 0000000..cfeb37d --- /dev/null +++ b/LayoutTests/http/tests/resources/redirect.php @@ -0,0 +1,16 @@ +<?php + $url = $_GET['url']; + $refresh = $_GET['refresh']; + + if (isset($refresh)) { + header("HTTP/1.1 200"); + header("Refresh: $refresh; url=$url"); + return; + } + + $code = $_GET['code']; + if (!isset($code)) + $code = 302; + header("HTTP/1.1 $code"); + header("Location: $url"); +?> diff --git a/LayoutTests/http/tests/resources/reset-temp-file.php b/LayoutTests/http/tests/resources/reset-temp-file.php new file mode 100755 index 0000000..186376b --- /dev/null +++ b/LayoutTests/http/tests/resources/reset-temp-file.php @@ -0,0 +1,19 @@ +<?php +require_once 'portabilityLayer.php'; + +if (!sys_get_temp_dir()) { + echo "FAIL: No temp dir was returned.\n"; + exit(); +} + +$tmpFile = sys_get_temp_dir() . "/" . $_GET['filename']; + +if (!file_put_contents($tmpFile, "test")) { + echo "FAIL: unable to write to file: " . $tmpFile . "\n"; + exit(); +} +if (!unlink($tmpFile)) { + echo "FAIL: Unable to delete file: " . $tmpFile . "\n"; + exit(); +} +?> diff --git a/LayoutTests/http/tests/resources/silence.mpg b/LayoutTests/http/tests/resources/silence.mpg Binary files differnew file mode 100644 index 0000000..b6bbf20 --- /dev/null +++ b/LayoutTests/http/tests/resources/silence.mpg diff --git a/LayoutTests/http/tests/resources/touch-temp-file.php b/LayoutTests/http/tests/resources/touch-temp-file.php new file mode 100644 index 0000000..d2829df --- /dev/null +++ b/LayoutTests/http/tests/resources/touch-temp-file.php @@ -0,0 +1,22 @@ +<?php +require_once 'portabilityLayer.php'; + +if (!sys_get_temp_dir()) { + echo "FAIL: No temp dir was returned.\n"; + exit(); +} + +$tmpFile = sys_get_temp_dir() . "/" . $_GET['filename']; + +$stat = stat($tmpFile); +if (!$stat) { + echo "FAIL: stat() call failed.\n"; + exit(); +} + +$mtime = $stat['mtime'] + 1; + +if (!touch($tmpFile, $mtime)) { + echo "FAIL: touch() call failed.\n"; +} +?> diff --git a/LayoutTests/http/tests/resources/tripmine.php b/LayoutTests/http/tests/resources/tripmine.php new file mode 100644 index 0000000..635dea6 --- /dev/null +++ b/LayoutTests/http/tests/resources/tripmine.php @@ -0,0 +1,63 @@ +<?php +require_once 'portabilityLayer.php'; + +// This script detects requests that could not be sent before cross-site XMLHttpRequest appeared. + +header("Expires: Thu, 01 Dec 2003 16:00:00 GMT"); +header("Cache-Control: no-cache, no-store, must-revalidate"); +header("Pragma: no-cache"); + +if (!sys_get_temp_dir()) { + echo "FAIL: No temp dir was returned.\n"; + exit(); +} + +function setState($newState, $file) +{ + file_put_contents($file, $newState); +} + +function getState($file) +{ + if (!file_exists($file)) { + return ""; + } + return file_get_contents($file); +} + +$stateFile = sys_get_temp_dir() . "/tripmine-status"; +$command = $_GET['command']; +if ($command) { + if ($command == "status") + echo getState($stateFile); + exit(); +} + +$method = $_SERVER['REQUEST_METHOD']; +$contentType = $_SERVER['CONTENT_TYPE']; + +if ($method == "OPTIONS") { + // Don't allow cross-site requests with preflight. + exit(); +} + +// Only allow simple cross-site requests - since we did not allow preflight, this is all we should ever get. + +if ($method != "GET" && $method != "HEAD" && $method != "POST") { + setState("FAIL. Non-simple method $method.", $stateFile); + exit(); +} + +if (isset($contentType) + && !preg_match("/^application\/x\-www\-form\-urlencoded(;.+)?$/", $contentType) + && !preg_match("/^multipart\/form\-data(;.+)?$/", $contentType) + && !preg_match("/^text\/plain(;.+)?$/", $contentType)) { + setState("FAIL. Non-simple content type: $contentType.", $stateFile); + exit(); +} + +if (isset($_SERVER['HTTP_X_WEBKIT_TEST'])) { + setState("FAIL. Custom header sent with a simple request.", $stateFile); + exit(); +} +?> diff --git a/LayoutTests/http/tests/resources/write-temp-file.php b/LayoutTests/http/tests/resources/write-temp-file.php new file mode 100644 index 0000000..7abe358 --- /dev/null +++ b/LayoutTests/http/tests/resources/write-temp-file.php @@ -0,0 +1,17 @@ +<?php +require_once 'portabilityLayer.php'; + +if (!sys_get_temp_dir()) { + echo "FAIL: No temp dir was returned.\n"; + exit(); +} + +$tmpFile = sys_get_temp_dir() . "/" . $_GET['filename']; + +if (!file_put_contents($tmpFile, $_GET['data'])) { + echo "FAIL: unable to write to file: " . $tmpFile . "\n"; + exit(); +} + +echo $tmpFile; +?> |