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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/run_loop.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/signin/fake_signin_manager.h" | 12 #include "chrome/browser/signin/fake_signin_manager.h" |
12 #include "chrome/browser/signin/oauth2_token_service.h" | 13 #include "chrome/browser/signin/oauth2_token_service.h" |
13 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
15 #include "chrome/browser/signin/signin_manager.h" | 16 #include "chrome/browser/signin/signin_manager.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/signin/token_service.h" | 18 #include "chrome/browser/signin/token_service.h" |
18 #include "chrome/browser/signin/token_service_factory.h" | 19 #include "chrome/browser/signin/token_service_factory.h" |
19 #include "chrome/browser/sync/glue/data_type_manager.h" | 20 #include "chrome/browser/sync/glue/data_type_manager.h" |
20 #include "chrome/browser/sync/glue/data_type_manager_mock.h" | 21 #include "chrome/browser/sync/glue/data_type_manager_mock.h" |
21 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 22 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_test_util.h" | 24 #include "chrome/browser/sync/profile_sync_test_util.h" |
24 #include "chrome/browser/sync/sync_prefs.h" | 25 #include "chrome/browser/sync/sync_prefs.h" |
25 #include "chrome/browser/sync/test_profile_sync_service.h" | 26 #include "chrome/browser/sync/test_profile_sync_service.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
30 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "content/public/test/test_utils.h" |
31 #include "google_apis/gaia/gaia_auth_consumer.h" | 33 #include "google_apis/gaia/gaia_auth_consumer.h" |
32 #include "google_apis/gaia/gaia_constants.h" | 34 #include "google_apis/gaia/gaia_constants.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
34 | 36 |
35 using browser_sync::DataTypeManager; | 37 using browser_sync::DataTypeManager; |
36 using browser_sync::DataTypeManagerMock; | 38 using browser_sync::DataTypeManagerMock; |
37 using content::BrowserThread; | 39 using content::BrowserThread; |
38 using testing::_; | 40 using testing::_; |
39 using testing::AnyNumber; | 41 using testing::AnyNumber; |
40 using testing::DoAll; | 42 using testing::DoAll; |
(...skipping 23 matching lines...) Expand all Loading... |
64 content::NotificationService::current()->Notify( | 66 content::NotificationService::current()->Notify( |
65 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 67 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
66 content::Source<TokenService>(this), | 68 content::Source<TokenService>(this), |
67 content::NotificationService::NoDetails()); | 69 content::NotificationService::NoDetails()); |
68 } | 70 } |
69 }; | 71 }; |
70 | 72 |
71 class ProfileSyncServiceStartupTest : public testing::Test { | 73 class ProfileSyncServiceStartupTest : public testing::Test { |
72 public: | 74 public: |
73 ProfileSyncServiceStartupTest() | 75 ProfileSyncServiceStartupTest() |
74 : ui_thread_(BrowserThread::UI, &ui_loop_), | 76 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | |
75 db_thread_(BrowserThread::DB), | 77 content::TestBrowserThreadBundle::REAL_FILE_THREAD | |
76 file_thread_(BrowserThread::FILE), | 78 content::TestBrowserThreadBundle::REAL_IO_THREAD), |
77 io_thread_(BrowserThread::IO), | |
78 profile_(new TestingProfile), | 79 profile_(new TestingProfile), |
79 sync_(NULL) {} | 80 sync_(NULL) {} |
80 | 81 |
81 virtual ~ProfileSyncServiceStartupTest() { | 82 virtual ~ProfileSyncServiceStartupTest() { |
82 } | 83 } |
83 | 84 |
84 virtual void SetUp() { | 85 virtual void SetUp() { |
85 file_thread_.Start(); | |
86 io_thread_.StartIOThread(); | |
87 profile_->CreateRequestContext(); | |
88 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
89 SigninManagerFactory::GetInstance()->SetTestingFactory( | 87 SigninManagerFactory::GetInstance()->SetTestingFactory( |
90 profile_.get(), FakeSigninManagerBase::Build); | 88 profile_.get(), FakeSigninManagerBase::Build); |
91 #else | 89 #else |
92 SigninManagerFactory::GetInstance()->SetTestingFactory( | 90 SigninManagerFactory::GetInstance()->SetTestingFactory( |
93 profile_.get(), FakeSigninManager::Build); | 91 profile_.get(), FakeSigninManager::Build); |
94 #endif | 92 #endif |
95 } | 93 } |
96 | 94 |
97 virtual void TearDown() { | 95 virtual void TearDown() { |
98 sync_->RemoveObserver(&observer_); | 96 sync_->RemoveObserver(&observer_); |
99 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( | 97 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( |
100 profile_.get(), NULL); | 98 profile_.get(), NULL); |
101 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | 99 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( |
102 profile_.get(), NULL); | 100 profile_.get(), NULL); |
103 profile_.reset(); | 101 profile_.reset(); |
104 | 102 |
105 // Pump messages posted by the sync core thread (which may end up | 103 // Pump messages posted by the sync core thread (which may end up |
106 // posting on the IO thread). | 104 // posting on the IO thread). |
107 ui_loop_.RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
108 io_thread_.Stop(); | 106 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
109 file_thread_.Stop(); | 107 base::RunLoop().RunUntilIdle(); |
110 ui_loop_.RunUntilIdle(); | |
111 } | 108 } |
112 | 109 |
113 static BrowserContextKeyedService* BuildService( | 110 static BrowserContextKeyedService* BuildService( |
114 content::BrowserContext* profile) { | 111 content::BrowserContext* profile) { |
115 return new TestProfileSyncService( | 112 return new TestProfileSyncService( |
116 new ProfileSyncComponentsFactoryMock(), | 113 new ProfileSyncComponentsFactoryMock(), |
117 static_cast<Profile*>(profile), | 114 static_cast<Profile*>(profile), |
118 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)), | 115 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)), |
119 ProfileSyncService::MANUAL_START, | 116 ProfileSyncService::MANUAL_START, |
120 true); | 117 true); |
(...skipping 11 matching lines...) Expand all Loading... |
132 | 129 |
133 protected: | 130 protected: |
134 DataTypeManagerMock* SetUpDataTypeManager() { | 131 DataTypeManagerMock* SetUpDataTypeManager() { |
135 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); | 132 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); |
136 EXPECT_CALL(*sync_->components_factory_mock(), | 133 EXPECT_CALL(*sync_->components_factory_mock(), |
137 CreateDataTypeManager(_, _, _, _, _, _)). | 134 CreateDataTypeManager(_, _, _, _, _, _)). |
138 WillOnce(Return(data_type_manager)); | 135 WillOnce(Return(data_type_manager)); |
139 return data_type_manager; | 136 return data_type_manager; |
140 } | 137 } |
141 | 138 |
142 base::MessageLoop ui_loop_; | 139 content::TestBrowserThreadBundle thread_bundle_; |
143 content::TestBrowserThread ui_thread_; | |
144 content::TestBrowserThread db_thread_; | |
145 content::TestBrowserThread file_thread_; | |
146 content::TestBrowserThread io_thread_; | |
147 scoped_ptr<TestingProfile> profile_; | 140 scoped_ptr<TestingProfile> profile_; |
148 TestProfileSyncService* sync_; | 141 TestProfileSyncService* sync_; |
149 ProfileSyncServiceObserverMock observer_; | 142 ProfileSyncServiceObserverMock observer_; |
150 }; | 143 }; |
151 | 144 |
152 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { | 145 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { |
153 public: | 146 public: |
154 virtual void SetUp() { | 147 virtual void SetUp() { |
155 ProfileSyncServiceStartupTest::SetUp(); | 148 ProfileSyncServiceStartupTest::SetUp(); |
156 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | 149 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 549 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
557 GaiaConstants::kSyncService, "token"); | 550 GaiaConstants::kSyncService, "token"); |
558 sync_->fail_initial_download(); | 551 sync_->fail_initial_download(); |
559 | 552 |
560 sync_->SetSetupInProgress(true); | 553 sync_->SetSetupInProgress(true); |
561 sync_->Initialize(); | 554 sync_->Initialize(); |
562 sync_->SetSetupInProgress(false); | 555 sync_->SetSetupInProgress(false); |
563 EXPECT_FALSE(sync_->sync_initialized()); | 556 EXPECT_FALSE(sync_->sync_initialized()); |
564 EXPECT_TRUE(sync_->GetBackendForTest()); | 557 EXPECT_TRUE(sync_->GetBackendForTest()); |
565 } | 558 } |
OLD | NEW |