#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include <stddef.h>
#include <algorithm>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/features.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_model.h"
#include "chrome/browser/ui/tabs/tab_strip_user_gesture_details.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/test_util.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
WebContents;
namespace {
const char kTabStripModelTestIDUserDataKey[] = …;
class TabStripModelTestIDUserData : public base::SupportsUserData::Data { … };
class MockTabStripModelObserver : public TabStripModelObserver { … };
const char* const MockTabStripModelObserver::State::kActionNames[]{ … };
}
class TabStripModelTest : public testing::Test,
public ::testing::WithParamInterface<bool> { … };
TEST_P(TabStripModelTest, TestBasicAPI) { … }
TEST_P(TabStripModelTest, TestTabHandlesStaticTabstrip) { … }
TEST_P(TabStripModelTest, TestTabHandlesMovingTabInSameTabstrip) { … }
TEST_P(TabStripModelTest, TestTabHandlesTabClosed) { … }
TEST_P(TabStripModelTest, TestTabHandlesOutOfBounds) { … }
TEST_P(TabStripModelTest, TestTabHandlesAcrossModels) { … }
TEST_P(TabStripModelTest, TestBasicOpenerAPI) { … }
static int GetInsertionIndex(TabStripModel* tabstrip) { … }
static void InsertWebContentses(TabStripModel* tabstrip,
std::unique_ptr<WebContents> contents1,
std::unique_ptr<WebContents> contents2,
std::unique_ptr<WebContents> contents3) { … }
static bool IsSiteInContentSettingExceptionList(
HostContentSettingsMap* settings,
GURL& url,
ContentSettingsType type) { … }
TEST_P(TabStripModelTest, TestLTRInsertionOptions) { … }
TEST_P(TabStripModelTest, TestInsertionIndexDetermination) { … }
TEST_P(TabStripModelTest, TestInsertionIndexDeterminationAfterDragged) { … }
TEST_P(TabStripModelTest, TestInsertionIndexDeterminationNestedOpener) { … }
TEST_P(TabStripModelTest, CloseInactiveTabKeepsSelection) { … }
TEST_P(TabStripModelTest, CloseActiveTabShiftsSelectionRight) { … }
TEST_P(TabStripModelTest, CloseGroupedTabShiftsSelectionWithinGroup) { … }
TEST_P(TabStripModelTest, CollapseGroupShiftsSelection_SuccessNextTab) { … }
TEST_P(TabStripModelTest, CollapseGroupShiftsSelection_SuccessPreviousTab) { … }
TEST_P(TabStripModelTest, CollapseGroupShiftsSelection_NoAvailableTabs) { … }
TEST_P(TabStripModelTest, CloseTabWithOpenerShiftsSelectionWithinOpened) { … }
TEST_P(TabStripModelTest, CloseTabWithOpenerShiftsSelectionToOpener) { … }
TEST_P(TabStripModelTest, CommandCloseTab) { … }
TEST_P(TabStripModelTest, CommandCloseOtherTabs) { … }
TEST_P(TabStripModelTest, CommandCloseTabsToRight) { … }
TEST_P(TabStripModelTest, CommandTogglePinned) { … }
TEST_P(TabStripModelTest, CommandToggleGrouped) { … }
TEST_P(TabStripModelTest, TestContextMenuCloseCommands) { … }
TEST_P(TabStripModelTest, GetIndicesClosedByCommand) { … }
TEST_P(TabStripModelTest, AddWebContents_MiddleClickLinksAndClose) { … }
TEST_P(TabStripModelTest, AddWebContents_LeftClickPopup) { … }
TEST_P(TabStripModelTest, AddWebContents_CreateNewBlankTab) { … }
TEST_P(TabStripModelTest, AddWebContents_ForgetOpeners) { … }
TEST_P(TabStripModelTest, AddWebContents_LinkOpensInSameGroupAsOpener) { … }
TEST_P(TabStripModelTest, AddWebContents_UngroupedTabDoesNotBreakContinuity) { … }
TEST_P(TabStripModelTest, AppendContentsReselectionTest) { … }
TEST_P(TabStripModelTest, ReselectionConsidersChildrenTest) { … }
TEST_P(TabStripModelTest, NewTabAtEndOfStripInheritsOpener) { … }
TEST_P(TabStripModelTest, NavigationForgetsOpeners) { … }
TEST_P(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { … }
namespace {
class UnloadListenerTabStripModelDelegate : public TestTabStripModelDelegate { … };
}
TEST_P(TabStripModelTest, FastShutdown) { … }
TEST_P(TabStripModelTest, Pinning) { … }
TEST_P(TabStripModelTest, ReplaceSendsSelected) { … }
TEST_P(TabStripModelTest, MoveWebContentsAtWithPinned) { … }
TEST_P(TabStripModelTest, MoveTabNext) { … }
TEST_P(TabStripModelTest, MoveTabNext_Pinned) { … }
TEST_P(TabStripModelTest, MoveTabNext_Group) { … }
TEST_P(TabStripModelTest, MoveTabNext_GroupAtEnd) { … }
TEST_P(TabStripModelTest, MoveTabNext_PinnedDoesNotGroup) { … }
TEST_P(TabStripModelTest, MoveTabPrevious) { … }
TEST_P(TabStripModelTest, MoveTabPrevious_Pinned) { … }
TEST_P(TabStripModelTest, MoveTabPrevious_Group) { … }
TEST_P(TabStripModelTest, MoveTabPrevious_GroupAtEnd) { … }
TEST_P(TabStripModelTest, MoveSelectedTabsTo) { … }
TEST_P(TabStripModelTest, MoveSelectedTabsTo_ForgetOpeners) { … }
TEST_P(TabStripModelTest, CloseSelectedTabs) { … }
TEST_P(TabStripModelTest, FirstTabIsActive) { … }
TEST_P(TabStripModelTest, MultipleSelection) { … }
TEST_P(TabStripModelTest, MultipleToSingle) { … }
namespace {
class TabBlockedStateTestBrowser
: public TabStripModelObserver,
public web_modal::WebContentsModalDialogManagerDelegate { … };
class DummySingleWebContentsDialogManager
: public web_modal::SingleWebContentsDialogManager { … };
}
TEST_P(TabStripModelTest, TabBlockedState) { … }
TEST_P(TabStripModelTest, LinkClicksWithPinnedTabOrdering) { … }
TEST_P(TabStripModelTest, MoveWebContentsAt) { … }
TEST_P(TabStripModelTest, NewTabsUngrouped) { … }
TEST_P(TabStripModelTest, AddTabToNewGroup) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupUpdatesObservers) { … }
TEST_P(TabStripModelTest, ReplacingTabGroupUpdatesObservers) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupMiddleOfExistingGroup) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupMiddleOfExistingGroupTwoGroups) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupReorders) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupUnpins) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupUnpinsAndReorders) { … }
TEST_P(TabStripModelTest, AddTabToNewGroupMovesPinnedAndUnpinnedTabs) { … }
TEST_P(TabStripModelTest, AddTabToExistingGroupIdempotent) { … }
TEST_P(TabStripModelTest, AddTabToExistingGroup) { … }
TEST_P(TabStripModelTest, AddTabToExistingGroupUpdatesObservers) { … }
TEST_P(TabStripModelTest, AddTabToLeftOfExistingGroupReorders) { … }
TEST_P(TabStripModelTest, AddTabToRighOfExistingGroupReorders) { … }
TEST_P(TabStripModelTest, AddTabToExistingGroupReorders) { … }
TEST_P(TabStripModelTest, AddTabToExistingGroupUnpins) { … }
TEST_P(TabStripModelTest, PinTabInGroupUngroups) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupNoopForUngroupedTab) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroup) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupUpdatesObservers) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupMaintainsOrder) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupDoesntReorderIfNoGroup) { … }
TEST_P(TabStripModelTest,
RemoveTabFromGroupMaintainsRelativeOrderOfSelectedTabs) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupMixtureOfGroups) { … }
TEST_P(TabStripModelTest, RemoveTabFromGroupDeletesGroup) { … }
TEST_P(TabStripModelTest, AddToNewGroupDeletesGroup) { … }
TEST_P(TabStripModelTest, MoveGroupToTest) { … }
TEST_P(TabStripModelTest, AddToExistingGroupDeletesGroup) { … }
TEST_P(TabStripModelTest, CloseTabDeletesGroup) { … }
TEST_P(TabStripModelTest, CloseTabNotifiesObserversOfGroupChange) { … }
TEST_P(TabStripModelTest, InsertWebContentsAtWithGroupNotifiesObservers) { … }
TEST_P(TabStripModelTest, InsertWebContentsAtDoesNotGroupByDefault) { … }
TEST_P(TabStripModelTest, InsertWebContentsAtWithGroupGroups) { … }
TEST_P(TabStripModelTest, NewTabWithGroup) { … }
TEST_P(TabStripModelTest, NewTabWithGroupDeletedCorrectly) { … }
TEST_P(TabStripModelTest, NewTabWithoutIndexInsertsAtEndOfGroup) { … }
TEST_P(TabStripModelTest, DiscontinuousNewTabIndexTooHigh) { … }
TEST_P(TabStripModelTest, DiscontinuousNewTabIndexTooLow) { … }
TEST_P(TabStripModelTest, CreateGroupSetsVisualData) { … }
TEST_P(TabStripModelTest, SetVisualDataForGroup) { … }
TEST_P(TabStripModelTest, VisualDataChangeNotifiesObservers) { … }
TEST_P(TabStripModelTest, ObserverCanBeDestroyedEarly) { … }
TEST_P(TabStripModelTest, MovingTabToStartOfGroupDoesNotChangeGroup) { … }
TEST_P(TabStripModelTest, MovingTabToMiddleOfGroupDoesNotChangeGroup) { … }
TEST_P(TabStripModelTest, MovingTabToEndOfGroupDoesNotChangeGroup) { … }
TEST_P(TabStripModelTest, MovingTabOutsideOfGroupToStartOfTabstripClearsGroup) { … }
TEST_P(TabStripModelTest, MovingTabOutsideOfGroupToEndOfTabstripClearsGroup) { … }
TEST_P(TabStripModelTest, MovingTabBetweenUngroupedTabsClearsGroup) { … }
TEST_P(TabStripModelTest, MovingUngroupedTabBetweenGroupsDoesNotAssignGroup) { … }
TEST_P(TabStripModelTest,
MovingUngroupedTabBetweenGroupAndUngroupedDoesNotAssignGroup) { … }
TEST_P(TabStripModelTest,
MovingUngroupedTabBetweenUngroupedAndGroupDoesNotAssignGroup) { … }
TEST_P(TabStripModelTest,
MovingGroupMemberBetweenTwoDifferentGroupsClearsGroup) { … }
TEST_P(TabStripModelTest,
MovingSingleTabGroupBetweenTwoGroupsDoesNotClearGroup) { … }
TEST_P(TabStripModelTest, MovingUngroupedTabIntoGroupSetsGroup) { … }
TEST_P(TabStripModelTest, MovingGroupedTabIntoGroupChangesGroup) { … }
TEST_P(TabStripModelTest, MoveWebContentsAtCorrectlyRemovesGroupEntries) { … }
TEST_P(TabStripModelTest, MoveWebContentsAtCorrectlySendsGroupChangedEvent) { … }
TEST_P(TabStripModelTest, MoveWebContentsAtCorrectlySendsGroupClearedEvent) { … }
TEST_P(TabStripModelTest, DanglingOpener) { … }
class TabToWindowTestTabStripModelDelegate : public TestTabStripModelDelegate { … };
TEST_P(TabStripModelTest, MoveTabsToNewWindow) { … }
TEST_P(TabStripModelTest, SurroundingGroupAtIndex) { … }
TEST_P(TabStripModelTest, ActivateRecordsStartTime) { … }
TEST_P(TabStripModelTest, ToggleSiteMuted) { … }
TEST_P(TabStripModelTest, ToggleSiteMutedWithLessSpecificRule) { … }
TEST_P(TabStripModelTest, ToggleSiteMutedWithOtherDisjointRule) { … }
TEST_P(TabStripModelTest, ToggleSiteMutedWithDifferentDefault) { … }
TEST_P(TabStripModelTest, ToggleMuteUnmuteMultipleSites) { … }
TEST_P(TabStripModelTest, AppendTab) { … }
INSTANTIATE_TEST_SUITE_P(…);