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

Side by Side Diff: tests/lib_strong/html/js_test.dart

Issue 2587203002: Correct handling of cross-frame functions in ddc. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
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 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:typed_data' show ByteBuffer, Int32List; 6 import 'dart:typed_data' show Int32List;
7 import 'dart:indexed_db' show IdbFactory, KeyRange; 7 import 'dart:indexed_db' show IdbFactory, KeyRange;
8 import 'dart:js'; 8 import 'dart:js';
9 import 'package:js/js_util.dart' as js_util;
9 10
10 import 'package:expect/minitest.dart'; 11 import 'package:expect/minitest.dart';
11 12
12 _injectJs() { 13 _injectJs() {
13 final script = new ScriptElement(); 14 final script = new ScriptElement();
14 script.type = 'text/javascript'; 15 script.type = 'text/javascript';
15 script.innerHtml = r""" 16 script.innerHtml = r"""
16 var x = 42; 17 var x = 42;
17 18
18 var _x = 123; 19 var _x = 123;
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 expect(context.callMethod('isPropertyInstanceOf', 502 expect(context.callMethod('isPropertyInstanceOf',
502 ['a', context['Array']]), isTrue); 503 ['a', context['Array']]), isTrue);
503 var a = context['a']; 504 var a = context['a'];
504 expect(a is JsArray, isTrue); 505 expect(a is JsArray, isTrue);
505 expect(a, [1, 2, 3]); 506 expect(a, [1, 2, 3]);
506 context.deleteProperty('a'); 507 context.deleteProperty('a');
507 }); 508 });
508 509
509 test('pass Array to JS', () { 510 test('pass Array to JS', () {
510 context['a'] = [1, 2, 3]; 511 context['a'] = [1, 2, 3];
511 expect(context.callMethod('isPropertyInstanceOf',
512 ['a', context['Array']]), isTrue);
513 var a = context['a']; 512 var a = context['a'];
514 expect(a is List, isTrue); 513 expect(a is List, isTrue);
515 expect(a is JsArray, isFalse); 514 expect(a is JsArray, isFalse);
516 expect(a, [1, 2, 3]); 515 expect(a, [1, 2, 3]);
517 context.deleteProperty('a'); 516 context.deleteProperty('a');
518 }); 517 });
519 518
520 test('[]', () { 519 test('[]', () {
521 var array = new JsArray.from([1, 2]); 520 var array = new JsArray.from([1, 2]);
522 expect(array[0], 1); 521 expect(array[0], 1);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 834
836 test('DateTime', () { 835 test('DateTime', () {
837 var date = context.callMethod('getNewDate'); 836 var date = context.callMethod('getNewDate');
838 expect(date is DateTime, isTrue); 837 expect(date is DateTime, isTrue);
839 }); 838 });
840 839
841 test('window', () { 840 test('window', () {
842 expect(context['window'] is Window, isTrue); 841 expect(context['window'] is Window, isTrue);
843 }); 842 });
844 843
845 // Bug: dartbug.com/24520
846 /*
847 test('foreign browser objects should be proxied', () { 844 test('foreign browser objects should be proxied', () {
848 var iframe = new IFrameElement(); 845 var iframe = new IFrameElement();
849 document.body.children.add(iframe); 846 document.body.children.add(iframe);
850 var proxy = new JsObject.fromBrowserObject(iframe); 847 var proxy = new JsObject.fromBrowserObject(iframe);
851 848
852 // Window 849 // Window
853 var contentWindow = proxy['contentWindow']; 850 var contentWindow = proxy['contentWindow'];
854 expect(contentWindow, isNot(new isInstanceOf<Window>())); 851 expect(contentWindow is! Window, isTrue);
855 expect(contentWindow, new isInstanceOf<JsObject>()); 852 expect(contentWindow is JsObject, isTrue);
856 853
857 // Node 854 // Node
858 var foreignDoc = contentWindow['document']; 855 var foreignDoc = contentWindow['document'];
859 expect(foreignDoc, isNot(new isInstanceOf<Node>())); 856 expect(foreignDoc is! Node, isTrue);
860 expect(foreignDoc, new isInstanceOf<JsObject>()); 857 expect(foreignDoc is JsObject, isTrue);
861 858
862 // Event 859 // Event
863 var clicked = false; 860 var clicked = false;
864 foreignDoc['onclick'] = (e) { 861 foreignDoc['onclick'] = (e) {
865 expect(e, isNot(new isInstanceOf<Event>())); 862 expect(e is! Event, isTrue);
866 expect(e, new isInstanceOf<JsObject>()); 863 expect(e is JsObject, isTrue);
867 clicked = true; 864 clicked = true;
868 }; 865 };
869 866
870 context.callMethod('fireClickEvent', [contentWindow]); 867 context.callMethod('fireClickEvent', [contentWindow]);
871 expect(clicked, isTrue); 868 expect(clicked, isTrue);
872 }); 869 });
873 */ 870
871 test('foreign functions pass function is checks', () {
872 var iframe = new IFrameElement();
873 document.body.children.add(iframe);
874 var proxy = new JsObject.fromBrowserObject(iframe);
875
876 var contentWindow = proxy['contentWindow'];
877 var foreignDoc = contentWindow['document'];
878
879 // Function
880 var foreignFunction = foreignDoc['createElement'];
881 expect(foreignFunction is JsFunction, isTrue);
882
883 // Verify that internal isChecks in callMethod work.
884 foreignDoc.callMethod('createElement', ['div']);
885
886 var typedContentWindow = js_util.getProperty(iframe, 'contentWindow');
887 var typedForeignDoc = js_util.getProperty(typedContentWindow, 'document' );
888
889 var typedForeignFunction = js_util.getProperty(typedForeignDoc, 'createE lement');
890 expect(typedForeignFunction is Function, isTrue);
891 js_util.callMethod(typedForeignDoc, 'createElement', ['div']);
892 });
874 893
875 test('document', () { 894 test('document', () {
876 expect(context['document'] is Document, isTrue); 895 expect(context['document'] is Document, isTrue);
877 }); 896 });
878 897
879 skipIE9_test('Blob', () { 898 skipIE9_test('Blob', () {
880 var blob = context.callMethod('getNewBlob'); 899 var blob = context.callMethod('getNewBlob');
881 expect(blob is Blob, isTrue); 900 expect(blob is Blob, isTrue);
882 expect(blob.type, equals('text/html')); 901 expect(blob.type, equals('text/html'));
883 }); 902 });
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), 1017 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]),
999 // isTrue); 1018 // isTrue);
1000 context.deleteProperty('o'); 1019 context.deleteProperty('o');
1001 } 1020 }
1002 }); 1021 });
1003 1022
1004 }); 1023 });
1005 }); 1024 });
1006 1025
1007 } 1026 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698