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

Side by Side Diff: chrome/browser/sync/engine/clear_data_command_unittest.cc

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/engine/clear_data_command.h"
6 #include "chrome/browser/sync/test/engine/syncer_command_test.h"
7 #include "chrome/browser/sync/test/sessions/test_scoped_session_event_listener.h "
8 #include "sync/protocol/autofill_specifics.pb.h"
9 #include "sync/protocol/bookmark_specifics.pb.h"
10 #include "sync/protocol/preference_specifics.pb.h"
11 #include "sync/protocol/sync.pb.h"
12
13 namespace browser_sync {
14
15 using sessions::TestScopedSessionEventListener;
16 using syncable::FIRST_REAL_MODEL_TYPE;
17 using syncable::MODEL_TYPE_COUNT;
18
19 // A test fixture for tests exercising ClearDataCommandTest.
20 class ClearDataCommandTest : public SyncerCommandTest {
21 protected:
22 ClearDataCommandTest() {}
23 ClearDataCommand command_;
24
25 virtual void OnShouldStopSyncingPermanently() {
26 on_should_stop_syncing_permanently_called_ = true;
27 }
28
29 protected:
30 bool on_should_stop_syncing_permanently_called_;
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(ClearDataCommandTest);
34 };
35
36 class ClearEventHandler : public SyncEngineEventListener {
37 public:
38 ClearEventHandler() {
39 ResetReceivedEvents();
40 }
41 bool ReceievedClearSuccessEvent() { return received_clear_success_event_; }
42 bool ReceievedClearFailedEvent() { return received_clear_failed_event_; }
43 void ResetReceivedEvents() {
44 received_clear_success_event_ = false;
45 received_clear_failed_event_ = false;
46 }
47
48 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) {
49 if (event.what_happened == SyncEngineEvent::CLEAR_SERVER_DATA_FAILED) {
50 received_clear_failed_event_ = true;
51 } else if (event.what_happened ==
52 SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED) {
53 received_clear_success_event_ = true;
54 }
55 }
56
57 private:
58 bool received_clear_success_event_;
59 bool received_clear_failed_event_;
60 };
61
62 TEST_F(ClearDataCommandTest, ClearDataCommandExpectFailed) {
63 ConfigureMockServerConnection();
64 scoped_ptr<ClearEventHandler> handler(new ClearEventHandler());
65 TestScopedSessionEventListener reg(context(), handler.get());
66
67 directory()->set_store_birthday(mock_server()->store_birthday());
68 mock_server()->SetServerNotReachable();
69 on_should_stop_syncing_permanently_called_ = false;
70
71 command_.Execute(session());
72
73 // Expect that the client sent a clear request, received failure,
74 // fired a failure event, but did not disable sync.
75 //
76 // A failure event will be bubbled back to the user's UI, and the
77 // user can press "clear" again.
78 //
79 // We do not want to disable sync in the client because the user may
80 // incorrectly get the impression that their private data has been cleared
81 // from the server (from the fact that their data is gone on the client).
82 //
83 // Any subsequent GetUpdates/Commit requests or attempts to enable sync
84 // will cause the server to attempt to resume the clearing process (within
85 // a bounded window of time)
86 const sync_pb::ClientToServerMessage& r = mock_server()->last_request();
87 EXPECT_TRUE(r.has_clear_user_data());
88
89 EXPECT_TRUE(handler.get()->ReceievedClearFailedEvent());
90
91 EXPECT_FALSE(handler.get()->ReceievedClearSuccessEvent());
92 EXPECT_FALSE(on_should_stop_syncing_permanently_called_);
93 }
94
95 TEST_F(ClearDataCommandTest, ClearDataCommandExpectSuccess) {
96 ConfigureMockServerConnection();
97 scoped_ptr<ClearEventHandler> handler(new ClearEventHandler());
98 TestScopedSessionEventListener reg(context(), handler.get());
99
100 directory()->set_store_birthday(mock_server()->store_birthday());
101 mock_server()->SetClearUserDataResponseStatus(sync_pb::SyncEnums::SUCCESS);
102 on_should_stop_syncing_permanently_called_ = false;
103
104 command_.Execute(session());
105
106 // Expect that the client sent a clear request, fired off the success event
107 // in response, and disabled sync
108 const sync_pb::ClientToServerMessage& r = mock_server()->last_request();
109 EXPECT_TRUE(r.has_clear_user_data());
110
111 EXPECT_TRUE(handler->ReceievedClearSuccessEvent());
112 EXPECT_TRUE(on_should_stop_syncing_permanently_called_);
113
114 EXPECT_FALSE(handler->ReceievedClearFailedEvent());
115 }
116
117 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/clear_data_command.cc ('k') | chrome/browser/sync/engine/conflict_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698