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

Side by Side Diff: components/sync_sessions/sessions_sync_manager_unittest.cc

Issue 2753753005: [sync] WebContentsObserver based sessions notifications (Closed)
Patch Set: [sync] WebContentsObserver based sessions notifications Created 3 years, 9 months 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 "components/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 int http_count = 0; 204 int http_count = 0;
205 for (auto& entry : entries_) { 205 for (auto& entry : entries_) {
206 if (!entry->virtual_url().is_valid()) 206 if (!entry->virtual_url().is_valid())
207 return false; 207 return false;
208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) 208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS())
209 http_count++; 209 http_count++;
210 } 210 }
211 return http_count > 0; 211 return http_count > 0;
212 } 212 }
213 213
214 SessionID::id_type GetSourceTabID() const override { return -1; }
Nicolas Zea 2017/03/16 19:57:44 Would it be possible to use kUnknownTabId here (a
Patrick Noland 2017/03/16 20:23:27 Done.
215
214 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { 216 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) {
215 entries_.push_back(std::move(entry)); 217 entries_.push_back(std::move(entry));
216 } 218 }
217 219
218 void set_current_entry_index(int i) { current_entry_index_ = i; } 220 void set_current_entry_index(int i) { current_entry_index_ = i; }
219 221
220 void SetWindowId(SessionID::id_type window_id) { 222 void SetWindowId(SessionID::id_type window_id) {
221 window_id_.set_id(window_id); 223 window_id_.set_id(window_id);
222 } 224 }
223 225
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* 317 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>*
316 GetBlockedNavigations() const override { 318 GetBlockedNavigations() const override {
317 NOTREACHED(); 319 NOTREACHED();
318 return nullptr; 320 return nullptr;
319 } 321 }
320 bool ShouldSync(SyncSessionsClient* sessions_client) override { 322 bool ShouldSync(SyncSessionsClient* sessions_client) override {
321 NOTREACHED(); 323 NOTREACHED();
322 return false; 324 return false;
323 } 325 }
324 326
327 SessionID::id_type GetSourceTabID() const override { return -1; }
328
325 private: 329 private:
326 SessionID::id_type session_id_; 330 SessionID::id_type session_id_;
327 int sync_id_; 331 int sync_id_;
328 }; 332 };
329 333
330 class TestSyncedWindowDelegate : public SyncedWindowDelegate { 334 class TestSyncedWindowDelegate : public SyncedWindowDelegate {
331 public: 335 public:
332 TestSyncedWindowDelegate() {} 336 TestSyncedWindowDelegate() {}
333 ~TestSyncedWindowDelegate() override {} 337 ~TestSyncedWindowDelegate() override {}
334 338
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 509
506 void SetUp() override { 510 void SetUp() override {
507 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>( 511 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>(
508 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k", 512 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k",
509 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); 513 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id");
510 sync_client_ = base::MakeUnique<syncer::FakeSyncClient>(); 514 sync_client_ = base::MakeUnique<syncer::FakeSyncClient>();
511 sessions_client_shim_ = 515 sessions_client_shim_ =
512 base::MakeUnique<SyncSessionsClientShim>(&window_getter_); 516 base::MakeUnique<SyncSessionsClientShim>(&window_getter_);
513 sync_prefs_ = 517 sync_prefs_ =
514 base::MakeUnique<syncer::SyncPrefs>(sync_client_->GetPrefService()); 518 base::MakeUnique<syncer::SyncPrefs>(sync_client_->GetPrefService());
519 router_ = base::MakeUnique<DummyRouter>();
515 manager_ = base::MakeUnique<SessionsSyncManager>( 520 manager_ = base::MakeUnique<SessionsSyncManager>(
516 sessions_client_shim(), sync_prefs_.get(), local_device_.get(), 521 sessions_client_shim(), sync_prefs_.get(), local_device_.get(),
517 std::unique_ptr<LocalSessionEventRouter>(NewDummyRouter()), 522 router_.get(),
518 base::Bind(&SessionNotificationObserver::NotifyOfUpdate, 523 base::Bind(&SessionNotificationObserver::NotifyOfUpdate,
519 base::Unretained(&observer_)), 524 base::Unretained(&observer_)),
520 base::Bind(&SessionNotificationObserver::NotifyOfRefresh, 525 base::Bind(&SessionNotificationObserver::NotifyOfRefresh,
521 base::Unretained(&observer_))); 526 base::Unretained(&observer_)));
522 } 527 }
523 528
524 void TearDown() override { 529 void TearDown() override {
525 test_processor_ = nullptr; 530 test_processor_ = nullptr;
526 helper()->Reset(); 531 helper()->Reset();
527 sync_prefs_.reset(); 532 sync_prefs_.reset();
(...skipping 11 matching lines...) Expand all
539 SessionsSyncManager* manager() { return manager_.get(); } 544 SessionsSyncManager* manager() { return manager_.get(); }
540 SessionSyncTestHelper* helper() { return &helper_; } 545 SessionSyncTestHelper* helper() { return &helper_; }
541 LocalDeviceInfoProvider* local_device() { return local_device_.get(); } 546 LocalDeviceInfoProvider* local_device() { return local_device_.get(); }
542 SessionNotificationObserver* observer() { return &observer_; } 547 SessionNotificationObserver* observer() { return &observer_; }
543 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } 548 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); }
544 SyncSessionsClient* sessions_client_shim() { 549 SyncSessionsClient* sessions_client_shim() {
545 return sessions_client_shim_.get(); 550 return sessions_client_shim_.get();
546 } 551 }
547 SyncedWindowDelegatesGetter* window_getter() { return &window_getter_; } 552 SyncedWindowDelegatesGetter* window_getter() { return &window_getter_; }
548 553
549 std::unique_ptr<LocalSessionEventRouter> NewDummyRouter() {
550 std::unique_ptr<DummyRouter> router(new DummyRouter());
551 router_ = router.get();
552 return std::unique_ptr<LocalSessionEventRouter>(std::move(router));
553 }
554
555 void InitWithSyncDataTakeOutput(const SyncDataList& initial_data, 554 void InitWithSyncDataTakeOutput(const SyncDataList& initial_data,
556 SyncChangeList* output) { 555 SyncChangeList* output) {
557 test_processor_ = new TestSyncChangeProcessor(output); 556 test_processor_ = new TestSyncChangeProcessor(output);
558 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( 557 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing(
559 syncer::SESSIONS, initial_data, 558 syncer::SESSIONS, initial_data,
560 std::unique_ptr<syncer::SyncChangeProcessor>(test_processor_), 559 std::unique_ptr<syncer::SyncChangeProcessor>(test_processor_),
561 std::unique_ptr<syncer::SyncErrorFactory>( 560 std::unique_ptr<syncer::SyncErrorFactory>(
562 new syncer::SyncErrorFactoryMock())); 561 new syncer::SyncErrorFactoryMock()));
563 EXPECT_FALSE(result.error().IsSet()); 562 EXPECT_FALSE(result.error().IsSet());
564 } 563 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); 720 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>());
722 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); 721 window_getter_.AddSyncedWindowDelegate(windows_.back().get());
723 return windows_.back().get(); 722 return windows_.back().get();
724 } 723 }
725 724
726 private: 725 private:
727 std::unique_ptr<syncer::FakeSyncClient> sync_client_; 726 std::unique_ptr<syncer::FakeSyncClient> sync_client_;
728 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_; 727 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_;
729 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; 728 std::unique_ptr<syncer::SyncPrefs> sync_prefs_;
730 SessionNotificationObserver observer_; 729 SessionNotificationObserver observer_;
731 DummyRouter* router_ = nullptr; 730 std::unique_ptr<DummyRouter> router_;
732 std::unique_ptr<SessionsSyncManager> manager_; 731 std::unique_ptr<SessionsSyncManager> manager_;
733 SessionSyncTestHelper helper_; 732 SessionSyncTestHelper helper_;
734 TestSyncChangeProcessor* test_processor_ = nullptr; 733 TestSyncChangeProcessor* test_processor_ = nullptr;
735 TestSyncedWindowDelegatesGetter window_getter_; 734 TestSyncedWindowDelegatesGetter window_getter_;
736 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_; 735 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_;
737 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_; 736 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_;
738 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; 737 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_;
739 }; 738 };
740 739
741 // Test that the SyncSessionManager can properly fill in a SessionHeader. 740 // Test that the SyncSessionManager can properly fill in a SessionHeader.
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 // Because tab 2 is a placeholder, tab 1's URL will be preserved. 2396 // Because tab 2 is a placeholder, tab 1's URL will be preserved.
2398 VerifyLocalTabChange(out[1], 1, kFoo1); 2397 VerifyLocalTabChange(out[1], 1, kFoo1);
2399 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); 2398 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id());
2400 EXPECT_EQ(tab2.GetSessionId(), 2399 EXPECT_EQ(tab2.GetSessionId(),
2401 out[1].sync_data().GetSpecifics().session().tab().tab_id()); 2400 out[1].sync_data().GetSpecifics().session().tab().tab_id());
2402 EXPECT_EQ(window2->GetSessionId(), 2401 EXPECT_EQ(window2->GetSessionId(),
2403 out[1].sync_data().GetSpecifics().session().tab().window_id()); 2402 out[1].sync_data().GetSpecifics().session().tab().window_id());
2404 } 2403 }
2405 2404
2406 } // namespace sync_sessions 2405 } // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698