OnionSoup: Replace WTF::ScopedMockClock by TestMockTimeTaskRunner
As part of removing wtf/time.h we are replacing almost all the usages of WTF::ScopedMockClock by base::'s TestMockTimeTaskRunner. The remaining migrations, web_view_test.cc and window_performance_test.cc, will be done in a followup CL as they require additional changes. The migrations are all pretty similar. A Clock/TickClock object is added to the class that is being tested. That class will be internally used to retrieve the current time/timeticks instead of directly using base/time functions. Production code will use the DefaultClock/DefaultTickClock which are mostly wrappers to base::Time::Now() and base::TimeTicks::Now() so there is no change in behaviour (apart from an extra indirection). Using a clock class has the benefit of allowing tests to overwrite, by using Set{Clock|TickClock}ForTesting(), that clock with a mock one they can handle with no changes in the production code. Note that setting a mock clock sometimes requires additional changes like recomputing some timestamps that were calculated at object's creation time using the default (real time) clock. Last but not least, by using TestMockTimeTaskRunner we are avoiding all the complications that overwritting the global time functions brings, like the lack of protection of those global pointers or the inherent disparities of using a mock and a real clock at the same time. Bug: 919383 Change-Id: I4f1882643ae817cf68a05f2583a9756f4deff554 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1518518 Commit-Queue: Sergio Villar <svillar@igalia.com> Reviewed-by:Daniel Cheng <dcheng@chromium.org> Reviewed-by:
Jeremy Roman <jbroman@chromium.org> Cr-Commit-Position: refs/heads/master@{#660347}
Showing
Please register or sign in to comment