| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "google_apis/gaia/gaia_constants.h" | 38 #include "google_apis/gaia/gaia_constants.h" |
| 39 #include "googleurl/src/gurl.h" | 39 #include "googleurl/src/gurl.h" |
| 40 #include "sync/internal_api/public/base/model_type.h" | 40 #include "sync/internal_api/public/base/model_type.h" |
| 41 #include "sync/internal_api/public/change_record.h" | 41 #include "sync/internal_api/public/change_record.h" |
| 42 #include "sync/internal_api/public/read_node.h" | 42 #include "sync/internal_api/public/read_node.h" |
| 43 #include "sync/internal_api/public/read_transaction.h" | 43 #include "sync/internal_api/public/read_transaction.h" |
| 44 #include "sync/internal_api/public/write_node.h" | 44 #include "sync/internal_api/public/write_node.h" |
| 45 #include "sync/internal_api/public/write_transaction.h" | 45 #include "sync/internal_api/public/write_transaction.h" |
| 46 #include "sync/protocol/session_specifics.pb.h" | 46 #include "sync/protocol/session_specifics.pb.h" |
| 47 #include "sync/protocol/sync.pb.h" | 47 #include "sync/protocol/sync.pb.h" |
| 48 #include "sync/test/engine/test_id_factory.h" | |
| 49 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
| 50 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
| 51 #include "ui/base/ui_base_types.h" | 50 #include "ui/base/ui_base_types.h" |
| 52 | 51 |
| 53 using browser_sync::SessionChangeProcessor; | 52 using browser_sync::SessionChangeProcessor; |
| 54 using browser_sync::SessionDataTypeController; | 53 using browser_sync::SessionDataTypeController; |
| 55 using browser_sync::SessionModelAssociator; | 54 using browser_sync::SessionModelAssociator; |
| 56 using browser_sync::SyncBackendHost; | 55 using browser_sync::SyncBackendHost; |
| 57 using content::BrowserThread; | 56 using content::BrowserThread; |
| 58 using syncer::ChangeRecord; | 57 using syncer::ChangeRecord; |
| 59 using testing::_; | 58 using testing::_; |
| 60 using testing::Return; | 59 using testing::Return; |
| 61 using syncer::TestIdFactory; | |
| 62 | 60 |
| 63 namespace browser_sync { | 61 namespace browser_sync { |
| 64 | 62 |
| 65 namespace { | 63 namespace { |
| 66 | 64 |
| 67 void BuildSessionSpecifics(const std::string& tag, | 65 void BuildSessionSpecifics(const std::string& tag, |
| 68 sync_pb::SessionSpecifics* meta) { | 66 sync_pb::SessionSpecifics* meta) { |
| 69 meta->set_session_tag(tag); | 67 meta->set_session_tag(tag); |
| 70 sync_pb::SessionHeader* header = meta->mutable_header(); | 68 sync_pb::SessionHeader* header = meta->mutable_header(); |
| 71 header->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX); | 69 header->set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_LINUX); |
| 72 header->set_client_name("name"); | 70 header->set_client_name("name"); |
| 73 } | 71 } |
| 74 | 72 |
| 75 void AddWindowSpecifics(int window_id, | 73 void AddWindowSpecifics(int window_id, |
| 76 const std::vector<int>& tab_list, | 74 const std::vector<int>& tab_list, |
| 77 sync_pb::SessionSpecifics* meta) { | 75 sync_pb::SessionSpecifics* meta) { |
| 78 sync_pb::SessionHeader* header = meta->mutable_header(); | 76 sync_pb::SessionHeader* header = meta->mutable_header(); |
| 79 sync_pb::SessionWindow* window = header->add_window(); | 77 sync_pb::SessionWindow* window = header->add_window(); |
| 80 window->set_window_id(window_id); | 78 window->set_window_id(window_id); |
| 81 window->set_selected_tab_index(0); | 79 window->set_selected_tab_index(0); |
| 82 window->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); | 80 window->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); |
| 83 for (std::vector<int>::const_iterator iter = tab_list.begin(); | 81 for (std::vector<int>::const_iterator iter = tab_list.begin(); |
| 84 iter != tab_list.end(); ++iter) { | 82 iter != tab_list.end(); ++iter) { |
| 85 window->add_tab(*iter); | 83 window->add_tab(*iter); |
| 86 } | 84 } |
| 87 } | 85 } |
| 88 | 86 |
| 89 void BuildTabSpecifics(const std::string& tag, int window_id, int tab_id, | 87 void BuildTabSpecifics(const std::string& tag, int window_id, int tab_id, |
| 90 sync_pb::SessionSpecifics* tab_base) { | 88 sync_pb::SessionSpecifics* tab_base) { |
| 91 tab_base->set_session_tag(tag); | 89 tab_base->set_session_tag(tag); |
| 92 sync_pb::SessionTab* tab = tab_base->mutable_tab(); | 90 sync_pb::SessionTab* tab = tab_base->mutable_tab(); |
| 93 tab->set_tab_id(tab_id); | 91 tab->set_tab_id(tab_id); |
| 94 tab->set_tab_visual_index(1); | 92 tab->set_tab_visual_index(1); |
| 95 tab->set_current_navigation_index(0); | 93 tab->set_current_navigation_index(0); |
| 96 tab->set_pinned(true); | 94 tab->set_pinned(true); |
| 97 tab->set_extension_app_id("app_id"); | 95 tab->set_extension_app_id("app_id"); |
| 98 sync_pb::TabNavigation* navigation = tab->add_navigation(); | 96 sync_pb::TabNavigation* navigation = tab->add_navigation(); |
| 99 navigation->set_virtual_url("http://foo/1"); | 97 navigation->set_virtual_url("http://foo/1"); |
| 100 navigation->set_referrer("referrer"); | 98 navigation->set_referrer("referrer"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 : public BrowserWithTestWindowTest, | 151 : public BrowserWithTestWindowTest, |
| 154 public content::NotificationObserver { | 152 public content::NotificationObserver { |
| 155 public: | 153 public: |
| 156 ProfileSyncServiceSessionTest() | 154 ProfileSyncServiceSessionTest() |
| 157 : io_thread_(BrowserThread::IO), | 155 : io_thread_(BrowserThread::IO), |
| 158 window_bounds_(0, 1, 2, 3), | 156 window_bounds_(0, 1, 2, 3), |
| 159 notified_of_update_(false), | 157 notified_of_update_(false), |
| 160 notified_of_refresh_(false) {} | 158 notified_of_refresh_(false) {} |
| 161 ProfileSyncService* sync_service() { return sync_service_.get(); } | 159 ProfileSyncService* sync_service() { return sync_service_.get(); } |
| 162 | 160 |
| 163 TestIdFactory* ids() { return sync_service_->id_factory(); } | |
| 164 | |
| 165 protected: | 161 protected: |
| 166 virtual TestingProfile* CreateProfile() OVERRIDE { | 162 virtual TestingProfile* CreateProfile() OVERRIDE { |
| 167 TestingProfile* profile = new TestingProfile(); | 163 TestingProfile* profile = new TestingProfile(); |
| 168 // Don't want the profile to create a real ProfileSyncService. | 164 // Don't want the profile to create a real ProfileSyncService. |
| 169 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, | 165 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, |
| 170 NULL); | 166 NULL); |
| 171 return profile; | 167 return profile; |
| 172 } | 168 } |
| 173 | 169 |
| 174 virtual void SetUp() { | 170 virtual void SetUp() { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 277 } |
| 282 | 278 |
| 283 virtual ~CreateRootHelper() {} | 279 virtual ~CreateRootHelper() {} |
| 284 | 280 |
| 285 const base::Closure& callback() const { return callback_; } | 281 const base::Closure& callback() const { return callback_; } |
| 286 bool success() { return success_; } | 282 bool success() { return success_; } |
| 287 | 283 |
| 288 private: | 284 private: |
| 289 void CreateRootCallback(ProfileSyncServiceSessionTest* test) { | 285 void CreateRootCallback(ProfileSyncServiceSessionTest* test) { |
| 290 success_ = ProfileSyncServiceTestHelper::CreateRoot( | 286 success_ = ProfileSyncServiceTestHelper::CreateRoot( |
| 291 syncer::SESSIONS, test->sync_service()->GetUserShare(), test->ids()); | 287 syncer::SESSIONS, test->sync_service()->GetUserShare()); |
| 292 } | 288 } |
| 293 | 289 |
| 294 base::Closure callback_; | 290 base::Closure callback_; |
| 295 bool success_; | 291 bool success_; |
| 296 }; | 292 }; |
| 297 | 293 |
| 298 // Test that we can write this machine's session to a node and retrieve it. | 294 // Test that we can write this machine's session to a node and retrieve it. |
| 299 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { | 295 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { |
| 300 CreateRootHelper create_root(this); | 296 CreateRootHelper create_root(this); |
| 301 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 297 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 sync_pb::SessionSpecifics specifics; | 1191 sync_pb::SessionSpecifics specifics; |
| 1196 header.SetSessionSpecifics(specifics); | 1192 header.SetSessionSpecifics(specifics); |
| 1197 } | 1193 } |
| 1198 // Ensure we associate properly despite the pre-existing node with our local | 1194 // Ensure we associate properly despite the pre-existing node with our local |
| 1199 // tag. | 1195 // tag. |
| 1200 error = model_associator_->AssociateModels(); | 1196 error = model_associator_->AssociateModels(); |
| 1201 ASSERT_FALSE(error.IsSet()); | 1197 ASSERT_FALSE(error.IsSet()); |
| 1202 } | 1198 } |
| 1203 | 1199 |
| 1204 } // namespace browser_sync | 1200 } // namespace browser_sync |
| OLD | NEW |