Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 1408643002: [Sync] Componentize synced_tab_delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test broken by rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "chrome/browser/sync/chrome_sync_client.h"
10 #include "chrome/browser/sync/glue/session_sync_test_helper.h" 11 #include "chrome/browser/sync/glue/session_sync_test_helper.h"
11 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
12 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" 12 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
13 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" 13 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h"
14 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 14 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/browser_with_test_window_test.h" 16 #include "chrome/test/base/browser_with_test_window_test.h"
17 #include "components/sessions/content/content_serialized_navigation_builder.h"
17 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" 18 #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
18 #include "components/sessions/core/session_id.h" 19 #include "components/sessions/core/session_id.h"
19 #include "components/sessions/core/session_types.h" 20 #include "components/sessions/core/session_types.h"
20 #include "components/sync_driver/device_info.h" 21 #include "components/sync_driver/device_info.h"
21 #include "components/sync_driver/glue/synced_window_delegate.h" 22 #include "components/sync_driver/glue/synced_window_delegate.h"
22 #include "components/sync_driver/local_device_info_provider_mock.h" 23 #include "components/sync_driver/local_device_info_provider_mock.h"
23 #include "components/sync_driver/sessions/synced_window_delegates_getter.h" 24 #include "components/sync_driver/sessions/synced_window_delegates_getter.h"
25 #include "components/sync_driver/sync_api_component_factory.h"
26 #include "components/sync_sessions/synced_tab_delegate.h"
24 #include "content/public/browser/navigation_entry.h" 27 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
29 #include "sync/api/attachments/attachment_id.h" 32 #include "sync/api/attachments/attachment_id.h"
30 #include "sync/api/sync_error_factory_mock.h" 33 #include "sync/api/sync_error_factory_mock.h"
31 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h" 34 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h"
32 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 public: 112 public:
110 TestSyncedWindowDelegatesGetter( 113 TestSyncedWindowDelegatesGetter(
111 const std::set<const SyncedWindowDelegate*>& delegates) 114 const std::set<const SyncedWindowDelegate*>& delegates)
112 : delegates_(delegates) {} 115 : delegates_(delegates) {}
113 116
114 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { 117 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override {
115 return delegates_; 118 return delegates_;
116 } 119 }
117 120
118 const SyncedWindowDelegate* FindById(SessionID::id_type id) override { 121 const SyncedWindowDelegate* FindById(SessionID::id_type id) override {
122 for (auto* window : delegates_) {
123 if (window->GetSessionId() == id)
124 return window;
125 }
119 return nullptr; 126 return nullptr;
120 } 127 }
121 128
122 private: 129 private:
123 const std::set<const SyncedWindowDelegate*> delegates_; 130 const std::set<const SyncedWindowDelegate*> delegates_;
124 }; 131 };
125 132
126 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { 133 class TestSyncProcessorStub : public syncer::SyncChangeProcessor {
127 public: 134 public:
128 explicit TestSyncProcessorStub(syncer::SyncChangeList* output) 135 explicit TestSyncProcessorStub(syncer::SyncChangeList* output)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 public: 236 public:
230 ~DummyRouter() override {} 237 ~DummyRouter() override {}
231 void StartRoutingTo(LocalSessionEventHandler* handler) override {} 238 void StartRoutingTo(LocalSessionEventHandler* handler) override {}
232 void Stop() override {} 239 void Stop() override {}
233 }; 240 };
234 241
235 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { 242 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() {
236 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); 243 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter());
237 } 244 }
238 245
239 scoped_ptr<SyncedWindowDelegatesGetter> NewBrowserWindowGetter() {
240 return make_scoped_ptr(new BrowserSyncedWindowDelegatesGetter());
241 }
242
243 } // namespace 246 } // namespace
244 247
245 class SessionsSyncManagerTest 248 class SessionsSyncManagerTest
246 : public BrowserWithTestWindowTest { 249 : public BrowserWithTestWindowTest {
247 public: 250 public:
248 SessionsSyncManagerTest() 251 SessionsSyncManagerTest()
249 : test_processor_(NULL) { 252 : test_processor_(NULL) {
250 local_device_.reset(new LocalDeviceInfoProviderMock( 253 local_device_.reset(new LocalDeviceInfoProviderMock(
251 "cache_guid", 254 "cache_guid",
252 "Wayne Gretzky's Hacking Box", 255 "Wayne Gretzky's Hacking Box",
253 "Chromium 10k", 256 "Chromium 10k",
254 "Chrome 10k", 257 "Chrome 10k",
255 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, 258 sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
256 "device_id")); 259 "device_id"));
257 } 260 }
258 261
259 void SetUp() override { 262 void SetUp() override {
260 BrowserWithTestWindowTest::SetUp(); 263 BrowserWithTestWindowTest::SetUp();
264 sync_client_.reset(new browser_sync::ChromeSyncClient(profile(), nullptr));
261 browser_sync::NotificationServiceSessionsRouter* router( 265 browser_sync::NotificationServiceSessionsRouter* router(
262 new browser_sync::NotificationServiceSessionsRouter( 266 new browser_sync::NotificationServiceSessionsRouter(
263 profile(), syncer::SyncableService::StartSyncFlare())); 267 profile(), GetSyncSessionsClient(),
268 syncer::SyncableService::StartSyncFlare()));
264 manager_.reset(new SessionsSyncManager( 269 manager_.reset(new SessionsSyncManager(
265 profile(), local_device_.get(), 270 GetSyncSessionsClient(), profile(), local_device_.get(),
266 scoped_ptr<LocalSessionEventRouter>(router), 271 scoped_ptr<LocalSessionEventRouter>(router)));
267 NewBrowserWindowGetter()));
268 } 272 }
269 273
270 void TearDown() override { 274 void TearDown() override {
271 test_processor_ = NULL; 275 test_processor_ = NULL;
272 helper()->Reset(); 276 helper()->Reset();
273 manager_.reset(); 277 manager_.reset();
274 BrowserWithTestWindowTest::TearDown(); 278 BrowserWithTestWindowTest::TearDown();
275 } 279 }
276 280
277 const DeviceInfo* GetLocalDeviceInfo() { 281 const DeviceInfo* GetLocalDeviceInfo() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 it = list->erase(it); 323 it = list->erase(it);
320 found = true; 324 found = true;
321 } else { 325 } else {
322 ++it; 326 ++it;
323 } 327 }
324 } 328 }
325 EXPECT_TRUE(found); 329 EXPECT_TRUE(found);
326 return list; 330 return list;
327 } 331 }
328 332
333 sync_sessions::SyncSessionsClient* GetSyncSessionsClient() {
334 return sync_client_->GetSyncSessionsClient();
335 }
336
329 private: 337 private:
338 scoped_ptr<browser_sync::ChromeSyncClient> sync_client_;
330 scoped_ptr<SessionsSyncManager> manager_; 339 scoped_ptr<SessionsSyncManager> manager_;
331 SessionSyncTestHelper helper_; 340 SessionSyncTestHelper helper_;
332 TestSyncProcessorStub* test_processor_; 341 TestSyncProcessorStub* test_processor_;
333 scoped_ptr<LocalDeviceInfoProviderMock> local_device_; 342 scoped_ptr<LocalDeviceInfoProviderMock> local_device_;
334 }; 343 };
335 344
336 // Test that the SyncSessionManager can properly fill in a SessionHeader. 345 // Test that the SyncSessionManager can properly fill in a SessionHeader.
337 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) { 346 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) {
338 sync_pb::SessionHeader header_s; 347 sync_pb::SessionHeader header_s;
339 header_s.set_client_name("Client 1"); 348 header_s.set_client_name("Client 1");
(...skipping 25 matching lines...) Expand all
365 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); 374 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type);
366 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); 375 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions());
367 ASSERT_EQ(1U, 376 ASSERT_EQ(1U,
368 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); 377 manager()->session_tracker_.num_synced_tabs(std::string("tag")));
369 } 378 }
370 379
371 namespace { 380 namespace {
372 381
373 class SyncedTabDelegateFake : public SyncedTabDelegate { 382 class SyncedTabDelegateFake : public SyncedTabDelegate {
374 public: 383 public:
375 SyncedTabDelegateFake() : current_entry_index_(0), 384 SyncedTabDelegateFake()
376 pending_entry_index_(-1), 385 : current_entry_index_(0), is_supervised_(false), sync_id_(-1) {}
377 is_supervised_(false),
378 sync_id_(-1),
379 blocked_navigations_(NULL) {}
380 ~SyncedTabDelegateFake() override {} 386 ~SyncedTabDelegateFake() override {}
381 387
382 bool IsInitialBlankNavigation() const override { 388 bool IsInitialBlankNavigation() const override {
383 // This differs from NavigationControllerImpl, which has an initial blank 389 // This differs from NavigationControllerImpl, which has an initial blank
384 // NavigationEntry. 390 // NavigationEntry.
385 return GetEntryCount() == 0; 391 return GetEntryCount() == 0;
386 } 392 }
387 int GetCurrentEntryIndex() const override { return current_entry_index_; } 393 int GetCurrentEntryIndex() const override { return current_entry_index_; }
388 void set_current_entry_index(int i) { 394 void set_current_entry_index(int i) {
389 current_entry_index_ = i; 395 current_entry_index_ = i;
390 } 396 }
391 397
392 content::NavigationEntry* GetEntryAtIndex(int i) const override {
393 const int size = entries_.size();
394 return (size < i + 1) ? NULL : entries_[i];
395 }
396
397 void AppendEntry(scoped_ptr<content::NavigationEntry> entry) { 398 void AppendEntry(scoped_ptr<content::NavigationEntry> entry) {
398 entries_.push_back(entry.Pass()); 399 entries_.push_back(entry.Pass());
399 } 400 }
400 401
402 GURL GetVirtualURLAtIndex(int i) const override {
403 if (static_cast<size_t>(i) >= entries_.size())
404 return GURL();
405 return entries_[i]->GetVirtualURL();
406 }
407
408 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); }
409
410 ui::PageTransition GetTransitionAtIndex(int i) const override {
411 if (static_cast<size_t>(i) >= entries_.size())
412 return ui::PAGE_TRANSITION_LINK;
413 return entries_[i]->GetTransitionType();
414 }
415
416 void GetSerializedNavigationAtIndex(
417 int i,
418 sessions::SerializedNavigationEntry* serialized_entry) const override {
419 if (static_cast<size_t>(i) >= entries_.size())
420 return;
421 *serialized_entry =
422 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
423 i, *entries_[i]);
424 }
425
401 int GetEntryCount() const override { return entries_.size(); } 426 int GetEntryCount() const override { return entries_.size(); }
402 427
403 int GetPendingEntryIndex() const override { return pending_entry_index_; }
404 void set_pending_entry_index(int i) {
405 pending_entry_index_ = i;
406 }
407
408 SessionID::id_type GetWindowId() const override { 428 SessionID::id_type GetWindowId() const override {
409 return SessionID::id_type(); 429 return SessionID::id_type();
410 } 430 }
411 431
412 SessionID::id_type GetSessionId() const override { 432 SessionID::id_type GetSessionId() const override {
413 return SessionID::id_type(); 433 return SessionID::id_type();
414 } 434 }
415 435
416 bool IsBeingDestroyed() const override { return false; } 436 bool IsBeingDestroyed() const override { return false; }
417 Profile* profile() const override { return NULL; }
418 std::string GetExtensionAppId() const override { return std::string(); } 437 std::string GetExtensionAppId() const override { return std::string(); }
419 content::NavigationEntry* GetPendingEntry() const override { return NULL; }
420 content::NavigationEntry* GetActiveEntry() const override { return NULL; }
421 bool ProfileIsSupervised() const override { return is_supervised_; } 438 bool ProfileIsSupervised() const override { return is_supervised_; }
422 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } 439 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; }
423 const std::vector<const content::NavigationEntry*>* GetBlockedNavigations() 440 const std::vector<const sessions::SerializedNavigationEntry*>*
424 const override { 441 GetBlockedNavigations() const override {
425 return blocked_navigations_; 442 return &blocked_navigations_.get();
426 } 443 }
427 void set_blocked_navigations( 444 void set_blocked_navigations(
428 std::vector<const content::NavigationEntry*>* navs) { 445 std::vector<const content::NavigationEntry*>* navs) {
429 blocked_navigations_ = navs; 446 for (auto* entry : *navs) {
447 scoped_ptr<sessions::SerializedNavigationEntry> serialized_entry(
448 new sessions::SerializedNavigationEntry());
449 *serialized_entry =
450 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
451 blocked_navigations_.size(), *entry);
452 blocked_navigations_.push_back(serialized_entry.release());
453 }
430 } 454 }
431 bool IsPinned() const override { return false; } 455 bool IsPlaceholderTab() const override { return true; }
432 bool HasWebContents() const override { return false; }
433 content::WebContents* GetWebContents() const override { return NULL; }
434 456
435 // Session sync related methods. 457 // Session sync related methods.
436 int GetSyncId() const override { return sync_id_; } 458 int GetSyncId() const override { return sync_id_; }
437 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } 459 void SetSyncId(int sync_id) override { sync_id_ = sync_id; }
438 460
461 bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override {
462 return false;
463 }
464
439 void reset() { 465 void reset() {
440 current_entry_index_ = 0; 466 current_entry_index_ = 0;
441 pending_entry_index_ = -1;
442 sync_id_ = -1; 467 sync_id_ = -1;
443 entries_.clear(); 468 entries_.clear();
444 } 469 }
445 470
446 private: 471 private:
447 int current_entry_index_; 472 int current_entry_index_;
448 int pending_entry_index_;
449 bool is_supervised_; 473 bool is_supervised_;
450 int sync_id_; 474 int sync_id_;
451 std::vector<const content::NavigationEntry*>* blocked_navigations_; 475 ScopedVector<const sessions::SerializedNavigationEntry> blocked_navigations_;
452 ScopedVector<content::NavigationEntry> entries_; 476 ScopedVector<content::NavigationEntry> entries_;
453 }; 477 };
454 478
455 } // namespace 479 } // namespace
456 480
457 // Make sure GetCurrentVirtualURL() returns the virtual URL of the pending
458 // entry if the current entry is pending.
459 TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLPending) {
460 SyncedTabDelegateFake tab;
461 scoped_ptr<content::NavigationEntry> entry(
462 content::NavigationEntry::Create());
463 GURL url("http://www.google.com/");
464 entry->SetVirtualURL(url);
465 tab.AppendEntry(entry.Pass());
466 EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab));
467 }
468
469 // Make sure GetCurrentVirtualURL() returns the virtual URL of the current
470 // entry if the current entry is non-pending.
471 TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLNonPending) {
472 SyncedTabDelegateFake tab;
473 scoped_ptr<content::NavigationEntry> entry(
474 content::NavigationEntry::Create());
475 GURL url("http://www.google.com/");
476 entry->SetVirtualURL(url);
477 tab.AppendEntry(entry.Pass());
478 EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab));
479 }
480
481 static const base::Time kTime0 = base::Time::FromInternalValue(100); 481 static const base::Time kTime0 = base::Time::FromInternalValue(100);
482 static const base::Time kTime1 = base::Time::FromInternalValue(110); 482 static const base::Time kTime1 = base::Time::FromInternalValue(110);
483 static const base::Time kTime2 = base::Time::FromInternalValue(120); 483 static const base::Time kTime2 = base::Time::FromInternalValue(120);
484 static const base::Time kTime3 = base::Time::FromInternalValue(130); 484 static const base::Time kTime3 = base::Time::FromInternalValue(130);
485 static const base::Time kTime4 = base::Time::FromInternalValue(140); 485 static const base::Time kTime4 = base::Time::FromInternalValue(140);
486 static const base::Time kTime5 = base::Time::FromInternalValue(150); 486 static const base::Time kTime5 = base::Time::FromInternalValue(150);
487 static const base::Time kTime6 = base::Time::FromInternalValue(160); 487 static const base::Time kTime6 = base::Time::FromInternalValue(160);
488 static const base::Time kTime7 = base::Time::FromInternalValue(170); 488 static const base::Time kTime7 = base::Time::FromInternalValue(170);
489 static const base::Time kTime8 = base::Time::FromInternalValue(180); 489 static const base::Time kTime8 = base::Time::FromInternalValue(180);
490 static const base::Time kTime9 = base::Time::FromInternalValue(190); 490 static const base::Time kTime9 = base::Time::FromInternalValue(190);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 session_tab.tab_visual_index = 1; 525 session_tab.tab_visual_index = 1;
526 session_tab.current_navigation_index = 1; 526 session_tab.current_navigation_index = 1;
527 session_tab.pinned = true; 527 session_tab.pinned = true;
528 session_tab.extension_app_id = "app id"; 528 session_tab.extension_app_id = "app id";
529 session_tab.user_agent_override = "override"; 529 session_tab.user_agent_override = "override";
530 session_tab.timestamp = kTime5; 530 session_tab.timestamp = kTime5;
531 session_tab.navigations.push_back( 531 session_tab.navigations.push_back(
532 SerializedNavigationEntryTestHelper::CreateNavigation( 532 SerializedNavigationEntryTestHelper::CreateNavigation(
533 "http://www.example.com", "Example")); 533 "http://www.example.com", "Example"));
534 session_tab.session_storage_persistent_id = "persistent id"; 534 session_tab.session_storage_persistent_id = "persistent id";
535 manager()->SetSessionTabFromDelegate(tab, kTime4, &session_tab); 535 manager()->SetSessionTabFromDelegate(
536 manager()->GetSyncedWindowDelegatesGetter(), tab, kTime4, &session_tab);
536 537
537 EXPECT_EQ(0, session_tab.window_id.id()); 538 EXPECT_EQ(0, session_tab.window_id.id());
538 EXPECT_EQ(0, session_tab.tab_id.id()); 539 EXPECT_EQ(0, session_tab.tab_id.id());
539 EXPECT_EQ(0, session_tab.tab_visual_index); 540 EXPECT_EQ(0, session_tab.tab_visual_index);
540 EXPECT_EQ(2, session_tab.current_navigation_index); 541 EXPECT_EQ(2, session_tab.current_navigation_index);
541 EXPECT_FALSE(session_tab.pinned); 542 EXPECT_FALSE(session_tab.pinned);
542 EXPECT_TRUE(session_tab.extension_app_id.empty()); 543 EXPECT_TRUE(session_tab.extension_app_id.empty());
543 EXPECT_TRUE(session_tab.user_agent_override.empty()); 544 EXPECT_TRUE(session_tab.user_agent_override.empty());
544 EXPECT_EQ(kTime4, session_tab.timestamp); 545 EXPECT_EQ(kTime4, session_tab.timestamp);
545 ASSERT_EQ(3u, session_tab.navigations.size()); 546 ASSERT_EQ(3u, session_tab.navigations.size());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 tab.AppendEntry(entry3.Pass()); 633 tab.AppendEntry(entry3.Pass());
633 tab.AppendEntry(entry4.Pass()); 634 tab.AppendEntry(entry4.Pass());
634 tab.AppendEntry(entry5.Pass()); 635 tab.AppendEntry(entry5.Pass());
635 tab.AppendEntry(entry6.Pass()); 636 tab.AppendEntry(entry6.Pass());
636 tab.AppendEntry(entry7.Pass()); 637 tab.AppendEntry(entry7.Pass());
637 tab.AppendEntry(entry8.Pass()); 638 tab.AppendEntry(entry8.Pass());
638 tab.AppendEntry(entry9.Pass()); 639 tab.AppendEntry(entry9.Pass());
639 tab.set_current_entry_index(8); 640 tab.set_current_entry_index(8);
640 641
641 sessions::SessionTab session_tab; 642 sessions::SessionTab session_tab;
642 manager()->SetSessionTabFromDelegate(tab, kTime9, &session_tab); 643 manager()->SetSessionTabFromDelegate(
644 manager()->GetSyncedWindowDelegatesGetter(), tab, kTime9, &session_tab);
643 645
644 EXPECT_EQ(6, session_tab.current_navigation_index); 646 EXPECT_EQ(6, session_tab.current_navigation_index);
645 ASSERT_EQ(8u, session_tab.navigations.size()); 647 ASSERT_EQ(8u, session_tab.navigations.size());
646 EXPECT_EQ(url2, session_tab.navigations[0].virtual_url()); 648 EXPECT_EQ(url2, session_tab.navigations[0].virtual_url());
647 EXPECT_EQ(url3, session_tab.navigations[1].virtual_url()); 649 EXPECT_EQ(url3, session_tab.navigations[1].virtual_url());
648 EXPECT_EQ(url4, session_tab.navigations[2].virtual_url()); 650 EXPECT_EQ(url4, session_tab.navigations[2].virtual_url());
649 } 651 }
650 652
651 // Ensure the current_navigation_index gets set to the end of the navigation 653 // Ensure the current_navigation_index gets set to the end of the navigation
652 // stack if the current navigation is invalid. 654 // stack if the current navigation is invalid.
(...skipping 20 matching lines...) Expand all
673 entry3->SetTimestamp(kTime3); 675 entry3->SetTimestamp(kTime3);
674 entry3->SetHttpStatusCode(200); 676 entry3->SetHttpStatusCode(200);
675 677
676 tab.AppendEntry(entry0.Pass()); 678 tab.AppendEntry(entry0.Pass());
677 tab.AppendEntry(entry1.Pass()); 679 tab.AppendEntry(entry1.Pass());
678 tab.AppendEntry(entry2.Pass()); 680 tab.AppendEntry(entry2.Pass());
679 tab.AppendEntry(entry3.Pass()); 681 tab.AppendEntry(entry3.Pass());
680 tab.set_current_entry_index(1); 682 tab.set_current_entry_index(1);
681 683
682 sessions::SessionTab session_tab; 684 sessions::SessionTab session_tab;
683 manager()->SetSessionTabFromDelegate(tab, kTime9, &session_tab); 685 manager()->SetSessionTabFromDelegate(
686 manager()->GetSyncedWindowDelegatesGetter(), tab, kTime9, &session_tab);
684 687
685 EXPECT_EQ(2, session_tab.current_navigation_index); 688 EXPECT_EQ(2, session_tab.current_navigation_index);
686 ASSERT_EQ(3u, session_tab.navigations.size()); 689 ASSERT_EQ(3u, session_tab.navigations.size());
687 } 690 }
688 691
689 // Tests that variation ids are set correctly. 692 // Tests that variation ids are set correctly.
690 TEST_F(SessionsSyncManagerTest, SetVariationIds) { 693 TEST_F(SessionsSyncManagerTest, SetVariationIds) {
691 // Create two trials with a group which has a variation id for Chrome Sync 694 // Create two trials with a group which has a variation id for Chrome Sync
692 // and one with a variation id for another service. 695 // and one with a variation id for another service.
693 const variations::VariationID kVariationId1 = 3300200; 696 const variations::VariationID kVariationId1 = 3300200;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 session_tab.tab_visual_index = 1; 747 session_tab.tab_visual_index = 1;
745 session_tab.current_navigation_index = 1; 748 session_tab.current_navigation_index = 1;
746 session_tab.pinned = true; 749 session_tab.pinned = true;
747 session_tab.extension_app_id = "app id"; 750 session_tab.extension_app_id = "app id";
748 session_tab.user_agent_override = "override"; 751 session_tab.user_agent_override = "override";
749 session_tab.timestamp = kTime5; 752 session_tab.timestamp = kTime5;
750 session_tab.navigations.push_back( 753 session_tab.navigations.push_back(
751 SerializedNavigationEntryTestHelper::CreateNavigation( 754 SerializedNavigationEntryTestHelper::CreateNavigation(
752 "http://www.example.com", "Example")); 755 "http://www.example.com", "Example"));
753 session_tab.session_storage_persistent_id = "persistent id"; 756 session_tab.session_storage_persistent_id = "persistent id";
754 manager()->SetSessionTabFromDelegate(tab, kTime4, &session_tab); 757 manager()->SetSessionTabFromDelegate(
758 manager()->GetSyncedWindowDelegatesGetter(), tab, kTime4, &session_tab);
755 759
756 EXPECT_EQ(0, session_tab.window_id.id()); 760 EXPECT_EQ(0, session_tab.window_id.id());
757 EXPECT_EQ(0, session_tab.tab_id.id()); 761 EXPECT_EQ(0, session_tab.tab_id.id());
758 EXPECT_EQ(0, session_tab.tab_visual_index); 762 EXPECT_EQ(0, session_tab.tab_visual_index);
759 EXPECT_EQ(0, session_tab.current_navigation_index); 763 EXPECT_EQ(0, session_tab.current_navigation_index);
760 EXPECT_FALSE(session_tab.pinned); 764 EXPECT_FALSE(session_tab.pinned);
761 EXPECT_TRUE(session_tab.extension_app_id.empty()); 765 EXPECT_TRUE(session_tab.extension_app_id.empty());
762 EXPECT_TRUE(session_tab.user_agent_override.empty()); 766 EXPECT_TRUE(session_tab.user_agent_override.empty());
763 EXPECT_EQ(kTime4, session_tab.timestamp); 767 EXPECT_EQ(kTime4, session_tab.timestamp);
764 ASSERT_EQ(3u, session_tab.navigations.size()); 768 ASSERT_EQ(3u, session_tab.navigations.size());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 815
812 // Now take that header node and feed it in as input. 816 // Now take that header node and feed it in as input.
813 SyncData d(SyncData::CreateRemoteData( 817 SyncData d(SyncData::CreateRemoteData(
814 1, 818 1,
815 data.GetSpecifics(), 819 data.GetSpecifics(),
816 base::Time(), 820 base::Time(),
817 syncer::AttachmentIdList(), 821 syncer::AttachmentIdList(),
818 syncer::AttachmentServiceProxyForTest::Create())); 822 syncer::AttachmentServiceProxyForTest::Create()));
819 syncer::SyncDataList in(&d, &d + 1); 823 syncer::SyncDataList in(&d, &d + 1);
820 out.clear(); 824 out.clear();
821 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(), 825 SessionsSyncManager manager2(GetSyncSessionsClient(), profile(),
822 NewBrowserWindowGetter()); 826 local_device(), NewDummyRouter());
823 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 827 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
824 syncer::SESSIONS, in, 828 syncer::SESSIONS, in,
825 scoped_ptr<syncer::SyncChangeProcessor>( 829 scoped_ptr<syncer::SyncChangeProcessor>(
826 new TestSyncProcessorStub(&out)), 830 new TestSyncProcessorStub(&out)),
827 scoped_ptr<syncer::SyncErrorFactory>( 831 scoped_ptr<syncer::SyncErrorFactory>(
828 new syncer::SyncErrorFactoryMock())); 832 new syncer::SyncErrorFactoryMock()));
829 ASSERT_FALSE(result.error().IsSet()); 833 ASSERT_FALSE(result.error().IsSet());
830 834
831 EXPECT_EQ(1U, out.size()); 835 EXPECT_EQ(1U, out.size());
832 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 836 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 t1_override.SetSyncId(1); // No WebContents by default. 892 t1_override.SetSyncId(1); // No WebContents by default.
889 t2_override.SetSyncId(2); // No WebContents by default. 893 t2_override.SetSyncId(2); // No WebContents by default.
890 SyncedWindowDelegateOverride window_override(*windows.begin()); 894 SyncedWindowDelegateOverride window_override(*windows.begin());
891 window_override.OverrideTabAt(1, &t1_override, kNewTabId); 895 window_override.OverrideTabAt(1, &t1_override, kNewTabId);
892 window_override.OverrideTabAt(2, &t2_override, 896 window_override.OverrideTabAt(2, &t2_override,
893 t2.GetSpecifics().session().tab().tab_id()); 897 t2.GetSpecifics().session().tab().tab_id());
894 std::set<const SyncedWindowDelegate*> delegates; 898 std::set<const SyncedWindowDelegate*> delegates;
895 delegates.insert(&window_override); 899 delegates.insert(&window_override);
896 scoped_ptr<TestSyncedWindowDelegatesGetter> getter( 900 scoped_ptr<TestSyncedWindowDelegatesGetter> getter(
897 new TestSyncedWindowDelegatesGetter(delegates)); 901 new TestSyncedWindowDelegatesGetter(delegates));
898 manager()->synced_window_getter_.reset(getter.release()); 902 manager()->synced_window_getter_ = getter.get();
899 903
900 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( 904 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing(
901 syncer::SESSIONS, in, 905 syncer::SESSIONS, in,
902 scoped_ptr<syncer::SyncChangeProcessor>( 906 scoped_ptr<syncer::SyncChangeProcessor>(
903 new TestSyncProcessorStub(&out)), 907 new TestSyncProcessorStub(&out)),
904 scoped_ptr<syncer::SyncErrorFactory>( 908 scoped_ptr<syncer::SyncErrorFactory>(
905 new syncer::SyncErrorFactoryMock())); 909 new syncer::SyncErrorFactoryMock()));
906 910
907 // There should be two changes, one for the fully associated tab, and 911 // There should be two changes, one for the fully associated tab, and
908 // one for the tab_id update to t1. t2 shouldn't need to be updated. 912 // one for the tab_id update to t1. t2 shouldn't need to be updated.
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); 1405 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics());
1402 entity.mutable_session()->mutable_tab()->set_tab_id(1); 1406 entity.mutable_session()->mutable_tab()->set_tab_id(1);
1403 SyncData d(SyncData::CreateRemoteData( 1407 SyncData d(SyncData::CreateRemoteData(
1404 1, 1408 1,
1405 entity, 1409 entity,
1406 base::Time(), 1410 base::Time(),
1407 syncer::AttachmentIdList(), 1411 syncer::AttachmentIdList(),
1408 syncer::AttachmentServiceProxyForTest::Create())); 1412 syncer::AttachmentServiceProxyForTest::Create()));
1409 syncer::SyncDataList in(&d, &d + 1); 1413 syncer::SyncDataList in(&d, &d + 1);
1410 changes.clear(); 1414 changes.clear();
1411 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(), 1415 SessionsSyncManager manager2(GetSyncSessionsClient(), profile(),
1412 NewBrowserWindowGetter()); 1416 local_device(), NewDummyRouter());
1413 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 1417 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
1414 syncer::SESSIONS, in, 1418 syncer::SESSIONS, in,
1415 scoped_ptr<syncer::SyncChangeProcessor>( 1419 scoped_ptr<syncer::SyncChangeProcessor>(
1416 new TestSyncProcessorStub(&changes)), 1420 new TestSyncProcessorStub(&changes)),
1417 scoped_ptr<syncer::SyncErrorFactory>( 1421 scoped_ptr<syncer::SyncErrorFactory>(
1418 new syncer::SyncErrorFactoryMock())); 1422 new syncer::SyncErrorFactoryMock()));
1419 ASSERT_FALSE(result.error().IsSet()); 1423 ASSERT_FALSE(result.error().IsSet());
1420 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); 1424 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty());
1421 } 1425 }
1422 1426
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 out[8].sync_data().GetSpecifics().session().tab(); 1598 out[8].sync_data().GetSpecifics().session().tab();
1595 ASSERT_EQ(1, tab2_1.navigation_size()); 1599 ASSERT_EQ(1, tab2_1.navigation_size());
1596 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url()); 1600 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url());
1597 const sync_pb::SessionTab& tab2_2 = 1601 const sync_pb::SessionTab& tab2_2 =
1598 out[10].sync_data().GetSpecifics().session().tab(); 1602 out[10].sync_data().GetSpecifics().session().tab();
1599 ASSERT_EQ(2, tab2_2.navigation_size()); 1603 ASSERT_EQ(2, tab2_2.navigation_size());
1600 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url()); 1604 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url());
1601 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url()); 1605 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url());
1602 } 1606 }
1603 1607
1608 // Check that if a tab becomes uninteresting (for example no syncable URLs),
1609 // we correctly remove it from the header node.
1610 TEST_F(SessionsSyncManagerTest, TabBecomesUninteresting) {
1611 syncer::SyncChangeList out;
1612 // Init with no local data, relies on MergeLocalSessionNoTabs.
1613 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
1614 ASSERT_FALSE(manager()->current_machine_tag().empty());
1615 ASSERT_EQ(2U, out.size());
1616 out.clear();
1617
1618 const GURL kValidUrl("http://foo/1");
1619 const GURL kInternalUrl("chrome://internal");
1620
1621 // Add an interesting tab.
1622 AddTab(browser(), kValidUrl);
1623 // No-op header update, tab creation, tab update, header update.
1624 ASSERT_EQ(4U, out.size());
1625 // The last two are the interesting updates.
1626 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab());
1627 EXPECT_EQ(kValidUrl.spec(), out[2]
1628 .sync_data()
1629 .GetSpecifics()
1630 .session()
1631 .tab()
1632 .navigation(0)
1633 .virtual_url());
1634 ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header());
1635 ASSERT_EQ(1,
1636 out[3].sync_data().GetSpecifics().session().header().window_size());
1637 ASSERT_EQ(1, out[3]
1638 .sync_data()
1639 .GetSpecifics()
1640 .session()
1641 .header()
1642 .window(0)
1643 .tab_size());
1644
1645 // Navigate five times to uninteresting urls to push the interesting one off
1646 // the back of the stack.
1647 NavigateAndCommitActiveTab(kInternalUrl);
1648 NavigateAndCommitActiveTab(kInternalUrl);
1649 NavigateAndCommitActiveTab(kInternalUrl);
1650 NavigateAndCommitActiveTab(kInternalUrl);
1651
1652 // Reset |out| so we only see the effects of the final navigation.
1653 out.clear();
1654 NavigateAndCommitActiveTab(kInternalUrl);
1655
1656 // Only the header node should be updated, and it should no longer have any
1657 // valid windows/tabs.
1658 ASSERT_EQ(2U, out.size()); // Two header updates (first is a no-op).
1659 ASSERT_TRUE(out[1].sync_data().GetSpecifics().session().has_header());
1660 EXPECT_EQ(1,
1661 out[1].sync_data().GetSpecifics().session().header().window_size());
1662 }
1663
1604 // Ensure model association associates the pre-existing tabs. 1664 // Ensure model association associates the pre-existing tabs.
1605 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) { 1665 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) {
1606 AddTab(browser(), GURL("http://foo1")); 1666 AddTab(browser(), GURL("http://foo1"));
1607 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry. 1667 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry.
1608 AddTab(browser(), GURL("http://bar1")); 1668 AddTab(browser(), GURL("http://bar1"));
1609 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry. 1669 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry.
1610 1670
1611 syncer::SyncChangeList out; 1671 syncer::SyncChangeList out;
1612 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); 1672 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
1613 ASSERT_EQ(6U, out.size()); 1673 ASSERT_EQ(6U, out.size());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 const sync_pb::SessionHeader& header_s2 = specifics2.header(); 1719 const sync_pb::SessionHeader& header_s2 = specifics2.header();
1660 EXPECT_EQ(1, header_s2.window_size()); 1720 EXPECT_EQ(1, header_s2.window_size());
1661 1721
1662 // Verify TabLinks. 1722 // Verify TabLinks.
1663 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; 1723 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_;
1664 ASSERT_EQ(2U, tab_map.size()); 1724 ASSERT_EQ(2U, tab_map.size());
1665 // Tabs are ordered by sessionid in tab_map, so should be able to traverse 1725 // Tabs are ordered by sessionid in tab_map, so should be able to traverse
1666 // the tree based on order of tabs created 1726 // the tree based on order of tabs created
1667 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); 1727 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin();
1668 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); 1728 ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
1669 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()-> 1729 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0));
1670 GetEntryAtIndex(0)->GetVirtualURL()); 1730 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1));
1671 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->
1672 GetEntryAtIndex(1)->GetVirtualURL());
1673 iter++; 1731 iter++;
1674 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); 1732 ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
1675 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()-> 1733 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0));
1676 GetEntryAtIndex(0)->GetVirtualURL()); 1734 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1));
1677 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->
1678 GetEntryAtIndex(1)->GetVirtualURL());
1679 } 1735 }
1680 1736
1681 // Test garbage collection of stale foreign sessions. 1737 // Test garbage collection of stale foreign sessions.
1682 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { 1738 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) {
1683 // Fill two instances of session specifics with a foreign session's data. 1739 // Fill two instances of session specifics with a foreign session's data.
1684 std::string tag1 = "tag1"; 1740 std::string tag1 = "tag1";
1685 SessionID::id_type n1[] = {5, 10, 13, 17}; 1741 SessionID::id_type n1[] = {5, 10, 13, 17};
1686 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); 1742 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
1687 std::vector<sync_pb::SessionSpecifics> tabs1; 1743 std::vector<sync_pb::SessionSpecifics> tabs1;
1688 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( 1744 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 base::Time last_time; 2265 base::Time last_time;
2210 for (size_t i = 0; i < tabs.size(); ++i) { 2266 for (size_t i = 0; i < tabs.size(); ++i) {
2211 base::Time this_time = tabs[i]->timestamp; 2267 base::Time this_time = tabs[i]->timestamp;
2212 if (i > 0) 2268 if (i > 0)
2213 ASSERT_GE(last_time, this_time); 2269 ASSERT_GE(last_time, this_time);
2214 last_time = tabs[i]->timestamp; 2270 last_time = tabs[i]->timestamp;
2215 } 2271 }
2216 } 2272 }
2217 2273
2218 } // namespace browser_sync 2274 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698