• Sergio Villar Senin's avatar
    OnionSoup: Replace WTF::ScopedMockClock by TestMockTimeTaskRunner · 9985a686
    Sergio Villar Senin authored
    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: default avatarDaniel Cheng <dcheng@chromium.org>
    Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#660347}
    9985a686
histogram.h 4.9 KB