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

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: Rebased against master. 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 fc1403f36d89877ff18b70a848c3999edd2506e5..2754c84082f860e7350a9fca31e78d92e1275d4b 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/25 22:50:32 We'll have to see how long this takes in practice
+ 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