#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/sync/glue/device_info.h"
+#include "chrome/browser/sync/glue/local_device_info_provider_mock.h"
#include "chrome/browser/sync/glue/session_sync_test_helper.h"
#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "sync/api/attachments/attachment_id.h"
-#include "sync/api/attachments/attachment_service_proxy_for_test.h"
#include "sync/api/sync_error_factory_mock.h"
+#include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
} // namespace
class SessionsSyncManagerTest
- : public BrowserWithTestWindowTest,
- public SessionsSyncManager::SyncInternalApiDelegate {
+ : public BrowserWithTestWindowTest {
public:
- SessionsSyncManagerTest() : test_processor_(NULL) {}
+ SessionsSyncManagerTest()
+ : test_processor_(NULL) {
+ local_device_.reset(new LocalDeviceInfoProviderMock(
+ "cache_guid",
+ "Wayne Gretzky's Hacking Box",
+ "Chromium 10k",
+ "Chrome 10k",
+ sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
+ "device_id"));
+ }
virtual void SetUp() OVERRIDE {
BrowserWithTestWindowTest::SetUp();
browser_sync::NotificationServiceSessionsRouter* router(
new browser_sync::NotificationServiceSessionsRouter(
profile(), syncer::SyncableService::StartSyncFlare()));
- manager_.reset(new SessionsSyncManager(profile(), this,
+ manager_.reset(new SessionsSyncManager(profile(), local_device_.get(),
scoped_ptr<LocalSessionEventRouter>(router)));
}
BrowserWithTestWindowTest::TearDown();
}
- virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const OVERRIDE {
- return scoped_ptr<DeviceInfo>(
- new DeviceInfo(GetLocalSyncCacheGUID(),
- "Wayne Gretzky's Hacking Box",
- "Chromium 10k",
- "Chrome 10k",
- sync_pb::SyncEnums_DeviceType_TYPE_LINUX));
- }
-
- virtual std::string GetLocalSyncCacheGUID() const OVERRIDE {
- return "cache_guid";
+ const DeviceInfo* GetLocalDeviceInfo() {
+ return local_device_->GetLocalDeviceInfo();
}
SessionsSyncManager* manager() { return manager_.get(); }
SessionSyncTestHelper* helper() { return &helper_; }
+ LocalDeviceInfoProvider* local_device() { return local_device_.get(); }
void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data,
syncer::SyncChangeList* output) {
scoped_ptr<SessionsSyncManager> manager_;
SessionSyncTestHelper helper_;
TestSyncProcessorStub* test_processor_;
+ scoped_ptr<LocalDeviceInfoProviderMock> local_device_;
};
// Test that the SyncSessionManager can properly fill in a SessionHeader.
EXPECT_EQ(entry->GetVirtualURL(), manager()->GetCurrentVirtualURL(tab));
}
-static const base::Time kTime1 = base::Time::FromInternalValue(100);
-static const base::Time kTime2 = base::Time::FromInternalValue(105);
-static const base::Time kTime3 = base::Time::FromInternalValue(110);
-static const base::Time kTime4 = base::Time::FromInternalValue(120);
-static const base::Time kTime5 = base::Time::FromInternalValue(130);
+static const base::Time kTime0 = base::Time::FromInternalValue(100);
+static const base::Time kTime1 = base::Time::FromInternalValue(110);
+static const base::Time kTime2 = base::Time::FromInternalValue(120);
+static const base::Time kTime3 = base::Time::FromInternalValue(130);
+static const base::Time kTime4 = base::Time::FromInternalValue(140);
+static const base::Time kTime5 = base::Time::FromInternalValue(150);
+static const base::Time kTime6 = base::Time::FromInternalValue(160);
+static const base::Time kTime7 = base::Time::FromInternalValue(170);
+static const base::Time kTime8 = base::Time::FromInternalValue(180);
+static const base::Time kTime9 = base::Time::FromInternalValue(190);
// Populate the mock tab delegate with some data and navigation
// entries and make sure that setting a SessionTab from it preserves
EXPECT_TRUE(session_tab.session_storage_persistent_id.empty());
}
+// Ensure the current_navigation_index gets set properly when the navigation
+// stack gets trucated to +/- 6 entries.
+TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateNavigationIndex) {
+ SyncedTabDelegateFake tab;
+ content::NavigationEntry* entry0(content::NavigationEntry::Create());
+ entry0->SetVirtualURL(GURL("http://www.google.com"));
+ entry0->SetTimestamp(kTime0);
+ entry0->SetHttpStatusCode(200);
+ content::NavigationEntry* entry1(content::NavigationEntry::Create());
+ entry1->SetVirtualURL(GURL("http://www.zoogle.com"));
+ entry1->SetTimestamp(kTime1);
+ entry1->SetHttpStatusCode(200);
+ content::NavigationEntry* entry2(content::NavigationEntry::Create());
+ entry2->SetVirtualURL(GURL("http://www.noogle.com"));
+ entry2->SetTimestamp(kTime2);
+ entry2->SetHttpStatusCode(200);
+ content::NavigationEntry* entry3(content::NavigationEntry::Create());
+ entry3->SetVirtualURL(GURL("http://www.doogle.com"));
+ entry3->SetTimestamp(kTime3);
+ entry3->SetHttpStatusCode(200);
+ content::NavigationEntry* entry4(content::NavigationEntry::Create());
+ entry4->SetVirtualURL(GURL("http://www.yoogle.com"));
+ entry4->SetTimestamp(kTime4);
+ entry4->SetHttpStatusCode(200);
+ content::NavigationEntry* entry5(content::NavigationEntry::Create());
+ entry5->SetVirtualURL(GURL("http://www.foogle.com"));
+ entry5->SetTimestamp(kTime5);
+ entry5->SetHttpStatusCode(200);
+ content::NavigationEntry* entry6(content::NavigationEntry::Create());
+ entry6->SetVirtualURL(GURL("http://www.boogle.com"));
+ entry6->SetTimestamp(kTime6);
+ entry6->SetHttpStatusCode(200);
+ content::NavigationEntry* entry7(content::NavigationEntry::Create());
+ entry7->SetVirtualURL(GURL("http://www.moogle.com"));
+ entry7->SetTimestamp(kTime7);
+ entry7->SetHttpStatusCode(200);
+ content::NavigationEntry* entry8(content::NavigationEntry::Create());
+ entry8->SetVirtualURL(GURL("http://www.poogle.com"));
+ entry8->SetTimestamp(kTime8);
+ entry8->SetHttpStatusCode(200);
+ content::NavigationEntry* entry9(content::NavigationEntry::Create());
+ entry9->SetVirtualURL(GURL("http://www.roogle.com"));
+ entry9->SetTimestamp(kTime9);
+ entry9->SetHttpStatusCode(200);
+
+ tab.AppendEntry(entry0);
+ tab.AppendEntry(entry1);
+ tab.AppendEntry(entry2);
+ tab.AppendEntry(entry3);
+ tab.AppendEntry(entry4);
+ tab.AppendEntry(entry5);
+ tab.AppendEntry(entry6);
+ tab.AppendEntry(entry7);
+ tab.AppendEntry(entry8);
+ tab.AppendEntry(entry9);
+ tab.set_current_entry_index(8);
+
+ SessionTab session_tab;
+ manager()->SetSessionTabFromDelegate(tab, kTime9, &session_tab);
+
+ EXPECT_EQ(6, session_tab.current_navigation_index);
+ ASSERT_EQ(8u, session_tab.navigations.size());
+ EXPECT_EQ(entry2->GetVirtualURL(),
+ session_tab.navigations[0].virtual_url());
+ EXPECT_EQ(entry3->GetVirtualURL(),
+ session_tab.navigations[1].virtual_url());
+ EXPECT_EQ(entry4->GetVirtualURL(),
+ session_tab.navigations[2].virtual_url());
+}
+
+// Ensure the current_navigation_index gets set to the end of the navigation
+// stack if the current navigation is invalid.
+TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateCurrentInvalid) {
+ SyncedTabDelegateFake tab;
+ content::NavigationEntry* entry0(content::NavigationEntry::Create());
+ entry0->SetVirtualURL(GURL("http://www.google.com"));
+ entry0->SetTimestamp(kTime0);
+ entry0->SetHttpStatusCode(200);
+ content::NavigationEntry* entry1(content::NavigationEntry::Create());
+ entry1->SetVirtualURL(GURL(""));
+ entry1->SetTimestamp(kTime1);
+ entry1->SetHttpStatusCode(200);
+ content::NavigationEntry* entry2(content::NavigationEntry::Create());
+ entry2->SetVirtualURL(GURL("http://www.noogle.com"));
+ entry2->SetTimestamp(kTime2);
+ entry2->SetHttpStatusCode(200);
+ content::NavigationEntry* entry3(content::NavigationEntry::Create());
+ entry3->SetVirtualURL(GURL("http://www.doogle.com"));
+ entry3->SetTimestamp(kTime3);
+ entry3->SetHttpStatusCode(200);
+
+ tab.AppendEntry(entry0);
+ tab.AppendEntry(entry1);
+ tab.AppendEntry(entry2);
+ tab.AppendEntry(entry3);
+ tab.set_current_entry_index(1);
+
+ SessionTab session_tab;
+ manager()->SetSessionTabFromDelegate(tab, kTime9, &session_tab);
+
+ EXPECT_EQ(2, session_tab.current_navigation_index);
+ ASSERT_EQ(3u, session_tab.navigations.size());
+}
+
// Tests that for supervised users blocked navigations are recorded and marked
// as such, while regular navigations are marked as allowed.
TEST_F(SessionsSyncManagerTest, BlockedNavigations) {
syncer::AttachmentServiceProxyForTest::Create()));
syncer::SyncDataList in(&d, &d + 1);
out.clear();
- SessionsSyncManager manager2(profile(), this, NewDummyRouter());
+ SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter());
syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
syncer::SESSIONS, in,
scoped_ptr<syncer::SyncChangeProcessor>(
syncer::AttachmentServiceProxyForTest::Create()));
syncer::SyncDataList in(&d, &d + 1);
changes.clear();
- SessionsSyncManager manager2(profile(), this, NewDummyRouter());
+ SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter());
syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
syncer::SESSIONS, in,
scoped_ptr<syncer::SyncChangeProcessor>(