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

Side by Side Diff: chrome/test/live_sync/live_sessions_sync_test.h

Issue 5705004: [SYNC] Sessions datatype refactor. Most things related to sessions under-the-... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Rebase Created 9 years, 11 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) 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 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_ 5 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_
6 #define CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_ 6 #define CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 return; 85 return;
86 } 86 }
87 SessionService::SessionCallback* callback = 87 SessionService::SessionCallback* callback =
88 NewCallback(this, &TestSessionService::OnGotSession); 88 NewCallback(this, &TestSessionService::OnGotSession);
89 service()->GetCurrentSession(&consumer_, callback); 89 service()->GetCurrentSession(&consumer_, callback);
90 } 90 }
91 91
92 // Internal method used in the callback to obtain the current session. 92 // Internal method used in the callback to obtain the current session.
93 // Lives on and called from backend thread (file_thread). 93 // Lives on and called from backend thread (file_thread).
94 // We don't own windows so need to make a deep copy. 94 // We don't own windows so need to make a deep copy.
95 // In this case, we only copy those values compared against in WindowsMatch
96 // (number of windows, number of tabs, and navigations within tabs).
95 void OnGotSession(int handle, std::vector<SessionWindow*>* windows) { 97 void OnGotSession(int handle, std::vector<SessionWindow*>* windows) {
96 // Hacky. We need to make a deep copy of the session windows. One way to do 98 scoped_ptr<ForeignSession> foreign_session(new ForeignSession());
97 // this is to use the session model associators functionality to create 99 for (size_t w = 0; w < windows->size(); ++w) {
98 // foreign sessions, which themselves wrap a SessionWindow vector. We just 100 const SessionWindow& window = *windows->at(w);
99 // need to make sure to destroy all the foreign sessions we created when 101 scoped_ptr<SessionWindow> new_window(new SessionWindow());
100 // we're done. That's what the foreign_sessions_ ScopedVector is for. 102 for (size_t t = 0; t < window.tabs.size(); ++t) {
101 sync_pb::SessionSpecifics session; 103 const SessionTab& tab = *window.tabs.at(t);
102 profile_->GetProfileSyncService()-> 104 scoped_ptr<SessionTab> new_tab(new SessionTab());
103 GetSessionModelAssociator()-> 105 new_tab->navigations.resize(tab.navigations.size());
104 FillSpecificsFromSessions(windows, &session); 106 std::copy(tab.navigations.begin(), tab.navigations.end(),
105 107 new_tab->navigations.begin());
106 std::vector<ForeignSession*> foreign_sessions; 108 new_window->tabs.push_back(new_tab.release());
107 profile_->GetProfileSyncService()-> 109 }
108 GetSessionModelAssociator()-> 110 foreign_session->windows.push_back(new_window.release());
109 AppendForeignSessionFromSpecifics(&session, &foreign_sessions); 111 }
110 ASSERT_EQ(foreign_sessions.size(), 1U); 112 windows_ = &(foreign_session->windows);
111 foreign_sessions_.push_back(foreign_sessions[0]); 113 foreign_sessions_.push_back(foreign_session.release());
112 windows_ = &foreign_sessions[0]->windows;
113 got_windows_.Signal(); 114 got_windows_.Signal();
114 } 115 }
115 116
116 private: 117 private:
117 ~TestSessionService() { 118 ~TestSessionService() {
118 ReleaseService(); // We don't own this, so don't destroy it. 119 ReleaseService(); // We don't own this, so don't destroy it.
119 } 120 }
120 121
121 friend class base::RefCountedThreadSafe<TestSessionService>; 122 friend class base::RefCountedThreadSafe<TestSessionService>;
122 123
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 234
234 // Returns number of open windows for a profile. 235 // Returns number of open windows for a profile.
235 int GetNumWindows(int index) { 236 int GetNumWindows(int index) {
236 // We don't own windows. 237 // We don't own windows.
237 std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows(); 238 std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows();
238 return windows->size(); 239 return windows->size();
239 } 240 }
240 241
241 // Returns number of foreign sessions for a profile. 242 // Returns number of foreign sessions for a profile.
242 int GetNumForeignSessions(int index) { 243 int GetNumForeignSessions(int index) {
243 ScopedVector<ForeignSession> sessions; 244 std::vector<const ForeignSession*> sessions;
244 if (!GetProfile(index)->GetProfileSyncService()-> 245 if (!GetProfile(index)->GetProfileSyncService()->
245 GetSessionModelAssociator()->GetSessionData(&sessions.get())) 246 GetSessionModelAssociator()->GetAllForeignSessions(&sessions))
246 return 0; 247 return 0;
247 return sessions.size(); 248 return sessions.size();
248 } 249 }
249 250
250 // Fills the sessions vector with the model associator's foreign session data. 251 // Fills the sessions vector with the model associator's foreign session data.
251 // Caller owns sessions. 252 // Caller owns |sessions|, but not ForeignSession objects within.
252 bool GetSessionData(int index, std::vector<ForeignSession*>* sessions) 253 bool GetSessionData(int index, std::vector<const ForeignSession*>* sessions)
253 WARN_UNUSED_RESULT { 254 WARN_UNUSED_RESULT {
254 if (!GetProfile(index)->GetProfileSyncService()-> 255 if (!GetProfile(index)->GetProfileSyncService()->
255 GetSessionModelAssociator()->GetSessionData(sessions)) 256 GetSessionModelAssociator()->GetAllForeignSessions(sessions))
256 return false; 257 return false;
257 SortForeignSessions(sessions); 258 SortForeignSessions(sessions);
258 return true; 259 return true;
259 } 260 }
260 261
261 // Compare session windows based on their first tab's url. 262 // Compare session windows based on their first tab's url.
262 // Returns true if the virtual url of the lhs is < the rhs. 263 // Returns true if the virtual url of the lhs is < the rhs.
263 static bool CompareSessionWindows(SessionWindow* lhs, SessionWindow* rhs) { 264 static bool CompareSessionWindows(SessionWindow* lhs, SessionWindow* rhs) {
264 if (!lhs || 265 if (!lhs ||
265 !rhs || 266 !rhs ||
(...skipping 11 matching lines...) Expand all
277 278
278 // Sort session windows using our custom comparator (first tab url 279 // Sort session windows using our custom comparator (first tab url
279 // comparison). 280 // comparison).
280 void SortSessionWindows(std::vector<SessionWindow*>* windows) { 281 void SortSessionWindows(std::vector<SessionWindow*>* windows) {
281 std::sort(windows->begin(), windows->end(), 282 std::sort(windows->begin(), windows->end(),
282 LiveSessionsSyncTest::CompareSessionWindows); 283 LiveSessionsSyncTest::CompareSessionWindows);
283 } 284 }
284 285
285 // Compares a foreign session based on the first session window. 286 // Compares a foreign session based on the first session window.
286 // Returns true based on the comparison of the session windows. 287 // Returns true based on the comparison of the session windows.
287 static bool CompareForeignSessions(ForeignSession* lhs, ForeignSession* rhs) { 288 static bool CompareForeignSessions(
289 const ForeignSession* lhs,
290 const ForeignSession* rhs) {
288 if (!lhs || 291 if (!lhs ||
289 !rhs || 292 !rhs ||
290 lhs->windows.size() < 1 || 293 lhs->windows.size() < 1 ||
291 rhs->windows.size() < 1) { 294 rhs->windows.size() < 1) {
292 // Catchall for uncomparable data. 295 // Catchall for uncomparable data.
293 return false; 296 return false;
294 } 297 }
295 298
296 return CompareSessionWindows(lhs->windows[0], rhs->windows[0]); 299 return CompareSessionWindows(lhs->windows[0], rhs->windows[0]);
297 } 300 }
298 301
299 // Sort a foreign session vector using our custom foreign session comparator. 302 // Sort a foreign session vector using our custom foreign session comparator.
300 void SortForeignSessions(std::vector<ForeignSession*>* sessions) { 303 void SortForeignSessions(std::vector<const ForeignSession*>* sessions) {
301 std::sort(sessions->begin(), sessions->end(), 304 std::sort(sessions->begin(), sessions->end(),
302 LiveSessionsSyncTest::CompareForeignSessions); 305 LiveSessionsSyncTest::CompareForeignSessions);
303 } 306 }
304 307
308 // Compares two tab navigations base on the parameters we sync.
309 // (Namely, we don't sync state or type mask)
310 bool NavigationEquals(const TabNavigation& expected,
311 const TabNavigation& actual) {
312 if (expected.virtual_url() != actual.virtual_url())
313 return false;
314 if (expected.referrer() != actual.referrer())
315 return false;
316 if (expected.title() != actual.title())
317 return false;
318 if (expected.transition() != actual.transition())
319 return false;
320 return true;
321 }
322
305 // Verifies that two SessionWindows match. 323 // Verifies that two SessionWindows match.
306 // Returns: 324 // Returns:
307 // - true if all the following match: 325 // - true if all the following match:
308 // 1. number of SessionWindows per vector, 326 // 1. number of SessionWindows,
309 // 2. number of tabs per SessionWindow, 327 // 2. number of tabs per SessionWindow,
310 // 3. number of tab navigations per nab, 328 // 3. number of tab navigations per tab,
311 // 4. actual tab navigations 329 // 4. actual tab navigations contents
312 // - false otherwise. 330 // - false otherwise.
313 bool WindowsMatch(const std::vector<SessionWindow*> &win1, 331 bool WindowsMatch(const std::vector<SessionWindow*> &win1,
314 const std::vector<SessionWindow*> &win2) WARN_UNUSED_RESULT { 332 const std::vector<SessionWindow*> &win2) WARN_UNUSED_RESULT {
315 SessionTab* client0_tab; 333 SessionTab* client0_tab;
316 SessionTab* client1_tab; 334 SessionTab* client1_tab;
317 if (win1.size() != win2.size()) 335 if (win1.size() != win2.size())
318 return false; 336 return false;
319 for (size_t i = 0; i < win1.size(); ++i) { 337 for (size_t i = 0; i < win1.size(); ++i) {
320 if (win1[i]->tabs.size() != win2[i]->tabs.size()) 338 if (win1[i]->tabs.size() != win2[i]->tabs.size())
321 return false; 339 return false;
322 for (size_t j = 0; j < win1[i]->tabs.size(); ++j) { 340 for (size_t j = 0; j < win1[i]->tabs.size(); ++j) {
323 client0_tab = win1[i]->tabs[j]; 341 client0_tab = win1[i]->tabs[j];
324 client1_tab = win2[i]->tabs[j]; 342 client1_tab = win2[i]->tabs[j];
325 for (size_t k = 0; k < client0_tab->navigations.size(); ++k) { 343 for (size_t k = 0; k < client0_tab->navigations.size(); ++k) {
326 GetHelper(0)->AssertNavigationEquals(client0_tab->navigations[k], 344 if (!NavigationEquals(client0_tab->navigations[k],
327 client1_tab->navigations[k]); 345 client1_tab->navigations[k])) {
346 return false;
347 }
328 } 348 }
329 } 349 }
330 } 350 }
331 351
332 return true; 352 return true;
333 } 353 }
334 354
335 // Retrieves the foreign sessions for a particular profile and compares them 355 // Retrieves the foreign sessions for a particular profile and compares them
336 // with a reference SessionWindow list. 356 // with a reference SessionWindow list.
337 // Returns true if the session windows of the foreign session matches the 357 // Returns true if the session windows of the foreign session matches the
338 // reference. 358 // reference.
339 bool CheckForeignSessionsAgainst(int index, 359 bool CheckForeignSessionsAgainst(int index,
340 const std::vector<std::vector<SessionWindow*>* >& windows) 360 const std::vector<std::vector<SessionWindow*>* >& windows)
341 WARN_UNUSED_RESULT { 361 WARN_UNUSED_RESULT {
342 ScopedVector<ForeignSession> sessions; 362 std::vector<const ForeignSession*> sessions;
343 if (!GetSessionData(index, &sessions.get())) 363 if (!GetSessionData(index, &sessions))
344 return false; 364 return false;
345 if ((size_t)(num_clients()-1) != sessions.size()) 365 if ((size_t)(num_clients()-1) != sessions.size())
346 return false; 366 return false;
347 367
348 int window_index = 0; 368 int window_index = 0;
349 for (size_t j = 0; j < sessions->size(); ++j, ++window_index) { 369 for (size_t j = 0; j < sessions.size(); ++j, ++window_index) {
350 if (window_index == index) 370 if (window_index == index)
351 window_index++; // Skip self. 371 window_index++; // Skip self.
352 if (!WindowsMatch(sessions[j]->windows, *windows[window_index])) 372 if (!WindowsMatch(sessions[j]->windows, *windows[window_index]))
353 return false; 373 return false;
354 } 374 }
355 375
356 return true; 376 return true;
357 } 377 }
358 378
359 protected: 379 protected:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 public: 427 public:
408 MultipleClientLiveSessionsSyncTest() 428 MultipleClientLiveSessionsSyncTest()
409 : LiveSessionsSyncTest(MULTIPLE_CLIENT) {} 429 : LiveSessionsSyncTest(MULTIPLE_CLIENT) {}
410 virtual ~MultipleClientLiveSessionsSyncTest() {} 430 virtual ~MultipleClientLiveSessionsSyncTest() {}
411 431
412 private: 432 private:
413 DISALLOW_COPY_AND_ASSIGN(MultipleClientLiveSessionsSyncTest); 433 DISALLOW_COPY_AND_ASSIGN(MultipleClientLiveSessionsSyncTest);
414 }; 434 };
415 435
416 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_ 436 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SESSIONS_SYNC_TEST_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/live_sync/single_client_live_sessions_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698