Skip to content

Commit

Permalink
Add all dart:html tests from the sdk to test/codegen. All tests are a…
Browse files Browse the repository at this point in the history
…dded except for js_array_test.dart and js_dart_to_string_test.dart which have to be stripped out for now due to failures.

BUG=
R=vsm@google.com

Review URL: https://codereview.chromium.org/1930043002 .
  • Loading branch information
jacob314 committed Apr 28, 2016
1 parent acc4d68 commit efa2303
Show file tree
Hide file tree
Showing 214 changed files with 18,931 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/dev_compiler/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ module.exports = function(config) {
'test/codegen/expect/async_helper/async_helper.js',
'test/codegen/expect/dom/dom.js',
'test/codegen/expect/expect/expect.js',
'test/codegen/expect/js/js.js',
'test/codegen/expect/matcher/matcher.js',
'test/codegen/expect/unittest/unittest.js',
'test/codegen/expect/syncstar_syntax.js',
'test/codegen/expect/language/**.js',
'test/codegen/expect/language/sub/sub.js',
'test/codegen/expect/language/*.lib',
'test/codegen/expect/lib-typed_data/**.js',
'test/codegen/expect/lib-html/**.js',
'test/browser/*.js',
'test-main.js',
],
Expand Down
11 changes: 11 additions & 0 deletions pkg/dev_compiler/test/codegen/expect/html_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dart_library.library('html_config', null, /* Imports */[
'dart_sdk'
], function(exports, dart_sdk) {
'use strict';
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const html_config = Object.create(null);
// Exports:
exports.html_config = html_config;
});
Empty file.
98 changes: 96 additions & 2 deletions pkg/dev_compiler/test/codegen/expect/unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ dart_library.library('unittest', null, /* Imports */[
], function(exports, dart_sdk, matcher) {
'use strict';
const core = dart_sdk.core;
const js = dart_sdk.js;
const async = dart_sdk.async;
const js = dart_sdk.js;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const src__interfaces = matcher.src__interfaces;
const src__util = matcher.src__util;
const src__interfaces = matcher.src__interfaces;
const src__description = matcher.src__description;
const src__numeric_matchers = matcher.src__numeric_matchers;
const src__error_matchers = matcher.src__error_matchers;
Expand All @@ -19,6 +19,91 @@ dart_library.library('unittest', null, /* Imports */[
const src__operator_matchers = matcher.src__operator_matchers;
const src__map_matchers = matcher.src__map_matchers;
const unittest = Object.create(null);
dart.defineLazy(unittest, {
get _wrapAsync() {
return dart.fn((f, id) => {
if (id === void 0) id = null;
return f;
}, core.Function, [core.Function], [dart.dynamic]);
},
set _wrapAsync(_) {}
});
const _matcher = Symbol('_matcher');
unittest.Throws = class Throws extends src__interfaces.Matcher {
Throws(matcher) {
if (matcher === void 0) matcher = null;
this[_matcher] = matcher;
super.Matcher();
}
matches(item, matchState) {
if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) return false;
if (dart.is(item, async.Future)) {
let done = dart.dcall(unittest._wrapAsync, dart.fn(fn => dart.dcall(fn)));
item.then(dart.fn(value => {
dart.dcall(done, dart.fn(() => {
unittest.fail(`Expected future to fail, but succeeded with '${value}'.`);
}));
}), {onError: dart.fn((error, trace) => {
dart.dcall(done, dart.fn(() => {
if (this[_matcher] == null) return;
let reason = null;
if (trace != null) {
let stackTrace = dart.toString(trace);
stackTrace = ` ${stackTrace[dartx.replaceAll]("\n", "\n ")}`;
reason = `Actual exception trace:\n${stackTrace}`;
}
unittest.expect(error, this[_matcher], {reason: dart.as(reason, core.String)});
}));
})});
return true;
}
try {
dart.dcall(item);
return false;
} catch (e) {
let s = dart.stackTrace(e);
if (this[_matcher] == null || dart.notNull(this[_matcher].matches(e, matchState))) {
return true;
} else {
src__util.addStateInfo(matchState, dart.map({exception: e, stack: s}));
return false;
}
}

}
describe(description) {
if (this[_matcher] == null) {
return description.add("throws");
} else {
return description.add('throws ').addDescriptionOf(this[_matcher]);
}
}
describeMismatch(item, mismatchDescription, matchState, verbose) {
if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) {
return mismatchDescription.add('is not a Function or Future');
} else if (this[_matcher] == null || matchState[dartx.get]('exception') == null) {
return mismatchDescription.add('did not throw');
} else {
mismatchDescription.add('threw ').addDescriptionOf(matchState[dartx.get]('exception'));
if (dart.notNull(verbose)) {
mismatchDescription.add(' at ').add(dart.toString(matchState[dartx.get]('stack')));
}
return mismatchDescription;
}
}
};
dart.setSignature(unittest.Throws, {
constructors: () => ({Throws: [unittest.Throws, [], [src__interfaces.Matcher]]}),
methods: () => ({
matches: [core.bool, [dart.dynamic, core.Map]],
describe: [src__interfaces.Description, [src__interfaces.Description]]
})
});
unittest.throws = dart.const(new unittest.Throws());
unittest.throwsA = function(matcher) {
return new unittest.Throws(src__util.wrapMatcher(matcher));
};
dart.fn(unittest.throwsA, src__interfaces.Matcher, [dart.dynamic]);
unittest.group = function(name, body) {
return js.context.callMethod('suite', dart.list([name, body], core.Object));
};
Expand Down Expand Up @@ -54,6 +139,11 @@ dart_library.library('unittest', null, /* Imports */[
dart.setSignature(unittest.TestFailure, {
constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]})
});
unittest.TestCase = class TestCase extends core.Object {
get isComplete() {
return !dart.notNull(this.enabled) || this.result != null;
}
};
unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionType(core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, core.bool]));
unittest.expect = function(actual, matcher, opts) {
let reason = opts && 'reason' in opts ? opts.reason : null;
Expand Down Expand Up @@ -91,6 +181,10 @@ dart_library.library('unittest', null, /* Imports */[
return description.toString();
};
dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, core.bool]);
unittest.useHtmlConfiguration = function(isLayoutTest) {
if (isLayoutTest === void 0) isLayoutTest = false;
};
dart.fn(unittest.useHtmlConfiguration, dart.void, [], [core.bool]);
unittest.isPositive = src__numeric_matchers.isPositive;
unittest.isRangeError = src__error_matchers.isRangeError;
unittest.isStateError = src__error_matchers.isStateError;
Expand Down
11 changes: 11 additions & 0 deletions pkg/dev_compiler/test/codegen/expect/unittest/html_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dart_library.library('html_config', null, /* Imports */[
'dart_sdk'
], function(exports, dart_sdk) {
'use strict';
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const html_config = Object.create(null);
// Exports:
exports.html_config = html_config;
});
Empty file.
98 changes: 96 additions & 2 deletions pkg/dev_compiler/test/codegen/expect/unittest/unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ dart_library.library('unittest', null, /* Imports */[
], function(exports, dart_sdk, matcher) {
'use strict';
const core = dart_sdk.core;
const js = dart_sdk.js;
const async = dart_sdk.async;
const js = dart_sdk.js;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const src__interfaces = matcher.src__interfaces;
const src__util = matcher.src__util;
const src__interfaces = matcher.src__interfaces;
const src__description = matcher.src__description;
const src__numeric_matchers = matcher.src__numeric_matchers;
const src__error_matchers = matcher.src__error_matchers;
Expand All @@ -19,6 +19,91 @@ dart_library.library('unittest', null, /* Imports */[
const src__operator_matchers = matcher.src__operator_matchers;
const src__map_matchers = matcher.src__map_matchers;
const unittest = Object.create(null);
dart.defineLazy(unittest, {
get _wrapAsync() {
return dart.fn((f, id) => {
if (id === void 0) id = null;
return f;
}, core.Function, [core.Function], [dart.dynamic]);
},
set _wrapAsync(_) {}
});
const _matcher = Symbol('_matcher');
unittest.Throws = class Throws extends src__interfaces.Matcher {
Throws(matcher) {
if (matcher === void 0) matcher = null;
this[_matcher] = matcher;
super.Matcher();
}
matches(item, matchState) {
if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) return false;
if (dart.is(item, async.Future)) {
let done = dart.dcall(unittest._wrapAsync, dart.fn(fn => dart.dcall(fn)));
item.then(dart.fn(value => {
dart.dcall(done, dart.fn(() => {
unittest.fail(`Expected future to fail, but succeeded with '${value}'.`);
}));
}), {onError: dart.fn((error, trace) => {
dart.dcall(done, dart.fn(() => {
if (this[_matcher] == null) return;
let reason = null;
if (trace != null) {
let stackTrace = dart.toString(trace);
stackTrace = ` ${stackTrace[dartx.replaceAll]("\n", "\n ")}`;
reason = `Actual exception trace:\n${stackTrace}`;
}
unittest.expect(error, this[_matcher], {reason: dart.as(reason, core.String)});
}));
})});
return true;
}
try {
dart.dcall(item);
return false;
} catch (e) {
let s = dart.stackTrace(e);
if (this[_matcher] == null || dart.notNull(this[_matcher].matches(e, matchState))) {
return true;
} else {
src__util.addStateInfo(matchState, dart.map({exception: e, stack: s}));
return false;
}
}

}
describe(description) {
if (this[_matcher] == null) {
return description.add("throws");
} else {
return description.add('throws ').addDescriptionOf(this[_matcher]);
}
}
describeMismatch(item, mismatchDescription, matchState, verbose) {
if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) {
return mismatchDescription.add('is not a Function or Future');
} else if (this[_matcher] == null || matchState[dartx.get]('exception') == null) {
return mismatchDescription.add('did not throw');
} else {
mismatchDescription.add('threw ').addDescriptionOf(matchState[dartx.get]('exception'));
if (dart.notNull(verbose)) {
mismatchDescription.add(' at ').add(dart.toString(matchState[dartx.get]('stack')));
}
return mismatchDescription;
}
}
};
dart.setSignature(unittest.Throws, {
constructors: () => ({Throws: [unittest.Throws, [], [src__interfaces.Matcher]]}),
methods: () => ({
matches: [core.bool, [dart.dynamic, core.Map]],
describe: [src__interfaces.Description, [src__interfaces.Description]]
})
});
unittest.throws = dart.const(new unittest.Throws());
unittest.throwsA = function(matcher) {
return new unittest.Throws(src__util.wrapMatcher(matcher));
};
dart.fn(unittest.throwsA, src__interfaces.Matcher, [dart.dynamic]);
unittest.group = function(name, body) {
return js.context.callMethod('suite', dart.list([name, body], core.Object));
};
Expand Down Expand Up @@ -54,6 +139,11 @@ dart_library.library('unittest', null, /* Imports */[
dart.setSignature(unittest.TestFailure, {
constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]})
});
unittest.TestCase = class TestCase extends core.Object {
get isComplete() {
return !dart.notNull(this.enabled) || this.result != null;
}
};
unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionType(core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, core.bool]));
unittest.expect = function(actual, matcher, opts) {
let reason = opts && 'reason' in opts ? opts.reason : null;
Expand Down Expand Up @@ -91,6 +181,10 @@ dart_library.library('unittest', null, /* Imports */[
return description.toString();
};
dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, core.bool]);
unittest.useHtmlConfiguration = function(isLayoutTest) {
if (isLayoutTest === void 0) isLayoutTest = false;
};
dart.fn(unittest.useHtmlConfiguration, dart.void, [], [core.bool]);
unittest.isPositive = src__numeric_matchers.isPositive;
unittest.isRangeError = src__error_matchers.isRangeError;
unittest.isStateError = src__error_matchers.isStateError;
Expand Down
8 changes: 8 additions & 0 deletions pkg/dev_compiler/test/codegen/html_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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.

