Commit feae6e0e authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

Revert "Reland "Notification scheduler: Add a browser test.""

This reverts commit 2eda3ac7.

Reason for revert: continues to fail on Linux Tests Builder.
https://ci.chromium.org/p/chromium/builders/ci/Linux%20Tests

Original change's description:
> Reland "Notification scheduler: Add a browser test."
> 
> Reverted in
> https://chromium-review.googlesource.com/c/chromium/src/+/1787277
> due to flakiness on chromeos builders.
> 
> This CL tries to reland the browser test that the test seems no longer
> failed on those trybots. Also can't reproduce the test failure on
> local machine with linux-chromeos build.
> 
> TBR=dtrainor@chromium.org
> 
> Bug: 1001003,963295
> Change-Id: Ia1b553aa46f9256b9a94004d2426cf35bc9bf4e6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793821
> Reviewed-by: Xing Liu <xingliu@chromium.org>
> Commit-Queue: Xing Liu <xingliu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#695001}

TBR=dtrainor@chromium.org,xingliu@chromium.org,hesen@chromium.org

Change-Id: I3bf84db4e976a7c79a79122dd14282d7ee73f61d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1001003, 963295
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1795522Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695099}
parent 0619fe67
// 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 <memory>
#include <set>
#include <string>
#include <utility>
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/notifications/scheduler/notification_background_task_scheduler_impl.h"
#include "chrome/browser/notifications/scheduler/public/display_agent.h"
#include "chrome/browser/notifications/scheduler/public/features.h"
#include "chrome/browser/notifications/scheduler/public/notification_params.h"
#include "chrome/browser/notifications/scheduler/public/notification_schedule_service.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_client.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_client_registrar.h"
#include "chrome/browser/notifications/scheduler/schedule_service_factory_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
namespace notifications {
namespace {
const base::FilePath::CharType kTestDir[] =
FILE_PATH_LITERAL("NotificationScheduleServiceTest");
class TestClient : public NotificationSchedulerClient {
public:
TestClient() {}
~TestClient() override = default;
private:
// NotificationSchedulerClient implementation.
void BeforeShowNotification(
std::unique_ptr<NotificationData> notification_data,
NotificationDataCallback callback) override {
std::move(callback).Run(std::move(notification_data));
}
void OnSchedulerInitialized(bool success,
std::set<std::string> guids) override {}
void OnUserAction(const UserActionData& action_data) override {}
DISALLOW_COPY_AND_ASSIGN(TestClient);
};
class TestBackgroundTaskScheduler : public NotificationBackgroundTaskScheduler {
public:
TestBackgroundTaskScheduler() = default;
~TestBackgroundTaskScheduler() override = default;
// Waits until a background task has been updated.
void WaitForTaskUpdated() {
DCHECK(!run_loop_);
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
base::TimeDelta window_start() { return window_start_; }
private:
void QuitRunLoopIfNeeded() {
if (run_loop_ && run_loop_->running()) {
run_loop_->Quit();
}
}
// NotificationBackgroundTaskScheduler implementation.
void Schedule(notifications::SchedulerTaskTime scheduler_task_time,
base::TimeDelta window_start,
base::TimeDelta window_end) override {
QuitRunLoopIfNeeded();
}
void Cancel() override { QuitRunLoopIfNeeded(); }
base::TimeDelta window_start_;
std::unique_ptr<base::RunLoop> run_loop_;
DISALLOW_COPY_AND_ASSIGN(TestBackgroundTaskScheduler);
};
// Browser test for notification scheduling system. Uses real database
// instances. Mainly to cover service initialization flow in chrome layer.
class NotificationScheduleServiceTest : public InProcessBrowserTest {
public:
NotificationScheduleServiceTest() : task_scheduler_(nullptr) {
scoped_feature_list_.InitWithFeatures(
{features::kNotificationScheduleService}, {});
}
~NotificationScheduleServiceTest() override {}
protected:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
}
void TearDownOnMainThread() override {
InProcessBrowserTest::TearDownOnMainThread();
ASSERT_TRUE(tmp_dir_.Delete());
}
// Initializes |service_|. Injects database test data before this call.
void Init() {
auto* profile = browser()->profile();
auto client = std::make_unique<TestClient>();
auto client_registrar =
std::make_unique<NotificationSchedulerClientRegistrar>();
client_registrar->RegisterClient(SchedulerClientType::kTest1,
std::move(client));
auto display_agent = notifications::DisplayAgent::Create();
auto background_task_scheduler =
std::make_unique<TestBackgroundTaskScheduler>();
task_scheduler_ = background_task_scheduler.get();
auto* db_provider =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetProtoDatabaseProvider();
NotificationScheduleService* service =
static_cast<NotificationScheduleService*>(
CreateNotificationScheduleService(
std::move(client_registrar),
std::move(background_task_scheduler), std::move(display_agent),
db_provider, tmp_dir_.GetPath().Append(kTestDir),
profile->IsOffTheRecord()));
service_ = std::unique_ptr<NotificationScheduleService>(service);
}
NotificationScheduleService* schedule_service() { return service_.get(); }
TestBackgroundTaskScheduler* task_scheduler() {
DCHECK(task_scheduler_);
return task_scheduler_;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
base::ScopedTempDir tmp_dir_;
std::unique_ptr<NotificationScheduleService> service_;
TestBackgroundTaskScheduler* task_scheduler_;
DISALLOW_COPY_AND_ASSIGN(NotificationScheduleServiceTest);
};
// Test to schedule a notification.
IN_PROC_BROWSER_TEST_F(NotificationScheduleServiceTest, ScheduleNotification) {
Init();
ScheduleParams schedule_params;
schedule_params.deliver_time_start = base::Time::Now();
schedule_params.deliver_time_end =
base::Time::Now() + base::TimeDelta::FromMinutes(5);
NotificationData data;
data.title = base::UTF8ToUTF16("title");
data.message = base::UTF8ToUTF16("message");
auto params = std::make_unique<notifications::NotificationParams>(
notifications::SchedulerClientType::kTest1, std::move(data),
std::move(schedule_params));
schedule_service()->Schedule(std::move(params));
// A background task should be scheduled.
task_scheduler()->WaitForTaskUpdated();
EXPECT_LE(task_scheduler()->window_start(), base::TimeDelta::FromMinutes(5));
}
} // namespace
} // namespace notifications
......@@ -42,10 +42,9 @@ class NotificationScheduleService : public KeyedService {
// Returns the user action handler to process notification events.
virtual UserActionHandler* GetUserActionHandler() = 0;
~NotificationScheduleService() override = default;
protected:
NotificationScheduleService() = default;
~NotificationScheduleService() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(NotificationScheduleService);
......
......@@ -983,7 +983,6 @@ if (!is_android) {
"../browser/net/websocket_browsertest.cc",
"../browser/no_best_effort_tasks_browsertest.cc",
"../browser/no_best_effort_tasks_during_startup_browsertest.cc",
"../browser/notifications/scheduler/notification_schedule_service_browsertest.cc",
"../browser/ntp_snippets/content_suggestions_service_factory_browsertest.cc",
"../browser/ntp_tiles/ntp_tiles_browsertest.cc",
"../browser/optimization_guide/optimization_guide_keyed_service_browsertest.cc",
......
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