#include "chrome/browser/sessions/session_service.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <vector>
#include "base/containers/adapters.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/atomic_flag.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/buildflags.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/session_service_base_test_helper.h"
#include "chrome/browser/sessions/session_service_log.h"
#include "chrome/browser/sessions/session_service_test_helper.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/sessions/content/content_serialized_navigation_builder.h"
#include "components/sessions/content/content_test_helper.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "components/sessions/core/session_command.h"
#include "components/sessions/core/session_types.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/page_state/page_state.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/skia/include/core/SkColor.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/components/kiosk/kiosk_test_utils.h"
#endif
NavigationEntry;
ContentTestHelper;
SerializedNavigationEntry;
SerializedNavigationEntryTestHelper;
class SessionServiceTest : public BrowserWithTestWindowTest { … };
TEST_F(SessionServiceTest, Basic) { … }
TEST_F(SessionServiceTest, PersistPostData) { … }
TEST_F(SessionServiceTest, ClosingTabStaysClosed) { … }
TEST_F(SessionServiceTest, CloseSingleTabClosesWindowAndTab) { … }
TEST_F(SessionServiceTest, Pruning) { … }
TEST_F(SessionServiceTest, TwoWindows) { … }
TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { … }
TEST_F(SessionServiceTest, ClosingLastWindowDoesntCloseTabs) { … }
TEST_F(SessionServiceTest, ClosingSecondWindowClosesTabs) { … }
TEST_F(SessionServiceTest, LockingWindowRemembersAll) { … }
TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { … }
TEST_F(SessionServiceTest, RemoveUnusedRestoreWindowsTest) { … }
TEST_F(SessionServiceTest, PruneFromFront) { … }
TEST_F(SessionServiceTest, PruneFromMiddle) { … }
TEST_F(SessionServiceTest, AvailableRanges) { … }
TEST_F(SessionServiceTest, PruneToEmpty) { … }
TEST_F(SessionServiceTest, PinnedDefaultsToFalse) { … }
TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { … }
TEST_F(SessionServiceTest, PinnedTrue) { … }
TEST_F(SessionServiceTest, PersistApplicationExtensionID) { … }
TEST_F(SessionServiceTest, PersistUserAgentOverrides) { … }
TEST_F(SessionServiceTest, PersistExtraData) { … }
TEST_F(SessionServiceTest, DontPersistDefault) { … }
TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { … }
TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { … }
TEST_F(SessionServiceTest, ReplacePendingNavigation) { … }
TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) { … }
TEST_F(SessionServiceTest, RestoreActivation1) { … }
TEST_F(SessionServiceTest, RestoreActivation2) { … }
TEST_F(SessionServiceTest, IgnoreBlockedUrls) { … }
TEST_F(SessionServiceTest, TabGroupDefaultsToNone) { … }
TEST_F(SessionServiceTest, TabGroupsSaved) { … }
TEST_F(SessionServiceTest, TabGroupMetadataSaved) { … }
TEST_F(SessionServiceTest, Workspace) { … }
TEST_F(SessionServiceTest, WorkspaceSavedOnOpened) { … }
TEST_F(SessionServiceTest, VisibleOnAllWorkspaces) { … }
TEST_F(SessionServiceTest, PinnedAfterReset) { … }
namespace {
void OnGotPreviousSession(
std::vector<std::unique_ptr<sessions::SessionWindow>> windows,
SessionID ignored_active_window,
bool error_reading) { … }
void SimulateWaitForTesting(const base::AtomicFlag* flag) { … }
}
TEST_F(SessionServiceTest, GetSessionsAndDestroy) { … }
TEST_F(SessionServiceTest, LogExit) { … }
TEST_F(SessionServiceTest, OnErrorWritingSessionCommands) { … }
TEST_F(SessionServiceTest, OnErrorWritingSessionCommandsUnrecoverable) { … }
TEST_F(SessionServiceTest, DisableSaving) { … }
#if BUILDFLAG(IS_CHROMEOS)
class SessionServiceKioskTest : public SessionServiceTest {
public:
void LogIn(const std::string& email) override {
chromeos::SetUpFakeKioskSession(email);
#if BUILDFLAG(IS_CHROMEOS_ASH)
ash_test_helper()->test_session_controller_client()->AddUserSession(
email, user_manager::UserType::kKioskApp);
#endif
}
};
TEST_F(SessionServiceTest, OpenedWindowNotRestored) {
helper_.SetHasOpenTrackableBrowsers(false);
service()->WindowClosing(window_id);
service()->WindowClosed(window_id);
EXPECT_TRUE(session_service_->ShouldRestore(browser()));
}
TEST_F(SessionServiceKioskTest, OpenedWindowNotRestored) {
helper_.SetHasOpenTrackableBrowsers(false);
service()->WindowClosing(window_id);
service()->WindowClosed(window_id);
EXPECT_FALSE(session_service_->ShouldRestore(browser()));
}
#endif