| Index: third_party/WebKit/Source/wtf/CurrentTime.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/CurrentTime.cpp b/third_party/WebKit/Source/wtf/CurrentTime.cpp
|
| index c29636f98c9cc551ec735476ecca99893408a8a3..dc64e33663f4e558739a699d96be1a4519a2098d 100644
|
| --- a/third_party/WebKit/Source/wtf/CurrentTime.cpp
|
| +++ b/third_party/WebKit/Source/wtf/CurrentTime.cpp
|
| @@ -30,29 +30,31 @@
|
|
|
| #include "wtf/CurrentTime.h"
|
|
|
| -namespace WTF {
|
| +#include "base/time/time.h"
|
|
|
| -static TimeFunction currentTimeFunction;
|
| -static TimeFunction monotonicallyIncreasingTimeFunction;
|
| +namespace WTF {
|
|
|
| -void setCurrentTimeFunction(TimeFunction func)
|
| -{
|
| - currentTimeFunction = func;
|
| -}
|
| +static TimeFunction mockTimeFunctionForTesting = nullptr;
|
|
|
| -void setMonotonicallyIncreasingTimeFunction(TimeFunction func)
|
| +double currentTime()
|
| {
|
| - monotonicallyIncreasingTimeFunction = func;
|
| + if (mockTimeFunctionForTesting)
|
| + return mockTimeFunctionForTesting();
|
| + return base::Time::Now().ToDoubleT();
|
| }
|
|
|
| -double currentTime()
|
| +double monotonicallyIncreasingTime()
|
| {
|
| - return (*currentTimeFunction)();
|
| + if (mockTimeFunctionForTesting)
|
| + return mockTimeFunctionForTesting();
|
| + return base::TimeTicks::Now().ToInternalValue() / static_cast<double>(base::Time::kMicrosecondsPerSecond);
|
| }
|
|
|
| -double monotonicallyIncreasingTime()
|
| +TimeFunction setTimeFunctionsForTesting(TimeFunction newFunction)
|
| {
|
| - return (*monotonicallyIncreasingTimeFunction)();
|
| + TimeFunction oldFunction = mockTimeFunctionForTesting;
|
| + mockTimeFunctionForTesting = newFunction;
|
| + return oldFunction;
|
| }
|
|
|
| } // namespace WTF
|
|
|