Index: chrome/browser/sync/profile_sync_service_session_unittest.cc |
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc |
index fef7e14b02efb59d78b35c5885191b8a6f94a066..d74c054ac940f269b367e5f76b847947f8ed0762 100644 |
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc |
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc |
@@ -49,6 +49,32 @@ using browser_sync::TestIdFactory; |
namespace browser_sync { |
+static const std::string kCrosUserForTest = "test user"; |
+ |
+// Ensures the we use our own ProfileSyncService. This is necessary since only |
+// it has the correct cros_user value, which avoids some codepaths that aren't |
+// relevant to tests. |
+class TestingProfileForSyncTests : public TestingProfile { |
+ public: |
+ TestingProfileForSyncTests() |
+ : sync_service_(NULL) {} |
+ virtual bool HasProfileSyncService() const { |
+ return (sync_service_ != NULL); |
+ } |
+ virtual ProfileSyncService* GetProfileSyncService() { |
+ return GetProfileSyncService(std::string()); |
+ } |
+ virtual ProfileSyncService* GetProfileSyncService( |
+ const std::string& cros_user) { |
+ return sync_service_; |
+ } |
+ void set_sync_service(ProfileSyncService* sync_service) { |
+ sync_service_ = sync_service; |
+ } |
+ private: |
+ ProfileSyncService* sync_service_; |
+}; |
+ |
class ProfileSyncServiceSessionTest |
: public BrowserWithTestWindowTest, |
public NotificationObserver { |
@@ -56,7 +82,10 @@ class ProfileSyncServiceSessionTest |
ProfileSyncServiceSessionTest() |
: window_bounds_(0, 1, 2, 3), |
notified_of_update_(false) {} |
- |
+ ~ProfileSyncServiceSessionTest() { |
+ reinterpret_cast<TestingProfileForSyncTests *>(profile())-> |
+ set_sync_service(NULL); |
+ } |
ProfileSyncService* sync_service() { return sync_service_.get(); } |
TestIdFactory* ids() { return sync_service_->id_factory(); } |
@@ -65,7 +94,12 @@ class ProfileSyncServiceSessionTest |
SessionService* service() { return helper_.service(); } |
virtual void SetUp() { |
- BrowserWithTestWindowTest::SetUp(); |
+ // BrowserWithTestWindowTest implementation. |
+ set_profile(new TestingProfileForSyncTests()); |
+ set_browser(new Browser(Browser::TYPE_NORMAL, profile())); |
+ set_window(new TestBrowserWindow(browser())); |
+ browser()->set_window(window()); |
+ |
profile()->set_has_history_service(true); |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
SessionService* session_service = new SessionService(temp_dir_.path()); |
@@ -98,9 +132,10 @@ class ProfileSyncServiceSessionTest |
bool StartSyncService(Task* task, bool will_fail_association) { |
if (sync_service_.get()) |
return false; |
- |
sync_service_.reset(new TestProfileSyncService( |
- &factory_, profile(), "test user", false, task)); |
+ &factory_, profile(), kCrosUserForTest, false, task)); |
+ reinterpret_cast<TestingProfileForSyncTests *>(profile())-> |
+ set_sync_service(sync_service_.get()); |
profile()->set_session_service(helper_.service()); |
// Register the session data type. |