| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library jsTest; | 5 library jsTest; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:typed_data' show ByteBuffer, Int32List; | 9 import 'dart:typed_data' show ByteBuffer, Int32List; |
| 10 import 'dart:indexed_db' show IdbFactory, KeyRange; | 10 import 'dart:indexed_db' show IdbFactory, KeyRange; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 function getNewDate() { | 106 function getNewDate() { |
| 107 return new Date(1995, 11, 17); | 107 return new Date(1995, 11, 17); |
| 108 } | 108 } |
| 109 | 109 |
| 110 function getNewDivElement() { | 110 function getNewDivElement() { |
| 111 return document.createElement("div"); | 111 return document.createElement("div"); |
| 112 } | 112 } |
| 113 | 113 |
| 114 function getNewEvent() { |
| 115 return new CustomEvent('test'); |
| 116 } |
| 117 |
| 114 function getNewBlob() { | 118 function getNewBlob() { |
| 115 var fileParts = ['<a id="a"><b id="b">hey!</b></a>']; | 119 var fileParts = ['<a id="a"><b id="b">hey!</b></a>']; |
| 116 return new Blob(fileParts, {type : 'text/html'}); | 120 return new Blob(fileParts, {type : 'text/html'}); |
| 117 } | 121 } |
| 118 | 122 |
| 119 function getNewIDBKeyRange() { | 123 function getNewIDBKeyRange() { |
| 120 return IDBKeyRange.only(1); | 124 return IDBKeyRange.only(1); |
| 121 } | 125 } |
| 122 | 126 |
| 123 function getNewImageData() { | 127 function getNewImageData() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 | 144 |
| 141 function testJsMap(callback) { | 145 function testJsMap(callback) { |
| 142 var result = callback(); | 146 var result = callback(); |
| 143 return result['value']; | 147 return result['value']; |
| 144 } | 148 } |
| 145 | 149 |
| 146 function addTestProperty(o) { | 150 function addTestProperty(o) { |
| 147 o.testProperty = "test"; | 151 o.testProperty = "test"; |
| 148 } | 152 } |
| 149 | 153 |
| 154 function fireClickEvent(w) { |
| 155 var event = w.document.createEvent('Events'); |
| 156 event.initEvent('click', true, false); |
| 157 w.document.body.dispatchEvent(event); |
| 158 } |
| 159 |
| 150 function Bar() { | 160 function Bar() { |
| 151 return "ret_value"; | 161 return "ret_value"; |
| 152 } | 162 } |
| 153 Bar.foo = "property_value"; | 163 Bar.foo = "property_value"; |
| 154 | 164 |
| 155 function Baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11) { | 165 function Baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11) { |
| 156 this.f1 = p1; | 166 this.f1 = p1; |
| 157 this.f2 = p2; | 167 this.f2 = p2; |
| 158 this.f3 = p3; | 168 this.f3 = p3; |
| 159 this.f4 = p4; | 169 this.f4 = p4; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 group('transferrables', () { | 827 group('transferrables', () { |
| 818 | 828 |
| 819 group('JS->Dart', () { | 829 group('JS->Dart', () { |
| 820 | 830 |
| 821 test('DateTime', () { | 831 test('DateTime', () { |
| 822 var date = context.callMethod('getNewDate'); | 832 var date = context.callMethod('getNewDate'); |
| 823 expect(date is DateTime, isTrue); | 833 expect(date is DateTime, isTrue); |
| 824 }); | 834 }); |
| 825 | 835 |
| 826 test('window', () { | 836 test('window', () { |
| 827 expect(context['window'] is Window, isFalse); | 837 expect(context['window'] is Window, isTrue); |
| 838 }); |
| 839 |
| 840 test('foreign browser objects should be proxied', () { |
| 841 var iframe = new IFrameElement(); |
| 842 document.body.children.add(iframe); |
| 843 var proxy = new JsObject.fromBrowserObject(iframe); |
| 844 |
| 845 // Window |
| 846 var contentWindow = proxy['contentWindow']; |
| 847 expect(contentWindow, isNot(new isInstanceOf<Window>())); |
| 848 expect(contentWindow, new isInstanceOf<JsObject>()); |
| 849 |
| 850 // Node |
| 851 var foreignDoc = contentWindow['document']; |
| 852 expect(foreignDoc, isNot(new isInstanceOf<Node>())); |
| 853 expect(foreignDoc, new isInstanceOf<JsObject>()); |
| 854 |
| 855 // Event |
| 856 var clicked = false; |
| 857 foreignDoc['onclick'] = (e) { |
| 858 expect(e, isNot(new isInstanceOf<Event>())); |
| 859 expect(e, new isInstanceOf<JsObject>()); |
| 860 clicked = true; |
| 861 }; |
| 862 |
| 863 context.callMethod('fireClickEvent', [contentWindow]); |
| 864 expect(clicked, isTrue); |
| 828 }); | 865 }); |
| 829 | 866 |
| 830 test('document', () { | 867 test('document', () { |
| 831 expect(context['document'] is Document, isTrue); | 868 expect(context['document'] is Document, isTrue); |
| 832 }); | 869 }); |
| 833 | 870 |
| 834 skipIE9_test('Blob', () { | 871 skipIE9_test('Blob', () { |
| 835 var blob = context.callMethod('getNewBlob'); | 872 var blob = context.callMethod('getNewBlob'); |
| 836 expect(blob is Blob, isTrue); | 873 expect(blob is Blob, isTrue); |
| 837 expect(blob.type, equals('text/html')); | 874 expect(blob.type, equals('text/html')); |
| 838 }); | 875 }); |
| 839 | 876 |
| 840 test('unattached DivElement', () { | 877 test('unattached DivElement', () { |
| 841 var node = context.callMethod('getNewDivElement'); | 878 var node = context.callMethod('getNewDivElement'); |
| 842 expect(node is DivElement, isTrue); | 879 expect(node is DivElement, isTrue); |
| 843 }); | 880 }); |
| 844 | 881 |
| 882 test('Event', () { |
| 883 var event = context.callMethod('getNewEvent'); |
| 884 expect(event is Event, true); |
| 885 }); |
| 886 |
| 845 test('KeyRange', () { | 887 test('KeyRange', () { |
| 846 if (IdbFactory.supported) { | 888 if (IdbFactory.supported) { |
| 847 var node = context.callMethod('getNewIDBKeyRange'); | 889 var node = context.callMethod('getNewIDBKeyRange'); |
| 848 expect(node is KeyRange, isTrue); | 890 expect(node is KeyRange, isTrue); |
| 849 } | 891 } |
| 850 }); | 892 }); |
| 851 | 893 |
| 852 test('ImageData', () { | 894 test('ImageData', () { |
| 853 var node = context.callMethod('getNewImageData'); | 895 var node = context.callMethod('getNewImageData'); |
| 854 expect(node is ImageData, isTrue); | 896 expect(node is ImageData, isTrue); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 872 var dateType = context['Date']; | 914 var dateType = context['Date']; |
| 873 expect(context.callMethod('isPropertyInstanceOf', ['o', dateType]), | 915 expect(context.callMethod('isPropertyInstanceOf', ['o', dateType]), |
| 874 isTrue); | 916 isTrue); |
| 875 context.deleteProperty('o'); | 917 context.deleteProperty('o'); |
| 876 }); | 918 }); |
| 877 | 919 |
| 878 skipIE9_test('window', () { | 920 skipIE9_test('window', () { |
| 879 context['o'] = window; | 921 context['o'] = window; |
| 880 var windowType = context['Window']; | 922 var windowType = context['Window']; |
| 881 expect(context.callMethod('isPropertyInstanceOf', ['o', windowType]), | 923 expect(context.callMethod('isPropertyInstanceOf', ['o', windowType]), |
| 882 isFalse); | 924 isTrue); |
| 883 context.deleteProperty('o'); | 925 context.deleteProperty('o'); |
| 884 }); | 926 }); |
| 885 | 927 |
| 886 skipIE9_test('document', () { | 928 skipIE9_test('document', () { |
| 887 context['o'] = document; | 929 context['o'] = document; |
| 888 var documentType = context['Document']; | 930 var documentType = context['Document']; |
| 889 expect(context.callMethod('isPropertyInstanceOf', ['o', documentType]), | 931 expect(context.callMethod('isPropertyInstanceOf', ['o', documentType]), |
| 890 isTrue); | 932 isTrue); |
| 891 context.deleteProperty('o'); | 933 context.deleteProperty('o'); |
| 892 }); | 934 }); |
| 893 | 935 |
| 894 skipIE9_test('Blob', () { | 936 skipIE9_test('Blob', () { |
| 895 var fileParts = ['<a id="a"><b id="b">hey!</b></a>']; | 937 var fileParts = ['<a id="a"><b id="b">hey!</b></a>']; |
| 896 context['o'] = new Blob(fileParts, 'text/html'); | 938 context['o'] = new Blob(fileParts, 'text/html'); |
| 897 var blobType = context['Blob']; | 939 var blobType = context['Blob']; |
| 898 expect(context.callMethod('isPropertyInstanceOf', ['o', blobType]), | 940 expect(context.callMethod('isPropertyInstanceOf', ['o', blobType]), |
| 899 isTrue); | 941 isTrue); |
| 900 context.deleteProperty('o'); | 942 context.deleteProperty('o'); |
| 901 }); | 943 }); |
| 902 | 944 |
| 903 test('unattached DivElement', () { | 945 test('unattached DivElement', () { |
| 904 context['o'] = new DivElement(); | 946 context['o'] = new DivElement(); |
| 905 var divType = context['HTMLDivElement']; | 947 var divType = context['HTMLDivElement']; |
| 906 expect(context.callMethod('isPropertyInstanceOf', ['o', divType]), | 948 expect(context.callMethod('isPropertyInstanceOf', ['o', divType]), |
| 907 isTrue); | 949 isTrue); |
| 908 context.deleteProperty('o'); | 950 context.deleteProperty('o'); |
| 909 }); | 951 }); |
| 910 | 952 |
| 953 test('Event', () { |
| 954 context['o'] = new CustomEvent('test'); |
| 955 var eventType = context['Event']; |
| 956 expect(context.callMethod('isPropertyInstanceOf', ['o', eventType]), |
| 957 isTrue); |
| 958 context.deleteProperty('o'); |
| 959 }); |
| 960 |
| 911 test('KeyRange', () { | 961 test('KeyRange', () { |
| 912 if (IdbFactory.supported) { | 962 if (IdbFactory.supported) { |
| 913 context['o'] = new KeyRange.only(1); | 963 context['o'] = new KeyRange.only(1); |
| 914 var keyRangeType = context['IDBKeyRange']; | 964 var keyRangeType = context['IDBKeyRange']; |
| 915 expect(context.callMethod('isPropertyInstanceOf', ['o', keyRangeType])
, | 965 expect(context.callMethod('isPropertyInstanceOf', ['o', keyRangeType])
, |
| 916 isTrue); | 966 isTrue); |
| 917 context.deleteProperty('o'); | 967 context.deleteProperty('o'); |
| 918 } | 968 } |
| 919 }); | 969 }); |
| 920 | 970 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 939 // is lost when typed arrays are passed between JS and Dart. | 989 // is lost when typed arrays are passed between JS and Dart. |
| 940 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), | 990 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), |
| 941 // isTrue); | 991 // isTrue); |
| 942 context.deleteProperty('o'); | 992 context.deleteProperty('o'); |
| 943 } | 993 } |
| 944 }); | 994 }); |
| 945 | 995 |
| 946 }); | 996 }); |
| 947 }); | 997 }); |
| 948 } | 998 } |
| OLD | NEW |