/// A simple unit test library for running tests in a browser.
library unittest.html_config;

// void useHtmlConfiguration([bool isLayoutTest = false]) { }
Binary file added pkg/dev_compiler/test/codegen/lib/html/Ahem.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
library async_cancellingisolate;

import 'dart:async';
import 'package:unittest/unittest.dart';

main(message, replyTo) {
var command = message.first;
expect(command, 'START');
var shot = false;
var oneshot;
var periodic;
periodic = new Timer.periodic(const Duration(milliseconds: 10), (timer) {
expect(shot, isFalse);
shot = true;
expect(timer, same(periodic));
periodic.cancel();
oneshot.cancel();
// Wait some more time to be sure callbacks won't be invoked any
// more.
new Timer(const Duration(milliseconds: 50), () {
replyTo.send('DONE');
});
});
// We launch the oneshot timer after the periodic timer. Otherwise a
// (very long) context switch could make this test flaky: assume the
// oneshot timer is created first and then there is a 30ms context switch.
// when the periodic timer is scheduled it would execute after the oneshot.
oneshot = new Timer(const Duration(milliseconds: 30), () {
fail('Should never be invoked');
});
}
11 changes: 11 additions & 0 deletions pkg/dev_compiler/test/codegen/lib/html/async_oneshot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:async';
import 'package:unittest/unittest.dart';

main(message, replyTo) {
var command = message.first;
expect(command, 'START');
new Timer(const Duration(milliseconds: 10), () {
replyTo.send('DONE');
});
}

24 changes: 24 additions & 0 deletions pkg/dev_compiler/test/codegen/lib/html/async_periodictimer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library async_periodictimer;

import 'dart:async';
import 'package:unittest/unittest.dart';

main(message, replyTo) {
var command = message.first;
expect(command, 'START');
int counter = 0;
new Timer.periodic(const Duration(milliseconds: 10), (timer) {
if (counter == 3) {
counter = 1024;
timer.cancel();
// Wait some more time to be sure callback won't be invoked any
// more.
new Timer(const Duration(milliseconds: 30), () {
replyTo.send('DONE');
});
return;
}
assert(counter < 3);
counter++;
});
}
Loading

0 comments on commit efa2303

Please sign in to comment.