[dart:html] Migrate tests with only null asserts

Remaining tests that don't belong to any particular test
suite, and only needed null asserts to be migrated.

Change-Id: I05141d60e7b50653aa9633e14e832e91d9116408
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140651
Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Srujan Gaddam 2020-04-06 20:41:14 +00:00 committed by commit-bot@chromium.org
parent 5b2482004b
commit 4d4846c57a
22 changed files with 61 additions and 104 deletions

View file

@ -2,8 +2,6 @@
// 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
// @dart = 2.7
import 'dart:html';
import 'dart:typed_data';
@ -23,7 +21,7 @@ main() {
int height = 100;
CanvasElement canvas = new CanvasElement(width: width, height: height);
document.body.append(canvas);
document.body!.append(canvas);
CanvasRenderingContext2D context = canvas.context2D;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library CanvasTest;
import 'dart:html';
@ -17,7 +15,7 @@ main() {
int height = 100;
canvas = new CanvasElement(width: width, height: height);
document.body.append(canvas);
document.body!.append(canvas);
context = canvas.context2D;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -25,7 +23,7 @@ main() {
block of text multiple times to see each line
highlight with every click of the mouse button.
''';
document.body.append(element);
document.body!.append(element);
return element;
}
@ -38,8 +36,8 @@ main() {
});
test("ClientRect ==", () {
var rect1 = document.body.getBoundingClientRect();
var rect2 = document.body.getBoundingClientRect();
var rect1 = document.body!.getBoundingClientRect();
var rect2 = document.body!.getBoundingClientRect();
expect(rect1, isRectangle);
expect(rect1, isDomRectReadOnly);
expect(rect1, equals(rect2));

View file

@ -2,22 +2,20 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
main() {
var uri = Uri.parse(window.location.href);
var crossOriginPort = int.parse(uri.queryParameters['crossOriginPort']);
var crossOriginPort = int.parse(uri.queryParameters['crossOriginPort']!);
var crossOrigin = '${uri.scheme}://${uri.host}:$crossOriginPort';
var crossOriginUrl =
'$crossOrigin/root_dart/tests/lib_2/html/cross_domain_iframe_script.html';
var iframe = new IFrameElement();
iframe.src = crossOriginUrl;
document.body.append(iframe);
document.body!.append(iframe);
return window.onMessage
.where((MessageEvent event) {

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -17,7 +15,7 @@ main() {
var isHistory = predicate((x) => x is History, 'is a History');
final dynamic iframe = new IFrameElement();
document.body.append(iframe);
document.body!.append(iframe);
test('window', () {
expect(window, isWindow);

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -13,7 +11,7 @@ import 'utils.dart';
main() {
test('create via custom tag', () {
var element = new Element.tag('x-basic1')..id = 'basic1';
document.body.nodes.add(element);
document.body!.nodes.add(element);
var queryById = querySelector('#basic1');
expect(queryById, equals(element));
@ -27,7 +25,7 @@ main() {
var element = new DivElement();
element.setInnerHtml("<x-basic2 id='basic2'></x-basic2>",
treeSanitizer: new NullTreeSanitizer());
document.body.nodes.add(element);
document.body!.nodes.add(element);
var queryById = querySelector('#basic2');
expect(queryById is Element, isTrue);
@ -41,7 +39,7 @@ main() {
var element = new DivElement();
element.setInnerHtml("<div is='x-basic3' id='basic3'></div>",
treeSanitizer: new NullTreeSanitizer());
document.body.nodes.add(element);
document.body!.nodes.add(element);
var queryById = querySelector('#basic3');
expect(queryById is DivElement, isTrue);

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -14,7 +12,7 @@ import 'package:expect/minitest.dart';
// effectively testing dart_object_local_storage in the underlying dom
// object.
main() {
BodyElement body = document.body;
BodyElement body = document.body!;
Storage localStorage = window.localStorage;
Storage sessionStorage = window.sessionStorage;
var element = new Element.tag('canvas');

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -16,7 +14,7 @@ main() {
setUp(() {
div = new DivElement();
document.body.append(div);
document.body!.append(div);
div.innerHtml = """
<input id="input" list="browsers" />
<datalist id="browsers">
@ -30,7 +28,7 @@ main() {
});
tearDown(() {
document.body.nodes.removeLast();
document.body!.nodes.removeLast();
});
test('is', () {

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -53,8 +51,8 @@ main() {
var doc = document.implementation.createHtmlDocument('');
expect(doc.adoptNode(div), div);
expect(div.ownerDocument, doc);
doc.body.nodes.add(div);
expect(doc.querySelector('#foo').text, 'bar');
doc.body!.nodes.add(div);
expect(doc.querySelector('#foo')!.text, 'bar');
});
test('importNode', () {
@ -63,8 +61,8 @@ main() {
var div2 = doc.importNode(div, true);
expect(div2, notEquals(div));
expect(div2.ownerDocument, doc);
doc.body.nodes.add(div2);
expect(doc.querySelector('#foo').text, 'bar');
doc.body!.nodes.add(div2);
expect(doc.querySelector('#foo')!.text, 'bar');
});
test('typeTest1', () {

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library EventCustomEventTest;
import 'package:async_helper/async_minitest.dart';
@ -48,7 +46,7 @@ main() {
var script = new ScriptElement();
script.text = scriptContents;
document.body.append(script);
document.body!.append(script);
expect(fired, isTrue);
});
@ -64,7 +62,7 @@ main() {
window.console.log('here' + e.detail);
}, false);''';
document.body.append(new ScriptElement()..text = scriptContents);
document.body!.append(new ScriptElement()..text = scriptContents);
var event = new CustomEvent('dart_custom_event', detail: 'dart_message');
window.dispatchEvent(event);
@ -79,7 +77,7 @@ main() {
expect(event.detail.dartValue, 666);
});
document.body.dispatchEvent(event);
document.body!.dispatchEvent(event);
return future;
});
}

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library fontface_loaded_test;
import 'package:async_helper/async_minitest.dart';
@ -31,7 +29,7 @@ main() {
}
</style>
''', treeSanitizer: new NullTreeSanitizer());
document.head.append(style);
document.head!.append(style);
test('document fonts - temporary', () async {
var atLeastOneFont = false;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library interactive_test;
import 'dart:async';
@ -52,7 +50,7 @@ main() async {
completer.complete(video);
});
document.body.append(video);
document.body!.append(video);
video.src = url;
return completer.future;
@ -85,7 +83,7 @@ main() async {
completer.complete(video);
});
document.body.append(video);
document.body!.append(video);
video.src = url;
return completer.future;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library interactive_test;
import 'dart:async';
@ -14,43 +12,44 @@ import 'utils.dart';
main() {
group('KeyEvent', () {
keydownHandlerTest(KeyEvent e) {
document.body.innerHtml =
'${document.body.innerHtml}KeyDOWN: CharCode: ${e.charCode}, KeyCode:'
' ${e.keyCode}<br />';
document.body!.innerHtml =
'${document.body!.innerHtml}KeyDOWN: CharCode: ${e.charCode}, '
'KeyCode: ${e.keyCode}<br />';
expect(e.charCode, 0);
}
keypressHandlerTest(KeyEvent e) {
document.body.innerHtml =
'${document.body.innerHtml}KeyPRESS: CharCode: ${e.charCode}, '
document.body!.innerHtml =
'${document.body!.innerHtml}KeyPRESS: CharCode: ${e.charCode}, '
'KeyCode: ${e.keyCode}<br />';
}
keyupHandlerTest(KeyEvent e) {
document.body.innerHtml =
'${document.body.innerHtml}KeyUP: CharCode: ${e.charCode}, KeyCode:'
document.body!.innerHtml =
'${document.body!.innerHtml}KeyUP: CharCode: ${e.charCode}, KeyCode:'
' ${e.keyCode}<br />';
expect(e.charCode, 0);
}
keyupHandlerTest2(KeyEvent e) {
document.body.innerHtml =
'${document.body.innerHtml}A second KeyUP handler: CharCode: '
document.body!.innerHtml =
'${document.body!.innerHtml}A second KeyUP handler: CharCode: '
'${e.charCode}, KeyCode: ${e.keyCode}<br />';
expect(e.charCode, 0);
}
test('keys', () {
document.body.innerHtml =
'${document.body.innerHtml}To test keyboard event values, press some '
'keys on your keyboard.<br /><br />The charcode for keydown and keyup'
' should be 0, and the keycode should (generally) be populated with a'
' value. Keycode and charcode should both have values for the '
document.body!.innerHtml =
'${document.body!.innerHtml}To test keyboard event values, press '
'some keys on your keyboard.<br /><br />The charcode for keydown and '
'keyup should be 0, and the keycode should (generally) be populated '
'with a value. Keycode and charcode should both have values for the '
'keypress event.';
KeyboardEventStream.onKeyDown(document.body).listen(keydownHandlerTest);
KeyboardEventStream.onKeyPress(document.body).listen(keypressHandlerTest);
KeyboardEventStream.onKeyUp(document.body).listen(keyupHandlerTest);
KeyboardEventStream.onKeyUp(document.body).listen(keyupHandlerTest2);
KeyboardEventStream.onKeyDown(document.body!).listen(keydownHandlerTest);
KeyboardEventStream.onKeyPress(document.body!)
.listen(keypressHandlerTest);
KeyboardEventStream.onKeyUp(document.body!).listen(keyupHandlerTest);
KeyboardEventStream.onKeyUp(document.body!).listen(keyupHandlerTest2);
});
});
}

View file

@ -2,8 +2,6 @@
// 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
// @dart = 2.7
library postmessage_js_test;
import 'dart:async';
@ -21,7 +19,7 @@ void injectSource(String code) {
final script = new ScriptElement();
script.type = 'text/javascript';
script.innerHtml = code;
document.body.append(script);
document.body!.append(script);
}
Future go(String name, dynamic value) {
@ -179,10 +177,10 @@ Future iframe() async {
Future postMessageClonesData() {
var iframe = new IFrameElement();
var future = iframe.onLoad.first.then((_) {
iframe.contentWindow.postMessage(new HashMap<String, num>(), '*');
iframe.contentWindow!.postMessage(new HashMap<String, num>(), '*');
});
iframe.src = 'about:blank';
document.body.append(iframe);
document.body!.append(iframe);
return future;
}

View file

@ -2,8 +2,6 @@
// 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
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -16,7 +14,7 @@ main() {
var div = new DivElement();
div.id = 'test';
document.body.append(div);
document.body!.append(div);
div.nodes.addAll([
new DivElement(),

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -18,7 +16,7 @@ main() {
group('functional', () {
test('supported works', () {
var range = new Range();
range.selectNode(document.body);
range.selectNode(document.body!);
var expectation =
Range.supportsCreateContextualFragment ? returnsNormally : throws;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -31,8 +29,8 @@ main() {
shadowRoot.append(paragraph1);
shadowRoot.append(new ContentElement());
div2.append(paragraph2);
document.body.append(div1);
document.body.append(div2);
document.body!.append(div1);
document.body!.append(div2);
}
var expectation = ShadowRoot.supported ? returnsNormally : throws;

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
// A regression test for dart2js generating illegal JavaScript code
// dynamically in non-csp mode. The name of the field "defaultValue"
// in JavaScript is "default". This meant that dart2js would create a
@ -18,7 +16,7 @@ import 'package:expect/minitest.dart';
void main() {
test('', () {
if (!TrackElement.supported) return;
document.body.append(new TrackElement()..defaultValue = true);
document.body!.append(new TrackElement()..defaultValue = true);
var trackElement = document.querySelector('track') as TrackElement;
if (!trackElement.defaultValue) {
throw 'Expected default value to be true';

View file

@ -2,8 +2,6 @@
// 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
// @dart = 2.7
library transition_event_test;
import 'dart:html';
@ -13,7 +11,7 @@ import 'package:expect/minitest.dart';
Future testTransitionEnd() async {
var element = new DivElement();
document.body.append(element);
document.body!.append(element);
element.style.opacity = '0';
element.style.width = '100px';

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
/// This tests HTML validation and sanitization, which is very important
/// for prevent XSS or other attacks. If you suppress this, or parts of it
/// please make it a critical bug and bring it to the attention of the
@ -39,17 +37,17 @@ main() {
tearDown(restoreOldAdoptNode);
test('setInnerHtml', () {
document.body.setInnerHtml('<div foo="baz">something</div>',
document.body!.setInnerHtml('<div foo="baz">something</div>',
treeSanitizer: NodeTreeSanitizer.trusted);
expect(document.body.innerHtml, '<div foo="baz">something</div>');
expect(document.body!.innerHtml, '<div foo="baz">something</div>');
});
test("appendHtml", () {
var oldStuff = document.body.innerHtml;
var oldStuff = document.body!.innerHtml;
var newStuff = '<div rumplestiltskin="value">content</div>';
document.body
document.body!
.appendHtml(newStuff, treeSanitizer: NodeTreeSanitizer.trusted);
expect(document.body.innerHtml, oldStuff + newStuff);
expect(document.body!.innerHtml, oldStuff + newStuff);
});
});
@ -57,7 +55,7 @@ main() {
setUp(makeDocumentFragmentAdoptionThrow);
tearDown(restoreOldAdoptNode);
test('untrusted', () {
expect(() => document.body.innerHtml = "<p>anything</p>", throws);
expect(() => document.body!.innerHtml = "<p>anything</p>", throws);
});
});
}

View file

@ -2,8 +2,6 @@
// 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
// @dart = 2.7
import 'dart:html';
import 'package:expect/minitest.dart';
@ -16,7 +14,7 @@ main() {
foo.id = 'foo';
var bar = new Element.tag('bar');
bar.id = 'bar';
document.body.nodes.addAll(<Node>[foo, bar]);
document.body!.nodes.addAll(<Node>[foo, bar]);
test('type-check', () {
expect(foo, isUnknownElement);

View file

@ -2,8 +2,6 @@
// 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.
// @dart = 2.7
library XHRTest;
import 'dart:async';
@ -187,7 +185,7 @@ Future testXhrPostFormData() async {
var parts = [];
for (var key in data.keys) {
parts.add('${Uri.encodeQueryComponent(key)}='
'${Uri.encodeQueryComponent(data[key])}');
'${Uri.encodeQueryComponent(data[key]!)}');
}
var encodedData = parts.join('&');
@ -226,7 +224,7 @@ Future testResponseHeaders() async {
var contentTypeHeader = xhr.responseHeaders['content-type'];
expect(contentTypeHeader, isNotNull);
// Should be like: 'text/plain; charset=utf-8'
expect(contentTypeHeader.contains('text/plain'), isTrue);
expect(contentTypeHeader!.contains('text/plain'), isTrue);
expect(contentTypeHeader.contains('charset=utf-8'), isTrue);
}