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

Unified Diff: chrome/browser/extensions/api/alarms/alarms_api_unittest.cc

Issue 12314056: Make chrome/browser/extensions use base::Clock instead of MockTimeProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add include Created 7 years, 10 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 | « chrome/browser/extensions/api/alarms/alarms_api.cc ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
diff --git a/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc b/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
index ec3a50514733e9c7221bc77de6aa7a8cf44f991f..fdb9ffa42fa15bae9e3eb353907ae7a21740990c 100644
--- a/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
+++ b/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
@@ -4,7 +4,7 @@
// This file tests the chrome.alarms extension API.
-#include "base/test/mock_time_provider.h"
+#include "base/test/simple_test_clock.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/alarms/alarm_manager.h"
#include "chrome/browser/extensions/api/alarms/alarms_api.h"
@@ -51,7 +51,7 @@ class ExtensionAlarmsTest : public BrowserWithTestWindowTest {
TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
ExtensionSystem::Get(browser()->profile()));
- system->CreateAlarmManager(&base::MockTimeProvider::StaticNow);
+ system->CreateAlarmManager(&test_clock_);
alarm_manager_ = system->alarm_manager();
alarm_delegate_ = new AlarmDelegate();
@@ -64,9 +64,7 @@ class ExtensionAlarmsTest : public BrowserWithTestWindowTest {
AddTab(browser(), extension_->GetBackgroundURL());
contents_ = browser()->tab_strip_model()->GetActiveWebContents();
- current_time_ = base::Time::FromDoubleT(10);
- ON_CALL(mock_time_, Now())
- .WillByDefault(testing::ReturnPointee(&current_time_));
+ test_clock_.SetNow(base::Time::FromDoubleT(10));
}
base::Value* RunFunctionWithExtension(
@@ -102,8 +100,7 @@ class ExtensionAlarmsTest : public BrowserWithTestWindowTest {
}
void CreateAlarm(const std::string& args) {
- RunFunction(new AlarmsCreateFunction(&base::MockTimeProvider::StaticNow),
- args);
+ RunFunction(new AlarmsCreateFunction(&test_clock_), args);
}
// Takes a JSON result from a function and converts it to a vector of
@@ -134,15 +131,13 @@ class ExtensionAlarmsTest : public BrowserWithTestWindowTest {
};
for (size_t i = 0; i < num_alarms; ++i) {
scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDict(
- new AlarmsCreateFunction(&base::MockTimeProvider::StaticNow),
- kCreateArgs[i]));
+ new AlarmsCreateFunction(&test_clock_), kCreateArgs[i]));
EXPECT_FALSE(result.get());
}
}
protected:
- base::Time current_time_;
- testing::NiceMock<base::MockTimeProvider> mock_time_;
+ base::SimpleTestClock test_clock_;
AlarmManager* alarm_manager_;
AlarmDelegate* alarm_delegate_;
scoped_refptr<extensions::Extension> extension_;
@@ -150,7 +145,7 @@ class ExtensionAlarmsTest : public BrowserWithTestWindowTest {
};
TEST_F(ExtensionAlarmsTest, Create) {
- current_time_ = base::Time::FromDoubleT(10);
+ test_clock_.SetNow(base::Time::FromDoubleT(10));
// Create 1 non-repeating alarm.
CreateAlarm("[null, {\"delayInMinutes\": 0}]");
@@ -177,7 +172,7 @@ TEST_F(ExtensionAlarmsTest, Create) {
}
TEST_F(ExtensionAlarmsTest, CreateRepeating) {
- current_time_ = base::Time::FromDoubleT(10);
+ test_clock_.SetNow(base::Time::FromDoubleT(10));
// Create 1 repeating alarm.
CreateAlarm("[null, {\"periodInMinutes\": 0.001}]");
@@ -190,12 +185,12 @@ TEST_F(ExtensionAlarmsTest, CreateRepeating) {
EXPECT_THAT(alarm->js_alarm->period_in_minutes,
testing::Pointee(testing::DoubleEq(0.001)));
- current_time_ += base::TimeDelta::FromSeconds(1);
+ test_clock_.Advance(base::TimeDelta::FromSeconds(1));
// Now wait for the alarm to fire. Our test delegate will quit the
// MessageLoop when that happens.
MessageLoop::current()->Run();
- current_time_ += base::TimeDelta::FromSeconds(1);
+ test_clock_.Advance(base::TimeDelta::FromSeconds(1));
// Wait again, and ensure the alarm fires again.
alarm_manager_->ScheduleNextPoll();
MessageLoop::current()->Run();
@@ -205,7 +200,7 @@ TEST_F(ExtensionAlarmsTest, CreateRepeating) {
}
TEST_F(ExtensionAlarmsTest, CreateAbsolute) {
- current_time_ = base::Time::FromDoubleT(9.99);
+ test_clock_.SetNow(base::Time::FromDoubleT(9.99));
CreateAlarm("[null, {\"when\": 10001}]");
const Alarm* alarm =
@@ -216,7 +211,7 @@ TEST_F(ExtensionAlarmsTest, CreateAbsolute) {
EXPECT_THAT(alarm->js_alarm->period_in_minutes,
testing::IsNull());
- current_time_ = base::Time::FromDoubleT(10.1);
+ test_clock_.SetNow(base::Time::FromDoubleT(10.1));
// Now wait for the alarm to fire. Our test delegate will quit the
// MessageLoop when that happens.
MessageLoop::current()->Run();
@@ -228,7 +223,7 @@ TEST_F(ExtensionAlarmsTest, CreateAbsolute) {
}
TEST_F(ExtensionAlarmsTest, CreateRepeatingWithQuickFirstCall) {
- current_time_ = base::Time::FromDoubleT(9.99);
+ test_clock_.SetNow(base::Time::FromDoubleT(9.99));
CreateAlarm("[null, {\"when\": 10001, \"periodInMinutes\": 0.001}]");
const Alarm* alarm =
@@ -239,7 +234,7 @@ TEST_F(ExtensionAlarmsTest, CreateRepeatingWithQuickFirstCall) {
EXPECT_THAT(alarm->js_alarm->period_in_minutes,
testing::Pointee(testing::DoubleEq(0.001)));
- current_time_ = base::Time::FromDoubleT(10.1);
+ test_clock_.SetNow(base::Time::FromDoubleT(10.1));
// Now wait for the alarm to fire. Our test delegate will quit the
// MessageLoop when that happens.
MessageLoop::current()->Run();
@@ -247,7 +242,7 @@ TEST_F(ExtensionAlarmsTest, CreateRepeatingWithQuickFirstCall) {
ASSERT_TRUE(alarm_manager_->GetAlarm(extension_->id(), ""));
EXPECT_THAT(alarm_delegate_->alarms_seen, testing::ElementsAre(""));
- current_time_ = base::Time::FromDoubleT(10.7);
+ test_clock_.SetNow(base::Time::FromDoubleT(10.7));
MessageLoop::current()->Run();
ASSERT_TRUE(alarm_manager_->GetAlarm(extension_->id(), ""));
@@ -255,7 +250,7 @@ TEST_F(ExtensionAlarmsTest, CreateRepeatingWithQuickFirstCall) {
}
TEST_F(ExtensionAlarmsTest, CreateDupe) {
- current_time_ = base::Time::FromDoubleT(10);
+ test_clock_.SetNow(base::Time::FromDoubleT(10));
// Create 2 duplicate alarms. The first should be overridden.
CreateAlarm("[\"dup\", {\"delayInMinutes\": 1}]");
@@ -286,7 +281,7 @@ TEST_F(ExtensionAlarmsTest, CreateDelayBelowMinimum) {
}
TEST_F(ExtensionAlarmsTest, Get) {
- current_time_ = base::Time::FromDoubleT(4);
+ test_clock_.SetNow(base::Time::FromDoubleT(4));
// Create 2 alarms, and make sure we can query them.
CreateAlarms(2);
@@ -445,7 +440,7 @@ TEST_F(ExtensionAlarmsSchedulingTest, PollScheduling) {
alarm_manager_->RemoveAllAlarms(extension_->id());
}
{
- current_time_ = base::Time::FromDoubleT(10);
+ test_clock_.SetNow(base::Time::FromDoubleT(10));
CreateAlarm("[\"a\", {\"periodInMinutes\": 10}]");
Alarm alarm;
alarm.js_alarm->name = "bb";
@@ -457,7 +452,7 @@ TEST_F(ExtensionAlarmsSchedulingTest, PollScheduling) {
alarm_manager_->RemoveAllAlarms(extension_->id());
}
{
- current_time_ = base::Time::FromDoubleT(3 * 60 + 1);
+ test_clock_.SetNow(base::Time::FromDoubleT(3 * 60 + 1));
Alarm alarm;
alarm.js_alarm->name = "bb";
alarm.js_alarm->scheduled_time = 3 * 60000;
@@ -469,7 +464,7 @@ TEST_F(ExtensionAlarmsSchedulingTest, PollScheduling) {
alarm_manager_->RemoveAllAlarms(extension_->id());
}
{
- current_time_ = base::Time::FromDoubleT(4 * 60 + 1);
+ test_clock_.SetNow(base::Time::FromDoubleT(4 * 60 + 1));
CreateAlarm("[\"a\", {\"periodInMinutes\": 2}]");
alarm_manager_->RemoveAlarm(extension_->id(), "a");
Alarm alarm2;
@@ -492,7 +487,7 @@ TEST_F(ExtensionAlarmsSchedulingTest, PollScheduling) {
TEST_F(ExtensionAlarmsSchedulingTest, ReleasedExtensionPollsInfrequently) {
extension_ = utils::CreateEmptyExtensionWithLocation(
extensions::Manifest::INTERNAL);
- current_time_ = base::Time::FromJsTime(300000);
+ test_clock_.SetNow(base::Time::FromJsTime(300000));
CreateAlarm("[\"a\", {\"when\": 300010}]");
CreateAlarm("[\"b\", {\"when\": 340000}]");
« no previous file with comments | « chrome/browser/extensions/api/alarms/alarms_api.cc ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698