1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/borealis/borealis_shutdown_monitor.h"
#include <memory>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ash/borealis/borealis_context_manager_mock.h"
#include "chrome/browser/ash/borealis/borealis_features.h"
#include "chrome/browser/ash/borealis/borealis_service_fake.h"
#include "chrome/browser/ash/borealis/borealis_window_manager.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace borealis {
namespace {
class BorealisShutdownMonitorTest : public testing::Test {
protected:
BorealisShutdownMonitorTest()
: service_fake_(BorealisServiceFake::UseFakeForTesting(&profile_)),
features_(&profile_) {
borealis_window_manager_ =
std::make_unique<BorealisWindowManager>(&profile_);
service_fake_->SetFeaturesForTesting(&features_);
service_fake_->SetContextManagerForTesting(&context_manager_mock_);
service_fake_->SetWindowManagerForTesting(borealis_window_manager_.get());
}
Profile* profile() { return &profile_; }
content::BrowserTaskEnvironment task_environment_;
TestingProfile profile_;
std::unique_ptr<BorealisWindowManager> borealis_window_manager_;
raw_ptr<BorealisServiceFake> service_fake_;
BorealisFeatures features_;
testing::StrictMock<BorealisContextManagerMock> context_manager_mock_;
};
TEST_F(BorealisShutdownMonitorTest, CanShutdownImmediately) {
BorealisShutdownMonitor monitor(profile());
EXPECT_CALL(context_manager_mock_, ShutDownBorealis(testing::_));
monitor.ShutdownNow();
}
TEST_F(BorealisShutdownMonitorTest, CanShutdownWithDelay) {
BorealisShutdownMonitor monitor(profile());
monitor.SetShutdownDelayForTesting(base::Seconds(0));
monitor.ShutdownWithDelay();
EXPECT_CALL(context_manager_mock_, ShutDownBorealis(testing::_));
task_environment_.RunUntilIdle();
}
TEST_F(BorealisShutdownMonitorTest, CancelDelayedShutdownPreventsIt) {
BorealisShutdownMonitor monitor(profile());
EXPECT_CALL(context_manager_mock_, ShutDownBorealis(testing::_)).Times(0);
monitor.SetShutdownDelayForTesting(base::Seconds(0));
monitor.ShutdownWithDelay();
monitor.CancelDelayedShutdown();
task_environment_.RunUntilIdle();
}
TEST_F(BorealisShutdownMonitorTest, LaterShutdownOverridesEarlier) {
BorealisShutdownMonitor monitor(profile());
EXPECT_CALL(context_manager_mock_, ShutDownBorealis(testing::_)).Times(0);
monitor.SetShutdownDelayForTesting(base::Seconds(0));
monitor.ShutdownWithDelay();
// I'm assuming this thread won't be idle for 99 seconds.
monitor.SetShutdownDelayForTesting(base::Seconds(99));
monitor.ShutdownWithDelay();
task_environment_.RunUntilIdle();
}
TEST_F(BorealisShutdownMonitorTest, DeletingMonitorCancelsShutdowns) {
auto monitor = std::make_unique<BorealisShutdownMonitor>(profile());
EXPECT_CALL(context_manager_mock_, ShutDownBorealis(testing::_)).Times(0);
monitor->SetShutdownDelayForTesting(base::Seconds(0));
monitor->ShutdownWithDelay();
monitor.reset();
task_environment_.RunUntilIdle();
}
} // namespace
} // namespace borealis
|