OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 11 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager.h" | 12 #include "chrome/browser/signin/signin_manager.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "chrome/browser/signin/token_service.h" | 14 #include "chrome/browser/signin/token_service.h" |
15 #include "chrome/browser/signin/token_service_factory.h" | 15 #include "chrome/browser/signin/token_service_factory.h" |
16 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | 16 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
17 #include "chrome/browser/sync/glue/data_type_controller.h" | 17 #include "chrome/browser/sync/glue/data_type_controller.h" |
18 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 18 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
19 #include "chrome/browser/sync/test_profile_sync_service.h" | 19 #include "chrome/browser/sync/test_profile_sync_service.h" |
20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/test/base/testing_pref_service_syncable.h" | 22 #include "chrome/test/base/testing_pref_service_syncable.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "content/public/test/test_utils.h" |
25 #include "google/cacheinvalidation/include/types.h" | 26 #include "google/cacheinvalidation/include/types.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 27 #include "google_apis/gaia/gaia_constants.h" |
27 #include "sync/js/js_arg_list.h" | 28 #include "sync/js/js_arg_list.h" |
28 #include "sync/js/js_event_details.h" | 29 #include "sync/js/js_event_details.h" |
29 #include "sync/js/js_test_util.h" | 30 #include "sync/js/js_test_util.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 // TODO(akalin): Add tests here that exercise the whole | 34 // TODO(akalin): Add tests here that exercise the whole |
34 // ProfileSyncService/SyncBackendHost stack while mocking out as | 35 // ProfileSyncService/SyncBackendHost stack while mocking out as |
35 // little as possible. | 36 // little as possible. |
36 | 37 |
37 namespace browser_sync { | 38 namespace browser_sync { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 using content::BrowserThread; | |
42 using testing::_; | 42 using testing::_; |
43 using testing::AtLeast; | 43 using testing::AtLeast; |
44 using testing::AtMost; | 44 using testing::AtMost; |
45 using testing::Mock; | 45 using testing::Mock; |
46 using testing::Return; | 46 using testing::Return; |
47 using testing::StrictMock; | 47 using testing::StrictMock; |
48 | 48 |
49 class ProfileSyncServiceTestHarness { | 49 class ProfileSyncServiceTestHarness { |
50 public: | 50 public: |
51 ProfileSyncServiceTestHarness() | 51 ProfileSyncServiceTestHarness() |
52 : ui_thread_(BrowserThread::UI, &ui_loop_), | 52 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | |
53 db_thread_(BrowserThread::DB), | 53 content::TestBrowserThreadBundle::REAL_FILE_THREAD | |
54 file_thread_(BrowserThread::FILE), | 54 content::TestBrowserThreadBundle::REAL_IO_THREAD) { |
55 io_thread_(BrowserThread::IO) {} | 55 } |
56 | |
57 ~ProfileSyncServiceTestHarness() {} | |
58 | 56 |
59 void SetUp() { | 57 void SetUp() { |
60 file_thread_.Start(); | |
61 io_thread_.StartIOThread(); | |
62 profile.reset(new TestingProfile()); | 58 profile.reset(new TestingProfile()); |
63 profile->CreateRequestContext(); | |
64 invalidation::InvalidationServiceFactory::GetInstance()-> | 59 invalidation::InvalidationServiceFactory::GetInstance()-> |
65 SetBuildOnlyFakeInvalidatorsForTest(true); | 60 SetBuildOnlyFakeInvalidatorsForTest(true); |
66 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | 61 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( |
67 profile.get(), FakeOAuth2TokenService::BuildTokenService); | 62 profile.get(), FakeOAuth2TokenService::BuildTokenService); |
68 } | 63 } |
69 | 64 |
70 void TearDown() { | 65 void TearDown() { |
71 // Kill the service before the profile. | 66 // Kill the service before the profile. |
72 if (service) { | 67 if (service) { |
73 service->Shutdown(); | 68 service->Shutdown(); |
74 } | 69 } |
75 service.reset(); | 70 service.reset(); |
76 profile.reset(); | 71 profile.reset(); |
77 // Pump messages posted by the sync thread (which may end up | 72 // Pump messages posted by the sync thread (which may end up |
78 // posting on the IO thread). | 73 // posting on the IO thread). |
79 ui_loop_.RunUntilIdle(); | 74 base::RunLoop().RunUntilIdle(); |
80 io_thread_.Stop(); | 75 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
81 file_thread_.Stop(); | 76 base::RunLoop().RunUntilIdle(); |
82 // Ensure that the sync objects destruct to avoid memory leaks. | |
83 ui_loop_.RunUntilIdle(); | |
84 } | 77 } |
85 | 78 |
86 // TODO(akalin): Refactor the StartSyncService*() functions below. | 79 // TODO(akalin): Refactor the StartSyncService*() functions below. |
87 | 80 |
88 void StartSyncService() { | 81 void StartSyncService() { |
89 StartSyncServiceAndSetInitialSyncEnded( | 82 StartSyncServiceAndSetInitialSyncEnded( |
90 true, true, false, true, syncer::STORAGE_IN_MEMORY); | 83 true, true, false, true, syncer::STORAGE_IN_MEMORY); |
91 } | 84 } |
92 | 85 |
93 void StartSyncServiceAndSetInitialSyncEnded( | 86 void StartSyncServiceAndSetInitialSyncEnded( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 token_service->IssueAuthTokenForTest( | 126 token_service->IssueAuthTokenForTest( |
134 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 127 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
135 token_service->IssueAuthTokenForTest( | 128 token_service->IssueAuthTokenForTest( |
136 GaiaConstants::kSyncService, "token"); | 129 GaiaConstants::kSyncService, "token"); |
137 } | 130 } |
138 | 131 |
139 scoped_ptr<TestProfileSyncService> service; | 132 scoped_ptr<TestProfileSyncService> service; |
140 scoped_ptr<TestingProfile> profile; | 133 scoped_ptr<TestingProfile> profile; |
141 | 134 |
142 private: | 135 private: |
143 base::MessageLoop ui_loop_; | 136 content::TestBrowserThreadBundle thread_bundle_; |
144 // Needed by |service|. | |
145 content::TestBrowserThread ui_thread_; | |
146 content::TestBrowserThread db_thread_; | |
147 // Needed by DisableAndEnableSyncTemporarily test case. | |
148 content::TestBrowserThread file_thread_; | |
149 // Needed by |service| and |profile|'s request context. | |
150 content::TestBrowserThread io_thread_; | |
151 }; | 137 }; |
152 | 138 |
153 class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver { | 139 class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver { |
154 public: | 140 public: |
155 explicit TestProfileSyncServiceObserver(ProfileSyncService* service) | 141 explicit TestProfileSyncServiceObserver(ProfileSyncService* service) |
156 : service_(service), first_setup_in_progress_(false) {} | 142 : service_(service), first_setup_in_progress_(false) {} |
157 virtual void OnStateChanged() OVERRIDE { | 143 virtual void OnStateChanged() OVERRIDE { |
158 first_setup_in_progress_ = service_->FirstSetupInProgress(); | 144 first_setup_in_progress_ = service_->FirstSetupInProgress(); |
159 } | 145 } |
160 bool first_setup_in_progress() const { return first_setup_in_progress_; } | 146 bool first_setup_in_progress() const { return first_setup_in_progress_; } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) { | 447 TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) { |
462 harness_.StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, | 448 harness_.StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, |
463 syncer::STORAGE_IN_MEMORY); | 449 syncer::STORAGE_IN_MEMORY); |
464 | 450 |
465 // The backend is not ready. Ensure the PSS knows this. | 451 // The backend is not ready. Ensure the PSS knows this. |
466 EXPECT_FALSE(harness_.service->sync_initialized()); | 452 EXPECT_FALSE(harness_.service->sync_initialized()); |
467 } | 453 } |
468 | 454 |
469 } // namespace | 455 } // namespace |
470 } // namespace browser_sync | 456 } // namespace browser_sync |
OLD | NEW |