Commit 1a74620f authored by Prashant Malani's avatar Prashant Malani Committed by Commit Bot

[Power: ML]: Remove remaining uses of TestMockTimeTaskRunner

ScopedTaskEnvironment is sufficient for the purposes of power/ml
unit tests, so remove usages of TestMockTimeTaskRunner. This also
removes need to support both TestMockTimeTaskRunner *and*
ScopedTaskEnvironment in FakeBookClock.

Bug: 917580
Test: All related unit tests still pass.

Change-Id: Iec413bf52422a12462f8ff99ef5e02e23907925a
Reviewed-on: https://chromium-review.googlesource.com/c/1393896Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Prashant Malani <pmalani@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619877}
parent 3fe60950
......@@ -82,21 +82,24 @@ class AdaptiveScreenBrightnessManagerTest
: public ChromeRenderViewHostTestHarness {
public:
AdaptiveScreenBrightnessManagerTest()
: task_runner_(base::MakeRefCounted<base::TestMockTimeTaskRunner>()) {
: ChromeRenderViewHostTestHarness(
base::test::ScopedTaskEnvironment::MainThreadType::UI_MOCK_TIME,
base::test::ScopedTaskEnvironment::ExecutionMode::QUEUED,
content::TestBrowserThreadBundle::Options::DEFAULT) {
auto logger = std::make_unique<TestingAdaptiveScreenBrightnessUkmLogger>();
ukm_logger_ = logger.get();
fake_power_manager_client_.Init(nullptr);
viz::mojom::VideoDetectorObserverPtr observer;
auto periodic_timer = std::make_unique<base::RepeatingTimer>();
periodic_timer->SetTaskRunner(task_runner_);
periodic_timer->SetTaskRunner(thread_bundle()->GetMainThreadTaskRunner());
screen_brightness_manager_ =
std::make_unique<AdaptiveScreenBrightnessManager>(
std::move(logger), &user_activity_detector_,
&fake_power_manager_client_, nullptr, nullptr,
mojo::MakeRequest(&observer), std::move(periodic_timer),
task_runner_->GetMockClock(),
std::make_unique<FakeBootClock>(task_runner_,
const_cast<base::Clock*>(thread_bundle()->GetMockClock()),
std::make_unique<FakeBootClock>(thread_bundle(),
base::TimeDelta::FromSeconds(10)));
}
......@@ -150,7 +153,7 @@ class AdaptiveScreenBrightnessManagerTest
}
void FastForwardTimeBySecs(const int seconds) {
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(seconds));
thread_bundle()->FastForwardBy(base::TimeDelta::FromSeconds(seconds));
}
// Creates a test browser window and sets its visibility, activity and
......@@ -217,9 +220,6 @@ class AdaptiveScreenBrightnessManagerTest
const GURL kUrl3 = GURL("https://example3.com/");
private:
// TODO(crbug.com/917580): Remove this; thread_bundle() should be used
// instead.
const scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
chromeos::FakeChromeUserManager fake_user_manager_;
ui::UserActivityDetector user_activity_detector_;
......
......@@ -8,16 +8,6 @@ namespace chromeos {
namespace power {
namespace ml {
FakeBootClock::FakeBootClock(
scoped_refptr<const base::TestMockTimeTaskRunner> task_runner,
base::TimeDelta initial_time_since_boot)
: task_runner_(task_runner),
env_(nullptr),
initial_time_since_boot_(initial_time_since_boot) {
DCHECK_GE(initial_time_since_boot, base::TimeDelta());
initial_time_ticks_ = task_runner_->NowTicks();
}
FakeBootClock::FakeBootClock(base::test::ScopedTaskEnvironment* env,
base::TimeDelta initial_time_since_boot)
: env_(env), initial_time_since_boot_(initial_time_since_boot) {
......@@ -28,12 +18,7 @@ FakeBootClock::FakeBootClock(base::test::ScopedTaskEnvironment* env,
FakeBootClock::~FakeBootClock() = default;
base::TimeDelta FakeBootClock::GetTimeSinceBoot() {
base::TimeTicks now;
if (env_) {
now = env_->NowTicks();
} else {
now = task_runner_->NowTicks();
}
base::TimeTicks now = env_->NowTicks();
return (now - initial_time_ticks_) + initial_time_since_boot_;
}
......
......@@ -18,8 +18,6 @@ namespace ml {
class FakeBootClock : public BootClock {
public:
FakeBootClock(scoped_refptr<const base::TestMockTimeTaskRunner> task_runner,
base::TimeDelta initial_time_since_boot);
FakeBootClock(base::test::ScopedTaskEnvironment* env,
base::TimeDelta initial_time_since_boot);
~FakeBootClock() override;
......@@ -28,9 +26,6 @@ class FakeBootClock : public BootClock {
base::TimeDelta GetTimeSinceBoot() override;
private:
// TODO(crbug.com/917580): This is no longer needed and should be removed.
// |env_| should give sufficient access to fake clock values.
scoped_refptr<const base::TestMockTimeTaskRunner> task_runner_;
base::test::ScopedTaskEnvironment* env_;
base::TimeDelta initial_time_since_boot_;
base::TimeTicks initial_time_ticks_;
......
......@@ -79,15 +79,16 @@ class TestObserver : public IdleEventNotifier::Observer {
class IdleEventNotifierTest : public testing::Test {
public:
IdleEventNotifierTest()
: task_runner_(base::MakeRefCounted<base::TestMockTimeTaskRunner>(
base::TestMockTimeTaskRunner::Type::kBoundToThread)),
scoped_context_(task_runner_.get()) {
: scoped_task_env_(
base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME,
base::test::ScopedTaskEnvironment::ExecutionMode::QUEUED) {
viz::mojom::VideoDetectorObserverPtr observer;
idle_event_notifier_ = std::make_unique<IdleEventNotifier>(
&power_client_, &user_activity_detector_, mojo::MakeRequest(&observer));
idle_event_notifier_->SetClockForTesting(
task_runner_, task_runner_->GetMockClock(),
std::make_unique<FakeBootClock>(task_runner_,
scoped_task_env_.GetMainThreadTaskRunner(),
const_cast<base::Clock*>(scoped_task_env_.GetMockClock()),
std::make_unique<FakeBootClock>(&scoped_task_env_,
base::TimeDelta::FromSeconds(10)));
idle_event_notifier_->AddObserver(&test_observer_);
ac_power_.set_external_power(
......@@ -111,8 +112,7 @@ class IdleEventNotifierTest : public testing::Test {
EXPECT_TRUE(expected_activity_data == test_observer_.activity_data());
}
const scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
const base::TestMockTimeTaskRunner::ScopedContext scoped_context_;
base::test::ScopedTaskEnvironment scoped_task_env_;
TestObserver test_observer_;
std::unique_ptr<IdleEventNotifier> idle_event_notifier_;
......@@ -132,7 +132,7 @@ TEST_F(IdleEventNotifierTest, CheckInitialValues) {
// Lid is opened, followed by an idle event.
TEST_F(IdleEventNotifierTest, LidOpenEventReceived) {
base::Time now = task_runner_->Now();
base::Time now = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->LidEventReceived(
chromeos::PowerManagerClient::LidState::OPEN,
base::TimeTicks::UnixEpoch());
......@@ -148,7 +148,7 @@ TEST_F(IdleEventNotifierTest, LidOpenEventReceived) {
// PowerChanged signal is received but source isn't changed, so it won't change
// ActivityData that gets reported when an idle event is received.
TEST_F(IdleEventNotifierTest, PowerSourceNotChanged) {
base::Time now = task_runner_->Now();
base::Time now = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->PowerChanged(ac_power_);
IdleEventNotifier::ActivityData data;
data.last_activity_day = GetDayOfWeek(now);
......@@ -158,7 +158,7 @@ TEST_F(IdleEventNotifierTest, PowerSourceNotChanged) {
data.recent_time_active = base::TimeDelta();
ReportIdleEventAndCheckResults(1, data);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
idle_event_notifier_->PowerChanged(ac_power_);
ReportIdleEventAndCheckResults(2, data);
}
......@@ -166,7 +166,7 @@ TEST_F(IdleEventNotifierTest, PowerSourceNotChanged) {
// PowerChanged signal is received and source is changed, so a different
// ActivityData gets reported when the 2nd idle event is received.
TEST_F(IdleEventNotifierTest, PowerSourceChanged) {
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->PowerChanged(ac_power_);
IdleEventNotifier::ActivityData data_1;
data_1.last_activity_day = GetDayOfWeek(now_1);
......@@ -176,8 +176,8 @@ TEST_F(IdleEventNotifierTest, PowerSourceChanged) {
data_1.recent_time_active = base::TimeDelta();
ReportIdleEventAndCheckResults(1, data_1);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(100));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(100));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->PowerChanged(disconnected_power_);
IdleEventNotifier::ActivityData data_2;
data_2.last_activity_day = GetDayOfWeek(now_2);
......@@ -190,15 +190,15 @@ TEST_F(IdleEventNotifierTest, PowerSourceChanged) {
// Short sleep duration does not break up recent time active.
TEST_F(IdleEventNotifierTest, ShortSuspendDone) {
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->PowerChanged(ac_power_);
task_runner_->FastForwardBy(IdleEventNotifier::kIdleDelay / 2);
scoped_task_env_.FastForwardBy(IdleEventNotifier::kIdleDelay / 2);
idle_event_notifier_->SuspendDone(IdleEventNotifier::kIdleDelay / 2);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(5));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(5));
idle_event_notifier_->PowerChanged(disconnected_power_);
base::Time now_2 = task_runner_->Now();
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
IdleEventNotifier::ActivityData data;
data.last_activity_day = GetDayOfWeek(now_2);
......@@ -213,14 +213,14 @@ TEST_F(IdleEventNotifierTest, ShortSuspendDone) {
TEST_F(IdleEventNotifierTest, LongSuspendDone) {
idle_event_notifier_->PowerChanged(ac_power_);
task_runner_->FastForwardBy(IdleEventNotifier::kIdleDelay +
base::TimeDelta::FromSeconds(10));
base::Time now_1 = task_runner_->Now();
scoped_task_env_.FastForwardBy(IdleEventNotifier::kIdleDelay +
base::TimeDelta::FromSeconds(10));
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->SuspendDone(IdleEventNotifier::kIdleDelay +
base::TimeDelta::FromSeconds(10));
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->PowerChanged(disconnected_power_);
IdleEventNotifier::ActivityData data;
......@@ -233,7 +233,7 @@ TEST_F(IdleEventNotifierTest, LongSuspendDone) {
}
TEST_F(IdleEventNotifierTest, UserActivityKey) {
base::Time now = task_runner_->Now();
base::Time now = scoped_task_env_.GetMockClock()->Now();
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
idle_event_notifier_->OnUserActivity(&key_event);
IdleEventNotifier::ActivityData data;
......@@ -244,12 +244,12 @@ TEST_F(IdleEventNotifierTest, UserActivityKey) {
data.recent_time_active = base::TimeDelta();
data.time_since_last_key = base::TimeDelta::FromSeconds(10);
data.key_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, UserActivityMouse) {
base::Time now = task_runner_->Now();
base::Time now = scoped_task_env_.GetMockClock()->Now();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
......@@ -262,12 +262,12 @@ TEST_F(IdleEventNotifierTest, UserActivityMouse) {
data.recent_time_active = base::TimeDelta();
data.time_since_last_mouse = base::TimeDelta::FromSeconds(10);
data.mouse_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, UserActivityOther) {
base::Time now = task_runner_->Now();
base::Time now = scoped_task_env_.GetMockClock()->Now();
ui::GestureEvent gesture_event(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
......@@ -278,20 +278,20 @@ TEST_F(IdleEventNotifierTest, UserActivityOther) {
data.last_activity_time_of_day = time_of_day;
data.last_user_activity_time_of_day = time_of_day;
data.recent_time_active = base::TimeDelta();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data);
}
// Two consecutive activities separated by 2sec only. Only 1 idle event with
// different timestamps for the two activities.
TEST_F(IdleEventNotifierTest, TwoQuickUserActivities) {
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
idle_event_notifier_->OnUserActivity(&key_event);
......@@ -306,22 +306,22 @@ TEST_F(IdleEventNotifierTest, TwoQuickUserActivities) {
base::TimeDelta::FromSeconds(10) + (now_2 - now_1);
data.key_events_in_last_hour = 1;
data.mouse_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, ActivityAfterVideoStarts) {
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(1));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(1));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_3 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data;
......@@ -333,17 +333,17 @@ TEST_F(IdleEventNotifierTest, ActivityAfterVideoStarts) {
data.video_playing_time = now_3 - now_1;
data.time_since_video_ended = base::TimeDelta::FromSeconds(10);
data.mouse_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, IdleEventFieldReset) {
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
idle_event_notifier_->OnUserActivity(&key_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
idle_event_notifier_->OnUserActivity(&mouse_event);
......@@ -358,11 +358,11 @@ TEST_F(IdleEventNotifierTest, IdleEventFieldReset) {
data_1.time_since_last_mouse = base::TimeDelta::FromSeconds(10);
data_1.key_events_in_last_hour = 1;
data_1.mouse_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data_1);
idle_event_notifier_->PowerChanged(ac_power_);
base::Time now_3 = task_runner_->Now();
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
IdleEventNotifier::ActivityData data_2;
data_2.last_activity_day = GetDayOfWeek(now_3);
......@@ -375,28 +375,28 @@ TEST_F(IdleEventNotifierTest, IdleEventFieldReset) {
base::TimeDelta::FromSeconds(20) + now_3 - now_2;
data_2.key_events_in_last_hour = 1;
data_2.mouse_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
ReportIdleEventAndCheckResults(2, data_2);
}
TEST_F(IdleEventNotifierTest, TwoConsecutiveVideoPlaying) {
// Two video playing sessions with a gap shorter than kIdleDelay. They are
// merged into one playing session.
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
idle_event_notifier_->OnVideoActivityEnded();
task_runner_->FastForwardBy(IdleEventNotifier::kIdleDelay / 2);
scoped_task_env_.FastForwardBy(IdleEventNotifier::kIdleDelay / 2);
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_3 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
idle_event_notifier_->OnUserActivity(&mouse_event);
......@@ -411,30 +411,30 @@ TEST_F(IdleEventNotifierTest, TwoConsecutiveVideoPlaying) {
data.video_playing_time = now_2 - now_1;
data.time_since_video_ended =
base::TimeDelta::FromSeconds(25) + now_3 - now_2;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(25));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(25));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, TwoVideoPlayingFarApartOneIdleEvent) {
// Two video playing sessions with a gap larger than kIdleDelay.
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
idle_event_notifier_->OnVideoActivityEnded();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
gfx::Point(0, 0), base::TimeTicks(), 0, 0);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
idle_event_notifier_->OnUserActivity(&mouse_event);
base::Time now_2 = task_runner_->Now();
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_3 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data;
......@@ -446,18 +446,18 @@ TEST_F(IdleEventNotifierTest, TwoVideoPlayingFarApartOneIdleEvent) {
data.mouse_events_in_last_hour = 2;
data.video_playing_time = now_3 - now_2;
data.time_since_video_ended = base::TimeDelta::FromSeconds(25);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(25));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(25));
ReportIdleEventAndCheckResults(1, data);
}
TEST_F(IdleEventNotifierTest, TwoVideoPlayingFarApartTwoIdleEvents) {
// Two video playing sessions with a gap equal to kIdleDelay. An idle event
// is generated in between, both video sessions are reported.
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data_1;
......@@ -467,14 +467,14 @@ TEST_F(IdleEventNotifierTest, TwoVideoPlayingFarApartTwoIdleEvents) {
data_1.video_playing_time = now_2 - now_1;
data_1.time_since_video_ended =
IdleEventNotifier::kIdleDelay + base::TimeDelta::FromSeconds(10);
task_runner_->FastForwardBy(IdleEventNotifier::kIdleDelay +
base::TimeDelta::FromSeconds(10));
scoped_task_env_.FastForwardBy(IdleEventNotifier::kIdleDelay +
base::TimeDelta::FromSeconds(10));
ReportIdleEventAndCheckResults(1, data_1);
base::Time now_3 = task_runner_->Now();
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_4 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_4 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data_2;
......@@ -489,11 +489,11 @@ TEST_F(IdleEventNotifierTest, TwoVideoPlayingFarApartTwoIdleEvents) {
TEST_F(IdleEventNotifierTest, TwoVideoPlayingSeparatedByAnIdleEvent) {
// Two video playing sessions with gap shorter than kIdleDelay but separated
// by an idle event. They are considered as two video sessions.
const base::Time kNow1 = task_runner_->Now();
const base::Time kNow1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
const base::Time kNow2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(2));
const base::Time kNow2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data_1;
......@@ -502,13 +502,13 @@ TEST_F(IdleEventNotifierTest, TwoVideoPlayingSeparatedByAnIdleEvent) {
data_1.recent_time_active = kNow2 - kNow1;
data_1.video_playing_time = kNow2 - kNow1;
data_1.time_since_video_ended = base::TimeDelta::FromSeconds(1);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(1));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(1));
ReportIdleEventAndCheckResults(1, data_1);
const base::Time kNow3 = task_runner_->Now();
const base::Time kNow3 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
const base::Time kNow4 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
const base::Time kNow4 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data_2;
......@@ -521,15 +521,15 @@ TEST_F(IdleEventNotifierTest, TwoVideoPlayingSeparatedByAnIdleEvent) {
}
TEST_F(IdleEventNotifierTest, VideoPlayingPausedByShortSuspend) {
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(100));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(100));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->SuspendDone(IdleEventNotifier::kIdleDelay / 2);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_3 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_3 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data;
......@@ -545,12 +545,12 @@ TEST_F(IdleEventNotifierTest, VideoPlayingPausedByShortSuspend) {
TEST_F(IdleEventNotifierTest, VideoPlayingPausedByLongSuspend) {
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(2 * IdleEventNotifier::kIdleDelay);
base::Time now_1 = task_runner_->Now();
scoped_task_env_.FastForwardBy(2 * IdleEventNotifier::kIdleDelay);
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->SuspendDone(2 * IdleEventNotifier::kIdleDelay);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_2 = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(20));
base::Time now_2 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data;
......@@ -571,37 +571,37 @@ TEST_F(IdleEventNotifierTest, UserInputEventsOneIdleEvent) {
ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), base::TimeTicks::UnixEpoch(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
base::Time first_activity_time = task_runner_->Now();
base::Time first_activity_time = scoped_task_env_.GetMockClock()->Now();
// This key event will be too old to be counted.
idle_event_notifier_->OnUserActivity(&key_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_start_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_start_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_key_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_key_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&key_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_touch_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_touch_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_mouse_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_mouse_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_end_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_end_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data;
......@@ -622,7 +622,7 @@ TEST_F(IdleEventNotifierTest, UserInputEventsOneIdleEvent) {
data.mouse_events_in_last_hour = 2;
data.touch_events_in_last_hour = 3;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(30));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(30));
ReportIdleEventAndCheckResults(1, data);
}
......@@ -634,7 +634,7 @@ TEST_F(IdleEventNotifierTest, UserInputEventsTwoIdleEvents) {
ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), base::TimeTicks::UnixEpoch(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
base::Time now_1 = task_runner_->Now();
base::Time now_1 = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&key_event);
IdleEventNotifier::ActivityData data_1;
......@@ -644,37 +644,37 @@ TEST_F(IdleEventNotifierTest, UserInputEventsTwoIdleEvents) {
data_1.recent_time_active = base::TimeDelta();
data_1.time_since_last_key = base::TimeDelta::FromSeconds(30);
data_1.key_events_in_last_hour = 1;
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(30));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(30));
ReportIdleEventAndCheckResults(1, data_1);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_key_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_key_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&key_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_start_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_start_time = scoped_task_env_.GetMockClock()->Now();
// Keep playing video so we won't run into an idle event.
idle_event_notifier_->OnVideoActivityStarted();
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_touch_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_touch_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&touch_event);
task_runner_->FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_mouse_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromMinutes(11));
base::Time last_mouse_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnUserActivity(&mouse_event);
task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_end_time = task_runner_->Now();
scoped_task_env_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::Time video_end_time = scoped_task_env_.GetMockClock()->Now();
idle_event_notifier_->OnVideoActivityEnded();
IdleEventNotifier::ActivityData data_2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment