Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: test/codegen/lib/html/js_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: ptal Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/codegen/lib/html/js_test.dart
diff --git a/test/codegen/js_test.dart b/test/codegen/lib/html/js_test.dart
similarity index 54%
copy from test/codegen/js_test.dart
copy to test/codegen/lib/html/js_test.dart
index 44768010113ee4bdedd1d5f143c8405ca91407dd..ae9d9b3b9f1fd572254904ef702aebba7629cae0 100644
--- a/test/codegen/js_test.dart
+++ b/test/codegen/lib/html/js_test.dart
@@ -4,11 +4,204 @@
library jsTest;
+import 'dart:async';
+import 'dart:html';
+import 'dart:typed_data' show ByteBuffer, Int32List;
+import 'dart:indexed_db' show IdbFactory, KeyRange;
import 'dart:js';
-// TODO(jmesserly): get tests from package(s) instead.
-import 'dom.dart';
-import 'minitest.dart';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_individual_config.dart';
+
+_injectJs() {
+ final script = new ScriptElement();
+ script.type = 'text/javascript';
+ script.innerHtml = r"""
+var x = 42;
+
+var _x = 123;
+
+var myArray = ["value1"];
+
+var foreignDoc = (function(){
+ var doc = document.implementation.createDocument("", "root", null);
+ var element = doc.createElement('element');
+ element.setAttribute('id', 'abc');
+ doc.documentElement.appendChild(element);
+ return doc;
+})();
+
+function razzle() {
+ return x;
+}
+
+function returnThis() {
+ return this;
+}
+
+function getTypeOf(o) {
+ return typeof(o);
+}
+
+function varArgs() {
+ var args = arguments;
+ var sum = 0;
+ for (var i = 0; i < args.length; ++i) {
+ sum += args[i];
+ }
+ return sum;
+}
+
+function Foo(a) {
+ this.a = a;
+}
+
+Foo.b = 38;
+
+Foo.prototype.bar = function() {
+ return this.a;
+}
+Foo.prototype.toString = function() {
+ return "I'm a Foo a=" + this.a;
+}
+
+var container = new Object();
+container.Foo = Foo;
+
+function isArray(a) {
+ return a instanceof Array;
+}
+
+function checkMap(m, key, value) {
+ if (m.hasOwnProperty(key))
+ return m[key] == value;
+ else
+ return false;
+}
+
+function invokeCallback() {
+ return callback();
+}
+
+function invokeCallbackWith11params() {
+ return callbackWith11params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
+}
+
+function returnElement(element) {
+ return element;
+}
+
+function getElementAttribute(element, attr) {
+ return element.getAttribute(attr);
+}
+
+function addClassAttributes(list) {
+ var result = "";
+ for (var i=0; i < list.length; i++) {
+ result += list[i].getAttribute("class");
+ }
+ return result;
+}
+
+function getNewDate() {
+ return new Date(1995, 11, 17);
+}
+
+function getNewDivElement() {
+ return document.createElement("div");
+}
+
+function getNewEvent() {
+ return new CustomEvent('test');
+}
+
+function getNewBlob() {
+ var fileParts = ['<a id="a"><b id="b">hey!</b></a>'];
+ return new Blob(fileParts, {type : 'text/html'});
+}
+
+function getNewIDBKeyRange() {
+ return IDBKeyRange.only(1);
+}
+
+function getNewImageData() {
+ var canvas = document.createElement('canvas');
+ var context = canvas.getContext('2d');
+ return context.createImageData(1, 1);
+}
+
+function getNewInt32Array() {
+ return new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
+}
+
+function getNewArrayBuffer() {
+ return new ArrayBuffer(8);
+}
+
+function isPropertyInstanceOf(property, type) {
+ return window[property] instanceof type;
+}
+
+function testJsMap(callback) {
+ var result = callback();
+ return result['value'];
+}
+
+function addTestProperty(o) {
+ o.testProperty = "test";
+}
+
+function fireClickEvent(w) {
+ var event = w.document.createEvent('Events');
+ event.initEvent('click', true, false);
+ w.document.dispatchEvent(event);
+}
+
+function Bar() {
+ return "ret_value";
+}
+Bar.foo = "property_value";
+
+function Baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11) {
+ this.f1 = p1;
+ this.f2 = p2;
+ this.f3 = p3;
+ this.f4 = p4;
+ this.f5 = p5;
+ this.f6 = p6;
+ this.f7 = p7;
+ this.f8 = p8;
+ this.f9 = p9;
+ this.f10 = p10;
+ this.f11 = p11;
+}
+
+function Liar(){}
+
+Liar.prototype.toString = function() {
+ return 1;
+}
+
+function identical(o1, o2) {
+ return o1 === o2;
+}
+
+var someProto = { role: "proto" };
+var someObject = Object.create(someProto);
+someObject.role = "object";
+
+""";
+ document.body.append(script);
+}
+
+// Some test are either causing other test to fail in IE9, or they are failing
+// for unknown reasons
+// useHtmlConfiguration+ImageData bug: dartbug.com/14355
+skipIE9_test(String description, t()) {
+ if (Platform.supportsTypedData) {
+ test(description, t);
+ }
+}
class Foo {
final JsObject _proxy;
@@ -36,20 +229,42 @@ class Callable {
}
main() {
+ _injectJs();
+ useHtmlIndividualConfiguration();
+
group('identity', () {
test('context instances should be identical', () {
var c1 = context;
var c2 = context;
- expect(identical(c1, c2), true);
+ expect(identical(c1, c2), isTrue);
+ });
+
+ test('identical JS objects should have identical proxies', () {
+ var o1 = new JsObject(context['Foo'], [1]);
+ context['f1'] = o1;
+ var o2 = context['f1'];
+ expect(identical(o1, o2), isTrue);
+ });
+
+/*
+ TODO(jacobr): enable this test when dartium supports maintaining proxy
+ equality.
+ test('identical Dart objects should have identical proxies', () {
+ var o1 = new TestDartObject();
+ expect(context.callMethod('identical', [o1, o1]), isTrue);
});
+ */
- // TODO(jacobr): switch from equals to identical when dartium supports
- // maintaining proxy equality.
- test('identical JS functions should have equal proxies', () {
+ test('identical Dart functions should have identical proxies', () {
+ var f1 = allowInterop(() => print("I'm a Function!"));
+ expect(context.callMethod('identical', [f1, f1]), isTrue);
+ });
+
+ test('identical JS functions should have identical proxies', () {
var f1 = context['Object'];
var f2 = context['Object'];
- expect(f1, equals(f2));
+ expect(identical(f1, f2), isTrue);
});
// TODO(justinfagnani): old tests duplicate checks above, remove
@@ -59,8 +274,8 @@ main() {
var foo2 = new JsObject(context['Foo'], [2]);
context['foo1'] = foo1;
context['foo2'] = foo2;
- expect(foo1, isNot(context['foo2']));
- expect(foo2, context['foo2']);
+ expect(foo1, isNot(equals(context['foo2'])));
+ expect(foo2, equals(context['foo2']));
context.deleteProperty('foo1');
context.deleteProperty('foo2');
});
@@ -77,9 +292,9 @@ main() {
// Test that we are not pulling cached proxy from the prototype
// when asking for a proxy for the object.
final proto = context['someProto'];
- expect(proto['role'], 'proto');
+ expect(proto['role'], equals('proto'));
final obj = context['someObject'];
- expect(obj['role'], 'object');
+ expect(obj['role'], equals('object'));
});
});
@@ -88,28 +303,28 @@ main() {
group('context', () {
test('read global field', () {
- expect(context['x'], 42);
- expect(context['y'], null);
+ expect(context['x'], equals(42));
+ expect(context['y'], isNull);
});
test('read global field with underscore', () {
- expect(context['_x'], 123);
- expect(context['y'], null);
+ expect(context['_x'], equals(123));
+ expect(context['y'], isNull);
});
test('write global field', () {
context['y'] = 42;
- expect(context['y'], 42);
+ expect(context['y'], equals(42));
});
});
- group('new JsObject()', () {
+ group('new_JsObject', () {
test('new Foo()', () {
var foo = new JsObject(context['Foo'], [42]);
- expect(foo['a'], 42);
- expect(foo.callMethod('bar'), 42);
+ expect(foo['a'], equals(42));
+ expect(foo.callMethod('bar'), equals(42));
expect(() => foo.callMethod('baz'), throwsA(isNoSuchMethodError));
});
@@ -122,7 +337,7 @@ main() {
test('new Array()', () {
var a = new JsObject(context['Array']);
- expect(a, (a) => a is JsArray);
+ expect(a, new isInstanceOf<JsArray>());
// Test that the object still behaves via the base JsObject interface.
// JsArray specific tests are below.
@@ -143,20 +358,20 @@ main() {
test('new Date(12345678)', () {
final a = new JsObject(context['Date'], [12345678]);
- expect(a.callMethod('getTime'), 12345678);
+ expect(a.callMethod('getTime'), equals(12345678));
});
test('new Date("December 17, 1995 03:24:00 GMT")', () {
final a = new JsObject(context['Date'],
["December 17, 1995 03:24:00 GMT"]);
- expect(a.callMethod('getTime'), 819170640000);
+ expect(a.callMethod('getTime'), equals(819170640000));
});
test('new Date(1995,11,17)', () {
// Note: JS Date counts months from 0 while Dart counts from 1.
final a = new JsObject(context['Date'], [1995, 11, 17]);
final b = new DateTime(1995, 12, 17);
- expect(a.callMethod('getTime'), b.millisecondsSinceEpoch);
+ expect(a.callMethod('getTime'), equals(b.millisecondsSinceEpoch));
});
test('new Date(1995,11,17,3,24,0)', () {
@@ -164,7 +379,7 @@ main() {
final a = new JsObject(context['Date'],
[1995, 11, 17, 3, 24, 0]);
final b = new DateTime(1995, 12, 17, 3, 24, 0);
- expect(a.callMethod('getTime'), b.millisecondsSinceEpoch);
+ expect(a.callMethod('getTime'), equals(b.millisecondsSinceEpoch));
});
test('new Object()', () {
@@ -172,27 +387,27 @@ main() {
expect(a, isNotNull);
a['attr'] = "value";
- expect(a['attr'], "value");
+ expect(a['attr'], equals("value"));
});
test(r'new RegExp("^\w+$")', () {
final a = new JsObject(context['RegExp'], [r'^\w+$']);
expect(a, isNotNull);
- expect(a.callMethod('test', ['true']), true);
- expect(a.callMethod('test', [' false']), false);
+ expect(a.callMethod('test', ['true']), isTrue);
+ expect(a.callMethod('test', [' false']), isFalse);
});
test('js instantiation via map notation : new Array()', () {
final a = new JsObject(context['Array']);
expect(a, isNotNull);
- expect(a['length'], 0);
+ expect(a['length'], equals(0));
a.callMethod('push', ["value 1"]);
- expect(a['length'], 1);
- expect(a[0], "value 1");
+ expect(a['length'], equals(1));
+ expect(a[0], equals("value 1"));
a.callMethod('pop');
- expect(a['length'], 0);
+ expect(a['length'], equals(0));
});
test('js instantiation via map notation : new Date()', () {
@@ -200,12 +415,28 @@ main() {
expect(a.callMethod('getTime'), isNotNull);
});
+ test('typed array', () {
+ if (Platform.supportsTypedData) {
+ // Safari's ArrayBuffer is not a Function and so doesn't support bind
+ // which JsObject's constructor relies on.
+ // bug: https://bugs.webkit.org/show_bug.cgi?id=122976
+ if (context['ArrayBuffer']['bind'] != null) {
+ final codeUnits = "test".codeUnits;
+ final buf = new JsObject(context['ArrayBuffer'], [codeUnits.length]);
+ final bufView = new JsObject(context['Uint8Array'], [buf]);
+ for (var i = 0; i < codeUnits.length; i++) {
+ bufView[i] = codeUnits[i];
+ }
+ }
+ }
+ });
+
test('>10 parameters', () {
final o = new JsObject(context['Baz'], [1,2,3,4,5,6,7,8,9,10,11]);
for (var i = 1; i <= 11; i++) {
expect(o["f$i"], i);
}
- expect(o['constructor'], context['Baz']);
+ expect(o['constructor'], equals(context['Baz']));
});
});
@@ -213,33 +444,42 @@ main() {
test('new JsObject can return a JsFunction', () {
var f = new JsObject(context['Function']);
- expect(f, (a) => a is JsFunction);
+ expect(f, new isInstanceOf<JsFunction>());
});
test('JsFunction.apply on a function defined in JS', () {
- expect(context['razzle'].apply([]), 42);
+ expect(context['razzle'].apply([]), equals(42));
});
- test('JsFunction.apply on a function that uses "this"', () {
+ test('JsFunction.apply on a function that uses this', () {
var object = new Object();
expect(context['returnThis'].apply([], thisArg: object), same(object));
});
test('JsObject.callMethod on a function defined in JS', () {
- expect(context.callMethod('razzle'), 42);
+ expect(context.callMethod('razzle'), equals(42));
expect(() => context.callMethod('dazzle'), throwsA(isNoSuchMethodError));
});
test('callMethod with many arguments', () {
expect(context.callMethod('varArgs', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
- 55);
+ equals(55));
});
test('access a property of a function', () {
expect(context.callMethod('Bar'), "ret_value");
expect(context['Bar']['foo'], "property_value");
});
+/*
+ TODO(jacobr): evaluate whether we should be in the business of throwing
+ ArgumentError outside of checked mode. In unchecked mode this should just
+ return a NoSuchMethodError as the class lacks a method "true".
+ test('callMethod throws if name is not a String or num', () {
+ expect(() => context.callMethod(true),
+ throwsA(new isInstanceOf<ArgumentError>()));
+ });
+*/
});
group('JsArray', () {
@@ -264,9 +504,9 @@ main() {
test('get Array from JS', () {
context['a'] = new JsObject(context['Array'], [1, 2, 3]);
expect(context.callMethod('isPropertyInstanceOf',
- ['a', context['Array']]), true);
+ ['a', context['Array']]), isTrue);
var a = context['a'];
- expect(a, (a) => a is JsArray);
+ expect(a, new isInstanceOf<JsArray>());
expect(a, [1, 2, 3]);
context.deleteProperty('a');
});
@@ -274,10 +514,10 @@ main() {
test('pass Array to JS', () {
context['a'] = [1, 2, 3];
expect(context.callMethod('isPropertyInstanceOf',
- ['a', context['Array']]), false);
+ ['a', context['Array']]), isTrue);
var a = context['a'];
- expect(a, (a) => a is List);
- expect(a, isNot((a) => a is JsArray));
+ expect(a, new isInstanceOf<List>());
+ expect(a, isNot(new isInstanceOf<JsArray>()));
expect(a, [1, 2, 3]);
context.deleteProperty('a');
});
@@ -309,7 +549,7 @@ main() {
array.length = 3;
expect(array, [1, 2, null]);
});
-
+
test('add', () {
var array = new JsArray();
array.add('a');
@@ -389,56 +629,58 @@ main() {
group('JsObject.fromBrowserObject()', () {
test('Nodes are proxied', () {
- var node = new JsObject.fromBrowserObject(document.createElement('div'));
+ var node = new JsObject.fromBrowserObject(new DivElement());
context.callMethod('addTestProperty', [node]);
- expect(node is JsObject, true);
- expect(node.instanceof(context['HTMLDivElement']), true);
+ expect(node is JsObject, isTrue);
+ // TODO(justinfagnani): make this work in IE9
+ // expect(node.instanceof(context['HTMLDivElement']), isTrue);
expect(node['testProperty'], 'test');
});
test('primitives and null throw ArgumentError', () {
for (var v in ['a', 1, 2.0, true, null]) {
expect(() => new JsObject.fromBrowserObject(v),
- throwsA((a) => a is ArgumentError));
+ throwsA(new isInstanceOf<ArgumentError>()));
}
});
});
- group('Dart functions', () {
+ group('Dart_functions', () {
test('invoke Dart callback from JS', () {
expect(() => context.callMethod('invokeCallback'), throws);
context['callback'] = () => 42;
- expect(context.callMethod('invokeCallback'), 42);
+ expect(context.callMethod('invokeCallback'), equals(42));
context.deleteProperty('callback');
});
test('callback as parameter', () {
expect(context.callMethod('getTypeOf', [context['razzle']]),
- "function");
+ equals("function"));
});
test('invoke Dart callback from JS with this', () {
- // A JavaScript constructor implemented in Dart using 'this'
+ // A JavaScript constructor function implemented in Dart which
+ // uses 'this'
final constructor = new JsFunction.withThis(($this, arg1) {
+ var t = $this;
$this['a'] = 42;
});
var o = new JsObject(constructor, ["b"]);
- expect(o['a'], 42);
+ expect(o['a'], equals(42));
});
test('invoke Dart callback from JS with 11 parameters', () {
context['callbackWith11params'] = (p1, p2, p3, p4, p5, p6, p7,
p8, p9, p10, p11) => '$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10$p11';
expect(context.callMethod('invokeCallbackWith11params'),
- '1234567891011');
+ equals('1234567891011'));
});
test('return a JS proxy to JavaScript', () {
- var result = context.callMethod('testJsMap',
- [() => new JsObject.jsify({'value': 42})]);
+ var result = context.callMethod('testJsMap', [() => new JsObject.jsify({'value': 42})]);
expect(result, 42);
});
@@ -447,7 +689,7 @@ main() {
var result = context.callMethod('callable');
expect(result, 'called');
context.deleteProperty('callable');
- }, skip: "https://github.com/dart-lang/dev_compiler/issues/244");
+ });
});
@@ -456,29 +698,29 @@ main() {
test('convert a List', () {
final list = [1, 2, 3, 4, 5, 6, 7, 8];
var array = new JsObject.jsify(list);
- expect(context.callMethod('isArray', [array]), true);
- expect(array['length'], list.length);
+ expect(context.callMethod('isArray', [array]), isTrue);
+ expect(array['length'], equals(list.length));
for (var i = 0; i < list.length ; i++) {
- expect(array[i], list[i]);
+ expect(array[i], equals(list[i]));
}
});
test('convert an Iterable', () {
final set = new Set.from([1, 2, 3, 4, 5, 6, 7, 8]);
var array = new JsObject.jsify(set);
- expect(context.callMethod('isArray', [array]), true);
- expect(array['length'], set.length);
+ expect(context.callMethod('isArray', [array]), isTrue);
+ expect(array['length'], equals(set.length));
for (var i = 0; i < array['length'] ; i++) {
- expect(set.contains(array[i]), true);
+ expect(set.contains(array[i]), isTrue);
}
});
test('convert a Map', () {
var map = {'a': 1, 'b': 2, 'c': 3};
var jsMap = new JsObject.jsify(map);
- expect(!context.callMethod('isArray', [jsMap]), true);
+ expect(!context.callMethod('isArray', [jsMap]), isTrue);
for (final key in map.keys) {
- expect(context.callMethod('checkMap', [jsMap, key, map[key]]), true);
+ expect(context.callMethod('checkMap', [jsMap, key, map[key]]), isTrue);
}
});
@@ -492,37 +734,37 @@ main() {
'e': null
};
var jsObject = new JsObject.jsify(object);
- expect(jsObject['a'][0], object['a'][0]);
- expect(jsObject['a'][1][0], object['a'][1][0]);
- expect(jsObject['a'][1][1], object['a'][1][1]);
- expect(jsObject['b']['c'], object['b']['c']);
- expect(jsObject['b']['d'], object['b']['d']);
- expect(jsObject['b']['d'].callMethod('bar'), 42);
- expect(jsObject['e'], null);
+ expect(jsObject['a'][0], equals(object['a'][0]));
+ expect(jsObject['a'][1][0], equals(object['a'][1][0]));
+ expect(jsObject['a'][1][1], equals(object['a'][1][1]));
+ expect(jsObject['b']['c'], equals(object['b']['c']));
+ expect(jsObject['b']['d'], equals(object['b']['d']));
+ expect(jsObject['b']['d'].callMethod('bar'), equals(42));
+ expect(jsObject['e'], isNull);
});
test('throws if object is not a Map or Iterable', () {
expect(() => new JsObject.jsify('a'),
- throwsA((a) => a is ArgumentError));
+ throwsA(new isInstanceOf<ArgumentError>()));
});
});
- group('JsObject methods', () {
+ group('JsObject_methods', () {
test('hashCode and ==', () {
final o1 = context['Object'];
final o2 = context['Object'];
- expect(o1 == o2, true);
- expect(o1.hashCode == o2.hashCode, true);
+ expect(o1 == o2, isTrue);
+ expect(o1.hashCode == o2.hashCode, isTrue);
final d = context['document'];
- expect(o1 == d, false);
+ expect(o1 == d, isFalse);
});
test('toString', () {
var foo = new JsObject(context['Foo'], [42]);
- expect(foo.toString(), "I'm a Foo a=42");
+ expect(foo.toString(), equals("I'm a Foo a=42"));
var container = context['container'];
- expect(container.toString(), "[object Object]");
+ expect(container.toString(), equals("[object Object]"));
});
test('toString returns a String even if the JS object does not', () {
@@ -533,9 +775,9 @@ main() {
test('instanceof', () {
var foo = new JsObject(context['Foo'], [1]);
- expect(foo.instanceof(context['Foo']), true);
- expect(foo.instanceof(context['Object']), true);
- expect(foo.instanceof(context['String']), false);
+ expect(foo.instanceof(context['Foo']), isTrue);
+ expect(foo.instanceof(context['Object']), isTrue);
+ expect(foo.instanceof(context['String']), isFalse);
});
test('deleteProperty', () {
@@ -547,26 +789,51 @@ main() {
expect(context['Object'].callMethod('keys', [object])['length'], 0);
});
+/* TODO(jacobr): this is another test that is inconsistent with JS semantics.
+ test('deleteProperty throws if name is not a String or num', () {
+ var object = new JsObject.jsify({});
+ expect(() => object.deleteProperty(true),
+ throwsA(new isInstanceOf<ArgumentError>()));
+ });
+ */
+
test('hasProperty', () {
var object = new JsObject.jsify({});
object['a'] = 1;
- expect(object.hasProperty('a'), true);
- expect(object.hasProperty('b'), false);
+ expect(object.hasProperty('a'), isTrue);
+ expect(object.hasProperty('b'), isFalse);
});
+/* TODO(jacobr): is this really the correct unchecked mode behavior?
+ test('hasProperty throws if name is not a String or num', () {
+ var object = new JsObject.jsify({});
+ expect(() => object.hasProperty(true),
+ throwsA(new isInstanceOf<ArgumentError>()));
+ });
+*/
+
test('[] and []=', () {
final myArray = context['myArray'];
- expect(myArray['length'], 1);
- expect(myArray[0], "value1");
+ expect(myArray['length'], equals(1));
+ expect(myArray[0], equals("value1"));
myArray[0] = "value2";
- expect(myArray['length'], 1);
- expect(myArray[0], "value2");
+ expect(myArray['length'], equals(1));
+ expect(myArray[0], equals("value2"));
final foo = new JsObject(context['Foo'], [1]);
foo["getAge"] = () => 10;
- expect(foo.callMethod('getAge'), 10);
+ expect(foo.callMethod('getAge'), equals(10));
});
+/* TODO(jacobr): remove as we should only throw this in checked mode.
+ test('[] and []= throw if name is not a String or num', () {
+ var object = new JsObject.jsify({});
+ expect(() => object[true],
+ throwsA(new isInstanceOf<ArgumentError>()));
+ expect(() => object[true] = 1,
+ throwsA(new isInstanceOf<ArgumentError>()));
+ });
+*/
});
group('transferrables', () {
@@ -575,53 +842,56 @@ main() {
test('DateTime', () {
var date = context.callMethod('getNewDate');
- expect(date is DateTime, true);
+ expect(date is DateTime, isTrue);
});
test('window', () {
- expect(context['window'] is Window, true);
+ expect(context['window'] is Window, isTrue);
});
+ // Bug: dartbug.com/24520
+ /*
test('foreign browser objects should be proxied', () {
- var iframe = document.createElement('iframe');
- document.body.appendChild(iframe);
+ var iframe = new IFrameElement();
+ document.body.children.add(iframe);
var proxy = new JsObject.fromBrowserObject(iframe);
// Window
var contentWindow = proxy['contentWindow'];
- expect(contentWindow, isNot((a) => a is Window));
- expect(contentWindow, (a) => a is JsObject);
+ expect(contentWindow, isNot(new isInstanceOf<Window>()));
+ expect(contentWindow, new isInstanceOf<JsObject>());
// Node
var foreignDoc = contentWindow['document'];
- expect(foreignDoc, isNot((a) => a is Node));
- expect(foreignDoc, (a) => a is JsObject);
+ expect(foreignDoc, isNot(new isInstanceOf<Node>()));
+ expect(foreignDoc, new isInstanceOf<JsObject>());
// Event
var clicked = false;
foreignDoc['onclick'] = (e) {
- expect(e, isNot((a) => a is Event));
- expect(e, (a) => a is JsObject);
+ expect(e, isNot(new isInstanceOf<Event>()));
+ expect(e, new isInstanceOf<JsObject>());
clicked = true;
};
context.callMethod('fireClickEvent', [contentWindow]);
- expect(clicked, true);
+ expect(clicked, isTrue);
});
+ */
test('document', () {
- expect(context['document'] is Document, true);
+ expect(context['document'] is Document, isTrue);
});
- test('Blob', () {
+ skipIE9_test('Blob', () {
var blob = context.callMethod('getNewBlob');
- expect(blob is Blob, true);
- expect(blob.type, 'text/html');
+ expect(blob is Blob, isTrue);
+ expect(blob.type, equals('text/html'));
});
test('unattached DivElement', () {
var node = context.callMethod('getNewDivElement');
- expect(node is DivElement, true);
+ expect(node is DivElement, isTrue);
});
test('Event', () {
@@ -629,9 +899,25 @@ main() {
expect(event is Event, true);
});
+ test('KeyRange', () {
+ if (IdbFactory.supported) {
+ var node = context.callMethod('getNewIDBKeyRange');
+ expect(node is KeyRange, isTrue);
+ }
+ });
+
test('ImageData', () {
var node = context.callMethod('getNewImageData');
- expect(node is ImageData, true);
+ expect(node is ImageData, isTrue);
+ });
+
+ test('typed data: Int32Array', () {
+ if (Platform.supportsTypedData) {
+ var list = context.callMethod('getNewInt32Array');
+ print(list);
+ expect(list is Int32List, isTrue);
+ expect(list, orderedEquals([1, 2, 3, 4, 5, 6, 7, 8]));
+ }
});
});
@@ -642,40 +928,40 @@ main() {
context['o'] = new DateTime(1995, 12, 17);
var dateType = context['Date'];
expect(context.callMethod('isPropertyInstanceOf', ['o', dateType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
- test('window', () {
+ skipIE9_test('window', () {
context['o'] = window;
var windowType = context['Window'];
expect(context.callMethod('isPropertyInstanceOf', ['o', windowType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
- test('document', () {
+ skipIE9_test('document', () {
context['o'] = document;
var documentType = context['Document'];
expect(context.callMethod('isPropertyInstanceOf', ['o', documentType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
- test('Blob', () {
+ skipIE9_test('Blob', () {
var fileParts = ['<a id="a"><b id="b">hey!</b></a>'];
- context['o'] = new Blob(fileParts, type: 'text/html');
+ context['o'] = new Blob(fileParts, 'text/html');
var blobType = context['Blob'];
expect(context.callMethod('isPropertyInstanceOf', ['o', blobType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
test('unattached DivElement', () {
- context['o'] = document.createElement('div');
+ context['o'] = new DivElement();
var divType = context['HTMLDivElement'];
expect(context.callMethod('isPropertyInstanceOf', ['o', divType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
@@ -683,23 +969,46 @@ main() {
context['o'] = new CustomEvent('test');
var eventType = context['Event'];
expect(context.callMethod('isPropertyInstanceOf', ['o', eventType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
+ test('KeyRange', () {
+ if (IdbFactory.supported) {
+ context['o'] = new KeyRange.only(1);
+ var keyRangeType = context['IDBKeyRange'];
+ expect(context.callMethod('isPropertyInstanceOf', ['o', keyRangeType]),
+ isTrue);
+ context.deleteProperty('o');
+ }
+ });
+
// this test fails in IE9 for very weird, but unknown, reasons
// the expression context['ImageData'] fails if useHtmlConfiguration()
// is called, or if the other tests in this file are enabled
- test('ImageData', () {
- CanvasElement canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
+ skipIE9_test('ImageData', () {
+ var canvas = new CanvasElement();
+ var ctx = canvas.getContext('2d');
context['o'] = ctx.createImageData(1, 1);
var imageDataType = context['ImageData'];
expect(context.callMethod('isPropertyInstanceOf', ['o', imageDataType]),
- true);
+ isTrue);
context.deleteProperty('o');
});
+ test('typed data: Int32List', () {
+ if (Platform.supportsTypedData) {
+ context['o'] = new Int32List.fromList([1, 2, 3, 4]);
+ var listType = context['Int32Array'];
+ // TODO(jacobr): make this test pass. Currently some type information
+ // is lost when typed arrays are passed between JS and Dart.
+ // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]),
+ // isTrue);
+ context.deleteProperty('o');
+ }
+ });
+
});
});
+
}
« no previous file with comments | « test/codegen/lib/html/js_interop_1_test.dart ('k') | test/codegen/lib/html/js_typed_interop_anonymous2_exp_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698