chromium/chrome/browser/enterprise/idle/idle_service_interactive_uitest.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/idle/dialog_manager.h"
#include "chrome/browser/enterprise/idle/idle_service.h"
#include "chrome/browser/policy/profile_policy_connector_builder.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/idle_bubble.h"
#include "chrome/browser/ui/profiles/profile_picker.h"
#include "chrome/browser/ui/profiles/profile_ui_test_utils.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/user_education/user_education_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/testing_profile.h"
#include "components/enterprise/idle/idle_pref_names.h"
#include "components/enterprise/idle/metrics.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/idle/idle_polling_service.h"
#include "ui/base/idle/idle_time_provider.h"
#include "ui/base/ozone_buildflags.h"
#include "ui/base/test/idle_test_utils.h"

TestMockTimeTaskRunner;
_;
ElementsAre;
IsEmpty;
Not;
Return;

namespace {

class MockIdleTimeProvider : public ui::IdleTimeProvider {};

class BrowserCloseWaiter : public BrowserListObserver {};

}  // namespace

namespace enterprise_idle {

class IdleServiceTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(IdleServiceTest, Basic) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, DidNotClose) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, TenMinutes) {}

// TODO(crbug.com/40853067): Test flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_MultiProfile
#else
#define MAYBE_MultiProfile
#endif
IN_PROC_BROWSER_TEST_F(IdleServiceTest, MAYBE_MultiProfile) {}

// TODO(crbug.com/40064501): Flaky on MacOS
#if BUILDFLAG(IS_MAC)
#define MAYBE_MultiProfileWithDifferentThresholds
#else
#define MAYBE_MultiProfileWithDifferentThresholds
#endif
IN_PROC_BROWSER_TEST_F(IdleServiceTest,
                       MAYBE_MultiProfileWithDifferentThresholds) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, DialogDismissedByUser) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, NoActions) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, JustCloseBrowsers) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, JustShowProfilePicker) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, ReloadPages) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, ShowBubbleImmediately) {}

// It should be possible to focus the bubble with the "focus dialog" hotkey
// combination (Alt+Shift+A).
// TODO(crbug.com/40856612): Probably flaky on macOS.
#if BUILDFLAG(IS_MAC)
#define MAYBE_CanFocusBubbleWithFocusDialogHotkey
#else
#define MAYBE_CanFocusBubbleWithFocusDialogHotkey
#endif
IN_PROC_BROWSER_TEST_F(IdleServiceTest,
                       MAYBE_CanFocusBubbleWithFocusDialogHotkey) {}

// It should be possible to focus the bubble with the "rotate pane focus" (F6)
// hotkey.
// TODO(crbug.com/40852599): Probably flaky on macOS.
#if BUILDFLAG(IS_MAC)
#define MAYBE_CanFocusBubbleWithRotatePaneFocusHotkey
#else
#define MAYBE_CanFocusBubbleWithRotatePaneFocusHotkey
#endif
IN_PROC_BROWSER_TEST_F(IdleServiceTest,
                       MAYBE_CanFocusBubbleWithRotatePaneFocusHotkey) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, PRE_ShowBubbleOnStartup) {}

IN_PROC_BROWSER_TEST_F(IdleServiceTest, ShowBubbleOnStartup) {}

}  // namespace enterprise_idle