OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 |
| 3 <script src="../../resources/js-test.js"></script> |
| 4 <script> |
| 5 description('Test shouldBeNow() in js-test.js'); |
| 6 |
| 7 shouldBeNow("Date.now()"); |
| 8 shouldBeNow("new Date()"); |
| 9 |
| 10 debug("Testing type checking with a string. This should fail."); |
| 11 shouldBeNow("'Hello world!'"); |
| 12 |
| 13 function stubDateNow(stubValue, callback) |
| 14 { |
| 15 var realDateNow = Date.now; |
| 16 Date.now = function() { return stubValue; } |
| 17 try { |
| 18 callback(); |
| 19 } finally { |
| 20 Date.now = realDateNow; |
| 21 } |
| 22 } |
| 23 |
| 24 debug("Testing past dates. This should fail."); |
| 25 stubDateNow(60000, function() { |
| 26 shouldBeNow("50000"); |
| 27 }); |
| 28 |
| 29 debug("Testing future dates. This should fail."); |
| 30 stubDateNow(60000, function() { |
| 31 shouldBeNow("70000"); |
| 32 }); |
| 33 |
| 34 debug("Simulating a defective clock that always goes backwards. The test below s
hould fail."); |
| 35 var badClock = Date.now(); |
| 36 var realDateNow = Date.now; |
| 37 Date.now = function() { return --badClock; } |
| 38 shouldBeNow("new Date()"); |
| 39 Date.now = realDateNow; |
| 40 </script> |
OLD | NEW |