OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 using browser_sync::SessionDataTypeController; | 42 using browser_sync::SessionDataTypeController; |
43 using browser_sync::SessionModelAssociator; | 43 using browser_sync::SessionModelAssociator; |
44 using browser_sync::SyncBackendHost; | 44 using browser_sync::SyncBackendHost; |
45 using sync_api::SyncManager; | 45 using sync_api::SyncManager; |
46 using testing::_; | 46 using testing::_; |
47 using testing::Return; | 47 using testing::Return; |
48 using browser_sync::TestIdFactory; | 48 using browser_sync::TestIdFactory; |
49 | 49 |
50 namespace browser_sync { | 50 namespace browser_sync { |
51 | 51 |
| 52 static const std::string kCrosUserForTest = "test user"; |
| 53 |
| 54 // Ensures the we use our own ProfileSyncService. This is necessary since only |
| 55 // it has the correct cros_user value, which avoids some codepaths that aren't |
| 56 // relevant to tests. |
| 57 class TestingProfileForSyncTests : public TestingProfile { |
| 58 public: |
| 59 TestingProfileForSyncTests() |
| 60 : sync_service_(NULL) {} |
| 61 virtual bool HasProfileSyncService() const { |
| 62 return (sync_service_ != NULL); |
| 63 } |
| 64 virtual ProfileSyncService* GetProfileSyncService() { |
| 65 return GetProfileSyncService(std::string()); |
| 66 } |
| 67 virtual ProfileSyncService* GetProfileSyncService( |
| 68 const std::string& cros_user) { |
| 69 return sync_service_; |
| 70 } |
| 71 void set_sync_service(ProfileSyncService* sync_service) { |
| 72 sync_service_ = sync_service; |
| 73 } |
| 74 private: |
| 75 ProfileSyncService* sync_service_; |
| 76 }; |
| 77 |
52 class ProfileSyncServiceSessionTest | 78 class ProfileSyncServiceSessionTest |
53 : public BrowserWithTestWindowTest, | 79 : public BrowserWithTestWindowTest, |
54 public NotificationObserver { | 80 public NotificationObserver { |
55 public: | 81 public: |
56 ProfileSyncServiceSessionTest() | 82 ProfileSyncServiceSessionTest() |
57 : window_bounds_(0, 1, 2, 3), | 83 : window_bounds_(0, 1, 2, 3), |
58 notified_of_update_(false) {} | 84 notified_of_update_(false) {} |
59 | 85 ~ProfileSyncServiceSessionTest() { |
| 86 reinterpret_cast<TestingProfileForSyncTests *>(profile())-> |
| 87 set_sync_service(NULL); |
| 88 } |
60 ProfileSyncService* sync_service() { return sync_service_.get(); } | 89 ProfileSyncService* sync_service() { return sync_service_.get(); } |
61 | 90 |
62 TestIdFactory* ids() { return sync_service_->id_factory(); } | 91 TestIdFactory* ids() { return sync_service_->id_factory(); } |
63 | 92 |
64 protected: | 93 protected: |
65 SessionService* service() { return helper_.service(); } | 94 SessionService* service() { return helper_.service(); } |
66 | 95 |
67 virtual void SetUp() { | 96 virtual void SetUp() { |
68 BrowserWithTestWindowTest::SetUp(); | 97 // BrowserWithTestWindowTest implementation. |
| 98 set_profile(new TestingProfileForSyncTests()); |
| 99 set_browser(new Browser(Browser::TYPE_NORMAL, profile())); |
| 100 set_window(new TestBrowserWindow(browser())); |
| 101 browser()->set_window(window()); |
| 102 |
69 profile()->set_has_history_service(true); | 103 profile()->set_has_history_service(true); |
70 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
71 SessionService* session_service = new SessionService(temp_dir_.path()); | 105 SessionService* session_service = new SessionService(temp_dir_.path()); |
72 helper_.set_service(session_service); | 106 helper_.set_service(session_service); |
73 service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); | 107 service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); |
74 service()->SetWindowBounds(window_id_, window_bounds_, false); | 108 service()->SetWindowBounds(window_id_, window_bounds_, false); |
75 registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, | 109 registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, |
76 NotificationService::AllSources()); | 110 NotificationService::AllSources()); |
77 } | 111 } |
78 | 112 |
(...skipping 12 matching lines...) Expand all Loading... |
91 | 125 |
92 virtual void TearDown() { | 126 virtual void TearDown() { |
93 helper_.set_service(NULL); | 127 helper_.set_service(NULL); |
94 profile()->set_session_service(NULL); | 128 profile()->set_session_service(NULL); |
95 sync_service_.reset(); | 129 sync_service_.reset(); |
96 } | 130 } |
97 | 131 |
98 bool StartSyncService(Task* task, bool will_fail_association) { | 132 bool StartSyncService(Task* task, bool will_fail_association) { |
99 if (sync_service_.get()) | 133 if (sync_service_.get()) |
100 return false; | 134 return false; |
101 | |
102 sync_service_.reset(new TestProfileSyncService( | 135 sync_service_.reset(new TestProfileSyncService( |
103 &factory_, profile(), "test user", false, task)); | 136 &factory_, profile(), kCrosUserForTest, false, task)); |
| 137 reinterpret_cast<TestingProfileForSyncTests *>(profile())-> |
| 138 set_sync_service(sync_service_.get()); |
104 profile()->set_session_service(helper_.service()); | 139 profile()->set_session_service(helper_.service()); |
105 | 140 |
106 // Register the session data type. | 141 // Register the session data type. |
107 model_associator_ = | 142 model_associator_ = |
108 new SessionModelAssociator(sync_service_.get()); | 143 new SessionModelAssociator(sync_service_.get()); |
109 change_processor_ = new SessionChangeProcessor( | 144 change_processor_ = new SessionChangeProcessor( |
110 sync_service_.get(), model_associator_); | 145 sync_service_.get(), model_associator_); |
111 EXPECT_CALL(factory_, CreateSessionSyncComponents(_, _)). | 146 EXPECT_CALL(factory_, CreateSessionSyncComponents(_, _)). |
112 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 147 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
113 model_associator_, change_processor_))); | 148 model_associator_, change_processor_))); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 ASSERT_FALSE(model_associator_->tab_pool_.full()); | 450 ASSERT_FALSE(model_associator_->tab_pool_.full()); |
416 for (size_t i = 0; i < num_ids; ++i) { | 451 for (size_t i = 0; i < num_ids; ++i) { |
417 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); | 452 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); |
418 } | 453 } |
419 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); | 454 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); |
420 ASSERT_FALSE(model_associator_->tab_pool_.empty()); | 455 ASSERT_FALSE(model_associator_->tab_pool_.empty()); |
421 ASSERT_TRUE(model_associator_->tab_pool_.full()); | 456 ASSERT_TRUE(model_associator_->tab_pool_.full()); |
422 } | 457 } |
423 | 458 |
424 } // namespace browser_sync | 459 } // namespace browser_sync |
OLD | NEW |