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

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

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

Powered by Google App Engine
This is Rietveld 408576698