Commit 23a4547b authored by Benjamin C. Wiley Sittler's avatar Benjamin C. Wiley Sittler Committed by Commit Bot

Forms: Use checked-in files rather than CGIs in LayoutTests

The CGIs were previously the only way to test Unicode filenames in
file uploads, but introduced noticeable test slowdowns, especially
on Win32.

This also removes the test bifurcation previously added to avoid
occasional Win32 timeouts due to Win32 CGI slowness:
https://chromium.googlesource.com/chromium/src/+/78383443fce02079cbbec26f911abea2ca70dc5b

TBR=

Bug: 661819
Change-Id: Iab3295f665bdfe4c51688f4fa42162505f36a929
Reviewed-on: https://chromium-review.googlesource.com/802554
Commit-Queue: Marc-Antoine Ruel <maruel@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521947}
parent f85ab8f6
#!/usr/bin/perl -wT
#
# delete-temp-file.cgi - deletes a file and its temporary subdirectory
#
# The file's fully-qualified file path is passed in the filename query
# parameter.
#
# The file must have been previously created using
# write-temp-file.cgi, which creates files with test-chosen basenames
# inside random-named subdirectories of a system temporary directory,
# e.g. /tmp/LayoutTests_cgiXXXXX/name-chosen-by-test.txt or
# %LOCALAPPDATA%\Temp\cgiXXXXX\name-chosen-by-test.txt where XXXXX are
# random characters varying per write-temp-file.cgi run.
#
# Must be called using the HTTP POST method.
#
# Any output other than the string "OK" is an error message and
# indicates failure.
#
# Errors are redirected to stdout and UTF-8 encoded to aid diagnostics
# in the calling test suite.
#
# NOTE: "ACP" in this CGI refers to the Windows concept of "ANSI"
# Codepage, a (not actually ANSI-standardized) single- or double-byte
# non-Unicode ASCII-compatible character encoding used for some
# narrow-character Win32 APIs. It should not be confused with UTF-8
# (used for similar purposes on Linux, OS X, and other modern
# POSIX-like systems), nor with the usually-distinct OEM codepage
# used for other narrow-character Win32 APIs (for instance, console
# I/O and some filesystem data storage.)
use strict;
use warnings FATAL => 'all';
use CGI qw(-oldstyle_urls);
use Encode qw(encode decode);
use File::Basename qw(basename dirname);
use File::Spec::Functions qw(tmpdir);
use utf8;
my $win32 = eval 'use Win32; 1' ? 1 : 0;
open STDERR, '>&STDOUT'; # let the test see die() output
binmode STDOUT, ':encoding(utf-8)';
autoflush STDOUT 1;
autoflush STDERR 1;
print "content-type: text/plain; charset=utf-8\n\n";
# tmpdir() does not read environment variables in taint mode.
my $system_tmpdir = $ENV{TMPDIR} || $ENV{TEMP} || tmpdir();
$system_tmpdir =~ /\A([^\0- ]*)\z/s
or die "untaint failed: $!";
$system_tmpdir = $1;
if ($win32) {
$system_tmpdir = Win32::GetANSIPathName($system_tmpdir);
# Drive+directory path equality checks are performed in the 8.3
# "shortname" space (and case-insensitively) to decrease the
# likelihood of a false negative.
#
# ACP APIs return 8.3 names for some of the inputs currently used in
# tests.
$system_tmpdir = Win32::GetShortPathName($system_tmpdir);
}
my $req = CGI->new;
if (uc 'post' ne $req->request_method) {
die 'Wrong method: ' . $req->request_method;
}
# $file_path is a UTF-8-encoded representation of the "ACP"
# file path. $file_path_acp is a logically-equivalent ACP-encoded
# bytestring suitable for use in a (narrow-character) system
# call. These are only distinct on Win32.
my $file_path = decode utf8 => $req->url_param('filename');
my $file_path_acp = $file_path;
if ($win32) {
$file_path_acp = Win32::GetFullPathName(Win32::GetANSIPathName($file_path));
}
$file_path_acp =~ /\A([^\0- ]*)\z/s
or die "untaint failed: $!";
$file_path_acp = $1;
# This should be a random-named subdirectory of the system temporary
# directory holding the test file to be deleted.
my $temp_cgi_subdir = dirname($file_path_acp);
if ($win32) {
# Drive+directory path equality checks are performed in the 8.3
# "shortname" space (and case-insensitively) to decrease the
# likelihood of a false negative.
#
# ACP APIs return 8.3 names for some of the inputs currently used in
# tests.
$temp_cgi_subdir = Win32::GetShortPathName($temp_cgi_subdir);
}
# If the passed-in file path is actually one created by
# write-temp-file.cgi this will match $system_tmpdir computed from the
# environment.
my $file_path_implied_system_tmpdir = dirname($temp_cgi_subdir);
# This is the random-suffixed (LayoutTests_)?cgiXXXXX component.
my $temp_cgi_subdir_basename = basename($temp_cgi_subdir);
# The selected file must actually exist.
if (!-f $file_path_acp) {
die(encode utf8 => "Can't reset $file_path: missing file");
}
# Security check: ensure the supplied fully-qualified file path is in a
# subdirectory of the system temporary directory.
if (uc($file_path_implied_system_tmpdir) ne uc($system_tmpdir)) {
die(encode utf8 => ("Can't reset $file_path: " .
"$file_path_implied_system_tmpdir is not " .
"$system_tmpdir"));
}
# The system temporary directory must already exist.
if (!-d $system_tmpdir) {
die(encode utf8 => "Can't reset $file_path: missing $system_tmpdir");
}
# Ensure the random-named subdirectory matches write-temp-file.cgi
# naming conventions.
if (!($temp_cgi_subdir_basename =~ /\A(LayoutTests_)?cgi\w+\z/i)) {
die(encode utf8 => ("Can't reset $file_path: " .
"$temp_cgi_subdir_basename is not cgi*"));
}
# The random-named subdirectory must also already exist.
if (!-d $temp_cgi_subdir) {
die(encode utf8 => ("Can't reset $file_path: " .
"missing $temp_cgi_subdir"));
}
# Delete the selected file.
unlink($file_path_acp)
or die(encode utf8 => "unlink $file_path: $!");
# Delete its containing (LayoutTests_)?cgiXXXXX directory.
rmdir($temp_cgi_subdir)
or die(encode utf8 => "rmdir $temp_cgi_subdir: $!");
print 'OK';
#!/usr/bin/perl -wT
#
# write-temp-file.cgi - creates a file and its temporary subdirectory
#
# The file's desired basename is passed in the filename query parameter.
# The file's desired contents are passed in the data query parameter.
#
# The newly created temporary file will be inside a uniquely-named
# subdirectory to prevent crosstalk between parallel test runs. Once
# the test is done with the temporary file its <file_path> should be
# passed to delete-temp-file.cgi for cleanup.
#
# Must be called using the HTTP POST method.
#
# On success, outputs the following three-line plaintext UTF-8
# response:
#
# OK
# <file_path>
#
# Where <file_path> is the full file_path of the just-written
# temporary file suitable for use with wide-character Unicode APIs
# after UTF-8 decoding and UTF-16 reencoding.
#
# Any other output is an error message and indicates failure.
#
# Errors are redirected to stdout and UTF-8 encoded to aid diagnostics
# in the calling test suite.
#
# NOTE: This CGI allows writing files with filenames including
# non-ASCII Unicode characters, but note that Blink renderer crashes
# are expected on non-Windows hosts using such filenames when a
# non-UTF-8 locale is used. Use a UTF-8 locale to prevent this,
# e.g. with:
#
# bash$ export LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
#
# Any other locale should work too provided it uses UTF-8 character
# encoding.
#
# Test failures are expected when relying on this CGI on Windows when
# using any system "ANSI" codepage ("ACP" below) other than
# windows-1252. To fix this, upgrade your system's Win32.pm Perl
# module to the latest version. Any version of Win32.pm since
# Win32-0.45 (released in 2012) should have the needed method:
# https://rt.cpan.org/Public/Bug/Display.html?id=78820
#
# NOTE: "ACP" in this CGI refers to the Windows concept of "ANSI"
# Codepage, a (not actually ANSI-standardized) single- or double-byte
# non-Unicode ASCII-compatible character encoding used for some
# narrow-character Win32 APIs. It should not be confused with UTF-8
# (used for similar purposes on Linux, OS X, and other modern
# POSIX-like systems), nor with the usually-distinct OEM codepage
# used for other narrow-character Win32 APIs (for instance, console
# I/O and some filesystem data storage.)
use strict;
use warnings FATAL => 'all';
use CGI qw(-oldstyle_urls);
use Encode qw(encode decode is_utf8);
use File::Basename qw(dirname);
use File::Spec::Functions qw(catfile tmpdir);
use File::Temp qw(tempdir tempfile);
use utf8;
my $win32 = eval 'use Win32; 1' ? 1 : 0;
open STDERR, '>&STDOUT'; # let the test see die() output
binmode STDOUT, ':encoding(utf-8)';
autoflush STDOUT 1;
autoflush STDERR 1;
print "content-type: text/plain; charset=utf-8\n\n";
# tmpdir() does not read environment variables in taint mode.
my $system_tmpdir = $ENV{TMPDIR} || $ENV{TEMP} || tmpdir();
$system_tmpdir =~ /\A([^\0- ]*)\z/s
or die "untaint failed: $!";
$system_tmpdir = $1;
if ($win32) {
$system_tmpdir =
Win32::GetFullPathName(Win32::GetANSIPathName($system_tmpdir));
}
my $req = CGI->new;
if (uc 'post' ne $req->request_method) {
die 'Wrong method: ' . $req->request_method;
}
my $basename = decode utf8 => $req->url_param('filename');
$basename =~ /\A([^\0- ]*)\z/s
or die "untaint failed: $!";
$basename = $1;
my $data = decode utf8 => $req->url_param('data');
# The system temporary directory must already exist.
if (!-d $system_tmpdir) {
die(encode utf8 => "Can't create $basename: missing $system_tmpdir");
}
# Create a random-named subdirectory of the system temporary directory
# to hold the newly-created test file. The X's will be replaced with
# random printable characters by tempdir.
my $temp_cgi_subdir_template = 'LayoutTests_cgiXXXXX';
if ($win32) {
# On win32 this name needs to remain unique even after 8.3 shortname
# conversion so we drop the LayoutTests_ prefix.
$temp_cgi_subdir_template = 'cgiXXXXX';
}
my $temp_cgi_subdir =
tempdir($temp_cgi_subdir_template, DIR => $system_tmpdir);
my $file_path = catfile($temp_cgi_subdir, $basename);
if (dirname($file_path) ne $temp_cgi_subdir) {
die(encode utf8 => "$file_path not in $temp_cgi_subdir");
}
my $tempfile_contents_write_handle;
my $tempfile;
# $file_path_acp_utf8 is a UTF-8-encoded representation of the
# fully-qualified "ACP" file file_path. $file_path_acp is a
# logically-equivalent ACP-encoded bytestring suitable for use in a
# (narrow-character) system call. These are only distinct on Win32.
my $file_path_acp = $file_path;
my $file_path_acp_utf8 = $file_path;
if ($win32) {
# Win32::GetACP is a recently-added method and not yet available in
# some installations. Fall back to windows-1252 when GetACP is
# missing as that matches the ACP used by our Windows bots.
my $win32_ansi_codepage = 'windows-1252';
eval '$win32_ansi_codepage = "cp" . Win32::GetACP();';
Win32::CreateFile($file_path)
or die(encode utf8 => "CreateFile $file_path: $^E");
$file_path_acp = Win32::GetFullPathName(Win32::GetANSIPathName($file_path));
$file_path = Win32::GetLongPathName($file_path_acp);
$file_path_acp_utf8 = $file_path_acp;
if (!is_utf8($file_path_acp_utf8)) {
$file_path_acp_utf8 = decode($win32_ansi_codepage, $file_path_acp_utf8);
}
if (!is_utf8($file_path)) {
$file_path = decode($win32_ansi_codepage, $file_path);
}
open($tempfile_contents_write_handle, '>>', $file_path_acp)
or die(encode utf8 => "open >> $file_path_acp_utf8: $!");
$tempfile = $file_path_acp_utf8;
} else {
($tempfile_contents_write_handle, $tempfile) =
tempfile(DIR => $temp_cgi_subdir);
}
binmode $tempfile_contents_write_handle, ':encoding(utf-8)';
print $tempfile_contents_write_handle $data;
close $tempfile_contents_write_handle
or die(encode utf8 => "close $tempfile: $!");
if (!$win32) {
rename($tempfile, $file_path)
or die(encode utf8 => "rename $tempfile, $file_path: $!");
}
# Fail early to aid debugging when the newly-created file does not
# actually work with system calls or does not contain the correct
# bytes.
local $/ = undef;
my $tempfile_verification_read_handle;
open($tempfile_verification_read_handle, '<', $file_path_acp)
or die(encode utf8 => "open $file_path_acp_utf8: $!");
binmode $tempfile_verification_read_handle, ':encoding(utf-8)';
my $data2 = <$tempfile_verification_read_handle>;
close($tempfile_verification_read_handle)
or die(encode utf8 => "close $file_path_acp_utf8: $!");
if ($data ne $data2) {
die(encode utf8 => "Expected $data but got $data2");
}
print "OK\n$file_path";
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in ISO-2022-JP form (part 2)</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
NOTE: Blink renderer crashes are expected on non-Windows hosts using
filenames containing characters from outside ASCII. Use a UTF-8
locale to prevent this, e.g. with:
bash$ export LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
Any other locale should work too provided it uses UTF-8 character
encoding.
Test failures are expected on Windows when using any system "ANSI"
codepage other than windows-1252. To fix this, upgrade your system's
Win32.pm Perl module to the latest version.
-->
<script>
'use strict';
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: 'file-for-drag-to-send3-\x1B$B!z@1!z\x1B(B.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9786;&#128514;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: `file-for-drag-to-send3-${
kTestFallbackIso2022jp
}.txt`,
});
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in UTF-8 form (part 2)</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
NOTE: Blink renderer crashes are expected on non-Windows hosts using
filenames containing characters from outside ASCII. Use a UTF-8
locale to prevent this, e.g. with:
bash$ export LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
Any other locale should work too provided it uses UTF-8 character
encoding.
Test failures are expected on Windows when using any system "ANSI"
codepage other than windows-1252. To fix this, upgrade your system's
Win32.pm Perl module to the latest version.
-->
<script>
'use strict';
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'UTF-8',
expectedEncodedBaseName: 'file-for-drag-to-send3-★星★.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'UTF-8',
expectedEncodedBaseName: 'file-for-drag-to-send3-☺😂.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'UTF-8',
expectedEncodedBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
});
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in Windows-1252 form (part 1)</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
NOTE: Blink renderer crashes are expected on non-Windows hosts using
filenames containing characters from outside ASCII. Use a UTF-8
locale to prevent this, e.g. with:
bash$ export LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
Any other locale should work too provided it uses UTF-8 character
encoding.
Test failures are expected on Windows when using any system "ANSI"
codepage other than windows-1252. To fix this, upgrade your system's
Win32.pm Perl module to the latest version.
-->
<script>
'use strict';
formPostFileUploadTest({
fileNameSource: 'ASCII',
fileBaseName: 'file-for-drag-to-send3.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: 'file-for-drag-to-send3.txt',
});
formPostFileUploadTest({
fileNameSource: 'x-user-defined',
fileBaseName: 'file-for-drag-to-send3-\uF7F0\uF793\uF783\uF7A0.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: (
'file-for-drag-to-send3-&#63472;&#63379;&#63363;&#63392;.txt'),
});
formPostFileUploadTest({
fileNameSource: 'windows-1252',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: 'file-for-drag-to-send3-☺😂.txt',
});
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in x-user-defined form (part 2)</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
NOTE: Blink renderer crashes are expected on non-Windows hosts using
filenames containing characters from outside ASCII. Use a UTF-8
locale to prevent this, e.g. with:
bash$ export LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
Any other locale should work too provided it uses UTF-8 character
encoding.
Test failures are expected on Windows when using any system "ANSI"
codepage other than windows-1252. To fix this, upgrade your system's
Win32.pm Perl module to the latest version.
-->
<script>
'use strict';
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'x-user-defined',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9733;&#26143;&#9733;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'x-user-defined',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9786;&#128514;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'x-user-defined',
expectedEncodedBaseName: `file-for-drag-to-send3-${
kTestFallbackXUserDefined
}.txt`,
});
</script>
ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ
\ No newline at end of file
ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ
\ No newline at end of file
ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ
\ No newline at end of file
ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ
\ No newline at end of file
ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ
\ No newline at end of file
......@@ -93,17 +93,13 @@ const kTestFallbackWindows1252 =
const kTestFallbackXUserDefined =
kTestChars.replace(/[^\0-\x7F]/gu, x => `&#${x.codePointAt(0)};`);
// Web server hosting helper CGIs
// Web server hosting helper CGI
const kWebServer = 'http://127.0.0.1:8000';
// formPostFileUploadTest - verifies multipart upload structure and
// numeric character reference replacement for filenames, field names,
// and field values.
//
// Uses /fileapi/resources/write-temp-file.cgi to create the
// test file and /fileapi/resources/delete-temp-file.cgi to
// remove it at the end of the test.
//
// Uses /xmlhttprequest/resources/post-echo.cgi to echo the upload
// POST with UTF-8 byte interpretation, leading to the "UTF-8 goggles"
// behavior documented below for expectedEncodedBaseName when non-
......@@ -123,8 +119,7 @@ const kWebServer = 'http://127.0.0.1:8000';
// the fileBaseName, or Unicode if no smaller-than-Unicode source
// contains all the characters. Used in the test name.
// - fileBaseName: the not-necessarily-just-7-bit-ASCII file basename
// used to create and then upload the test file. Used in the test
// name.
// for the test file. Used in the test name.
// - formEncoding: the acceptCharset of the form used to submit the
// test file. Used in the test name.
// - expectedEncodedBaseName: the expected formEncoding-encoded
......@@ -133,12 +128,6 @@ const kWebServer = 'http://127.0.0.1:8000';
// through UTF-8 goggles; subsequences not interpretable as UTF-8
// have each byte represented here by \uFFFD REPLACEMENT CHARACTER.
//
// Only a subset of functionality representable in the active "ANSI"
// codepage is actually testable for filenames on Win32 at the moment
// due to Blink and test suite limitations. Elsewhere (Linux, OS X,
// etc.) full functionality is testable provided a UTF-8 locale is
// used to run the test.
//
// NOTE: This does not correctly account for varying representation of
// combining characters across platforms and filesystems due to
// Unicode normalization or similar platform-specific normalization
......@@ -211,29 +200,11 @@ const formPostFileUploadTest = ({
});
form.appendChild(fileInput);
const fileToDropLines = (await (await fetch(
`${kWebServer}/fileapi/resources/write-temp-file.cgi` +
`?filename=${
encodeURIComponent(fileBaseName)
}&data=${encodeURIComponent(kTestChars)}`,
{ method: 'post' })).text()).split('\n');
assert_equals(
fileToDropLines.length,
2,
`CGI response should have two lines but got ${fileToDropLines}`);
const [shouldBeOk, fileToDrop] = fileToDropLines;
assert_equals(
shouldBeOk,
'OK',
`CGI response should begin with OK but got ${fileToDropLines}`);
const fileToDrop = `resources/${fileBaseName}`;
// Removes c:\fakepath\ or other pseudofolder and returns just the
// final component of filePath; allows both / and \ as segment
// delimiters.
const baseNameOfFilePath = filePath => filePath.split(/[\/\\]/).pop();
assert_equals(
baseNameOfFilePath(fileToDrop),
fileBaseName,
`Unicode ${fileToDrop} basename should be ${fileBaseName}`);
fileInput.onchange = event => {
assert_equals(
fileInput.files[0].name,
......@@ -249,22 +220,14 @@ const formPostFileUploadTest = ({
`The basename of the field's value should match its files[0].name`);
form.submit();
};
try {
await new Promise(resolve => {
formTargetFrame.onload = resolve;
eventSender.beginDragWithFiles([fileToDrop]);
const centerX = fileInput.offsetLeft + fileInput.offsetWidth / 2;
const centerY = fileInput.offsetTop + fileInput.offsetHeight / 2;
eventSender.mouseMoveTo(centerX, centerY);
eventSender.mouseUp();
});
} finally {
const cleanupErrors = await (await fetch(
`${kWebServer}/fileapi/resources/delete-temp-file.cgi` +
`?filename=${encodeURIComponent(fileToDrop)}`,
{ method: 'post' })).text();
assert_equals(cleanupErrors, 'OK', 'Temp file cleanup should not fail');
}
await new Promise(resolve => {
formTargetFrame.onload = resolve;
eventSender.beginDragWithFiles([fileToDrop]);
const centerX = fileInput.offsetLeft + fileInput.offsetWidth / 2;
const centerY = fileInput.offsetTop + fileInput.offsetHeight / 2;
eventSender.mouseMoveTo(centerX, centerY);
eventSender.mouseUp();
});
const formDataText = formTargetFrame.contentDocument.body.textContent;
const formDataLines = formDataText.split('\n');
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in ISO-2022-JP form (part 1)</title>
<title>Upload files in ISO-2022-JP form</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
......@@ -50,4 +50,27 @@ formPostFileUploadTest({
'file-for-drag-to-send3-&#226;&#732;&#186;&#240;&#376;&#732;&#8218;.txt'),
});
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: 'file-for-drag-to-send3-\x1B$B!z@1!z\x1B(B.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9786;&#128514;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'ISO-2022-JP',
expectedEncodedBaseName: `file-for-drag-to-send3-${
kTestFallbackIso2022jp
}.txt`,
});
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in UTF-8 form (part 1)</title>
<title>Upload files in UTF-8 form</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
......@@ -49,4 +49,25 @@ formPostFileUploadTest({
expectedEncodedBaseName: 'file-for-drag-to-send3-☺😂.txt',
});
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'UTF-8',
expectedEncodedBaseName: 'file-for-drag-to-send3-★星★.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'UTF-8',
expectedEncodedBaseName: 'file-for-drag-to-send3-☺😂.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'UTF-8',
expectedEncodedBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
});
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in Windows-1252 form (part 2)</title>
<title>Upload files in Windows-1252 form</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
......@@ -27,6 +27,28 @@
<script>
'use strict';
formPostFileUploadTest({
fileNameSource: 'ASCII',
fileBaseName: 'file-for-drag-to-send3.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: 'file-for-drag-to-send3.txt',
});
formPostFileUploadTest({
fileNameSource: 'x-user-defined',
fileBaseName: 'file-for-drag-to-send3-\uF7F0\uF793\uF783\uF7A0.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: (
'file-for-drag-to-send3-&#63472;&#63379;&#63363;&#63392;.txt'),
});
formPostFileUploadTest({
fileNameSource: 'windows-1252',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'windows-1252',
expectedEncodedBaseName: 'file-for-drag-to-send3-☺😂.txt',
});
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Upload files in x-user-defined form (part 1)</title>
<title>Upload files in x-user-defined form</title>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<!--
......@@ -49,4 +49,27 @@ formPostFileUploadTest({
'&#226;&#732;&#186;&#240;&#376;&#732;&#8218;.txt'),
});
formPostFileUploadTest({
fileNameSource: 'JIS X 0201 and JIS X 0208',
fileBaseName: 'file-for-drag-to-send3-★星★.txt',
formEncoding: 'x-user-defined',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9733;&#26143;&#9733;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: 'file-for-drag-to-send3-☺😂.txt',
formEncoding: 'x-user-defined',
expectedEncodedBaseName: 'file-for-drag-to-send3-&#9786;&#128514;.txt',
});
formPostFileUploadTest({
fileNameSource: 'Unicode',
fileBaseName: `file-for-drag-to-send3-${kTestChars}.txt`,
formEncoding: 'x-user-defined',
expectedEncodedBaseName: `file-for-drag-to-send3-${
kTestFallbackXUserDefined
}.txt`,
});
</script>
......@@ -5,8 +5,8 @@
href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data">
<link rel="author" title="Benjamin C. Wiley Sittler"
href="mailto:bsittler@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="resources/send-dragged-file-form-helper.js"></script>
<script>
'use strict';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment