| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // TODO(akalin): Add tests here that exercise the whole | 25 // TODO(akalin): Add tests here that exercise the whole |
| 26 // ProfileSyncService/SyncBackendHost stack while mocking out as | 26 // ProfileSyncService/SyncBackendHost stack while mocking out as |
| 27 // little as possible. | 27 // little as possible. |
| 28 | 28 |
| 29 namespace browser_sync { | 29 namespace browser_sync { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 using testing::_; | 33 using testing::_; |
| 34 using testing::AnyNumber; |
| 34 using testing::AtLeast; | 35 using testing::AtLeast; |
| 35 using testing::AtMost; | 36 using testing::AtMost; |
| 36 using testing::Return; | 37 using testing::Return; |
| 37 using testing::StrictMock; | 38 using testing::StrictMock; |
| 38 | 39 |
| 39 class ProfileSyncServiceTest : public testing::Test { | 40 class ProfileSyncServiceTest : public testing::Test { |
| 40 protected: | 41 protected: |
| 41 ProfileSyncServiceTest() | 42 ProfileSyncServiceTest() |
| 42 : ui_thread_(BrowserThread::UI, &ui_loop_), | 43 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 43 io_thread_(BrowserThread::IO) {} | 44 io_thread_(BrowserThread::IO) {} |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 js_backend->RemoveHandler(&event_handler); | 166 js_backend->RemoveHandler(&event_handler); |
| 166 EXPECT_EQ(NULL, test_backend->GetJsBackend()->GetParentJsEventRouter()); | 167 EXPECT_EQ(NULL, test_backend->GetJsBackend()->GetParentJsEventRouter()); |
| 167 } | 168 } |
| 168 | 169 |
| 169 TEST_F(ProfileSyncServiceTest, | 170 TEST_F(ProfileSyncServiceTest, |
| 170 JsFrontendHandlersDelayedBackendInitialization) { | 171 JsFrontendHandlersDelayedBackendInitialization) { |
| 171 StartSyncServiceAndSetInitialSyncEnded(true, false, false, true); | 172 StartSyncServiceAndSetInitialSyncEnded(true, false, false, true); |
| 172 | 173 |
| 173 StrictMock<MockJsEventHandler> event_handler; | 174 StrictMock<MockJsEventHandler> event_handler; |
| 174 EXPECT_CALL(event_handler, | 175 EXPECT_CALL(event_handler, |
| 176 HandleJsEvent("onTransactionStart", _)).Times(AnyNumber()); |
| 177 EXPECT_CALL(event_handler, |
| 178 HandleJsEvent("onTransactionEnd", _)).Times(AnyNumber()); |
| 179 EXPECT_CALL(event_handler, |
| 175 HandleJsEvent("onServiceStateChanged", | 180 HandleJsEvent("onServiceStateChanged", |
| 176 HasDetails(JsEventDetails()))).Times(AtLeast(3)); | 181 HasDetails(JsEventDetails()))).Times(AtLeast(3)); |
| 177 // For some reason, these events may or may not fire. | 182 // For some reason, these events may or may not fire. |
| 178 // | 183 // |
| 179 // TODO(akalin): Figure out exactly why there's non-determinism | 184 // TODO(akalin): Figure out exactly why there's non-determinism |
| 180 // here, and if possible remove it. | 185 // here, and if possible remove it. |
| 181 EXPECT_CALL(event_handler, HandleJsEvent("onChangesApplied", _)) | 186 EXPECT_CALL(event_handler, HandleJsEvent("onChangesApplied", _)) |
| 182 .Times(AtMost(1)); | 187 .Times(AtMost(1)); |
| 183 EXPECT_CALL(event_handler, HandleJsEvent("onChangesComplete", _)) | 188 EXPECT_CALL(event_handler, HandleJsEvent("onChangesComplete", _)) |
| 184 .Times(AtMost(1)); | 189 .Times(AtMost(1)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 268 |
| 264 // Never replied to. | 269 // Never replied to. |
| 265 js_backend->ProcessMessage("notRepliedTo", args3, &event_handler); | 270 js_backend->ProcessMessage("notRepliedTo", args3, &event_handler); |
| 266 } | 271 } |
| 267 | 272 |
| 268 TEST_F(ProfileSyncServiceTest, | 273 TEST_F(ProfileSyncServiceTest, |
| 269 JsFrontendProcessMessageBasicDelayedBackendInitialization) { | 274 JsFrontendProcessMessageBasicDelayedBackendInitialization) { |
| 270 StartSyncServiceAndSetInitialSyncEnded(true, false, false, true); | 275 StartSyncServiceAndSetInitialSyncEnded(true, false, false, true); |
| 271 | 276 |
| 272 StrictMock<MockJsEventHandler> event_handler; | 277 StrictMock<MockJsEventHandler> event_handler; |
| 278 EXPECT_CALL(event_handler, |
| 279 HandleJsEvent("onTransactionStart", _)).Times(AnyNumber()); |
| 280 EXPECT_CALL(event_handler, |
| 281 HandleJsEvent("onTransactionEnd", _)).Times(AnyNumber()); |
| 273 // For some reason, these events may or may not fire. | 282 // For some reason, these events may or may not fire. |
| 274 EXPECT_CALL(event_handler, HandleJsEvent("onChangesApplied", _)) | 283 EXPECT_CALL(event_handler, HandleJsEvent("onChangesApplied", _)) |
| 275 .Times(AtMost(1)); | 284 .Times(AtMost(1)); |
| 276 EXPECT_CALL(event_handler, HandleJsEvent("onChangesComplete", _)) | 285 EXPECT_CALL(event_handler, HandleJsEvent("onChangesComplete", _)) |
| 277 .Times(AtMost(1)); | 286 .Times(AtMost(1)); |
| 278 EXPECT_CALL(event_handler, HandleJsEvent("onNotificationStateChange", _)) | 287 EXPECT_CALL(event_handler, HandleJsEvent("onNotificationStateChange", _)) |
| 279 .Times(AtMost(1)); | 288 .Times(AtMost(1)); |
| 280 | 289 |
| 281 ListValue arg_list1; | 290 ListValue arg_list1; |
| 282 arg_list1.Append(Value::CreateBooleanValue(true)); | 291 arg_list1.Append(Value::CreateBooleanValue(true)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // This will still exist, but the text should have changed. | 380 // This will still exist, but the text should have changed. |
| 372 ASSERT_TRUE(file_util::PathExists(sync_file2)); | 381 ASSERT_TRUE(file_util::PathExists(sync_file2)); |
| 373 std::string file2text; | 382 std::string file2text; |
| 374 ASSERT_TRUE(file_util::ReadFileToString(sync_file2, &file2text)); | 383 ASSERT_TRUE(file_util::ReadFileToString(sync_file2, &file2text)); |
| 375 ASSERT_NE(file2text.compare(nonsense2), 0); | 384 ASSERT_NE(file2text.compare(nonsense2), 0); |
| 376 } | 385 } |
| 377 | 386 |
| 378 } // namespace | 387 } // namespace |
| 379 | 388 |
| 380 } // namespace browser_sync | 389 } // namespace browser_sync |
| OLD | NEW |