Commit 3f020273 authored by dcampb's avatar dcampb Committed by Commit bot

Support converting utf-16 files when importing w3c tests

Previously, the test converter assumed that input files are always valid utf-8;
this change makes the converter also support utf-16 files. There are some files
in the wpt repo that are not valid utf-8 but are valid utf-16, e.g.
web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/utf-16be.html.
BUG=463001

Review-Url: https://codereview.chromium.org/2037743002
Cr-Commit-Position: refs/heads/master@{#397775}
parent 547e4190
......@@ -47,7 +47,10 @@ def convert_for_webkit(new_path, filename, reference_support_info, host=Host()):
if filename.endswith('.css'):
return converter.add_webkit_prefix_to_unprefixed_properties(contents.decode('utf-8'))
else:
converter.feed(contents.decode('utf-8'))
try:
converter.feed(contents.decode('utf-8'))
except UnicodeDecodeError:
converter.feed(contents.decode('utf-16'))
converter.close()
return converter.output()
......
......@@ -33,7 +33,9 @@ from webkitpy.common.host import Host
from webkitpy.common.system.outputcapture import OutputCapture
from webkitpy.common.webkit_finder import WebKitFinder
from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup
from webkitpy.w3c.test_converter import _W3CTestConverter
from webkitpy.w3c.test_converter import _W3CTestConverter, convert_for_webkit
from webkitpy.common.system.systemhost_mock import MockSystemHost
from webkitpy.common.system.filesystem_mock import MockFileSystem
DUMMY_FILENAME = 'dummy.html'
DUMMY_PATH = 'dummy/testharness/path'
......@@ -310,3 +312,16 @@ CONTENT OF TEST
index -= 1
return (test_properties, html)
def test_convert_for_webkit_with_non_utf8(self):
files = {'/file': 'e\x87[P',
'/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', }
host = MockSystemHost(filesystem=MockFileSystem(files=files))
convert_for_webkit('', '/file', '', host)
# This test passes if no Exception is raised
def test_convert_for_webkit_with_utf8(self):
files = {'/file': 'foo',
'/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', }
host = MockSystemHost(filesystem=MockFileSystem(files=files))
convert_for_webkit('', '/file', '', host)
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