Chromium Code Reviews| Index: tools/testing/dart/test_suite.dart |
| diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart |
| index 349a8a632a638f46211aaa4d86d36b7561979aed..5a602bbc3f537b93a4696b66c05c346d838ed70a 100644 |
| --- a/tools/testing/dart/test_suite.dart |
| +++ b/tools/testing/dart/test_suite.dart |
| @@ -812,6 +812,77 @@ class StandardTestSuite extends TestSuite { |
| }; |
| } |
| + |
| + /** |
| + * _createUrlPathFromFile takes a [file], which is either located in the dart |
| + * or in the build directory, and will return a String representing |
| + * the relative path to either the dart or the build directory. |
| + * Thus, the returned [String] will be the path component of the URL |
| + * corresponding to [file] (the http server serves files relative to the |
| + * dart/build directories). |
| + */ |
| + String _createUrlPathFromFile(Path file) { |
| + file = TestUtils.absolutePath(file); |
| + var fileString = file.toString(); |
| + |
| + var relativeBuildDir = TestUtils.buildDir(configuration); |
| + var buildDir = TestUtils.absolutePath(new Path(relativeBuildDir)); |
| + var dartDir = TestUtils.dartDir(); |
| + |
| + var pathComponent; |
| + if (fileString.startsWith(buildDir.toString())) { |
| + var fileRelativeToBuildDir = file.relativeTo(buildDir); |
| + pathComponent = "$relativeBuildDir/$fileRelativeToBuildDir"; |
| + } else if (fileString.startsWith(dartDir.toString())) { |
| + pathComponent = file.relativeTo(dartDir); |
| + } else { |
| + // Unreachable |
| + Except.isTrue(false); |
| + } |
| + return "/$pathComponent"; |
| + } |
| + |
| + void _getUriForBrowserTest(TestInformation info, |
| + String pathComponent, |
| + subtestNames, |
| + subtestIndex) { |
| + // Note: If we run test.py with the "--list" option, no http servers |
| + // will be started. Therefore serverList is an empty list in this |
| + // case. So we use PORT/CROSS_ORIGIN_PORT instead of real ports. |
| + var serverPort = "PORT"; |
| + var crossOriginPort = "CROSS_ORIGIN_PORT"; |
| + if (!configuration['list']) { |
| + serverPort = serverList[0].port.toString(); |
| + crossOriginPort = serverList[1].port.toString(); |
| + } |
| + |
| + var url= 'http://127.0.0.1:$serverPort$pathComponent' |
| + '?crossOriginPort=$crossOriginPort'; |
| + if (info.optionsFromFile['isMultiHtmlTest'] && subtestNames.length > 0) { |
| + url= '${url}&group=${subtestNames[subtestIndex]}'; |
| + } |
| + return url; |
| + } |
| + |
| + void _createWrapperFile(String dartWrapperFilename, dartLibraryFilename) { |
| + File file = new File(dartWrapperFilename); |
| + RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE); |
| + |
| + var usePackageImport = dartLibraryFilename.segments().contains("pkg"); |
| + var libraryPathComponent = _createUrlPathFromFile(dartLibraryFilename); |
| + dartWrapper.writeStringSync(dartTestWrapper(usePackageImport, |
| + libraryPathComponent)); |
| + dartWrapper.closeSync(); |
| + } |
| + |
| + void _createLibraryWrapperFile(Path dartLibraryFilename, filePath) { |
| + File file = new File(dartLibraryFilename.toNativePath()); |
| + RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE); |
| + dartLibrary.writeStringSync( |
| + wrapDartTestInLibrary(filePath.relativeTo(TestUtils.dartDir()))); |
| + dartLibrary.closeSync(); |
| + } |
| + |
| /** |
| * The [StandardTestSuite] has support for tests that |
| * compile a test from Dart to JavaScript, and then run the resulting |
| @@ -867,18 +938,9 @@ class StandardTestSuite extends TestSuite { |
| if (!isLibraryDefinition) { |
| dartLibraryFilename = new Path(tempDir).append( |
| 'test_as_library.dart'); |
| - File file = new File(dartLibraryFilename.toNativePath()); |
| - RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE); |
| - dartLibrary.writeStringSync( |
| - wrapDartTestInLibrary(filePath, file.name)); |
| - dartLibrary.closeSync(); |
| + _createLibraryWrapperFile(dartLibraryFilename, filePath); |
| } |
| - |
| - File file = new File(dartWrapperFilename); |
| - RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE); |
| - dartWrapper.writeStringSync( |
| - dartTestWrapper(dartDir, file.name, dartLibraryFilename)); |
| - dartWrapper.closeSync(); |
| + _createWrapperFile(dartWrapperFilename, dartLibraryFilename); |
| } else { |
| dartWrapperFilename = filename; |
| // TODO(whesse): Once test.py is retired, adjust the relative path in |
| @@ -895,8 +957,10 @@ class StandardTestSuite extends TestSuite { |
| } |
| htmlPath = '$tempDir/../$htmlFilename'; |
| } |
| - final String scriptPath = (compiler == 'none') ? |
| + String scriptPath = (compiler == 'none') ? |
| dartWrapperFilename : compiledDartWrapperFilename; |
| + scriptPath = _createUrlPathFromFile(new Path(scriptPath)); |
| + |
| // Create the HTML file for the test. |
| RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE); |
| String content = null; |
| @@ -907,22 +971,13 @@ class StandardTestSuite extends TestSuite { |
| Path expectedOutput = null; |
| if (new File.fromPath(pngPath).existsSync()) { |
| expectedOutput = pngPath; |
| - // TODO(efortuna): Unify path libraries in test.dart. |
| - content = getHtmlLayoutContents(scriptType, pathLib.relative(scriptPath, |
| - from: pathLib.dirname(htmlPath))); |
| + content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| } else if (new File.fromPath(txtPath).existsSync()) { |
| expectedOutput = txtPath; |
| - content = getHtmlLayoutContents(scriptType, pathLib.relative(scriptPath, |
| - from: pathLib.dirname(htmlPath))); |
| + content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| } else { |
| - final htmlLocation = new Path(htmlPath); |
| - content = getHtmlContents( |
| - filename, |
| - dartDir.append('pkg/unittest/test_controller.js') |
| - .relativeTo(htmlLocation), |
| - dartDir.append('pkg/browser/lib/dart.js').relativeTo(htmlLocation), |
| - scriptType, |
| - new Path(scriptPath).relativeTo(htmlLocation)); |
| + content = getHtmlContents(filename, scriptType, |
| + new Path("$scriptPath")); |
| } |
| htmlTest.writeStringSync(content); |
| htmlTest.closeSync(); |
| @@ -962,35 +1017,11 @@ class StandardTestSuite extends TestSuite { |
| commandSet = []; |
| } |
| - List<String> args = <String>[]; |
| - var basePath = TestUtils.dartDir().toString(); |
| - if (!htmlPath.startsWith('/') && !htmlPath.startsWith('http')) { |
| - htmlPath = '/$htmlPath'; |
| - } |
| - htmlPath = htmlPath.startsWith(basePath) ? |
| - htmlPath.substring(basePath.length) : htmlPath; |
| - String fullHtmlPath = htmlPath; |
| - var searchStr = '?'; |
| - if (!htmlPath.startsWith('http')) { |
| - // Note: If we run test.py with the "--list" option, no http servers |
| - // will be started. Therefore serverList is an empty list in this |
| - // case. So we use PORT/CROSS_ORIGIN_PORT instead of real ports. |
| - var serverPort = "PORT"; |
| - var crossOriginPort = "CROSS_ORIGIN_PORT"; |
| - if (!configuration['list']) { |
| - serverPort = serverList[0].port.toString(); |
| - crossOriginPort = serverList[1].port.toString(); |
| - } |
| - fullHtmlPath = 'http://127.0.0.1:$serverPort$htmlPath${searchStr}' |
| - 'crossOriginPort=$crossOriginPort'; |
| - searchStr = '&'; |
| - } |
| - if (info.optionsFromFile['isMultiHtmlTest'] |
| - && subtestNames.length > 0) { |
| - fullHtmlPath = '${fullHtmlPath}${searchStr}group=' |
| - '${subtestNames[subtestIndex]}'; |
| - } |
| + var htmlPath_subtest = _createUrlPathFromFile(new Path(htmlPath)); |
| + var fullHtmlPath = _getUriForBrowserTest(info, htmlPath_subtest, |
| + subtestNames, subtestIndex); |
| + List<String> args = <String>[]; |
| if (TestUtils.usesWebDriver(runtime)) { |
| args = [ |
| dartDir.append('tools/testing/run_selenium.py').toNativePath(), |
| @@ -1125,8 +1156,7 @@ class StandardTestSuite extends TestSuite { |
| var minified = configuration['minified'] ? '-minified' : ''; |
| var dirName = "${configuration['compiler']}-${configuration['runtime']}" |
| "$checked$minified"; |
| - Path generatedTestPath = new Path(dartDir.toNativePath()) |
| - .append(buildDir) |
| + Path generatedTestPath = new Path(buildDir) |
| .append('generated_tests') |
| .append(dirName) |
| .append(testUniqueName); |
| @@ -1816,6 +1846,10 @@ class TestUtils { |
| const ['d8', 'jsshell'].contains(runtime); |
| static String buildDir(Map configuration) { |
| + // FIXME(kustermann,ricow): Our code assumes that the returned 'buildDir' |
| + // is relative to the current working directory. |
| + // Thus, if we pass in an absolute path (e.g. '--build-directory=/tmp/out') |
| + // we get into trouble. |
| if (configuration['build_directory'] != '') { |
|
kustermann
2013/02/08 01:55:13
This is the place of the FIXME.
|
| return configuration['build_directory']; |
| } |