Commit 59dc2a72 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Make PRESUBMIT.py and tests in LayoutTests/ workable in web_tests/.

This CL makes LayoutTests/PRESUBMIT.py and some tests in LayoutTests/
workable in blink/web_tests/ too.
Moving LayoutTests directory gets easier by this CL.

* PRESUBMIT.py
 - Use PresubmitLocalPath() instead of 'LayoutTests'
 - Remove unnecessary check for existence of 'LayoutTests' in
  AffectedFiles(), which returns files under the PRESUBMIT directory.
  _FindNewViolationsOfRule() also handles only files under the
  PRESUBMIT directory.

* Tests
 - Update code searching for 'LayoutTests' so that it searches for
   'web_tests' too.
 - Drop 'LayoutTests' from test expectations if we can
 - Introduce relativeTestPath()

Change-Id: I741ab3cb29d8e6c2a35e3b7669f92744f76c2839
Bug: 843412
Reviewed-on: https://chromium-review.googlesource.com/c/1276047Reviewed-by: default avatarQuinten Yearsley <qyearsley@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599068}
parent ba3e8005
......@@ -39,15 +39,16 @@ def _CheckTestharnessResults(input_api, output_api):
def _TestharnessGenericBaselinesToCheck(input_api):
"""Returns a list of paths of generic baselines for testharness.js tests."""
baseline_files = []
this_dir = input_api.PresubmitLocalPath()
for f in input_api.AffectedFiles():
if f.Action() == 'D':
continue
path = f.AbsoluteLocalPath()
if not path.endswith('-expected.txt'):
continue
if (input_api.os_path.join('LayoutTests', 'platform') in path or
input_api.os_path.join('LayoutTests', 'virtual') in path or
input_api.os_path.join('LayoutTests', 'flag-specific') in path):
if (input_api.os_path.join(this_dir, 'platform') in path or
input_api.os_path.join(this_dir, 'virtual') in path or
input_api.os_path.join(this_dir, 'flag-specific') in path):
continue
baseline_files.append(path)
return baseline_files
......@@ -71,20 +72,18 @@ def _CheckFilesUsingEventSender(input_api, output_api):
def _CheckTestExpectations(input_api, output_api):
local_paths = [f.LocalPath() for f in input_api.AffectedFiles()]
if any('LayoutTests' in path for path in local_paths):
lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'..', '..', 'blink', 'tools', 'lint_test_expectations.py')
_, errs = input_api.subprocess.Popen(
[input_api.python_executable, lint_path],
stdout=input_api.subprocess.PIPE,
stderr=input_api.subprocess.PIPE).communicate()
if not errs:
return [output_api.PresubmitError(
"lint_test_expectations.py failed "
"to produce output; check by hand. ")]
if errs.strip() != 'Lint succeeded.':
return [output_api.PresubmitError(errs)]
lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'..', '..', 'blink', 'tools', 'lint_test_expectations.py')
_, errs = input_api.subprocess.Popen(
[input_api.python_executable, lint_path],
stdout=input_api.subprocess.PIPE,
stderr=input_api.subprocess.PIPE).communicate()
if not errs:
return [output_api.PresubmitError(
"lint_test_expectations.py failed "
"to produce output; check by hand. ")]
if errs.strip() != 'Lint succeeded.':
return [output_api.PresubmitError(errs)]
return []
......@@ -94,7 +93,7 @@ def _CheckForJSTest(input_api, output_api):
def source_file_filter(path):
return input_api.FilterSourceFile(path,
white_list=[r'third_party/WebKit/LayoutTests/.*\.(html|js|php|pl|svg)$'])
white_list=[r'\.(html|js|php|pl|svg)$'])
errors = input_api.canned_checks._FindNewViolationsOfRule(
lambda _, x: not jstest_re.search(x), input_api, source_file_filter)
......
<!DOCTYPE html>
<script src="../../LayoutTests/resources/testharness.js"></script>
<script src="../../LayoutTests/resources/testharnessreport.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<div id="target"></div>
......
......@@ -896,7 +896,7 @@ function assembleDescription() {
for (const line of getStack()) {
const match = RE_IN_ASSERT_SELECTION.exec(line);
if (!match) {
const RE_LAYOUTTESTS = new RegExp('LayoutTests.*');
const RE_LAYOUTTESTS = new RegExp('(?:LayoutTests|web_tests).*');
return RE_LAYOUTTESTS.exec(line);
}
}
......
......@@ -20,11 +20,11 @@ function startTest()
'./resources/drag-files-to-editable-element-fail',
'./resources/foo',
'./resources/bar']);
result = editable.innerHTML.replace(/file.*?LayoutTests/g, "LayoutTests");
result = editable.innerHTML.replace(/file.*?(LayoutTests|web_tests)/g, "web_tests");
shouldBeEqualToString('result',
'<div>LayoutTests/editing/pasteboard/resources/drag-files-to-editable-element-fails</div>'+
'<div>LayoutTests/editing/pasteboard/resources/foo</div>'+
'<div>LayoutTests/editing/pasteboard/resources/bar</div>');
'<div>web_tests/editing/pasteboard/resources/drag-files-to-editable-element-fails</div>'+
'<div>web_tests/editing/pasteboard/resources/foo</div>'+
'<div>web_tests/editing/pasteboard/resources/bar</div>');
editable.innerHTML = '';
finishJSTest();
}
......
document.URL: LayoutTests/fast/dom/Window/resources/dom-access-from-closure-iframe-child.html
window.document.URL: LayoutTests/fast/dom/Window/resources/notify-parent-done.html
document.URL: fast/dom/Window/resources/dom-access-from-closure-iframe-child.html
window.document.URL: fast/dom/Window/resources/notify-parent-done.html
name: child
window.name: child
document.URL: LayoutTests/fast/dom/Window/resources/dom-access-from-closure-window-child.html
window.document.URL: LayoutTests/fast/dom/Window/resources/notify-opener-done.html
document.URL: fast/dom/Window/resources/dom-access-from-closure-window-child.html
window.document.URL: fast/dom/Window/resources/notify-opener-done.html
name: child
window.name: child
document.URL: LayoutTests/fast/dom/Window/resources/dom-access-from-closure-window-child.html
window.document.URL: LayoutTests/fast/dom/Window/resources/notify-opener-done.html
document.URL: fast/dom/Window/resources/dom-access-from-closure-window-child.html
window.document.URL: fast/dom/Window/resources/notify-opener-done.html
name: child
window.name: child
<script src="../../../../resources/common.js"></script>
<script>
// Capture window.window and window.parent: once this context is navigated, these properties
// always return null.
......@@ -5,14 +6,9 @@
var p = parent;
parent.accessFrame = function()
{
function normalizeURL(url)
{
return url.substring(url.lastIndexOf("LayoutTests"));
}
try {
p.log("document.URL: " + normalizeURL(document.URL));
p.log("window.document.URL: " + normalizeURL(w.document.URL));
p.log("document.URL: " + relativeTestPath(document.URL));
p.log("window.document.URL: " + relativeTestPath(w.document.URL));
p.log("name: " + name);
p.log("window.name: " + w.name);
} catch (e) {
......
<script src="../../../../resources/common.js"></script>
<script>
// Capture window.window and window.opener: once this context is navigated, these properties
// always return null.
......@@ -5,14 +6,9 @@
var o = opener;
opener.accessFrame = function()
{
function normalizeURL(url)
{
return url.substring(url.lastIndexOf("LayoutTests"));
}
try {
o.log("document.URL: " + normalizeURL(document.URL));
o.log("window.document.URL: " + normalizeURL(w.document.URL));
o.log("document.URL: " + relativeTestPath(document.URL));
o.log("window.document.URL: " + relativeTestPath(w.document.URL));
o.log("name: " + name);
o.log("window.name: " + w.name);
} catch (e) {
......
The document.documentURI property should not be affected by the <base> tag.
LayoutTests/fast/dom/documenturi-not-affected-by-base-tag.html
fast/dom/documenturi-not-affected-by-base-tag.html
<html>
<head>
<script src="../../resources/common.js"></script>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function normalizeURL(url) {
return url.substring(url.lastIndexOf('LayoutTests'));
}
</script>
<base href="http://fail.example.com/">
</head>
<body>
<div>The document.documentURI property should not be affected by the &lt;base&gt; tag.</div>
<script>document.write(normalizeURL(document.documentURI));</script>
<script>document.write(relativeTestPath(document.documentURI));</script>
</body>
</html>
......@@ -5,7 +5,7 @@ Frame: '<!--framePath //<!--frame0-->-->'
--------
This test checks whether a frame element's 'src' attribute is a complete, rather than relative, URL.
PASS: Frame 'src' attribute should include 'LayoutTests/fast/frames' and does.
PASS: Frame 'src' attribute should include 'fast/frames' and does.
--------
Frame: '<!--framePath //<!--frame1-->-->'
......
<html>
<head>
<script src="../../resources/common.js"></script>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.dumpChildFramesAsText();
......@@ -13,8 +13,8 @@ function write(s)
}
function test() {
var layoutTestDir = location.href;
layoutTestDir = layoutTestDir.substring(layoutTestDir.indexOf("LayoutTests"), layoutTestDir.lastIndexOf("/"));
var layoutTestDir = relativeTestPath(location.href);
layoutTestDir = layoutTestDir.substring(0, layoutTestDir.lastIndexOf("/"));
var frameSrc = document.getElementsByTagName('frame')[1].src;
if (frameSrc.search(layoutTestDir) != -1)
......
......@@ -18,7 +18,7 @@ foo(); // line 11
// elements back into a comma separated string by simply stringifying the
// array. This makes it easier to compare the resultant stack trace info.
result = String(temp.match(/LayoutTests\/[^:]+\:[0-9]+/g));
result = String(temp.match(/(?:LayoutTests|web_tests)\/[^:]+\:[0-9]+/g));
shouldBe("result", '"LayoutTests/fast/js/script-tests/exception-line-number.js:6,LayoutTests/fast/js/script-tests/exception-line-number.js:11"');
......@@ -26,7 +26,7 @@ shouldBe("result", '"LayoutTests/fast/js/script-tests/exception-line-number.js:6
// Test window.onerror:
window.onerror = function(msg, url, line) {
url = String(url.match(/LayoutTests\/[^:]+/g));
url = String(url.match(/(?:LayoutTests|web_tests)\/[^:]+/g));
result = url + ':' + line;
shouldBe("result", '"LayoutTests/fast/js/script-tests/exception-line-number.js:36"');
return true; // We handled it.
......
......@@ -16,7 +16,7 @@ worker.postMessage("eval DONE");
worker.onmessage = function(evt) {
if (!/DONE/.test(evt.data))
debug(evt.data.replace(new RegExp("/.*LayoutTests"), "<...>"));
debug(evt.data.replace(new RegExp("/.*(LayoutTests|web_tests)"), "<...>"));
else
finishJSTest();
};
......
......@@ -25,7 +25,7 @@ worker.postMessage("eval foo//bar");
worker.onmessage = function(evt) {
if (!/foo\/\/bar/.test(evt.data))
log(evt.data.replace(new RegExp("/.*LayoutTests"), "<...>"));
log(evt.data.replace(new RegExp("/.*(LayoutTests|web_tests)"), "<...>"));
else {
log("DONE");
if (window.testRunner)
......
......@@ -22,7 +22,7 @@ worker.postMessage("eval foo//bar");
worker.onmessage = function(evt) {
if (!/foo\/\/bar/.test(evt.data))
log(evt.data.replace(new RegExp("/.*LayoutTests"), "<...>"));
log(evt.data.replace(new RegExp("/.*(LayoutTests|web_tests)"), "<...>"));
else {
log("DONE");
if (window.testRunner)
......
......@@ -15,7 +15,7 @@ worker.postMessage("eval foo//bar");
worker.onmessage = function(evt) {
if (!/foo\/\/bar/.test(evt.data))
log(evt.data.replace(new RegExp("/.*LayoutTests"), "<...>"));
log(evt.data.replace(new RegExp("/.*(LayoutTests|web_tests)"), "<...>"));
else {
log("DONE");
if (window.testRunner)
......
......@@ -17,7 +17,7 @@
}
function dumpUISourceCode(uiSourceCode, callback) {
TestRunner.addResult('UISourceCode: ' + uiSourceCode.url().replace(/.*LayoutTests/, 'LayoutTests'));
TestRunner.addResult('UISourceCode: ' + uiSourceCode.url().replace(/.*(LayoutTests|web_tests)./, ''));
if (uiSourceCode.contentType() === Common.resourceTypes.Script ||
uiSourceCode.contentType() === Common.resourceTypes.Document)
TestRunner.addResult(
......
......@@ -18,7 +18,7 @@
var target = TestRunner.mainTarget;
function uiSourceCodeURL(uiSourceCode) {
return uiSourceCode.url().replace(/.*LayoutTests/, 'LayoutTests');
return uiSourceCode.url().replace(/.*(LayoutTests|web_tests)./, '');
}
function dumpUISourceCode(uiSourceCode, callback) {
......
......@@ -135,7 +135,7 @@ Tests DOMSnapshot.getSnapshot method.
}
],
"layoutNodeIndex": 3,
"currentSourceURL": "<string>WebKit/LayoutTests/inspector-protocol/resources/1x.png"
"currentSourceURL": "<string>inspector-protocol/resources/1x.png"
},
{
"nodeType": 3,
......
......@@ -16,7 +16,7 @@
if (typeof value === 'string' && value.indexOf('/dom-snapshot/') !== -1)
value = '<value>';
if (typeof value === 'string' && value.indexOf('file://') !== -1)
value = '<string>' + value.substr(value.indexOf("WebKit/"));
value = '<string>' + value.replace(/.*(LayoutTests|web_tests)\//, '');
return value;
}
......
// Remove leading ...LayoutTests/ or ...web_tests/ .
function relativeTestPath(path) {
return path.replace(/.*\/(LayoutTests|web_tests)\//, '');
}
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