Index: LayoutTests/resources/js-test.js |
diff --git a/LayoutTests/resources/js-test.js b/LayoutTests/resources/js-test.js |
index 5909e86f6f3ba056753d1c7f6d81cd464958830d..5799d52ad09ad7696234e3ed10f049566f281db1 100644 |
--- a/LayoutTests/resources/js-test.js |
+++ b/LayoutTests/resources/js-test.js |
@@ -569,6 +569,39 @@ function shouldThrow(_a, _e) |
testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + "."); |
} |
+function shouldBeNow(_a) |
+{ |
+ for (var _i = 0; _i < 1000; ++_i) { |
ojan
2013/11/23 01:41:31
No need for the underscores. jsbell has a patch re
pwnall-personal
2013/11/23 01:56:22
Done.
|
+ var _startDate = Date.now(); |
+ var _av = eval(_a); |
+ var _date = _av.valueOf(); |
+ var _endDate = Date.now(); |
+ |
+ // On some occasions such as NTP updates, the current time can go |
+ // backwards. This should only happen rarely, so we can get away with |
+ // retrying the test a few times if we detect the time going backwards. |
+ if (_startDate > _endDate) |
+ continue; |
+ |
+ if (typeof _date !== "number") { |
+ testFailed(_a + " is not a number or a Date. Got " + _av); |
+ return; |
+ } |
+ if (_date < _startDate) { |
+ testFailed(_a + " is not the curent time. Got " + _av + " which is " + (_startDate - _date) / 1000 + " seconds in the past."); |
+ return; |
+ } |
+ if (_date > _endDate) { |
+ testFailed(_a + " is not the current time. Got " + _av + " which is " + (_date - _endDate) / 1000 + " seconds in the future."); |
+ return; |
+ } |
+ |
+ testPassed(_a + " is equivalent to Date.now()."); |
+ return; |
+ } |
+ testFailed(_a + " cannot be tested against the current time. The clock is going backwards too often."); |
+} |
+ |
function expectError() |
{ |
if (expectingError) { |