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.
5 #include "base/prefs/pref_member.h"
6 #include "base/prefs/pref_service.h"
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/profile_sync_service_harness.h"
9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
10 #include "chrome/browser/sync/test/integration/passwords_helper.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "chrome/common/pref_names.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "sync/protocol/sync_protocol_error.h"
16 using bookmarks_helper::AddFolder;
17 using bookmarks_helper::SetTitle;
19 class SyncErrorTest : public SyncTest {
21 SyncErrorTest() : SyncTest(SINGLE_CLIENT) {}
22 virtual ~SyncErrorTest() {}
25 DISALLOW_COPY_AND_ASSIGN(SyncErrorTest);
28 IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) {
29 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
31 const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
32 SetTitle(0, node1, L"new_title1");
33 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Offline state change."));
34 TriggerBirthdayError();
36 // Now make one more change so we will do another sync.
37 const BookmarkNode* node2 = AddFolder(0, 0, L"title2");
38 SetTitle(0, node2, L"new_title2");
39 ASSERT_TRUE(GetClient(0)->AwaitSyncDisabled("Birthday error."));
42 IN_PROC_BROWSER_TEST_F(SyncErrorTest, TransientErrorTest) {
43 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
45 const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
46 SetTitle(0, node1, L"new_title1");
47 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Offline state change."));
48 TriggerTransientError();
50 // Now make one more change so we will do another sync.
51 const BookmarkNode* node2 = AddFolder(0, 0, L"title2");
52 SetTitle(0, node2, L"new_title2");
54 GetClient(0)->AwaitExponentialBackoffVerification());
57 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ActionableErrorTest) {
58 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
60 const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
61 SetTitle(0, node1, L"new_title1");
62 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Sync."));
64 syncer::SyncProtocolError protocol_error;
65 protocol_error.error_type = syncer::TRANSIENT_ERROR;
66 protocol_error.action = syncer::UPGRADE_CLIENT;
67 protocol_error.error_description = "Not My Fault";
68 protocol_error.url = "www.google.com";
69 TriggerSyncError(protocol_error, SyncTest::ERROR_FREQUENCY_ALWAYS);
71 // Now make one more change so we will do another sync.
72 const BookmarkNode* node2 = AddFolder(0, 0, L"title2");
73 SetTitle(0, node2, L"new_title2");
75 GetClient(0)->AwaitActionableError());
76 ProfileSyncService::Status status = GetClient(0)->GetStatus();
77 ASSERT_EQ(status.sync_protocol_error.error_type, protocol_error.error_type);
78 ASSERT_EQ(status.sync_protocol_error.action, protocol_error.action);
79 ASSERT_EQ(status.sync_protocol_error.url, protocol_error.url);
80 ASSERT_EQ(status.sync_protocol_error.error_description,
81 protocol_error.error_description);
84 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ErrorWhileSettingUp) {
85 ASSERT_TRUE(SetupClients());
87 syncer::SyncProtocolError protocol_error;
88 protocol_error.error_type = syncer::TRANSIENT_ERROR;
89 protocol_error.error_description = "Not My Fault";
90 protocol_error.url = "www.google.com";
92 if (clients()[0]->AutoStartEnabled()) {
93 // In auto start enabled platforms like chrome os we should be
94 // able to set up even if the first sync while setting up fails.
95 // Trigger error on every 2 out of 3 requests.
96 TriggerSyncError(protocol_error, SyncTest::ERROR_FREQUENCY_TWO_THIRDS);
97 // Now setup sync and it should succeed.
98 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
100 // In Non auto start enabled environments if the setup sync fails then
101 // the setup would fail. So setup sync normally.
102 ASSERT_TRUE(SetupSync()) << "Setup sync failed";
103 ASSERT_TRUE(clients()[0]->DisableSyncForDatatype(syncer::AUTOFILL));
105 // Trigger error on every 2 out of 3 requests.
106 TriggerSyncError(protocol_error, SyncTest::ERROR_FREQUENCY_TWO_THIRDS);
108 // Now enable a datatype, whose first 2 syncs would fail, but we should
109 // recover and setup succesfully on the third attempt.
110 ASSERT_TRUE(clients()[0]->EnableSyncForDatatype(syncer::AUTOFILL));
115 IN_PROC_BROWSER_TEST_F(SyncErrorTest,
116 BirthdayErrorUsingActionableErrorTest) {
117 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
119 const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
120 SetTitle(0, node1, L"new_title1");
121 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Sync."));
123 syncer::SyncProtocolError protocol_error;
124 protocol_error.error_type = syncer::NOT_MY_BIRTHDAY;
125 protocol_error.action = syncer::DISABLE_SYNC_ON_CLIENT;
126 protocol_error.error_description = "Not My Fault";
127 protocol_error.url = "www.google.com";
128 TriggerSyncError(protocol_error, SyncTest::ERROR_FREQUENCY_ALWAYS);
130 // Now make one more change so we will do another sync.
131 const BookmarkNode* node2 = AddFolder(0, 0, L"title2");
132 SetTitle(0, node2, L"new_title2");
134 GetClient(0)->AwaitSyncDisabled("Birthday Error."));
135 ProfileSyncService::Status status = GetClient(0)->GetStatus();
136 ASSERT_EQ(status.sync_protocol_error.error_type, protocol_error.error_type);
137 ASSERT_EQ(status.sync_protocol_error.action, protocol_error.action);
138 ASSERT_EQ(status.sync_protocol_error.url, protocol_error.url);
139 ASSERT_EQ(status.sync_protocol_error.error_description,
140 protocol_error.error_description);
143 // TODO(pavely): Fix this test. Test needs to successfully setup sync. Then
144 // setup server to trigger auth error and setup FakeURLFetcher to return
145 // INVALID_CREDENTIALS failure for access token request. Then it should
146 // trigger sync and verify that error surfaced through
147 // ProfileSyncService::GetAuthError()
149 // Trigger an auth error and make sure the sync client displays a warning in the
151 IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_AuthErrorTest) {
152 ASSERT_TRUE(SetupClients());
155 ASSERT_FALSE(GetClient(0)->SetupSync());
156 ASSERT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS,
157 GetClient(0)->service()->GetAuthError().state());
160 // TODO(pavely): Fix this test. Test needs to successfully setup sync. Then
161 // setup server to trigger xmpp auth error and setup FakeURLFetcher to return
162 // INVALID_CREDENTIALS failure for access token request. Then it should
163 // trigger sync and verify that error surfaced through
164 // ProfileSyncService::GetAuthError()
166 // Trigger an XMPP auth error, and make sure sync treats it like any
168 IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_XmppAuthErrorTest) {
169 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
171 TriggerXmppAuthError();
173 ASSERT_FALSE(GetClient(0)->SetupSync());
175 ASSERT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS,
176 GetClient(0)->service()->GetAuthError().state());
179 // TODO(lipalani): Fix the typed_url dtc so this test case can pass.
180 IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_DisableDatatypeWhileRunning) {
181 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
182 syncer::ModelTypeSet synced_datatypes =
183 GetClient(0)->service()->GetPreferredDataTypes();
184 ASSERT_TRUE(synced_datatypes.Has(syncer::TYPED_URLS));
185 GetProfile(0)->GetPrefs()->SetBoolean(
186 prefs::kSavingBrowserHistoryDisabled, true);
188 synced_datatypes = GetClient(0)->service()->GetPreferredDataTypes();
189 ASSERT_FALSE(synced_datatypes.Has(syncer::TYPED_URLS));
191 const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
192 SetTitle(0, node1, L"new_title1");
193 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Sync."));
194 // TODO(lipalani)" Verify initial sync ended for typed url is false.