dart-sdk/tests/lib/html/js_dart_functions_test.dart
Srujan Gaddam a925f4770f [dart:html] Remove 2.7 annotation from lib/html
Strips out the temporary annotation so all the tests without
NNBD related changes can run in strong mode.

Change-Id: I88f18916f0c5a45a80eddb73941db19984f0bfcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140652
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-04-06 20:41:14 +00:00

74 lines
2.3 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'dart:indexed_db' show IdbFactory, KeyRange;
import 'dart:typed_data' show Int32List;
import 'dart:js';
import 'package:js/js_util.dart' as js_util;
import 'package:expect/minitest.dart';
import 'js_test_util.dart';
main() {
injectJs();
test('invoke Dart callback from JS', () {
expect(() => context.callMethod('invokeCallback'), throws);
context['callback'] = () => 42;
expect(context.callMethod('invokeCallback'), equals(42));
context.deleteProperty('callback');
});
test('pass a Dart function to JS and back', () {
var dartFunction = () => 42;
context['dartFunction'] = dartFunction;
expect(identical(context['dartFunction'], dartFunction), isTrue);
context.deleteProperty('dartFunction');
});
test('callback as parameter', () {
expect(context.callMethod('getTypeOf', [context['razzle']]),
equals("function"));
});
test('invoke Dart callback from JS with 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'], 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'),
equals('1234567891011'));
});
test('return a JS proxy to JavaScript', () {
var result = context.callMethod('testJsMap', [
() => new JsObject.jsify({'value': 42})
]);
expect(result, 42);
});
test('emulated functions should not be callable in JS', () {
context['callable'] = new Callable();
expect(() => context.callMethod('callable'), throwsNoSuchMethodError);
Function f = new Callable();
context['callable'] = f;
expect(context.callMethod('callable'), 'called');
context.deleteProperty('callable');
});
}