New issue
Advanced search Search tips

Issue 802217 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Apr 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 1
Type: Bug

Blocking:
issue 751993



Sign in to add a comment

Add a way to override base::Time/TimeTicks::Now

Project Member Reported by eseckler@chromium.org, Jan 16 2018

Issue description

Both headless and testing use cases would benefit from a global (process-wide) override of base::Time::Now() and base::TimeTicks::Now() to mock/emulate a specific time and/or control progression of time. See [1] for more info about the headless use.

Interface mockup for override:

base::TimeTicks::SetNowOverride(base::TickClock*);
base::Time::SetNowOverride(base::Clock*);

We should also add a way for clients to get the "real" current time/ticks regardless of whether an override is set. For example, test timeouts would not want to be affected by the override.

[1] https://docs.google.com/document/d/1uhPgWkUun6QKjwzrFR7KNo00Anftdvuxvm8fvvx4Db4/edit?ts%3D5a555063%23bookmark%3Did.dotlhwyghafm&sa=D&ust=1516178832168000&usg=AFQjCNFarIfuuMDbqjgV8lfwgyik8TrR6A#bookmark=id.dotlhwyghafm


 
Blocking: 751993
Project Member

Comment 2 by bugdroid1@chromium.org, Jan 25 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a936793513a285ef763bda87f1eb20ea676ad0f5

commit a936793513a285ef763bda87f1eb20ea676ad0f5
Author: Eric Seckler <eseckler@chromium.org>
Date: Thu Jan 25 17:04:12 2018

base: Add override mechanism for Time/TimeTicks/ThreadTicks::Now.

Allows clients to provide functions to override the return values of
Time::Now(), TimeTicks::Now(), ThreadTicks::Now().

Also adds a way to bypass the override in places where real timestamps
should be used even if an override is set.

Bug:  802217 ,  751993 
Change-Id: I76ce536caf9bf0ef5e580abcc23215ce9851ee34
Reviewed-on: https://chromium-review.googlesource.com/867911
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Yuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531923}
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/BUILD.gn
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time.cc
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_fuchsia.cc
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_mac.cc
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_now_posix.cc
[add] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_override.cc
[add] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_override.h
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_unittest.cc
[modify] https://crrev.com/a936793513a285ef763bda87f1eb20ea676ad0f5/base/time/time_win.cc

Status: Fixed (was: Assigned)

Sign in to add a comment