Chromium Code Reviews| 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 var expectation = History.supportsState ? returnsNormally : throws; | 15 var expectation = History.supportsState ? returnsNormally : throws; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 40 test('back', () { | 30 test('back', () { |
| 41 expect(() { | 31 expect(() { |
| 42 window.history.pushState(null, document.title, '?dummy1'); | 32 window.history.pushState(null, document.title, '?dummy1'); |
| 43 window.history.pushState(null, document.title, '?dummy2'); | 33 window.history.pushState(null, document.title, '?dummy2'); |
| 44 var length = window.history.length; | 34 var length = window.history.length; |
| 45 | 35 |
| 46 expect(window.location.href.endsWith('dummy2'), isTrue); | 36 expect(window.location.href.endsWith('dummy2'), isTrue); |
| 47 | 37 |
| 48 // Need to wait a frame or two to let the pushState events occur. | 38 // Need to wait a frame or two to let the pushState events occur. |
| 49 window.setTimeout(expectAsync0(() { | 39 window.setTimeout(expectAsync0(() { |
| 50 expectAsync1Once(window.on.popState, (_) { | 40 window.onPopState.take(1).listen((_) { |
|
floitsch
2013/01/24 17:17:18
don't you need to wrap this function in an expectA
| |
| 51 expect(window.history.length, length); | 41 expect(window.history.length, length); |
| 52 expect(window.location.href.endsWith('dummy1'), isTrue); | 42 expect(window.location.href.endsWith('dummy1'), isTrue); |
| 53 }); | 43 }); |
| 54 | 44 |
| 55 window.history.back(); | 45 window.history.back(); |
| 56 }), 100); | 46 }), 100); |
| 57 }, expectation); | 47 }, expectation); |
| 58 }); | 48 }); |
| 59 | 49 |
| 60 test('replaceState', () { | 50 test('replaceState', () { |
| 61 expect(() { | 51 expect(() { |
| 62 var length = window.history.length; | 52 var length = window.history.length; |
| 63 | 53 |
| 64 window.history.replaceState(null, document.title, '?foo=baz'); | 54 window.history.replaceState(null, document.title, '?foo=baz'); |
| 65 expect(window.history.length, length); | 55 expect(window.history.length, length); |
| 66 expect(window.location.href.endsWith('foo=baz'), isTrue); | 56 expect(window.location.href.endsWith('foo=baz'), isTrue); |
| 67 }, expectation); | 57 }, expectation); |
| 68 }); | 58 }); |
| 69 }); | 59 }); |
| 70 } | 60 } |
| OLD | NEW |