Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: LayoutTests/resources/js-test.js

Issue 69813015: Add shouldBeNow() to js-tests.js in LayoutTests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Don't use dates in fail testing. Their output is timezone-dependant. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/harness/should-be-now-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « LayoutTests/fast/harness/should-be-now-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698