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

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

Issue 15764010: Experimental functionize patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync: Expose sync functionality as functions Created 7 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
« no previous file with comments | « sync/engine/download.cc ('k') | sync/engine/download_updates_command.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sync/engine/download_updates_command.h" 5 #include "sync/engine/download.h"
6 #include "sync/protocol/sync.pb.h" 6 #include "sync/protocol/sync.pb.h"
7 #include "sync/sessions/nudge_tracker.h" 7 #include "sync/sessions/nudge_tracker.h"
8 #include "sync/test/engine/fake_model_worker.h" 8 #include "sync/test/engine/fake_model_worker.h"
9 #include "sync/test/engine/syncer_command_test.h" 9 #include "sync/test/engine/syncer_command_test.h"
10 10
11 using ::testing::_; 11 using ::testing::_;
12 12
13 namespace syncer { 13 namespace syncer {
14 14
15 // A test fixture for tests exercising DownloadUpdatesCommandTest. 15 // A test fixture for tests exercising download updates functions.
16 class DownloadUpdatesCommandTest : public SyncerCommandTest { 16 class DownloadUpdatesTest : public SyncerCommandTest {
17 protected: 17 protected:
18 DownloadUpdatesCommandTest() 18 DownloadUpdatesTest() {
19 : command_(true /* create_mobile_bookmarks_folder */) {} 19 }
20 20
21 virtual void SetUp() { 21 virtual void SetUp() {
22 workers()->clear(); 22 workers()->clear();
23 mutable_routing_info()->clear(); 23 mutable_routing_info()->clear();
24 workers()->push_back( 24 workers()->push_back(
25 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); 25 make_scoped_refptr(new FakeModelWorker(GROUP_DB)));
26 workers()->push_back( 26 workers()->push_back(
27 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); 27 make_scoped_refptr(new FakeModelWorker(GROUP_UI)));
28 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; 28 (*mutable_routing_info())[AUTOFILL] = GROUP_DB;
29 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; 29 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI;
30 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; 30 (*mutable_routing_info())[PREFERENCES] = GROUP_UI;
31 SyncerCommandTest::SetUp(); 31 SyncerCommandTest::SetUp();
32 } 32 }
33 33
34 DownloadUpdatesCommand command_;
35
36 private: 34 private:
37 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesCommandTest); 35 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest);
38 }; 36 };
39 37
40 TEST_F(DownloadUpdatesCommandTest, ExecuteNoStates) { 38 TEST_F(DownloadUpdatesTest, ExecuteNoStates) {
41 ConfigureMockServerConnection(); 39 ConfigureMockServerConnection();
42 40
43 sessions::NudgeTracker nudge_tracker; 41 sessions::NudgeTracker nudge_tracker;
44 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 42 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
45 43
46 mock_server()->ExpectGetUpdatesRequestTypes( 44 mock_server()->ExpectGetUpdatesRequestTypes(
47 GetRoutingInfoTypes(routing_info())); 45 GetRoutingInfoTypes(routing_info()));
48 scoped_ptr<sessions::SyncSession> session( 46 scoped_ptr<sessions::SyncSession> session(
49 sessions::SyncSession::BuildForNudge(context(), 47 sessions::SyncSession::Build(context(),
50 delegate(), 48 delegate(),
51 nudge_tracker.GetSourceInfo(), 49 nudge_tracker.GetSourceInfo()));
52 &nudge_tracker)); 50 NormalDownloadUpdates(session.get(),
53 command_.ExecuteImpl(session.get()); 51 false,
52 GetRoutingInfoTypes(routing_info()),
53 nudge_tracker);
54 } 54 }
55 55
56 TEST_F(DownloadUpdatesCommandTest, ExecuteWithStates) { 56 TEST_F(DownloadUpdatesTest, ExecuteWithStates) {
57 ConfigureMockServerConnection(); 57 ConfigureMockServerConnection();
58 58
59 sessions::NudgeTracker nudge_tracker; 59 sessions::NudgeTracker nudge_tracker;
60 nudge_tracker.RecordRemoteInvalidation( 60 nudge_tracker.RecordRemoteInvalidation(
61 ModelTypeSetToInvalidationMap(ModelTypeSet(AUTOFILL), 61 ModelTypeSetToInvalidationMap(ModelTypeSet(AUTOFILL),
62 "autofill_payload")); 62 "autofill_payload"));
63 nudge_tracker.RecordRemoteInvalidation( 63 nudge_tracker.RecordRemoteInvalidation(
64 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 64 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS),
65 "bookmark_payload")); 65 "bookmark_payload"));
66 nudge_tracker.RecordRemoteInvalidation( 66 nudge_tracker.RecordRemoteInvalidation(
67 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES), 67 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES),
68 "preferences_payload")); 68 "preferences_payload"));
69 69
70 mock_server()->ExpectGetUpdatesRequestTypes( 70 mock_server()->ExpectGetUpdatesRequestTypes(
71 GetRoutingInfoTypes(routing_info())); 71 GetRoutingInfoTypes(routing_info()));
72 mock_server()->ExpectGetUpdatesRequestStates( 72 mock_server()->ExpectGetUpdatesRequestStates(
73 nudge_tracker.GetSourceInfo().types); 73 nudge_tracker.GetSourceInfo().types);
74 scoped_ptr<sessions::SyncSession> session( 74 scoped_ptr<sessions::SyncSession> session(
75 sessions::SyncSession::BuildForNudge(context(), 75 sessions::SyncSession::Build(context(),
76 delegate(), 76 delegate(),
77 nudge_tracker.GetSourceInfo(), 77 nudge_tracker.GetSourceInfo()));
78 &nudge_tracker)); 78 NormalDownloadUpdates(session.get(),
79 command_.ExecuteImpl(session.get()); 79 false,
80 GetRoutingInfoTypes(routing_info()),
81 nudge_tracker);
80 } 82 }
81 83
82 TEST_F(DownloadUpdatesCommandTest, VerifyAppendDebugInfo) { 84 TEST_F(DownloadUpdatesTest, VerifyAppendDebugInfo) {
83 sync_pb::DebugInfo debug_info; 85 sync_pb::DebugInfo debug_info;
84 EXPECT_CALL(*(mock_debug_info_getter()), GetAndClearDebugInfo(_)) 86 EXPECT_CALL(*(mock_debug_info_getter()), GetAndClearDebugInfo(_))
85 .Times(1); 87 .Times(1);
86 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); 88 // The first of a set of repeated GUs will set it.
89 AppendClientDebugInfoIfNeeded(session(), &debug_info);
87 90
88 // Now try to add it once more and make sure |GetAndClearDebugInfo| is not 91 // Subsequent GUs will not.
89 // called. 92 // Verify by checking that GetAndClearDebugInfo() is not called again.
90 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); 93 AppendClientDebugInfoIfNeeded(session(), &debug_info);
91 } 94 }
92 95
93 } // namespace syncer 96 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/download.cc ('k') | sync/engine/download_updates_command.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698