Revision: 16671
Author:
efor...@google.com
Date: Fri Jan 4 18:43:31 2013
Log: Add cross-origin test with credentials. I modified the test
framework slightly
as well to Enable Cross-origin requests while testing from local files.
BUG=
Review URL:
https://codereview.chromium.org//11641005
http://code.google.com/p/dart/source/detail?r=16671
Modified:
/branches/bleeding_edge/dart/pkg/intl/test/bidi_format_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/bidi_utils_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_file_test_stub.dart
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_http_request_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_local_test_stub.dart
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_test_core.dart
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_uninitialized_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_browser_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_standalone_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/intl_message_basic_example_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/intl_test.dart
/branches/bleeding_edge/dart/pkg/intl/test/number_format_test.dart
/branches/bleeding_edge/dart/sdk/lib/html/dart2js/html_dart2js.dart
/branches/bleeding_edge/dart/sdk/lib/html/dartium/html_dartium.dart
/branches/bleeding_edge/dart/tests/html/exceptions_test.dart
/branches/bleeding_edge/dart/tests/html/form_data_test.dart
/branches/bleeding_edge/dart/tests/html/html.status
/branches/bleeding_edge/dart/tests/html/xhr_cross_origin_test.dart
/branches/bleeding_edge/dart/tests/html/xhr_test.dart
/branches/bleeding_edge/dart/tools/dom/src/_HttpRequestUtils.dart
/branches/bleeding_edge/dart/tools/test.dart
/branches/bleeding_edge/dart/tools/testing/dart/browser_test.dart
/branches/bleeding_edge/dart/tools/testing/dart/http_server.dart
/branches/bleeding_edge/dart/tools/testing/dart/test_suite.dart
/branches/bleeding_edge/dart/tools/testing/run_selenium.py
=======================================
--- /branches/bleeding_edge/dart/pkg/intl/test/bidi_format_test.dart Thu
Nov 1 16:09:47 2012
+++ /branches/bleeding_edge/dart/pkg/intl/test/bidi_format_test.dart Fri
Jan 4 18:43:31 2013
@@ -5,8 +5,8 @@
library bidi_format_test;
-import '../lib/intl.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:intl/intl.dart';
+import 'package:unittest/unittest.dart';
/**
* Tests the bidirectional text formatting library.
=======================================
--- /branches/bleeding_edge/dart/pkg/intl/test/bidi_utils_test.dart Thu
Nov 1 16:09:47 2012
+++ /branches/bleeding_edge/dart/pkg/intl/test/bidi_utils_test.dart Fri
Jan 4 18:43:31 2013
@@ -5,8 +5,8 @@
library bidi_utils_test;
-import '../lib/intl.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:intl/intl.dart';
+import 'package:unittest/unittest.dart';
/**
* Tests the bidi utilities library.
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_file_test_stub.dart
Tue Dec 11 11:51:54 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_file_test_stub.dart
Fri Jan 4 18:43:31 2013
@@ -8,12 +8,12 @@
*/
library date_time_format_file_test;
-import '../lib/intl.dart';
-import '../lib/date_symbol_data_file.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/date_symbol_data_file.dart';
import 'dart:io';
import 'date_time_format_test_core.dart';
import 'data_directory.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:unittest/unittest.dart';
runWith([Function getSubset]) {
// Initialize one locale just so we know what the list is.
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_http_request_test.dart
Thu Nov 1 16:36:51 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_http_request_test.dart
Fri Jan 4 18:43:31 2013
@@ -9,15 +9,18 @@
library date_time_format_http_request_test;
-import '../lib/intl.dart';
-import '../lib/date_symbol_data_http_request.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/date_symbol_data_http_request.dart';
import 'date_time_format_test_core.dart';
import 'dart:html';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
-var url = "
http://localhost:9876/pkg/intl/lib/src/data/dates/";
+var url = '';
main() {
+ useHtmlConfiguration();
+ url
= "http://localhost:${window.location.port}/pkg/intl/lib/src/data/dates/";
// Initialize one locale just so we know what the list is.
test('Run everything', () {
initializeDateFormatting("en_US",
url).then(expectAsync1(runEverything));});
@@ -29,11 +32,5 @@
(locale) => initializeDateFormatting(locale, url));
Futures.wait(futures).then(expectAsync1((_) {
runDateTests(smallSetOfLocales());
- shutDown();}));
-}
-
-void shutDown() {
- // The tiny web server knows to use this request as a cue to terminate.
- var source = '${url}terminate';
- var request = new HttpRequest.get(source, (_) {});
+ }));
}
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_local_test_stub.dart
Thu Nov 1 16:09:47 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_local_test_stub.dart
Fri Jan 4 18:43:31 2013
@@ -9,9 +9,9 @@
library date_time_format_test;
-import '../lib/intl.dart';
-import '../lib/date_time_patterns.dart';
-import '../lib/date_symbol_data_local.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/date_time_patterns.dart';
+import 'package:intl/date_symbol_data_local.dart';
import 'date_time_format_test_core.dart';
runWith([Function getSubset]) {
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_test_core.dart
Wed Jan 2 10:17:48 2013
+++
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_test_core.dart
Fri Jan 4 18:43:31 2013
@@ -10,10 +10,10 @@
library date_time_format_tests;
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:unittest/unittest.dart';
import 'date_time_format_test_data.dart';
-import '../lib/intl.dart';
-import '../lib/src/date_format_internal.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/src/date_format_internal.dart';
var formatsToTest = const [
DateFormat.DAY,
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_uninitialized_test.dart
Wed Jan 2 12:53:22 2013
+++
/branches/bleeding_edge/dart/pkg/intl/test/date_time_format_uninitialized_test.dart
Fri Jan 4 18:43:31 2013
@@ -8,10 +8,10 @@
*/
library date_time_format_file_test;
-import '../lib/intl.dart';
-import '../lib/date_symbol_data_local.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/date_symbol_data_local.dart';
import 'date_time_format_test_core.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:unittest/unittest.dart';
main() {
runDateTests(['en_US']);
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_browser_test.dart
Thu Nov 1 16:09:47 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_browser_test.dart
Fri Jan 4 18:43:31 2013
@@ -4,9 +4,9 @@
library find_default_locale_browser_test;
-import '../lib/intl.dart';
-import '../lib/intl_browser.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/intl_browser.dart';
+import 'package:unittest/unittest.dart';
main() {
test("Find system locale in browser", () {
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_standalone_test.dart
Thu Nov 1 16:09:47 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/find_default_locale_standalone_test.dart
Fri Jan 4 18:43:31 2013
@@ -4,9 +4,9 @@
library find_default_locale_browser_test;
-import '../lib/intl.dart';
-import '../lib/intl_standalone.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/intl_standalone.dart';
+import 'package:unittest/unittest.dart';
main() {
test("Find system locale standalone", () {
=======================================
---
/branches/bleeding_edge/dart/pkg/intl/test/intl_message_basic_example_test.dart
Thu Nov 1 16:09:47 2012
+++
/branches/bleeding_edge/dart/pkg/intl/test/intl_message_basic_example_test.dart
Fri Jan 4 18:43:31 2013
@@ -7,11 +7,11 @@
*/
library intl_message_test_2;
-import '../lib/date_symbol_data_local.dart';
-import '../lib/intl.dart';
-import '../lib/message_lookup_local.dart';
+import 'package:intl/date_symbol_data_local.dart';
+import 'package:intl/intl.dart';
+import 'package:intl//message_lookup_local.dart';
import '../example/basic/basic_example.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'package:unittest/unittest.dart';
List list;
=======================================
--- /branches/bleeding_edge/dart/pkg/intl/test/intl_test.dart Thu Nov 1
16:09:47 2012
+++ /branches/bleeding_edge/dart/pkg/intl/test/intl_test.dart Fri Jan 4
18:43:31 2013
@@ -4,10 +4,9 @@
library intl_test;
-import '../lib/intl.dart';
-// TODO(rnystrom): Use "package:" import when test.dart supports it
(#4968).
-import '../../../pkg/unittest/lib/unittest.dart';
-import '../lib/date_symbol_data_local.dart';
+import 'package:intl/intl.dart';
+import 'package:unittest/unittest.dart';
+import 'package:intl/date_symbol_data_local.dart';
main() {
test("Locale setting doesn't verify the core locale", () {
=======================================
--- /branches/bleeding_edge/dart/pkg/intl/test/number_format_test.dart Thu
Nov 1 16:09:47 2012
+++ /branches/bleeding_edge/dart/pkg/intl/test/number_format_test.dart Fri
Jan 4 18:43:31 2013
@@ -6,9 +6,9 @@
library number_format_test;
-import '../../../pkg/unittest/lib/unittest.dart';
-import '../lib/number_format.dart';
-import '../lib/intl.dart';
+import 'package:unittest/unittest.dart';
+import 'package:intl/number_format.dart';
+import 'package:intl/intl.dart';
/**
* Tests the Numeric formatting library in dart.
=======================================
--- /branches/bleeding_edge/dart/sdk/lib/html/dart2js/html_dart2js.dart Thu
Jan 3 14:52:59 2013
+++ /branches/bleeding_edge/dart/sdk/lib/html/dart2js/html_dart2js.dart Fri
Jan 4 18:43:31 2013
@@ -24024,18 +24024,25 @@
// Helper for factory HttpRequest.get
static HttpRequest get(String url,
- onSuccess(HttpRequest request),
+ onComplete(HttpRequest request),
bool withCredentials) {
final request = new HttpRequest();
request.open('GET', url, true);
request.withCredentials = withCredentials;
- // Status 0 is for local XHR request.
request.on.readyStateChange.add((e) {
- if (request.readyState == HttpRequest.DONE &&
- (request.status == 200 || request.status == 0)) {
- onSuccess(request);
+ if (request.readyState == HttpRequest.DONE) {
+ // TODO(efortuna): Previously HttpRequest.get only invoked the
callback
+ // when request.status was 0 or 200. This
+ // causes two problems 1) request.status = 0 for ANY local XHR
request
+ // (file found or not found) 2) the user facing function claims
that the
+ // callback is called on completion of the request, regardless of
+ // status. Because the new event model is coming in soon, rather
than
+ // fixing the callbacks version, we just need to revisit the
desired
+ // behavior when we're using streams/futures.
+ // Status 0 is for local XHR request.
+ onComplete(request);
}
});
=======================================
--- /branches/bleeding_edge/dart/sdk/lib/html/dartium/html_dartium.dart Thu
Jan 3 14:52:59 2013
+++ /branches/bleeding_edge/dart/sdk/lib/html/dartium/html_dartium.dart Fri
Jan 4 18:43:31 2013
@@ -28644,18 +28644,25 @@
// Helper for factory HttpRequest.get
static HttpRequest get(String url,
- onSuccess(HttpRequest request),
+ onComplete(HttpRequest request),
bool withCredentials) {
final request = new HttpRequest();
request.open('GET', url, true);
request.withCredentials = withCredentials;
- // Status 0 is for local XHR request.
request.on.readyStateChange.add((e) {
- if (request.readyState == HttpRequest.DONE &&
- (request.status == 200 || request.status == 0)) {
- onSuccess(request);
+ if (request.readyState == HttpRequest.DONE) {
+ // TODO(efortuna): Previously HttpRequest.get only invoked the
callback
+ // when request.status was 0 or 200. This
+ // causes two problems 1) request.status = 0 for ANY local XHR
request
+ // (file found or not found) 2) the user facing function claims
that the
+ // callback is called on completion of the request, regardless of
+ // status. Because the new event model is coming in soon, rather
than
+ // fixing the callbacks version, we just need to revisit the
desired
+ // behavior when we're using streams/futures.
+ // Status 0 is for local XHR request.
+ onComplete(request);
}
});
=======================================
--- /branches/bleeding_edge/dart/tests/html/exceptions_test.dart Wed Dec 5
09:48:38 2012
+++ /branches/bleeding_edge/dart/tests/html/exceptions_test.dart Fri Jan 4
18:43:31 2013
@@ -10,8 +10,8 @@
window.webkitNotifications.createNotification('', '', '');
} on DomException catch (e) {
expect(e.code, DomException.SECURITY_ERR);
- expect(
e.name, 'SECURITY_ERR');
- expect(e.message, 'SECURITY_ERR: DOM Exception 18');
+ expect(
e.name, 'SecurityError');
+ expect(e.message, 'SecurityError: DOM Exception 18');
}
});
test('EventException', () {
=======================================
--- /branches/bleeding_edge/dart/tests/html/form_data_test.dart Thu Dec 27
14:28:00 2012
+++ /branches/bleeding_edge/dart/tests/html/form_data_test.dart Fri Jan 4
18:43:31 2013
@@ -59,7 +59,7 @@
form.append('theBlob', blob, 'theBlob.txt');
var xhr = new HttpRequest();
- xhr.open("POST", "
http://localhost:9876/echo");
+ xhr.open("POST", "http://localhost:${window.location.port}/echo");
xhr.on.load.add(expectAsync1((e) {
expect(xhr.responseText.contains(blobString), true);
=======================================
--- /branches/bleeding_edge/dart/tests/html/html.status Fri Jan 4 01:22:37
2013
+++ /branches/bleeding_edge/dart/tests/html/html.status Fri Jan 4 18:43:31
2013
@@ -269,7 +269,6 @@
websocket_test: Pass, Fail # FF 10 is uses MozWebSocket, FF 11 uses
WebSocket.
# Exception... "Access to restricted URI denied" code: "1012"
nsresult: "0x805303f4"
# (NS_ERROR_DOM_BAD_URI) ...
-xhr_test: Fail
[ $runtime == ie9 && ($system == linux || $system == macos) ]
*: Skip
@@ -292,7 +291,6 @@
isolates_test: Skip # Timeout because leg does not support web workers.
[ $compiler == dart2js && $runtime == ff ]
-xhr_test: Skip # Timeout
inner_frame_test: Skip # Timeout
svg_3_test: Skip # Timeout
documentfragment_test: Skip # Timeout
=======================================
--- /branches/bleeding_edge/dart/tests/html/xhr_cross_origin_test.dart Thu
Nov 1 16:09:47 2012
+++ /branches/bleeding_edge/dart/tests/html/xhr_cross_origin_test.dart Fri
Jan 4 18:43:31 2013
@@ -7,12 +7,30 @@
import '../../pkg/unittest/lib/html_config.dart';
import 'dart:html';
import 'dart:json';
+
+/**
+ * Examine the value of "crossOriginPort" as passed in from the url from
+ * [window.location] to determine what the cross-origin port is for
+ * this test.
+ */
+ // TODO(efortuna): If we need to use this function frequently, make a
+ // url_analyzer library that is part of test.dart that these tests can
import.
+int get crossOriginPort {
+ var searchUrl = window.location.search;
+ var crossOriginStr = 'crossOriginPort=';
+ var index = searchUrl.indexOf(crossOriginStr);
+ var nextArg = searchUrl.indexOf('&', index);
+ return int.parse(searchUrl.substring(index + crossOriginStr.length,
+ nextArg == -1 ? searchUrl.length : nextArg));
+}
main() {
useHtmlConfiguration();
+ var port = crossOriginPort;
+
test('XHR Cross-domain', () {
- var url = "
http://localhost:9876/tests/html/xhr_cross_origin_data.txt";
+ var url
= "http://localhost:$port/tests/html/xhr_cross_origin_data.txt";
var xhr = new HttpRequest();
xhr.open('GET', url, true);
var validate = expectAsync1((data) {
@@ -31,7 +49,7 @@
});
test('XHR.get Cross-domain', () {
- var url = "
http://localhost:9876/tests/html/xhr_cross_origin_data.txt";
+ var url
= "http://localhost:$port/tests/html/xhr_cross_origin_data.txt";
new HttpRequest.get(url, expectAsync1((xhr) {
var data = JSON.parse(xhr.response);
expect(data, contains('feed'));
@@ -39,4 +57,14 @@
expect(data, isMap);
}));
});
+
+ test('XHR.getWithCredentials Cross-domain', () {
+ var url
= "http://localhost:$port/tests/html/xhr_cross_origin_data.txt";
+ new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
+ var data = JSON.parse(xhr.response);
+ expect(data, contains('feed'));
+ expect(data['feed'], contains('entry'));
+ expect(data, isMap);
+ }));
+ });
}
=======================================
--- /branches/bleeding_edge/dart/tests/html/xhr_test.dart Thu Nov 1
16:09:47 2012
+++ /branches/bleeding_edge/dart/tests/html/xhr_test.dart Fri Jan 4
18:43:31 2013
@@ -10,24 +10,68 @@
main() {
useHtmlConfiguration();
+ var url = "../../../../tests/html/xhr_cross_origin_data.txt";
test('XHR No file', () {
HttpRequest xhr = new HttpRequest();
xhr.open("GET", "NonExistingFile", true);
- xhr.on.readyStateChange.add(expectAsync1((event) {
+ xhr.on.readyStateChange.add(expectAsyncUntil1((event) {
if (xhr.readyState == HttpRequest.DONE) {
- expect(xhr.status, equals(0));
+ expect(xhr.status, equals(404));
expect(xhr.responseText, equals(''));
}
- }));
+ }, () => xhr.readyState == HttpRequest.DONE));
xhr.send();
});
+ test('XHR file', () {
+ var xhr = new HttpRequest();
+ xhr.open('GET', url, true);
+ xhr.on.readyStateChange.add(expectAsyncUntil1((e) {
+ if (xhr.readyState == HttpRequest.DONE) {
+ expect(xhr.status, equals(200));
+ var data = JSON.parse(xhr.response);
+ expect(data, contains('feed'));
+ expect(data['feed'], contains('entry'));
+ expect(data, isMap);
+ }
+ }, () => xhr.readyState == HttpRequest.DONE));
+ xhr.send();
+ });
+
test('XHR.get No file', () {
new HttpRequest.get("NonExistingFile", expectAsync1((xhr) {
expect(xhr.readyState, equals(HttpRequest.DONE));
- expect(xhr.status, equals(0));
+ expect(xhr.status, equals(404));
expect(xhr.responseText, equals(''));
}));
});
+
+ test('XHR.get file', () {
+ var xhr = new HttpRequest.get(url, expectAsync1((xhr) {
+ expect(xhr.readyState, equals(HttpRequest.DONE));
+ expect(xhr.status, equals(200));
+ var data = JSON.parse(xhr.response);
+ expect(data, contains('feed'));
+ expect(data['feed'], contains('entry'));
+ expect(data, isMap);
+ }));
+ });
+
+ test('XHR.getWithCredentials No file', () {
+ new HttpRequest.getWithCredentials("NonExistingFile",
expectAsync1((xhr) {
+ expect(xhr.status, equals(404));
+ expect(xhr.responseText, equals(''));
+ }));
+ });
+
+ test('XHR.getWithCredentials file', () {
+ new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
+ expect(xhr.status, equals(200));
+ var data = JSON.parse(xhr.response);
+ expect(data, contains('feed'));
+ expect(data['feed'], contains('entry'));
+ expect(data, isMap);
+ }));
+ });
}
=======================================
--- /branches/bleeding_edge/dart/tools/dom/src/_HttpRequestUtils.dart Fri
Dec 28 14:26:48 2012
+++ /branches/bleeding_edge/dart/tools/dom/src/_HttpRequestUtils.dart Fri
Jan 4 18:43:31 2013
@@ -8,18 +8,25 @@
// Helper for factory HttpRequest.get
static HttpRequest get(String url,
- onSuccess(HttpRequest request),
+ onComplete(HttpRequest request),
bool withCredentials) {
final request = new HttpRequest();
request.open('GET', url, true);
request.withCredentials = withCredentials;
- // Status 0 is for local XHR request.
request.on.readyStateChange.add((e) {
- if (request.readyState == HttpRequest.DONE &&
- (request.status == 200 || request.status == 0)) {
- onSuccess(request);
+ if (request.readyState == HttpRequest.DONE) {
+ // TODO(efortuna): Previously HttpRequest.get only invoked the
callback
+ // when request.status was 0 or 200. This
+ // causes two problems 1) request.status = 0 for ANY local XHR
request
+ // (file found or not found) 2) the user facing function claims
that the
+ // callback is called on completion of the request, regardless of
+ // status. Because the new event model is coming in soon, rather
than
+ // fixing the callbacks version, we just need to revisit the
desired
+ // behavior when we're using streams/futures.
+ // Status 0 is for local XHR request.
+ onComplete(request);
}
});
=======================================
--- /branches/bleeding_edge/dart/tools/test.dart Fri Dec 14 06:19:01 2012
+++ /branches/bleeding_edge/dart/tools/test.dart Fri Jan 4 18:43:31 2013
@@ -81,7 +81,7 @@
var verbose = firstConf['verbose'];
var printTiming = firstConf['time'];
var listTests = firstConf['list'];
-
+
if (!firstConf['append_flaky_log']) {
var file = new File(TestUtils.flakyFileName());
if (file.existsSync()) {
@@ -103,6 +103,22 @@
}
print(Strings.join(output_words, ' '));
}
+
+ // Start global http servers that serve the entire dart repo.
+ // The http server is available on window.location.port, and a second
server
+ // for cross-domain tests can be found by calling
getCrossOriginPortNumber().
+ List serverList = [];
+ if (!listTests) {
+ // Only start the server if we are running browser tests.
+ var runningBrowserTests = configurations.some((config) {
+ return TestUtils.isBrowserRuntime(config['runtime']);
+ });
+ if (runningBrowserTests) {
+ serverList.add(startHttpServer('127.0.0.1'));
+ // We start two servers so that we can test cross-domain tests.
+ serverList.add(startHttpServer('127.0.0.1', serverList[0].port));
+ }
+ }
var configurationIterator = configurations.iterator();
void enqueueConfiguration(ProcessQueue queue) {
@@ -126,21 +142,10 @@
final name = testSuiteDir.filename;
if (selectors.containsKey(name)) {
queue.addTestSuite(
- new StandardTestSuite.forDirectory(conf, testSuiteDir));
+ new StandardTestSuite.forDirectory(conf, testSuiteDir,
serverList));
}
}
}
-
- // Start global http server that serves the entire dart repo.
- // The http server is available on localhost:9876 for any
- // test that needs to load resources from the repo over http.
- if (!listTests) {
- // Only start the server if we are running browser tests.
- var runningBrowserTests = configurations.some((config) {
- return TestUtils.isBrowserRuntime(config['runtime']);
- });
- if (runningBrowserTests) startHttpServer('127.0.0.1', 9876);
- }
// Start process queue.
new ProcessQueue(maxProcesses,
@@ -148,7 +153,7 @@
startTime,
printTiming,
enqueueConfiguration,
- () => terminateHttpServer(),
+ () => terminateHttpServers(serverList),
verbose,
listTests);
}
=======================================
--- /branches/bleeding_edge/dart/tools/testing/dart/browser_test.dart Thu
Dec 20 17:06:48 2012
+++ /branches/bleeding_edge/dart/tools/testing/dart/browser_test.dart Fri
Jan 4 18:43:31 2013
@@ -54,25 +54,27 @@
part '$test';
""";
-String dartTestWrapper(Path dartHome, Path library) {
+String dartTestWrapper(Path dartHome, String testPath, Path library) {
+ var testPathDir = pathLib.dirname(testPath);
+ var dartHomePath = dartHome.toString();
+ var unitTest = pathLib.relative(pathLib.join(dartHomePath,
+ 'pkg/unittest/lib'), from: testPathDir);
+
+ var libString = library.toString();
+ if (!pathLib.isAbsolute(libString)) {
+ libString = pathLib.join(dartHome.toString(), libString);
+ }
// Tests inside "pkg" import unittest using "package:". All others use a
// relative path. The imports need to agree, so use a matching form here.
- var unitTest = dartHome.append("pkg/unittest/lib").toString();
-
- // TODO(rnystrom): Looking in the entire path here is wrong. It should
only
- // consider the relative path within dartHome. Unfortunately,
- // Path.relativeTo() does not handle cases where library is already a
relative
- // path, and Path.isAbsolute does not work on Windows.
- if (library.segments().contains("pkg")) {
+ if (pathLib.relative(libString, from:
dartHome.toString()).contains("pkg")) {
unitTest = 'package:unittest';
}
-
return """
library test;
import '$unitTest/unittest.dart' as unittest;
import '$unitTest/html_config.dart' as config;
-import '${library}' as Test;
+import '${pathLib.relative(libString, from: testPathDir)}' as Test;
main() {
config.useHtmlConfiguration();
=======================================
--- /branches/bleeding_edge/dart/tools/testing/dart/http_server.dart Thu
Dec 27 14:28:00 2012
+++ /branches/bleeding_edge/dart/tools/testing/dart/http_server.dart Fri
Jan 4 18:43:31 2013
@@ -8,19 +8,17 @@
import 'dart:isolate';
import 'test_suite.dart'; // For TestUtils.
-HttpServer _httpServer;
-
-void startHttpServer(String host, int port) {
+HttpServer startHttpServer(String host, [int allowedPort = -1]) {
var basePath = TestUtils.dartDir();
- _httpServer = new HttpServer();
- _httpServer.onError = (e) {
+ var httpServer = new HttpServer();
+ httpServer.onError = (e) {
// Consider errors in the builtin http server fatal.
// Intead of just throwing the exception we print
// a message that makes it clearer what happened.
print('Test http server error: $e');
exit(1);
};
- _httpServer.defaultRequestHandler = (request, resp) {
+ httpServer.defaultRequestHandler = (request, resp) {
var requestPath = new Path(request.path).canonicalize();
if (!requestPath.isAbsolute) {
resp.statusCode = HttpStatus.NOT_FOUND;
@@ -31,8 +29,23 @@
var file = new File(path.toNativePath());
file.exists().then((exists) {
if (exists) {
- // Allow loading from localhost in browsers.
- resp.headers.set("Access-Control-Allow-Origin", "*");
+ if (allowedPort != -1) {
+ // Allow loading from localhost:$allowedPort in browsers.
+ resp.headers.set("Access-Control-Allow-Origin",
+ "http://127.0.0.1:$allowedPort");
+ resp.headers.set('Access-Control-Allow-Credentials', 'true');
+ } else {
+ // No allowedPort specified. Allow from anywhere (but
cross-origin
+ // requests *with credentials* will fail because you can't
use "*").
+ resp.headers.set("Access-Control-Allow-Origin", "*");
+ }
+ if (path.toNativePath().endsWith('.html')) {
+ resp.headers.set('Content-Type', 'text/html');
+ } else if (path.toNativePath().endsWith('.js')) {
+ resp.headers.set('Content-Type', 'application/javascript');
+ } else if (path.toNativePath().endsWith('.dart')) {
+ resp.headers.set('Content-Type', 'application/dart');
+ }
file.openInputStream().pipe(resp.outputStream);
} else {
resp.statusCode = HttpStatus.NOT_FOUND;
@@ -43,15 +56,16 @@
};
// Echos back the contents of the request as the response data.
- _httpServer.addRequestHandler((req) => req.path == "/echo", (request,
resp) {
+ httpServer.addRequestHandler((req) => req.path == "/echo", (request,
resp) {
resp.headers.set("Access-Control-Allow-Origin", "*");
request.inputStream.pipe(resp.outputStream);
});
- _httpServer.listen(host, port);
+ httpServer.listen(host, 0);
+ return httpServer;
}
-terminateHttpServer() {
- if (_httpServer != null) _httpServer.close();
+terminateHttpServers(List<HttpServer> servers) {
+ for (var server in servers) server.close();
}
=======================================
--- /branches/bleeding_edge/dart/tools/testing/dart/test_suite.dart Fri
Jan 4 14:48:04 2013
+++ /branches/bleeding_edge/dart/tools/testing/dart/test_suite.dart Fri
Jan 4 18:43:31 2013
@@ -21,6 +21,7 @@
import "multitest.dart";
import "drt_updater.dart";
import "dart:uri";
+import '../../../pkg/path/lib/path.dart' as pathLib;
part "browser_test.dart";
@@ -401,11 +402,17 @@
final Path dartDir;
Predicate<String> isTestFilePredicate;
final bool listRecursively;
+ /**
+ * The set of servers that have been started to run these tests (Could be
+ * none).
+ */
+ List serverList;
StandardTestSuite(Map configuration,
String suiteName,
Path suiteDirectory,
this.statusFilePaths,
+ this.serverList,
{this.isTestFilePredicate,
bool recursive: false})
: super(configuration, suiteName),
@@ -439,14 +446,18 @@
* instead of having to create a custom [StandardTestSuite] subclass. In
* particular, if you add 'path/to/mytestsuite' to
[TEST_SUITE_DIRECTORIES]
* in test.dart, this will all be set up for you.
+ *
+ * The [StandardTestSuite] also optionally takes a list of servers that
have
+ * been started up by the test harness, to be used by browser tests.
*/
factory StandardTestSuite.forDirectory(
- Map configuration, Path directory) {
+ Map configuration, Path directory, [List serverList = const []]) {
final name = directory.filename;
return new StandardTestSuite(configuration,
name, directory,
['$directory/$name.status', '$directory/${name}_dart2js.status'],
+ serverList,
isTestFilePredicate: (filename) => filename.endsWith('_test.dart'),
recursive: true);
}
@@ -853,7 +864,7 @@
File file = new File(dartWrapperFilename);
RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE);
dartWrapper.writeStringSync(
- dartTestWrapper(dartDir, dartLibraryFilename));
+ dartTestWrapper(dartDir,
file.name, dartLibraryFilename));
dartWrapper.closeSync();
} else {
dartWrapperFilename = filename;
@@ -875,12 +886,6 @@
dartWrapperFilename : compiledDartWrapperFilename;
// Create the HTML file for the test.
RandomAccessFile htmlTest = new
File(htmlPath).openSync(FileMode.WRITE);
- String filePrefix = '';
- if (Platform.operatingSystem == 'windows') {
- // Firefox on Windows does not like absolute file path names that
start
- // with 'C:' adding 'file:///' solves the problem.
- filePrefix = 'file:///';
- }
String content = null;
Path dir = filePath.directoryPath;
String nameNoExt = filePath.filenameWithoutExtension;
@@ -889,10 +894,12 @@
Path expectedOutput = null;
if (new File.fromPath(pngPath).existsSync()) {
expectedOutput = pngPath;
- content =
getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath');
+ content = getHtmlLayoutContents(scriptType,
pathLib.relative(scriptPath,
+ from: pathLib.dirname(htmlPath)));
} else if (new File.fromPath(txtPath).existsSync()) {
expectedOutput = txtPath;
- content =
getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath');
+ content = getHtmlLayoutContents(scriptType,
pathLib.relative(scriptPath,
+ from: pathLib.dirname(htmlPath)));
} else {
final htmlLocation = new Path.fromNative(htmlPath);
content = getHtmlContents(
@@ -942,10 +949,15 @@
}
List<String> args = <String>[];
- String fullHtmlPath = htmlPath.startsWith('http:') ? htmlPath :
- (htmlPath.startsWith('/') ?
- 'file://$htmlPath' :
- 'file:///$htmlPath');
+ var basePath = TestUtils.dartDir().toString();
+ htmlPath = htmlPath.startsWith(basePath) ?
+ htmlPath.substring(basePath.length) : htmlPath;
+ String fullHtmlPath = htmlPath;
+ if (!htmlPath.startsWith('http')) {
+ if (!htmlPath.startsWith('/')) htmlPath = '/$htmlPath';
+ fullHtmlPath = 'http://127.0.0.1:${serverList[0].port}$htmlPath?'
+ 'crossOriginPort=${serverList[1].port}';
+ }
if (info.optionsFromFile['isMultiHtmlTest']
&& subtestNames.length > 0) {
fullHtmlPath = '${fullHtmlPath}#${subtestNames[subtestIndex]}';
@@ -987,8 +999,10 @@
var absolutePath =
TestUtils.absolutePath(new Path(packageRootPath));
packageRootUri = new Uri.fromComponents(
- scheme: 'file',
- path: absolutePath.toString());
+ scheme: 'http',
+ path: '127.0.0.1:${serverList[0].port}/'
+ '${pathLib.relative(absolutePath.toString(), from:
+ TestUtils.dartDir().toString())}');
}
}
@@ -1097,7 +1111,8 @@
var minified = configuration['minified'] ? '-minified' : '';
var dirName
= "${configuration['compiler']}-${configuration['runtime']}"
"$checked$minified";
- Path generatedTestPath = new Path.fromNative(buildDir)
+ Path generatedTestPath = new Path.fromNative(dartDir.toString())
+ .append(buildDir.toString())
.append('generated_tests')
.append(dirName)
.append(testUniqueName);
=======================================
--- /branches/bleeding_edge/dart/tools/testing/run_selenium.py Thu Nov 8
10:54:14 2012
+++ /branches/bleeding_edge/dart/tools/testing/run_selenium.py Fri Jan 4
18:43:31 2013
@@ -150,28 +150,27 @@
sys.exit(1)
def start_browser(browser, executable_path, html_out):
- if browser == 'chrome':
+ if browser == 'chrome' or browser == 'dartium':
# Note: you need ChromeDriver *in your path* to run Chrome, in
addition to
# installing Chrome. Also note that the build bot runs have a
different path
# from a normal user -- check the build logs.
- return
selenium.webdriver.Chrome()
- elif browser == 'dartium':
- script_dir = os.path.dirname(os.path.abspath(__file__))
- dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests',
- 'dartium')
options = selenium.webdriver.chrome.options.Options()
- # enable ShadowDOM and style scoped for Dartium
- options.add_argument('--enable-shadow-dom')
- options.add_argument('--enable-style-scoped')
- if executable_path is not None:
- options.binary_location = executable_path
- elif platform.system() == 'Windows':
- options.binary_location = os.path.join(dartium_dir, 'chrome.exe')
- elif platform.system() == 'Darwin':
- options.binary_location = os.path.join(dartium_dir, 'Chromium.app',
- 'Contents', 'MacOS', 'Chromium')
- else:
- options.binary_location = os.path.join(dartium_dir, 'chrome')
+ if browser == 'dartium':
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests',
+ 'dartium')
+ # enable ShadowDOM and style scoped for Dartium
+ options.add_argument('--enable-shadow-dom')
+ options.add_argument('--enable-style-scoped')
+ if executable_path is not None:
+ options.binary_location = executable_path
+ elif platform.system() == 'Windows':
+ options.binary_location = os.path.join(dartium_dir, 'chrome.exe')
+ elif platform.system() == 'Darwin':
+ options.binary_location = os.path.join(dartium_dir, 'Chromium.app',
+ 'Contents', 'MacOS', 'Chromium')
+ else:
+ options.binary_location = os.path.join(dartium_dir, 'chrome')
return
selenium.webdriver.Chrome(chrome_options=options)
elif browser == 'ff':
script_dir = os.path.dirname(os.path.abspath(__file__))