| OLD | NEW |
| 1 library HistoryTest; | 1 library HistoryTest; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_individual_config.dart'; | 3 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 | 5 |
| 6 /// Waits for a callback once, then removes the event handler. | |
| 7 void expectAsync1Once(EventListenerList list, void callback(arg)) { | |
| 8 var fn = null; | |
| 9 fn = expectAsync1((arg) { | |
| 10 list.remove(fn); | |
| 11 callback(arg); | |
| 12 }); | |
| 13 list.add(fn); | |
| 14 } | |
| 15 | |
| 16 main() { | 6 main() { |
| 17 useHtmlIndividualConfiguration(); | 7 useHtmlIndividualConfiguration(); |
| 18 | 8 |
| 19 group('supported_state', () { | 9 group('supported_state', () { |
| 20 test('supportsState', () { | 10 test('supportsState', () { |
| 21 expect(History.supportsState, true); | 11 expect(History.supportsState, true); |
| 22 }); | 12 }); |
| 23 }); | 13 }); |
| 24 | 14 |
| 25 group('supported_HashChangeEvent', () { | 15 group('supported_HashChangeEvent', () { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 test('back', () { | 36 test('back', () { |
| 47 expect(() { | 37 expect(() { |
| 48 window.history.pushState(null, document.title, '?dummy1'); | 38 window.history.pushState(null, document.title, '?dummy1'); |
| 49 window.history.pushState(null, document.title, '?dummy2'); | 39 window.history.pushState(null, document.title, '?dummy2'); |
| 50 var length = window.history.length; | 40 var length = window.history.length; |
| 51 | 41 |
| 52 expect(window.location.href.endsWith('dummy2'), isTrue); | 42 expect(window.location.href.endsWith('dummy2'), isTrue); |
| 53 | 43 |
| 54 // Need to wait a frame or two to let the pushState events occur. | 44 // Need to wait a frame or two to let the pushState events occur. |
| 55 window.setTimeout(expectAsync0(() { | 45 window.setTimeout(expectAsync0(() { |
| 56 expectAsync1Once(window.on.popState, (_) { | 46 window.onPopState.first.then(expectAsync1((_){ |
| 57 expect(window.history.length, length); | 47 expect(window.history.length, length); |
| 58 expect(window.location.href.endsWith('dummy1'), isTrue); | 48 expect(window.location.href.endsWith('dummy1'), isTrue); |
| 59 }); | 49 })); |
| 60 | 50 |
| 61 window.history.back(); | 51 window.history.back(); |
| 62 }), 100); | 52 }), 100); |
| 63 }, expectation); | 53 }, expectation); |
| 64 }); | 54 }); |
| 65 | 55 |
| 66 test('replaceState', () { | 56 test('replaceState', () { |
| 67 expect(() { | 57 expect(() { |
| 68 var length = window.history.length; | 58 var length = window.history.length; |
| 69 | 59 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 var expectation = HashChangeEvent.supported ? returnsNormally : throws; | 74 var expectation = HashChangeEvent.supported ? returnsNormally : throws; |
| 85 expect(() { | 75 expect(() { |
| 86 var event = new HashChangeEvent('change', oldUrl:'old', newUrl: 'new'); | 76 var event = new HashChangeEvent('change', oldUrl:'old', newUrl: 'new'); |
| 87 expect(event is HashChangeEvent, true); | 77 expect(event is HashChangeEvent, true); |
| 88 expect(event.oldUrl, 'old'); | 78 expect(event.oldUrl, 'old'); |
| 89 expect(event.newUrl, 'new'); | 79 expect(event.newUrl, 'new'); |
| 90 }, expectation); | 80 }, expectation); |
| 91 }); | 81 }); |
| 92 }); | 82 }); |
| 93 } | 83 } |
| OLD | NEW |