Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1075)

Unified Diff: base/test/mock_time_provider.h

Issue 7232023: Added last_modified field to TemplateURL and database. Updated unit tests, including refactoring ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | base/test/mock_time_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/mock_time_provider.h
===================================================================
--- base/test/mock_time_provider.h (revision 0)
+++ base/test/mock_time_provider.h (revision 0)
@@ -0,0 +1,66 @@
+// 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.
+
+// A helper class used to mock out calls to the static method base::Time::Now.
+//
+// Example usage:
+//
+// typedef base::Time(TimeProvider)();
+// class StopWatch {
+// public:
+// StopWatch(TimeProvider* time_provider);
+// void Start();
+// base::TimeDelta Stop();
+// private:
+// TimeProvider* time_provider_;
+// ...
+// }
+//
+// Normally, you would instantiate a StopWatch with the real Now function:
+//
+// StopWatch watch(&base::Time::Now);
+//
+// But when testing, you want to instantiate it with
+// MockTimeProvider::StaticNow, which calls an internally mocked out member.
+// This allows you to set expectations on the Now method. For example:
+//
+// TEST_F(StopWatchTest, BasicTest) {
+// InSequence s;
+// StrictMock<MockTimeProvider> mock_time;
+// EXPECT_CALL(mock_time, Now())
+// .WillOnce(Return(Time::FromDoubleT(4)));
+// EXPECT_CALL(mock_time, Now())
+// .WillOnce(Return(Time::FromDoubleT(10)));
+//
+// StopWatch sw(&MockTimeProvider::StaticNow);
+// sw.Start(); // First call to Now.
+// TimeDelta elapsed = sw.stop(); // Second call to Now.
+// ASSERT_EQ(elapsed, TimeDelta::FromSeconds(6));
+// }
+
+#include "base/time.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+#ifndef BASE_TEST_MOCK_TIME_PROVIDER_H_
+#define BASE_TEST_MOCK_TIME_PROVIDER_H_
+
+namespace base {
+
+class MockTimeProvider {
+ public:
+ MockTimeProvider();
+ ~MockTimeProvider();
+
+ MOCK_METHOD0(Now, Time());
+
+ static Time StaticNow();
+
+ private:
+ static MockTimeProvider* instance_;
+ DISALLOW_COPY_AND_ASSIGN(MockTimeProvider);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_MOCK_TIME_PROVIDER_H_
Property changes on: base\test\mock_time_provider.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « base/base.gyp ('k') | base/test/mock_time_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698