Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/sync/profile_sync_service_session_unittest.cc

Issue 218903005: Make push messaging not create InvalidationService for login and guest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make code resilient against tests that do not create the Default profile first. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <utility>
7 8
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
14 #include "base/guid.h" 15 #include "base/guid.h"
15 #include "base/location.h" 16 #include "base/location.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
20 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/invalidation/fake_invalidation_service.h" 23 #include "chrome/browser/invalidation/fake_invalidation_service.h"
22 #include "chrome/browser/invalidation/invalidation_service_factory.h" 24 #include "chrome/browser/invalidation/invalidation_service_factory.h"
25 #include "chrome/browser/prefs/pref_service_syncable.h"
23 #include "chrome/browser/sessions/session_tab_helper.h" 26 #include "chrome/browser/sessions/session_tab_helper.h"
24 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 27 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 28 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
27 #include "chrome/browser/signin/signin_manager_factory.h" 30 #include "chrome/browser/signin/signin_manager_factory.h"
28 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 31 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
29 #include "chrome/browser/sync/glue/device_info.h" 32 #include "chrome/browser/sync/glue/device_info.h"
30 #include "chrome/browser/sync/glue/session_change_processor.h" 33 #include "chrome/browser/sync/glue/session_change_processor.h"
31 #include "chrome/browser/sync/glue/session_data_type_controller.h" 34 #include "chrome/browser/sync/glue/session_data_type_controller.h"
32 #include "chrome/browser/sync/glue/session_model_associator.h" 35 #include "chrome/browser/sync/glue/session_model_associator.h"
33 #include "chrome/browser/sync/glue/session_sync_test_helper.h" 36 #include "chrome/browser/sync/glue/session_sync_test_helper.h"
34 #include "chrome/browser/sync/glue/sync_backend_host.h" 37 #include "chrome/browser/sync/glue/sync_backend_host.h"
35 #include "chrome/browser/sync/glue/synced_device_tracker.h" 38 #include "chrome/browser/sync/glue/synced_device_tracker.h"
36 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 39 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
37 #include "chrome/browser/sync/glue/tab_node_pool.h" 40 #include "chrome/browser/sync/glue/tab_node_pool.h"
38 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 41 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
39 #include "chrome/browser/sync/profile_sync_service_factory.h" 42 #include "chrome/browser/sync/profile_sync_service_factory.h"
40 #include "chrome/browser/sync/profile_sync_test_util.h" 43 #include "chrome/browser/sync/profile_sync_test_util.h"
41 #include "chrome/browser/sync/test_profile_sync_service.h" 44 #include "chrome/browser/sync/test_profile_sync_service.h"
42 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 45 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" 46 #include "chrome/browser/ui/tabs/tab_strip_model.h"
44 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
45 #include "chrome/test/base/browser_with_test_window_test.h" 48 #include "chrome/test/base/browser_with_test_window_test.h"
49 #include "chrome/test/base/testing_browser_process.h"
46 #include "chrome/test/base/testing_profile.h" 50 #include "chrome/test/base/testing_profile.h"
51 #include "chrome/test/base/testing_profile_manager.h"
52 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
47 #include "components/signin/core/browser/profile_oauth2_token_service.h" 53 #include "components/signin/core/browser/profile_oauth2_token_service.h"
48 #include "components/signin/core/browser/signin_manager.h" 54 #include "components/signin/core/browser/signin_manager.h"
49 #include "content/public/browser/navigation_controller.h" 55 #include "content/public/browser/navigation_controller.h"
50 #include "content/public/browser/navigation_entry.h" 56 #include "content/public/browser/navigation_entry.h"
51 #include "content/public/browser/notification_observer.h" 57 #include "content/public/browser/notification_observer.h"
52 #include "content/public/browser/notification_registrar.h" 58 #include "content/public/browser/notification_registrar.h"
53 #include "content/public/browser/notification_service.h" 59 #include "content/public/browser/notification_service.h"
54 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
55 #include "content/public/test/test_browser_thread.h" 61 #include "content/public/test/test_browser_thread.h"
56 #include "google_apis/gaia/gaia_constants.h" 62 #include "google_apis/gaia/gaia_constants.h"
(...skipping 19 matching lines...) Expand all
76 using content::BrowserThread; 82 using content::BrowserThread;
77 using content::WebContents; 83 using content::WebContents;
78 using syncer::ChangeRecord; 84 using syncer::ChangeRecord;
79 using testing::Return; 85 using testing::Return;
80 using testing::_; 86 using testing::_;
81 87
82 namespace browser_sync { 88 namespace browser_sync {
83 89
84 namespace { 90 namespace {
85 91
92 const char kTestProfileName[] = "test-profile";
93
86 class FakeProfileSyncService : public TestProfileSyncService { 94 class FakeProfileSyncService : public TestProfileSyncService {
87 public: 95 public:
88 FakeProfileSyncService( 96 FakeProfileSyncService(
89 ProfileSyncComponentsFactory* factory, 97 ProfileSyncComponentsFactory* factory,
90 Profile* profile, 98 Profile* profile,
91 SigninManagerBase* signin, 99 SigninManagerBase* signin,
92 ProfileOAuth2TokenService* oauth2_token_service, 100 ProfileOAuth2TokenService* oauth2_token_service,
93 ProfileSyncServiceStartBehavior behavior) 101 ProfileSyncServiceStartBehavior behavior)
94 : TestProfileSyncService(factory, 102 : TestProfileSyncService(factory,
95 profile, 103 profile,
(...skipping 28 matching lines...) Expand all
124 arg1, arg2, callback); 132 arg1, arg2, callback);
125 } 133 }
126 134
127 } // namespace 135 } // namespace
128 136
129 class ProfileSyncServiceSessionTest 137 class ProfileSyncServiceSessionTest
130 : public BrowserWithTestWindowTest, 138 : public BrowserWithTestWindowTest,
131 public content::NotificationObserver { 139 public content::NotificationObserver {
132 public: 140 public:
133 ProfileSyncServiceSessionTest() 141 ProfileSyncServiceSessionTest()
134 : window_bounds_(0, 1, 2, 3), 142 : profile_manager_(TestingBrowserProcess::GetGlobal()),
143 window_bounds_(0, 1, 2, 3),
135 notified_of_refresh_(false), 144 notified_of_refresh_(false),
136 notified_of_update_(false) {} 145 notified_of_update_(false) {}
137 ProfileSyncService* sync_service() { return sync_service_.get(); } 146 ProfileSyncService* sync_service() { return sync_service_.get(); }
138 147
139 protected: 148 protected:
140 virtual TestingProfile* CreateProfile() OVERRIDE { 149 virtual TestingProfile* CreateProfile() OVERRIDE {
141 TestingProfile::Builder builder; 150 TestingProfile::TestingFactories testing_factories;
142 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), 151 testing_factories.push_back(std::make_pair(
143 BuildAutoIssuingFakeProfileOAuth2TokenService); 152 ProfileOAuth2TokenServiceFactory::GetInstance(),
153 BuildAutoIssuingFakeProfileOAuth2TokenService));
144 // Don't want the profile to create a real ProfileSyncService. 154 // Don't want the profile to create a real ProfileSyncService.
145 builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(), NULL); 155 testing_factories.push_back(std::make_pair(
146 scoped_ptr<TestingProfile> profile(builder.Build()); 156 ProfileSyncServiceFactory::GetInstance(),
157 static_cast<BrowserContextKeyedServiceFactory::TestingFactoryFunction>(
158 NULL)));
159 TestingProfile* profile = profile_manager_.CreateTestingProfile(
160 kTestProfileName,
161 scoped_ptr<PrefServiceSyncable>(),
162 base::UTF8ToUTF16(kTestProfileName),
163 0,
164 std::string(),
165 testing_factories);
147 invalidation::InvalidationServiceFactory::GetInstance()->SetTestingFactory( 166 invalidation::InvalidationServiceFactory::GetInstance()->SetTestingFactory(
148 profile.get(), invalidation::FakeInvalidationService::Build); 167 profile, invalidation::FakeInvalidationService::Build);
149 return profile.release(); 168 return profile;
169 }
170
171 virtual void DestroyProfile(TestingProfile* profile) OVERRIDE {
172 EXPECT_EQ(kTestProfileName, profile->GetProfileName());
173 profile_manager_.DeleteTestingProfile(kTestProfileName);
150 } 174 }
151 175
152 virtual void SetUp() { 176 virtual void SetUp() {
153 // BrowserWithTestWindowTest implementation. 177 ASSERT_TRUE(profile_manager_.SetUp());
154 BrowserWithTestWindowTest::SetUp(); 178 BrowserWithTestWindowTest::SetUp();
155 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 179 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
156 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, 180 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
157 content::NotificationService::AllSources()); 181 content::NotificationService::AllSources());
158 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 182 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
159 content::NotificationService::AllSources()); 183 content::NotificationService::AllSources());
160 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 184 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
161 switches::kSyncDeferredStartupTimeoutSeconds, "0"); 185 switches::kSyncDeferredStartupTimeoutSeconds, "0");
162 } 186 }
163 187
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 257
234 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) 258 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())
235 ->UpdateCredentials("test_user", "oauth2_login_token"); 259 ->UpdateCredentials("test_user", "oauth2_login_token");
236 sync_service_->Initialize(); 260 sync_service_->Initialize();
237 base::MessageLoop::current()->Run(); 261 base::MessageLoop::current()->Run();
238 return true; 262 return true;
239 } 263 }
240 264
241 // Path used in testing. 265 // Path used in testing.
242 base::ScopedTempDir temp_dir_; 266 base::ScopedTempDir temp_dir_;
267 TestingProfileManager profile_manager_;
243 SessionModelAssociator* model_associator_; 268 SessionModelAssociator* model_associator_;
244 SessionChangeProcessor* change_processor_; 269 SessionChangeProcessor* change_processor_;
245 SessionID window_id_; 270 SessionID window_id_;
246 scoped_ptr<TestProfileSyncService> sync_service_; 271 scoped_ptr<TestProfileSyncService> sync_service_;
247 const gfx::Rect window_bounds_; 272 const gfx::Rect window_bounds_;
248 bool notified_of_refresh_; 273 bool notified_of_refresh_;
249 bool notified_of_update_; 274 bool notified_of_update_;
250 content::NotificationRegistrar registrar_; 275 content::NotificationRegistrar registrar_;
251 net::TestURLFetcherFactory fetcher_factory_; 276 net::TestURLFetcherFactory fetcher_factory_;
252 SessionSyncTestHelper helper_; 277 SessionSyncTestHelper helper_;
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 tab_node.SetSessionSpecifics(specifics); 1315 tab_node.SetSessionSpecifics(specifics);
1291 } 1316 }
1292 1317
1293 error = model_associator_->DisassociateModels(); 1318 error = model_associator_->DisassociateModels();
1294 ASSERT_FALSE(error.IsSet()); 1319 ASSERT_FALSE(error.IsSet());
1295 error = model_associator_->AssociateModels(NULL, NULL); 1320 error = model_associator_->AssociateModels(NULL, NULL);
1296 ASSERT_FALSE(error.IsSet()); 1321 ASSERT_FALSE(error.IsSet());
1297 } 1322 }
1298 1323
1299 } // namespace browser_sync 1324 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698