chrome/browser/sessions/session_types_unittest.cc
// Create a typical SessionTab protocol buffer and set an existing
// SessionTab from it.  The data from the protocol buffer should
// clobber the existing data.
Create a typical SessionTab protocol buffer and set an existing
SessionTab from it.  The data from the protocol buffer should
clobber the existing data.
Create a typical SessionTab protocol buffer and set an existing SessionTab from it . The data from the protocol buffer should clobber the existing data .
TEST(SessionTab, FromSyncData) {
  sync_pb::SessionTab sync_data;
  sync_data.set_tab_id(5);
  sync_data.set_window_id(10);
  sync_data.set_tab_visual_index(13);
  sync_data.set_current_navigation_index(3);
  sync_data.set_pinned(true);
  sync_data.set_extension_app_id("app_id");
  for (int i = 0; i < 5; ++i) {
    sync_pb::TabNavigation* navigation = sync_data.add_navigation();
    navigation->set_virtual_url("http://foo/" + base::IntToString(i));
    navigation->set_referrer("referrer");
    navigation->set_title("title");
    navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED);
  }
  SessionTab tab;
  tab.window_id.set_id(100);
  tab.tab_id.set_id(100);
  tab.tab_visual_index = 100;
  tab.current_navigation_index = 1000;
  tab.pinned = false;
  tab.extension_app_id = "fake";
  tab.user_agent_override = "fake";
  tab.timestamp = base::Time::FromInternalValue(100);
  tab.navigations.resize(100);
  tab.session_storage_persistent_id = "fake";
  tab.SetFromSyncData(sync_data, base::Time::FromInternalValue(5u));
  EXPECT_EQ(10, tab.window_id.id());
  EXPECT_EQ(5, tab.tab_id.id());
  EXPECT_EQ(13, tab.tab_visual_index);
  EXPECT_EQ(3, tab.current_navigation_index);
  EXPECT_TRUE(tab.pinned);
  EXPECT_EQ("app_id", tab.extension_app_id);
  EXPECT_TRUE(tab.user_agent_override.empty());
  EXPECT_EQ(5u, tab.timestamp.ToInternalValue());
  ASSERT_EQ(5u, tab.navigations.size());
  for (int i = 0; i < 5; ++i) {
    EXPECT_EQ(i, tab.navigations[i].index());
    EXPECT_EQ(GURL("referrer"),
              SessionTypesTestHelper::GetReferrer(tab.navigations[i]).url);
    EXPECT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[i].title());
    EXPECT_EQ(content::PAGE_TRANSITION_TYPED,
              SessionTypesTestHelper::GetTransitionType(tab.navigations[i]));
    EXPECT_EQ(GURL("http://foo/" + base::IntToString(i)),
              tab.navigations[i].virtual_url());
  }
  EXPECT_TRUE(tab.session_storage_persistent_id.empty());
}
TEST ( SessionTab , FromSyncData ) { sync_pb :: SessionTab sync_data ; sync_data . set_tab_id ( 5 ) ; sync_data . set_window_id ( 10 ) ; sync_data . set_tab_visual_index ( 13 ) ; sync_data . set_current_navigation_index ( 3 ) ; sync_data . set_pinned ( true ) ; sync_data . set_extension_app_id ( " " ) ; for ( int i = 0 ; i < 5 ; ++ i ) { sync_pb :: TabNavigation * navigation = sync_data . add_navigation ( ) ; navigation -> set_virtual_url ( " " + base :: IntToString ( i ) ) ; navigation -> set_referrer ( " " ) ; navigation -> set_title ( " " ) ; navigation -> set_page_transition ( sync_pb :: SyncEnums_PageTransition_TYPED ) ; } SessionTab tab ; tab . window_id . set_id ( 100 ) ; tab . tab_id . set_id ( 100 ) ; tab . tab_visual_index = 100 ; tab . current_navigation_index = 1000 ; tab . pinned = false ; tab . extension_app_id = " " ; tab . user_agent_override = " " ; tab . timestamp = base :: Time :: FromInternalValue ( 100 ) ; tab . navigations . resize ( 100 ) ; tab . session_storage_persistent_id = " " ; tab . SetFromSyncData ( sync_data , base :: Time :: FromInternalValue ( 5u ) ) ; EXPECT_EQ ( 10 , tab . window_id . id ( ) ) ; EXPECT_EQ ( 5 , tab . tab_id . id ( ) ) ; EXPECT_EQ ( 13 , tab . tab_visual_index ) ; EXPECT_EQ ( 3 , tab . current_navigation_index ) ; EXPECT_TRUE ( tab . pinned ) ; EXPECT_EQ ( " " , tab . extension_app_id ) ; EXPECT_TRUE ( tab . user_agent_override . empty ( ) ) ; EXPECT_EQ ( 5u , tab . timestamp . ToInternalValue ( ) ) ; ASSERT_EQ ( 5u , tab . navigations . size ( ) ) ; for ( int i = 0 ; i < 5 ; ++ i ) { EXPECT_EQ ( i , tab . navigations [ i ] . index ( ) ) ; EXPECT_EQ ( GURL ( " " ) , SessionTypesTestHelper :: GetReferrer ( tab . navigations [ i ] ) . url ) ; EXPECT_EQ ( string16 ( ASCIIToUTF16 ( " " ) ) , tab . navigations [ i ] . title ( ) ) ; EXPECT_EQ ( content :: PAGE_TRANSITION_TYPED , SessionTypesTestHelper :: GetTransitionType ( tab . navigations [ i ] ) ) ; EXPECT_EQ ( GURL ( " " + base :: IntToString ( i ) ) , tab . navigations [ i ] . virtual_url ( ) ) ; } EXPECT_TRUE ( tab . session_storage_persistent_id . empty ( ) ) ; }
Create a typical SessionTab protocol buffer and set an existing
SessionTab from it.
Create a typical SessionTab protocol buffer and set an existing SessionTab from it .