chrome/browser/sync/glue/session_model_associator_unittest.cc
// Populate the mock tab delegate with some data and navigation
// entries and make sure that setting a SessionTab from it preserves
// those entries (and clobbers any existing data).
Populate the mock tab delegate with some data and navigation
entries and make sure that setting a SessionTab from it preserves
those entries (and clobbers any existing data).
Populate the mock tab delegate with some data and navigation entries and make sure that setting a SessionTab from it preserves those entries ( and clobbers any existing data ) .
TEST_F(SyncSessionModelAssociatorTest, SetSessionTabFromDelegate) {
  NiceMock<SyncedTabDelegateMock> tab_mock;
  EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0));
  scoped_ptr<content::NavigationEntry> entry1(
      content::NavigationEntry::Create());
  entry1->SetVirtualURL(GURL("http://www.google.com"));
  entry1->SetTimestamp(kTime1);
  scoped_ptr<content::NavigationEntry> entry2(
      content::NavigationEntry::Create());
  entry2->SetVirtualURL(GURL("http://www.noodle.com"));
  entry2->SetTimestamp(kTime2);
  scoped_ptr<content::NavigationEntry> entry3(
      content::NavigationEntry::Create());
  entry3->SetVirtualURL(GURL("http://www.doodle.com"));
  entry3->SetTimestamp(kTime3);
  EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(2));
  EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
      Return(entry1.get()));
  EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
      Return(entry2.get()));
  EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
      Return(entry3.get()));
  EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
  EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
  SessionTab session_tab;
  session_tab.window_id.set_id(1);
  session_tab.tab_id.set_id(1);
  session_tab.tab_visual_index = 1;
  session_tab.current_navigation_index = 1;
  session_tab.pinned = true;
  session_tab.extension_app_id = "app id";
  session_tab.user_agent_override = "override";
  session_tab.timestamp = kTime5;
  session_tab.navigations.push_back(
      SessionTypesTestHelper::CreateNavigation(
          "http://www.example.com", "Example"));
  session_tab.session_storage_persistent_id = "persistent id";
  SetSessionTabFromDelegate(tab_mock, kTime4, &session_tab);
  EXPECT_EQ(0, session_tab.window_id.id());
  EXPECT_EQ(0, session_tab.tab_id.id());
  EXPECT_EQ(0, session_tab.tab_visual_index);
  EXPECT_EQ(2, session_tab.current_navigation_index);
  EXPECT_FALSE(session_tab.pinned);
  EXPECT_TRUE(session_tab.extension_app_id.empty());
  EXPECT_TRUE(session_tab.user_agent_override.empty());
  EXPECT_EQ(kTime4, session_tab.timestamp);
  ASSERT_EQ(3u, session_tab.navigations.size());
  EXPECT_EQ(entry1->GetVirtualURL(),
            session_tab.navigations[0].virtual_url());
  EXPECT_EQ(entry2->GetVirtualURL(),
            session_tab.navigations[1].virtual_url());
  EXPECT_EQ(entry3->GetVirtualURL(),
            session_tab.navigations[2].virtual_url());
  EXPECT_EQ(kTime1,
            SessionTypesTestHelper::GetTimestamp(session_tab.navigations[0]));
  EXPECT_EQ(kTime2,
            SessionTypesTestHelper::GetTimestamp(session_tab.navigations[1]));
  EXPECT_EQ(kTime3,
            SessionTypesTestHelper::GetTimestamp(session_tab.navigations[2]));
  EXPECT_TRUE(session_tab.session_storage_persistent_id.empty());
}
TEST_F ( SyncSessionModelAssociatorTest , SetSessionTabFromDelegate ) { NiceMock < SyncedTabDelegateMock > tab_mock ; EXPECT_CALL ( tab_mock , GetSessionId ( ) ) . WillRepeatedly ( Return ( 0 ) ) ; scoped_ptr < content :: NavigationEntry > entry1 ( content :: NavigationEntry :: Create ( ) ) ; entry1 -> SetVirtualURL ( GURL ( " " ) ) ; entry1 -> SetTimestamp ( kTime1 ) ; scoped_ptr < content :: NavigationEntry > entry2 ( content :: NavigationEntry :: Create ( ) ) ; entry2 -> SetVirtualURL ( GURL ( " " ) ) ; entry2 -> SetTimestamp ( kTime2 ) ; scoped_ptr < content :: NavigationEntry > entry3 ( content :: NavigationEntry :: Create ( ) ) ; entry3 -> SetVirtualURL ( GURL ( " " ) ) ; entry3 -> SetTimestamp ( kTime3 ) ; EXPECT_CALL ( tab_mock , GetCurrentEntryIndex ( ) ) . WillRepeatedly ( Return ( 2 ) ) ; EXPECT_CALL ( tab_mock , GetEntryAtIndex ( 0 ) ) . WillRepeatedly ( Return ( entry1 . get ( ) ) ) ; EXPECT_CALL ( tab_mock , GetEntryAtIndex ( 1 ) ) . WillRepeatedly ( Return ( entry2 . get ( ) ) ) ; EXPECT_CALL ( tab_mock , GetEntryAtIndex ( 2 ) ) . WillRepeatedly ( Return ( entry3 . get ( ) ) ) ; EXPECT_CALL ( tab_mock , GetEntryCount ( ) ) . WillRepeatedly ( Return ( 3 ) ) ; EXPECT_CALL ( tab_mock , GetPendingEntryIndex ( ) ) . WillRepeatedly ( Return ( -1 ) ) ; SessionTab session_tab ; session_tab . window_id . set_id ( 1 ) ; session_tab . tab_id . set_id ( 1 ) ; session_tab . tab_visual_index = 1 ; session_tab . current_navigation_index = 1 ; session_tab . pinned = true ; session_tab . extension_app_id = " " ; session_tab . user_agent_override = " " ; session_tab . timestamp = kTime5 ; session_tab . navigations . push_back ( SessionTypesTestHelper :: CreateNavigation ( " " , " " ) ) ; session_tab . session_storage_persistent_id = " " ; SetSessionTabFromDelegate ( tab_mock , kTime4 , & session_tab ) ; EXPECT_EQ ( 0 , session_tab . window_id . id ( ) ) ; EXPECT_EQ ( 0 , session_tab . tab_id . id ( ) ) ; EXPECT_EQ ( 0 , session_tab . tab_visual_index ) ; EXPECT_EQ ( 2 , session_tab . current_navigation_index ) ; EXPECT_FALSE ( session_tab . pinned ) ; EXPECT_TRUE ( session_tab . extension_app_id . empty ( ) ) ; EXPECT_TRUE ( session_tab . user_agent_override . empty ( ) ) ; EXPECT_EQ ( kTime4 , session_tab . timestamp ) ; ASSERT_EQ ( 3u , session_tab . navigations . size ( ) ) ; EXPECT_EQ ( entry1 -> GetVirtualURL ( ) , session_tab . navigations [ 0 ] . virtual_url ( ) ) ; EXPECT_EQ ( entry2 -> GetVirtualURL ( ) , session_tab . navigations [ 1 ] . virtual_url ( ) ) ; EXPECT_EQ ( entry3 -> GetVirtualURL ( ) , session_tab . navigations [ 2 ] . virtual_url ( ) ) ; EXPECT_EQ ( kTime1 , SessionTypesTestHelper :: GetTimestamp ( session_tab . navigations [ 0 ] ) ) ; EXPECT_EQ ( kTime2 , SessionTypesTestHelper :: GetTimestamp ( session_tab . navigations [ 1 ] ) ) ; EXPECT_EQ ( kTime3 , SessionTypesTestHelper :: GetTimestamp ( session_tab . navigations [ 2 ] ) ) ; EXPECT_TRUE ( session_tab . session_storage_persistent_id . empty ( ) ) ; }
Populate the mock tab delegate with some data and navigation
entries and make sure that setting a SessionTab from it preserves
those entries (and clobbers any existing data).
Populate the mock tab delegate with some data and navigation entries and make sure that setting a SessionTab from it preserves those entries ( and clobbers any existing data ) .
// Create a tab with three valid entries.