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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up and rebased Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop.h" 21 #include "base/message_loop.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "sync/engine/throttled_data_type_tracker.h"
26 #include "sync/engine/get_commit_ids_command.h" 27 #include "sync/engine/get_commit_ids_command.h"
27 #include "sync/engine/model_safe_worker.h" 28 #include "sync/engine/model_safe_worker.h"
28 #include "sync/engine/net/server_connection_manager.h" 29 #include "sync/engine/net/server_connection_manager.h"
29 #include "sync/engine/nigori_util.h" 30 #include "sync/engine/nigori_util.h"
30 #include "sync/engine/process_updates_command.h" 31 #include "sync/engine/process_updates_command.h"
31 #include "sync/engine/syncer.h" 32 #include "sync/engine/syncer.h"
32 #include "sync/engine/syncer_proto_util.h" 33 #include "sync/engine/syncer_proto_util.h"
33 #include "sync/engine/syncer_util.h" 34 #include "sync/engine/syncer_util.h"
34 #include "sync/engine/syncproto.h" 35 #include "sync/engine/syncproto.h"
35 #include "sync/engine/traffic_recorder.h" 36 #include "sync/engine/traffic_recorder.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EnableDatatype(syncable::BOOKMARKS); 224 EnableDatatype(syncable::BOOKMARKS);
224 EnableDatatype(syncable::NIGORI); 225 EnableDatatype(syncable::NIGORI);
225 EnableDatatype(syncable::PREFERENCES); 226 EnableDatatype(syncable::PREFERENCES);
226 EnableDatatype(syncable::NIGORI); 227 EnableDatatype(syncable::NIGORI);
227 worker_ = new FakeModelWorker(GROUP_PASSIVE); 228 worker_ = new FakeModelWorker(GROUP_PASSIVE);
228 std::vector<SyncEngineEventListener*> listeners; 229 std::vector<SyncEngineEventListener*> listeners;
229 listeners.push_back(this); 230 listeners.push_back(this);
230 context_.reset( 231 context_.reset(
231 new SyncSessionContext( 232 new SyncSessionContext(
232 mock_server_.get(), directory(), this, 233 mock_server_.get(), directory(), this,
233 &extensions_activity_monitor_, listeners, NULL, 234 &extensions_activity_monitor_,
235 &throttled_data_type_tracker_,
236 listeners, NULL,
234 &traffic_recorder_)); 237 &traffic_recorder_));
235 ASSERT_FALSE(context_->resolver()); 238 ASSERT_FALSE(context_->resolver());
236 syncer_ = new Syncer(); 239 syncer_ = new Syncer();
237 session_.reset(MakeSession()); 240 session_.reset(MakeSession());
238 241
239 ReadTransaction trans(FROM_HERE, directory()); 242 ReadTransaction trans(FROM_HERE, directory());
240 syncable::Directory::ChildHandles children; 243 syncable::Directory::ChildHandles children;
241 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 244 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
242 ASSERT_EQ(0u, children.size()); 245 ASSERT_EQ(0u, children.size());
243 saw_syncer_event_ = false; 246 saw_syncer_event_ = false;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // more confusing. 519 // more confusing.
517 syncable::Id root_id_; 520 syncable::Id root_id_;
518 syncable::Id parent_id_; 521 syncable::Id parent_id_;
519 syncable::Id child_id_; 522 syncable::Id child_id_;
520 523
521 TestIdFactory ids_; 524 TestIdFactory ids_;
522 525
523 TestDirectorySetterUpper dir_maker_; 526 TestDirectorySetterUpper dir_maker_;
524 FakeEncryptor encryptor_; 527 FakeEncryptor encryptor_;
525 FakeExtensionsActivityMonitor extensions_activity_monitor_; 528 FakeExtensionsActivityMonitor extensions_activity_monitor_;
529 ThrottledDataTypeTracker throttled_data_type_tracker_;
526 scoped_ptr<MockConnectionManager> mock_server_; 530 scoped_ptr<MockConnectionManager> mock_server_;
527 531
528 Syncer* syncer_; 532 Syncer* syncer_;
529 533
530 scoped_ptr<SyncSession> session_; 534 scoped_ptr<SyncSession> session_;
531 scoped_ptr<SyncSessionContext> context_; 535 scoped_ptr<SyncSessionContext> context_;
532 bool saw_syncer_event_; 536 bool saw_syncer_event_;
533 base::TimeDelta last_short_poll_interval_received_; 537 base::TimeDelta last_short_poll_interval_received_;
534 base::TimeDelta last_long_poll_interval_received_; 538 base::TimeDelta last_long_poll_interval_received_;
535 base::TimeDelta last_sessions_commit_delay_seconds_; 539 base::TimeDelta last_sessions_commit_delay_seconds_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 { 623 {
620 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 624 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
621 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 625 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
622 ASSERT_TRUE(A.good()); 626 ASSERT_TRUE(A.good());
623 A.Put(IS_UNSYNCED, true); 627 A.Put(IS_UNSYNCED, true);
624 A.Put(SPECIFICS, bookmark_data); 628 A.Put(SPECIFICS, bookmark_data);
625 A.Put(NON_UNIQUE_NAME, "bookmark"); 629 A.Put(NON_UNIQUE_NAME, "bookmark");
626 } 630 }
627 631
628 // Now set the throttled types. 632 // Now set the throttled types.
629 context_->SetUnthrottleTime( 633 context_->throttled_data_type_tracker()->SetUnthrottleTime(
630 throttled_types, 634 throttled_types,
631 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200)); 635 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200));
632 SyncShareNudge(); 636 SyncShareNudge();
633 637
634 { 638 {
635 // Nothing should have been committed as bookmarks is throttled. 639 // Nothing should have been committed as bookmarks is throttled.
636 ReadTransaction rtrans(FROM_HERE, directory()); 640 ReadTransaction rtrans(FROM_HERE, directory());
637 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 641 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
638 ASSERT_TRUE(entryA.good()); 642 ASSERT_TRUE(entryA.good());
639 EXPECT_TRUE(entryA.Get(IS_UNSYNCED)); 643 EXPECT_TRUE(entryA.Get(IS_UNSYNCED));
640 } 644 }
641 645
642 // Now unthrottle. 646 // Now unthrottle.
643 context_->SetUnthrottleTime( 647 context_->throttled_data_type_tracker()->SetUnthrottleTime(
644 throttled_types, 648 throttled_types,
645 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200)); 649 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200));
646 SyncShareNudge(); 650 SyncShareNudge();
647 { 651 {
648 // It should have been committed. 652 // It should have been committed.
649 ReadTransaction rtrans(FROM_HERE, directory()); 653 ReadTransaction rtrans(FROM_HERE, directory());
650 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 654 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
651 ASSERT_TRUE(entryA.good()); 655 ASSERT_TRUE(entryA.good());
652 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); 656 EXPECT_FALSE(entryA.Get(IS_UNSYNCED));
653 } 657 }
(...skipping 4147 matching lines...) Expand 10 before | Expand all | Expand 10 after
4801 4805
4802 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4806 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4803 Add(mid_id_); 4807 Add(mid_id_);
4804 Add(low_id_); 4808 Add(low_id_);
4805 Add(high_id_); 4809 Add(high_id_);
4806 SyncShareNudge(); 4810 SyncShareNudge();
4807 ExpectLocalOrderIsByServerId(); 4811 ExpectLocalOrderIsByServerId();
4808 } 4812 }
4809 4813
4810 } // namespace browser_sync 4814 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698