Files
sdk/tests/lib_2/html/history_test.dart
T
Srujan Gaddam 1ea7d52d63 Migrate the rest of html tests off unittest
Migrated to minitest where possible and async_minitest elsewhere,
but kept the same import for file suites (e.g. history_*).

Change-Id: Iecd16dfbbcf0691d290fcb82555ff53d715e8500
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139827
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-03-17 22:40:05 +00:00

78 lines
2.3 KiB
Dart

library HistoryTest;
import 'package:async_helper/async_minitest.dart';
import 'dart:html';
import 'dart:async';
main() {
var expectation = History.supportsState ? returnsNormally : throws;
test('pushState', () {
expect(() {
window.history.pushState(null, document.title, '?dummy');
var length = window.history.length;
window.history.pushState(null, document.title, '?foo=bar');
expect(window.location.href.endsWith('foo=bar'), isTrue);
}, expectation);
});
test('pushState with data', () {
expect(() {
window.history.pushState({'one': 1}, document.title, '?dummy');
expect(window.history.state, equals({'one': 1}));
window.history.pushState(null, document.title, '?foo=bar');
expect(window.location.href.endsWith('foo=bar'), isTrue);
}, expectation);
});
test('back', () {
expect(() {
window.history.pushState(null, document.title, '?dummy1');
window.history.pushState(null, document.title, '?dummy2');
var length = window.history.length;
expect(window.location.href.endsWith('dummy2'), isTrue);
// Need to wait a frame or two to let the pushState events occur.
new Timer(const Duration(milliseconds: 100), expectAsync(() {
window.onPopState.first.then(expectAsync((_) {
expect(window.history.length, length);
expect(window.location.href.endsWith('dummy1'), isTrue);
}));
window.history.back();
}));
}, expectation);
});
test('replaceState', () {
expect(() {
var length = window.history.length;
window.history.replaceState(null, document.title, '?foo=baz');
expect(window.history.length, length);
expect(window.location.href.endsWith('foo=baz'), isTrue);
}, expectation);
});
test('popstatevent', () {
expect(() {
var event = new Event.eventType('PopStateEvent', 'popstate');
expect(event is PopStateEvent, true);
}, expectation);
});
test('hashchangeevent', () {
var expectation = HashChangeEvent.supported ? returnsNormally : throws;
expect(() {
var event = new HashChangeEvent('change', oldUrl: 'old', newUrl: 'new');
expect(event is HashChangeEvent, true);
expect(event.oldUrl, 'old');
expect(event.newUrl, 'new');
}, expectation);
});
}