Commit 4594dbd8 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Notification scheduler]: Create MockNotificationBackgroundTaskScheduler

- Start working on all mock objects for scheduler.
- Moved this class under scheduler/tests.

Bug: 963304
Change-Id: I72ea3ed88028681acde31e4c80bfa8f095b22a74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716088
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680243}
parent 04060a20
......@@ -15,8 +15,8 @@
#include "chrome/browser/notifications/scheduler/internal/scheduler_config.h"
#include "chrome/browser/notifications/scheduler/public/notification_background_task_scheduler.h"
#include "chrome/browser/notifications/scheduler/test/fake_clock.h"
#include "chrome/browser/notifications/scheduler/test/mock_notification_background_task_scheduler.h"
#include "chrome/browser/notifications/scheduler/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
......@@ -44,21 +44,6 @@ const std::vector<test::ImpressionTestData> kClientsImpressionTestData = {
{},
base::nullopt /* suppression_info */}};
class MockNotificationBackgroundTaskScheduler
: public NotificationBackgroundTaskScheduler {
public:
MockNotificationBackgroundTaskScheduler() = default;
~MockNotificationBackgroundTaskScheduler() override = default;
MOCK_METHOD3(Schedule,
void(notifications::SchedulerTaskTime,
base::TimeDelta,
base::TimeDelta));
MOCK_METHOD0(Cancel, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockNotificationBackgroundTaskScheduler);
};
base::TimeDelta NoopTimeRandomizer(const base::TimeDelta& time_window) {
return base::TimeDelta();
}
......@@ -89,14 +74,14 @@ class BackgroundTaskCoordinatorTest : public testing::Test {
config_.suppression_duration = base::TimeDelta::FromDays(3);
auto background_task =
std::make_unique<MockNotificationBackgroundTaskScheduler>();
std::make_unique<test::MockNotificationBackgroundTaskScheduler>();
background_task_ = background_task.get();
coordinator_ = std::make_unique<BackgroundTaskCoordinator>(
std::move(background_task), &config_,
base::BindRepeating(&NoopTimeRandomizer, base::TimeDelta()), &clock_);
}
MockNotificationBackgroundTaskScheduler* background_task() {
test::MockNotificationBackgroundTaskScheduler* background_task() {
return background_task_;
}
......@@ -148,7 +133,7 @@ class BackgroundTaskCoordinatorTest : public testing::Test {
test::FakeClock clock_;
SchedulerConfig config_;
std::unique_ptr<BackgroundTaskCoordinator> coordinator_;
MockNotificationBackgroundTaskScheduler* background_task_;
test::MockNotificationBackgroundTaskScheduler* background_task_;
TestData test_data_;
std::map<SchedulerClientType, std::unique_ptr<ClientState>> client_states_;
......
......@@ -9,12 +9,15 @@ if (is_android) {
}
source_set("test_lib") {
testonly = true
visibility =
[ "//chrome/browser/notifications/scheduler/internal:unit_tests" ]
sources = [
"fake_clock.cc",
"fake_clock.h",
"mock_notification_background_task_scheduler.cc",
"mock_notification_background_task_scheduler.h",
"test_utils.cc",
"test_utils.h",
]
......@@ -24,5 +27,7 @@ source_set("test_lib") {
"//chrome/browser/notifications/scheduler/internal:lib",
"//chrome/browser/notifications/scheduler/public",
"//skia",
"//testing/gmock",
"//testing/gtest",
]
}
// Copyright 2019 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 "chrome/browser/notifications/scheduler/test/mock_notification_background_task_scheduler.h"
namespace notifications {
namespace test {
MockNotificationBackgroundTaskScheduler::
MockNotificationBackgroundTaskScheduler() = default;
MockNotificationBackgroundTaskScheduler::
~MockNotificationBackgroundTaskScheduler() = default;
} // namespace test
} // namespace notifications
// Copyright 2019 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.
#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_TEST_MOCK_NOTIFICATION_BACKGROUND_TASK_SCHEDULER_H_
#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_TEST_MOCK_NOTIFICATION_BACKGROUND_TASK_SCHEDULER_H_
#include "chrome/browser/notifications/scheduler/public/notification_background_task_scheduler.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace notifications {
namespace test {
class MockNotificationBackgroundTaskScheduler
: public NotificationBackgroundTaskScheduler {
public:
MockNotificationBackgroundTaskScheduler();
~MockNotificationBackgroundTaskScheduler() override;
MOCK_METHOD3(Schedule,
void(notifications::SchedulerTaskTime,
base::TimeDelta,
base::TimeDelta));
MOCK_METHOD0(Cancel, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockNotificationBackgroundTaskScheduler);
};
} // namespace test
} // namespace notifications
#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_TEST_MOCK_NOTIFICATION_BACKGROUND_TASK_SCHEDULER_H_
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