| Index: net/test/fake_time_system_unittest.cc
|
| diff --git a/net/test/fake_time_system_unittest.cc b/net/test/fake_time_system_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bb866bbcb3223ce34681cc7458cf849b3306ca12
|
| --- /dev/null
|
| +++ b/net/test/fake_time_system_unittest.cc
|
| @@ -0,0 +1,65 @@
|
| +// Copyright (c) 2013 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/location.h"
|
| +#include "base/bind.h"
|
| +#include "net/test/fake_time_system.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +
|
| +using ::testing::Mock;
|
| +using ::testing::StrictMock;
|
| +
|
| +namespace net {
|
| +namespace {
|
| +
|
| +class MockTask {
|
| + public:
|
| + MockTask() {}
|
| + ~MockTask() {}
|
| +
|
| + MOCK_METHOD0(Run1, void());
|
| + MOCK_METHOD0(Run2, void());
|
| + MOCK_METHOD0(Run3, void());
|
| +};
|
| +
|
| +TEST(FakeTimeSystemTest, RunPendingTasks) {
|
| + scoped_refptr<FakeTimeSystem> fake_time_system = new FakeTimeSystem();
|
| + base::Time default_time = base::Time::FromDoubleT(1234.0);
|
| + StrictMock<MockTask> task;
|
| +
|
| + fake_time_system->SetNow(default_time);
|
| + fake_time_system->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::Bind(&MockTask::Run2, base::Unretained(&task)),
|
| + base::TimeDelta::FromSeconds(5));
|
| +
|
| + fake_time_system->SetNow(default_time + base::TimeDelta::FromSeconds(2));
|
| + fake_time_system->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::Bind(&MockTask::Run3, base::Unretained(&task)),
|
| + base::TimeDelta::FromSeconds(5));
|
| +
|
| + fake_time_system->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&MockTask::Run1, base::Unretained(&task)));
|
| +
|
| + EXPECT_CALL(task, Run1());
|
| + fake_time_system->RunPendingTasks();
|
| + Mock::VerifyAndClear(&task);
|
| +
|
| + fake_time_system->SetNow(default_time + base::TimeDelta::FromSeconds(5));
|
| + EXPECT_CALL(task, Run2());
|
| + fake_time_system->RunPendingTasks();
|
| + Mock::VerifyAndClear(&task);
|
| +
|
| + fake_time_system->SetNow(default_time + base::TimeDelta::FromSeconds(7));
|
| + EXPECT_CALL(task, Run3());
|
| + fake_time_system->RunPendingTasks();
|
| + Mock::VerifyAndClear(&task);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +} // namespace net
|
|
|