#include "components/sync_sessions/local_session_event_handler_impl.h"
#include <map>
#include <utility>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "components/sync/base/features.h"
#include "components/sync/base/time.h"
#include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync_sessions/mock_sync_sessions_client.h"
#include "components/sync_sessions/synced_session_tracker.h"
#include "components/sync_sessions/test_matchers.h"
#include "components/sync_sessions/test_synced_window_delegates_getter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_sessions {
namespace {
SerializedNavigationEntry;
SerializedNavigationEntryTestHelper;
_;
ByMove;
IsEmpty;
NiceMock;
Pointee;
Return;
StrictMock;
const char kFoo1[] = …;
const char kBar1[] = …;
const char kBar2[] = …;
const char kBaz1[] = …;
const char kSessionTag[] = …;
const char kSessionName[] = …;
const base::Time kTime0 = …;
const base::Time kTime1 = …;
const base::Time kTime2 = …;
const base::Time kTime3 = …;
const int kWindowId1 = …;
const int kWindowId2 = …;
const int kWindowId3 = …;
const int kTabId1 = …;
const int kTabId2 = …;
const int kTabId3 = …;
sync_pb::SessionSpecifics MakeSessionTabSpecifics(int window_id,
int tab_id,
int tab_node_id) { … }
sync_pb::SessionSpecifics MakeSessionHeaderSpecifics(
const std::map<int, std::vector<int>>& window_id_to_tabs) { … }
class MockWriteBatch : public LocalSessionEventHandlerImpl::WriteBatch { … };
class MockDelegate : public LocalSessionEventHandlerImpl::Delegate { … };
class LocalSessionEventHandlerImplTest : public testing::Test { … };
TEST_F(LocalSessionEventHandlerImplTest, GetTabSpecificsFromDelegate) { … }
TEST_F(LocalSessionEventHandlerImplTest, BrowserTypeInTabSpecifics) { … }
TEST_F(LocalSessionEventHandlerImplTest,
SetSessionTabFromDelegateNavigationIndex) { … }
TEST_F(LocalSessionEventHandlerImplTest,
SetSessionTabFromDelegateCurrentInvalid) { … }
TEST_F(LocalSessionEventHandlerImplTest, BlockedNavigations) { … }
TEST_F(LocalSessionEventHandlerImplTest, AssociateWindowsAndTabsIfEmpty) { … }
TEST_F(LocalSessionEventHandlerImplTest, AssociateWindowsAndTabs) { … }
TEST_F(LocalSessionEventHandlerImplTest, DontUpdateWindowIdForPlaceholderTab) { … }
TEST_F(LocalSessionEventHandlerImplTest,
DeferAssociationDueToInitialSessionRestore) { … }
TEST_F(LocalSessionEventHandlerImplTest,
DeferAssociationDueToLateSessionRestore) { … }
TEST_F(LocalSessionEventHandlerImplTest, AssociateCustomTab) { … }
TEST_F(LocalSessionEventHandlerImplTest, PropagateNewNavigation) { … }
TEST_F(LocalSessionEventHandlerImplTest, PropagateNewTab) { … }
TEST_F(LocalSessionEventHandlerImplTest, PropagateClosedTab) { … }
TEST_F(LocalSessionEventHandlerImplTest, PropagateNewCustomTab) { … }
TEST_F(LocalSessionEventHandlerImplTest, PropagateNewWindow) { … }
TEST_F(LocalSessionEventHandlerImplTest,
PropagateNewNavigationWithoutTabbedWindows) { … }
TEST_F(LocalSessionEventHandlerImplTest, ShouldRemoveAllTabsOnEmptyWindow) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(LocalSessionEventHandlerImplTest, LoadPlaceholderTabFromDisk) {
TestSyncedWindowDelegate* window = AddWindow(kWindowId1);
PlaceholderTabDelegate placeholder_tab(
SessionID::FromSerializedValue(kTabId1));
auto snapshot = std::make_unique<TestSyncedTabDelegate>(
SessionID::FromSerializedValue(kWindowId1),
SessionID::FromSerializedValue(kTabId1), base::DoNothing());
snapshot->Navigate(kFoo1);
placeholder_tab.SetPlaceholderTabSyncedTabDelegate(std::move(snapshot));
window->OverrideTabAt(0, &placeholder_tab);
auto mock_batch = std::make_unique<StrictMock<MockWriteBatch>>();
EXPECT_CALL(
*mock_batch,
Put(Pointee(MatchesHeader(kSessionTag, {kWindowId1}, {kTabId1}))));
EXPECT_CALL(*mock_batch, Put(Pointee(MatchesTab(kSessionTag, kWindowId1,
kTabId1, 0,
{kFoo1}))));
EXPECT_CALL(*mock_batch, Commit());
EXPECT_CALL(mock_delegate_, CreateLocalSessionWriteBatch())
.WillOnce(Return(ByMove(std::move(mock_batch))));
InitHandler();
}
#endif
}
}