OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/live_sync/sessions_helper.h" | 5 #include "chrome/test/live_sync/sessions_helper.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.h" |
12 #include "chrome/browser/sync/profile_sync_service_harness.h" | 12 #include "chrome/browser/sync/profile_sync_service_harness.h" |
13 #include "chrome/browser/sync/glue/session_model_associator.h" | 13 #include "chrome/browser/sync/glue/session_model_associator.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "chrome/test/live_sync/sync_datatype_helper.h" | 16 #include "chrome/test/live_sync/sync_datatype_helper.h" |
17 #include "chrome/test/live_sync/live_sync_test.h" | 17 #include "chrome/test/live_sync/live_sync_test.h" |
18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 | 21 |
22 using sync_datatype_helper::test; | 22 using sync_datatype_helper::test; |
23 | 23 |
24 namespace sessions_helper { | 24 namespace sessions_helper { |
25 | 25 |
26 bool GetLocalSession(int index, const SyncedSession** session) { | 26 bool GetLocalSession(int index, const browser_sync::SyncedSession** session) { |
27 return test()->GetProfile(index)->GetProfileSyncService()-> | 27 return test()->GetProfile(index)->GetProfileSyncService()-> |
28 GetSessionModelAssociator()->GetLocalSession(session); | 28 GetSessionModelAssociator()->GetLocalSession(session); |
29 } | 29 } |
30 | 30 |
31 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { | 31 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { |
32 ui_test_utils::RunAllPendingInMessageLoop(); | 32 ui_test_utils::RunAllPendingInMessageLoop(); |
33 const SyncedSession* local_session; | 33 const browser_sync::SyncedSession* local_session; |
34 if (!GetLocalSession(index, &local_session)) { | 34 if (!GetLocalSession(index, &local_session)) { |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 if (local_session->windows.size() == 0) { | 38 if (local_session->windows.size() == 0) { |
39 VLOG(1) << "Empty windows vector"; | 39 VLOG(1) << "Empty windows vector"; |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 int nav_index; | 43 int nav_index; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ui_test_utils::RunMessageLoop(); | 112 ui_test_utils::RunMessageLoop(); |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 bool GetLocalWindows(int index, SessionWindowVector& local_windows) { | 119 bool GetLocalWindows(int index, SessionWindowVector& local_windows) { |
120 // The local session provided by GetLocalSession is owned, and has lifetime | 120 // The local session provided by GetLocalSession is owned, and has lifetime |
121 // controlled, by the model associator, so we must make our own copy. | 121 // controlled, by the model associator, so we must make our own copy. |
122 const SyncedSession* local_session; | 122 const browser_sync::SyncedSession* local_session; |
123 if (!GetLocalSession(index, &local_session)) { | 123 if (!GetLocalSession(index, &local_session)) { |
124 return false; | 124 return false; |
125 } | 125 } |
126 for (size_t w = 0; w < local_session->windows.size(); ++w) { | 126 for (size_t w = 0; w < local_session->windows.size(); ++w) { |
127 const SessionWindow& window = *local_session->windows.at(w); | 127 const SessionWindow& window = *local_session->windows.at(w); |
128 SessionWindow* new_window = new SessionWindow(); | 128 SessionWindow* new_window = new SessionWindow(); |
129 for (size_t t = 0; t < window.tabs.size(); ++t) { | 129 for (size_t t = 0; t < window.tabs.size(); ++t) { |
130 const SessionTab& tab = *window.tabs.at(t); | 130 const SessionTab& tab = *window.tabs.at(t); |
131 SessionTab* new_tab = new SessionTab(); | 131 SessionTab* new_tab = new SessionTab(); |
132 new_tab->navigations.resize(tab.navigations.size()); | 132 new_tab->navigations.resize(tab.navigations.size()); |
(...skipping 21 matching lines...) Expand all Loading... |
154 | 154 |
155 bool CheckInitialState(int index) { | 155 bool CheckInitialState(int index) { |
156 if (0 != GetNumWindows(index)) | 156 if (0 != GetNumWindows(index)) |
157 return false; | 157 return false; |
158 if (0 != GetNumForeignSessions(index)) | 158 if (0 != GetNumForeignSessions(index)) |
159 return false; | 159 return false; |
160 return true; | 160 return true; |
161 } | 161 } |
162 | 162 |
163 int GetNumWindows(int index) { | 163 int GetNumWindows(int index) { |
164 const SyncedSession* local_session; | 164 const browser_sync::SyncedSession* local_session; |
165 if (!GetLocalSession(index, &local_session)) { | 165 if (!GetLocalSession(index, &local_session)) { |
166 return 0; | 166 return 0; |
167 } | 167 } |
168 return local_session->windows.size(); | 168 return local_session->windows.size(); |
169 } | 169 } |
170 | 170 |
171 int GetNumForeignSessions(int index) { | 171 int GetNumForeignSessions(int index) { |
172 SyncedSessionVector sessions; | 172 SyncedSessionVector sessions; |
173 if (!test()->GetProfile(index)->GetProfileSyncService()-> | 173 if (!test()->GetProfile(index)->GetProfileSyncService()-> |
174 GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) | 174 GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) |
(...skipping 22 matching lines...) Expand all Loading... |
197 | 197 |
198 return lhs->tabs[0]->navigations[0].virtual_url() < | 198 return lhs->tabs[0]->navigations[0].virtual_url() < |
199 rhs->tabs[0]->navigations[0].virtual_url(); | 199 rhs->tabs[0]->navigations[0].virtual_url(); |
200 } | 200 } |
201 | 201 |
202 void SortSessionWindows(SessionWindowVector& windows) { | 202 void SortSessionWindows(SessionWindowVector& windows) { |
203 std::sort(windows.begin(), windows.end(), | 203 std::sort(windows.begin(), windows.end(), |
204 CompareSessionWindows); | 204 CompareSessionWindows); |
205 } | 205 } |
206 | 206 |
207 bool CompareSyncedSessions(const SyncedSession* lhs, const SyncedSession* rhs) { | 207 bool CompareSyncedSessions(const browser_sync::SyncedSession* lhs, |
| 208 const browser_sync::SyncedSession* rhs) { |
208 if (!lhs || | 209 if (!lhs || |
209 !rhs || | 210 !rhs || |
210 lhs->windows.size() < 1 || | 211 lhs->windows.size() < 1 || |
211 rhs->windows.size() < 1) { | 212 rhs->windows.size() < 1) { |
212 // Catchall for uncomparable data. | 213 // Catchall for uncomparable data. |
213 return false; | 214 return false; |
214 } | 215 } |
215 | 216 |
216 return CompareSessionWindows(lhs->windows[0], rhs->windows[0]); | 217 return CompareSessionWindows(lhs->windows[0], rhs->windows[0]); |
217 } | 218 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if (window_index == index) | 285 if (window_index == index) |
285 window_index++; // Skip self. | 286 window_index++; // Skip self. |
286 if (!WindowsMatch(sessions[j]->windows, *windows[window_index])) | 287 if (!WindowsMatch(sessions[j]->windows, *windows[window_index])) |
287 return false; | 288 return false; |
288 } | 289 } |
289 | 290 |
290 return true; | 291 return true; |
291 } | 292 } |
292 | 293 |
293 } // namespace sessions_helper | 294 } // namespace sessions_helper |
OLD | NEW |