Revert the revert.

BUG=

Review URL: https://codereview.chromium.org//12707003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20416 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 920c422..53b3e08 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -13202,7 +13202,19 @@
    */
   static bool get supportsProgressEvent {
     var xhr = new HttpRequest();
-    return JS('bool', '"onprogress" in #', xhr);
+    return JS('bool', '("onprogress" in #)', xhr);
+  }
+
+  /**
+   * Checks to see if the current platform supports making cross origin
+   * requests.
+   *
+   * Note that even if cross origin requests are supported, they still may fail
+   * if the destination server does not support CORS requests.
+   */
+  static bool get supportsCrossOrigin {
+    var xhr = new HttpRequest();
+    return JS('bool', '("withCredentials" in #)', xhr);
   }
 
   /**
@@ -13210,7 +13222,7 @@
    */
   static bool get supportsLoadEndEvent {
     var xhr = new HttpRequest();
-    return JS('bool', '"onloadend" in #', xhr);
+    return JS('bool', '("onloadend" in #)', xhr);
   }
 
 
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index fa38609..e1424ad 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -14012,6 +14012,17 @@
   }
 
   /**
+   * Checks to see if the current platform supports making cross origin
+   * requests.
+   *
+   * Note that even if cross origin requests are supported, they still may fail
+   * if the destination server does not support CORS requests.
+   */
+  static bool get supportsCrossOrigin {
+    return true;
+  }
+
+  /**
    * Checks to see if the LoadEnd event is supported on the current platform.
    */
   static bool get supportsLoadEndEvent {
diff --git a/tests/html/html.status b/tests/html/html.status
index c2e84bf..b7ecd42 100644
--- a/tests/html/html.status
+++ b/tests/html/html.status
@@ -106,7 +106,6 @@
 serialized_script_value_test: Fail
 url_test: Fail              # IE9 does not support createObjectURL (it is supported in IE10)
 window_open_test: Skip      # BUG(4016)
-xhr_cross_origin_test: Fail # Issue 6016.
 canvasrenderingcontext2d_test/drawImage_video_element: Fail # IE does not support drawImage w/ video element
 canvasrenderingcontext2d_test/drawImage_video_element_dataUrl: Fail # IE does not support drawImage w/ video element
 
@@ -189,6 +188,7 @@
 webgl_1_test/supported: Fail
 websocket_test/supported: Fail
 websql_test/supported: Fail
+xhr_cross_origin_test/supported: Fail
 xhr_test/supported_HttpRequestProgressEvent: Fail
 xhr_test/supported_onLoadEnd: Fail
 xhr_test/supported_onProgress: Fail
diff --git a/tests/html/xhr_cross_origin_test.dart b/tests/html/xhr_cross_origin_test.dart
index 7750046..cb56240 100644
--- a/tests/html/xhr_cross_origin_test.dart
+++ b/tests/html/xhr_cross_origin_test.dart
@@ -4,7 +4,7 @@
 
 library XHRCrossOriginTest;
 import '../../pkg/unittest/lib/unittest.dart';
-import '../../pkg/unittest/lib/html_config.dart';
+import '../../pkg/unittest/lib/html_individual_config.dart';
 import 'dart:html';
 import 'dart:json' as json;
 
@@ -25,47 +25,69 @@
 }
 
 main() {
-  useHtmlConfiguration();
+  useHtmlIndividualConfiguration();
 
-  var port = crossOriginPort;
-  var host = '${window.location.protocol}//${window.location.hostname}:$port';
-
-  test('XHR Cross-domain', () {
-    var url =  '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
-    var xhr = new HttpRequest();
-    xhr.open('GET', url, async: true);
-    var validate = expectAsync1((data) {
-      expect(data, contains('feed'));
-      expect(data['feed'], contains('entry'));
-      expect(data, isMap);
+  group('supported', () {
+    test('supported', () {
+      expect(HttpRequest.supportsCrossOrigin, isTrue);
     });
-    xhr.onReadyStateChange.listen((e) {
-      guardAsync(() {
-        if (xhr.readyState == HttpRequest.DONE) {
-          validate(json.parse(xhr.response));
-        }
+  });
+
+  group('functional', () {
+
+    var port = crossOriginPort;
+    var host = '${window.location.protocol}//${window.location.hostname}:$port';
+
+    test('XHR.get Cross-domain', () {
+      var gotError = false;
+      var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
+      return HttpRequest.request(url).then((xhr) {
+        var data = json.parse(xhr.response);
+        expect(data, contains('feed'));
+        expect(data['feed'], contains('entry'));
+        expect(data, isMap);
+      }).catchError((error) {}, test: (error) {
+        gotError = true;
+        // Consume errors when not supporting cross origin.
+        return !HttpRequest.supportsCrossOrigin;
+      }).whenComplete(() {
+        // Expect that we got an error when cross origin is not supported.
+        expect(gotError, !HttpRequest.supportsCrossOrigin);
       });
     });
-    xhr.send();
-  });
 
-  test('XHR.get Cross-domain', () {
-    var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
-    HttpRequest.request(url).then(expectAsync1((xhr) {
-      var data = json.parse(xhr.response);
-      expect(data, contains('feed'));
-      expect(data['feed'], contains('entry'));
-      expect(data, isMap);
-    }));
-  });
+    // Skip the rest if not supported.
+    if (!HttpRequest.supportsCrossOrigin) {
+      return;
+    }
 
-  test('XHR.getWithCredentials Cross-domain', () {
-    var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
-    HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) {
-      var data = json.parse(xhr.response);
-      expect(data, contains('feed'));
-      expect(data['feed'], contains('entry'));
-      expect(data, isMap);
-    }));
+    test('XHR Cross-domain', () {
+      var url =  '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
+      var xhr = new HttpRequest();
+      xhr.open('GET', url, async: true);
+      var validate = expectAsync1((data) {
+        expect(data, contains('feed'));
+        expect(data['feed'], contains('entry'));
+        expect(data, isMap);
+      });
+      xhr.onReadyStateChange.listen((e) {
+        guardAsync(() {
+          if (xhr.readyState == HttpRequest.DONE) {
+            validate(json.parse(xhr.response));
+          }
+        });
+      });
+      xhr.send();
+    });
+
+    test('XHR.getWithCredentials Cross-domain', () {
+      var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
+      return HttpRequest.request(url, withCredentials: true).then((xhr) {
+        var data = json.parse(xhr.response);
+        expect(data, contains('feed'));
+        expect(data['feed'], contains('entry'));
+        expect(data, isMap);
+      });
+    });
   });
 }
diff --git a/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate b/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
index 5e0f8b8..7ae7698 100644
--- a/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
+++ b/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
@@ -129,7 +129,23 @@
   static bool get supportsProgressEvent {
 $if DART2JS
     var xhr = new HttpRequest();
-    return JS('bool', '"onprogress" in #', xhr);
+    return JS('bool', '("onprogress" in #)', xhr);
+$else
+    return true;
+$endif
+  }
+
+  /**
+   * Checks to see if the current platform supports making cross origin
+   * requests.
+   *
+   * Note that even if cross origin requests are supported, they still may fail
+   * if the destination server does not support CORS requests.
+   */
+  static bool get supportsCrossOrigin {
+$if DART2JS
+    var xhr = new HttpRequest();
+    return JS('bool', '("withCredentials" in #)', xhr);
 $else
     return true;
 $endif
@@ -141,7 +157,7 @@
   static bool get supportsLoadEndEvent {
 $if DART2JS
     var xhr = new HttpRequest();
-    return JS('bool', '"onloadend" in #', xhr);
+    return JS('bool', '("onloadend" in #)', xhr);
 $else
     return true;
 $endif