chromium/chrome/browser/enterprise/idle/action_runner_unittest.cc

// Copyright 2022 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/enterprise/idle/action_runner.h"

#include "base/memory/raw_ptr.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/enterprise/idle/action.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/enterprise/idle/idle_pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/test/views/chrome_views_test_base.h"
#endif  // !BUILDFLAG(IS_ANDROID)

namespace enterprise_idle {

BrowsingDataRemover;

_;
IsEmpty;
Return;
UnorderedElementsAre;

namespace {

class FakeActionFactory : public ActionFactory {};

class MockAction : public Action {};

// testing::InvokeArgument<N> does not work with base::OnceCallback, so we
// define our own gMock action to run the 2nd argument.
ACTION_P(RunContinuation, success) {}

}  // namespace

// TODO(crbug.com/40222234): Enable this when Android supports >1 Action.
#if !BUILDFLAG(IS_ANDROID)
// Tests that actions are run in sequence, in order of priority.
TEST(IdleActionRunnerTest, RunsActionsInSequence) {}

// Tests that the order of actions in the pref doesn't matter. They still run
// by order of priority.
TEST(IdleActionRunnerTest, PrefOrderDoesNotMatter) {}

// Tests that when a higher-priority action fails, the lower-priority actions
// don't run.
TEST(IdleActionRunnerTest, OtherActionsDontRunOnFailure) {}
#endif  // !BUILDFLAG(IS_ANDROID)

// Tests that it does nothing when the "IdleTimeoutActions" pref is empty.
TEST(IdleActionRunnerTest, DoNothingWithEmptyPref) {}

// TODO(crbug.com/40222234): Enable this when Android supports >1 Action.
#if !BUILDFLAG(IS_ANDROID)
// Tests that ActionRunner only runs the actions configured via the
// "IdleTimeoutActions" pref.
TEST(IdleActionRunnerTest, JustCloseBrowsers) {}

// Tests that ActionRunner only runs the actions configured via the
// "IdleTimeoutActions" pref.
TEST(IdleActionRunnerTest, JustShowProfilePicker) {}
#endif  // !BUILDFLAG(IS_ANDROID)

// A basic implementation of BrowsingDataRemover, that doesn't remove any data.
//
// Doesn't use gmock methods, since we could technically accept any of the 4
// Remove*() methods. Instead, it saves the arguments for BrowsingDataRemover's
class FakeBrowsingDataRemover : public BrowsingDataRemover {};

#if !BUILDFLAG(IS_ANDROID)
class IdleActionRunnerClearDataTest : public ChromeViewsTestBase {};

TEST_F(IdleActionRunnerClearDataTest, ClearBrowsingHistory) {}

TEST_F(IdleActionRunnerClearDataTest, ClearDownloadHistory) {}

TEST_F(IdleActionRunnerClearDataTest, ClearCookies) {}

TEST_F(IdleActionRunnerClearDataTest, ClearCache) {}

TEST_F(IdleActionRunnerClearDataTest, ClearPasswordSignin) {}

TEST_F(IdleActionRunnerClearDataTest, ClearAutofill) {}

TEST_F(IdleActionRunnerClearDataTest, ClearSiteSettings) {}

TEST_F(IdleActionRunnerClearDataTest, ClearHostedAppData) {}

TEST_F(IdleActionRunnerClearDataTest, MultipleTypes) {}

TEST_F(IdleActionRunnerClearDataTest, MultipleTypesAndFailure) {}
#endif  // !BUILDFLAG(IS_ANDROID)

}  // namespace enterprise_idle