summaryrefslogtreecommitdiffstats
path: root/base/test/mock_time_provider.cc
blob: 9e5547fcd94119e3b2978f6c2c41fe5687708cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/logging.h"
#include "base/test/mock_time_provider.h"

using ::testing::DefaultValue;

namespace base {

MockTimeProvider* MockTimeProvider::instance_ = NULL;

MockTimeProvider::MockTimeProvider() {
  DCHECK(!instance_) << "Only one instance of MockTimeProvider can exist";
  DCHECK(!DefaultValue<Time>::IsSet());
  instance_ = this;
  DefaultValue<Time>::Set(Time::FromInternalValue(0));
}

MockTimeProvider::~MockTimeProvider() {
  instance_ = NULL;
  DefaultValue<Time>::Clear();
}

// static
Time MockTimeProvider::StaticNow() {
  return instance_->Now();
}

}  // namespace base