| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
| 10 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | 10 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 if (expect_create_dtm) { | 100 if (expect_create_dtm) { |
| 101 // Register the bookmark data type. | 101 // Register the bookmark data type. |
| 102 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 102 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 103 WillOnce(ReturnNewDataTypeManager()); | 103 WillOnce(ReturnNewDataTypeManager()); |
| 104 } else { | 104 } else { |
| 105 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); | 105 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); |
| 106 } | 106 } |
| 107 | 107 |
| 108 if (issue_auth_token) { | 108 if (issue_auth_token) { |
| 109 profile_->GetTokenService()->IssueAuthTokenForTest( | 109 IssueTestTokens(); |
| 110 GaiaConstants::kSyncService, "token"); | |
| 111 } | 110 } |
| 112 service_->Initialize(); | 111 service_->Initialize(); |
| 113 } | 112 } |
| 114 } | 113 } |
| 115 | 114 |
| 115 void IssueTestTokens() { |
| 116 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 117 GaiaConstants::kSyncService, "token1"); |
| 118 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 119 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "token2"); |
| 120 } |
| 121 |
| 116 MessageLoop ui_loop_; | 122 MessageLoop ui_loop_; |
| 117 // Needed by |service_|. | 123 // Needed by |service_|. |
| 118 content::TestBrowserThread ui_thread_; | 124 content::TestBrowserThread ui_thread_; |
| 119 // Needed by |service| and |profile_|'s request context. | 125 // Needed by |service| and |profile_|'s request context. |
| 120 content::TestBrowserThread io_thread_; | 126 content::TestBrowserThread io_thread_; |
| 121 | 127 |
| 122 scoped_ptr<TestProfileSyncService> service_; | 128 scoped_ptr<TestProfileSyncService> service_; |
| 123 scoped_ptr<TestingProfile> profile_; | 129 scoped_ptr<TestingProfile> profile_; |
| 124 ProfileSyncComponentsFactoryMock factory_; | 130 ProfileSyncComponentsFactoryMock factory_; |
| 125 }; | 131 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 service_.reset(); | 164 service_.reset(); |
| 159 } | 165 } |
| 160 | 166 |
| 161 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { | 167 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { |
| 162 service_.reset(new TestProfileSyncService( | 168 service_.reset(new TestProfileSyncService( |
| 163 &factory_, profile_.get(), "test", true, base::Closure())); | 169 &factory_, profile_.get(), "test", true, base::Closure())); |
| 164 // Register the bookmark data type. | 170 // Register the bookmark data type. |
| 165 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 171 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 166 WillRepeatedly(ReturnNewDataTypeManager()); | 172 WillRepeatedly(ReturnNewDataTypeManager()); |
| 167 | 173 |
| 168 profile_->GetTokenService()->IssueAuthTokenForTest( | 174 IssueTestTokens(); |
| 169 GaiaConstants::kSyncService, "token"); | |
| 170 | 175 |
| 171 service_->Initialize(); | 176 service_->Initialize(); |
| 172 EXPECT_TRUE(service_->sync_initialized()); | 177 EXPECT_TRUE(service_->sync_initialized()); |
| 173 EXPECT_TRUE(service_->GetBackendForTest() != NULL); | 178 EXPECT_TRUE(service_->GetBackendForTest() != NULL); |
| 174 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); | 179 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); |
| 175 | 180 |
| 176 service_->StopAndSuppress(); | 181 service_->StopAndSuppress(); |
| 177 EXPECT_FALSE(service_->sync_initialized()); | 182 EXPECT_FALSE(service_->sync_initialized()); |
| 178 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); | 183 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); |
| 179 | 184 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 200 StrictMock<MockJsEventHandler> event_handler; | 205 StrictMock<MockJsEventHandler> event_handler; |
| 201 EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1)); | 206 EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1)); |
| 202 | 207 |
| 203 EXPECT_EQ(NULL, service_->GetBackendForTest()); | 208 EXPECT_EQ(NULL, service_->GetBackendForTest()); |
| 204 EXPECT_FALSE(service_->sync_initialized()); | 209 EXPECT_FALSE(service_->sync_initialized()); |
| 205 | 210 |
| 206 JsController* js_controller = service_->GetJsController(); | 211 JsController* js_controller = service_->GetJsController(); |
| 207 js_controller->AddJsEventHandler(&event_handler); | 212 js_controller->AddJsEventHandler(&event_handler); |
| 208 // Since we're doing synchronous initialization, backend should be | 213 // Since we're doing synchronous initialization, backend should be |
| 209 // initialized by this call. | 214 // initialized by this call. |
| 210 profile_->GetTokenService()->IssueAuthTokenForTest( | 215 IssueTestTokens(); |
| 211 GaiaConstants::kSyncService, "token"); | |
| 212 EXPECT_TRUE(service_->sync_initialized()); | 216 EXPECT_TRUE(service_->sync_initialized()); |
| 213 js_controller->RemoveJsEventHandler(&event_handler); | 217 js_controller->RemoveJsEventHandler(&event_handler); |
| 214 } | 218 } |
| 215 | 219 |
| 216 TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) { | 220 TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) { |
| 217 StartSyncService(); | 221 StartSyncService(); |
| 218 | 222 |
| 219 StrictMock<MockJsReplyHandler> reply_handler; | 223 StrictMock<MockJsReplyHandler> reply_handler; |
| 220 | 224 |
| 221 ListValue arg_list1; | 225 ListValue arg_list1; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 246 JsArgList args1(&arg_list1); | 250 JsArgList args1(&arg_list1); |
| 247 EXPECT_CALL(reply_handler, | 251 EXPECT_CALL(reply_handler, |
| 248 HandleJsReply("getNotificationState", HasArgs(args1))); | 252 HandleJsReply("getNotificationState", HasArgs(args1))); |
| 249 | 253 |
| 250 { | 254 { |
| 251 JsController* js_controller = service_->GetJsController(); | 255 JsController* js_controller = service_->GetJsController(); |
| 252 js_controller->ProcessJsMessage("getNotificationState", | 256 js_controller->ProcessJsMessage("getNotificationState", |
| 253 args1, reply_handler.AsWeakHandle()); | 257 args1, reply_handler.AsWeakHandle()); |
| 254 } | 258 } |
| 255 | 259 |
| 256 profile_->GetTokenService()->IssueAuthTokenForTest( | 260 IssueTestTokens(); |
| 257 GaiaConstants::kSyncService, "token"); | |
| 258 | 261 |
| 259 // This forces the sync thread to process the message and reply. | 262 // This forces the sync thread to process the message and reply. |
| 260 service_.reset(); | 263 service_.reset(); |
| 261 ui_loop_.RunAllPending(); | 264 ui_loop_.RunAllPending(); |
| 262 } | 265 } |
| 263 | 266 |
| 264 // Make sure that things still work if sync is not enabled, but some old sync | 267 // Make sure that things still work if sync is not enabled, but some old sync |
| 265 // databases are lingering in the "Sync Data" folder. | 268 // databases are lingering in the "Sync Data" folder. |
| 266 TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) { | 269 TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) { |
| 267 const char* nonsense1 = "reginald"; | 270 const char* nonsense1 = "reginald"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 279 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2))); | 282 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2))); |
| 280 ASSERT_NE(-1, | 283 ASSERT_NE(-1, |
| 281 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3))); | 284 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3))); |
| 282 | 285 |
| 283 StartSyncServiceAndSetInitialSyncEnded(false, false, true, false, true); | 286 StartSyncServiceAndSetInitialSyncEnded(false, false, true, false, true); |
| 284 EXPECT_FALSE(service_->HasSyncSetupCompleted()); | 287 EXPECT_FALSE(service_->HasSyncSetupCompleted()); |
| 285 EXPECT_FALSE(service_->sync_initialized()); | 288 EXPECT_FALSE(service_->sync_initialized()); |
| 286 | 289 |
| 287 // Since we're doing synchronous initialization, backend should be | 290 // Since we're doing synchronous initialization, backend should be |
| 288 // initialized by this call. | 291 // initialized by this call. |
| 289 profile_->GetTokenService()->IssueAuthTokenForTest( | 292 IssueTestTokens(); |
| 290 GaiaConstants::kSyncService, "token"); | |
| 291 | 293 |
| 292 // Stop the service so we can read the new Sync Data files that were | 294 // Stop the service so we can read the new Sync Data files that were |
| 293 // created. | 295 // created. |
| 294 service_.reset(); | 296 service_.reset(); |
| 295 | 297 |
| 296 // This file should have been deleted when the whole directory was nuked. | 298 // This file should have been deleted when the whole directory was nuked. |
| 297 ASSERT_FALSE(file_util::PathExists(sync_file3)); | 299 ASSERT_FALSE(file_util::PathExists(sync_file3)); |
| 298 ASSERT_FALSE(file_util::PathExists(sync_file1)); | 300 ASSERT_FALSE(file_util::PathExists(sync_file1)); |
| 299 | 301 |
| 300 // This will still exist, but the text should have changed. | 302 // This will still exist, but the text should have changed. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 322 // The backend is not ready. Ensure the PSS knows this. | 324 // The backend is not ready. Ensure the PSS knows this. |
| 323 EXPECT_FALSE(service_->sync_initialized()); | 325 EXPECT_FALSE(service_->sync_initialized()); |
| 324 | 326 |
| 325 // Ensure we will be prepared to initialize a fresh DB next time. | 327 // Ensure we will be prepared to initialize a fresh DB next time. |
| 326 EXPECT_FALSE(service_->HasSyncSetupCompleted()); | 328 EXPECT_FALSE(service_->HasSyncSetupCompleted()); |
| 327 } | 329 } |
| 328 | 330 |
| 329 } // namespace | 331 } // namespace |
| 330 | 332 |
| 331 } // namespace browser_sync | 333 } // namespace browser_sync |
| OLD | NEW |