| 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 "chrome/browser/sync/test/integration/sessions_helper.h" | 5 #include "chrome/browser/sync/test/integration/sessions_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> |
| 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 17 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const SessionWindowMap* ScopedWindowMap::Get() const { | 56 const SessionWindowMap* ScopedWindowMap::Get() const { |
| 55 return &windows_; | 57 return &windows_; |
| 56 } | 58 } |
| 57 | 59 |
| 58 void ScopedWindowMap::Reset(SessionWindowMap* windows) { | 60 void ScopedWindowMap::Reset(SessionWindowMap* windows) { |
| 59 base::STLDeleteContainerPairSecondPointers(windows_.begin(), windows_.end()); | 61 base::STLDeleteContainerPairSecondPointers(windows_.begin(), windows_.end()); |
| 60 windows_.clear(); | 62 windows_.clear(); |
| 61 std::swap(*windows, windows_); | 63 std::swap(*windows, windows_); |
| 62 } | 64 } |
| 63 | 65 |
| 64 bool GetLocalSession(int index, const sync_driver::SyncedSession** session) { | 66 bool GetLocalSession(int index, const sync_sessions::SyncedSession** session) { |
| 65 return ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 67 return ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 66 test()->GetProfile(index))->GetOpenTabsUIDelegate()-> | 68 test()->GetProfile(index))->GetOpenTabsUIDelegate()-> |
| 67 GetLocalSession(session); | 69 GetLocalSession(session); |
| 68 } | 70 } |
| 69 | 71 |
| 70 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { | 72 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { |
| 71 content::RunAllPendingInMessageLoop(); | 73 content::RunAllPendingInMessageLoop(); |
| 72 const sync_driver::SyncedSession* local_session; | 74 const sync_sessions::SyncedSession* local_session; |
| 73 if (!GetLocalSession(index, &local_session)) { | 75 if (!GetLocalSession(index, &local_session)) { |
| 74 return false; | 76 return false; |
| 75 } | 77 } |
| 76 | 78 |
| 77 if (local_session->windows.size() == 0) { | 79 if (local_session->windows.size() == 0) { |
| 78 DVLOG(1) << "Empty windows vector"; | 80 DVLOG(1) << "Empty windows vector"; |
| 79 return false; | 81 return false; |
| 80 } | 82 } |
| 81 | 83 |
| 82 int nav_index; | 84 int nav_index; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 it != urls.end(); ++it) { | 127 it != urls.end(); ++it) { |
| 126 DVLOG(1) << "Opening tab: " << it->spec() << " using profile " << index | 128 DVLOG(1) << "Opening tab: " << it->spec() << " using profile " << index |
| 127 << "."; | 129 << "."; |
| 128 chrome::ShowSingletonTab(browser, *it); | 130 chrome::ShowSingletonTab(browser, *it); |
| 129 } | 131 } |
| 130 return WaitForTabsToLoad(index, urls); | 132 return WaitForTabsToLoad(index, urls); |
| 131 } | 133 } |
| 132 | 134 |
| 133 namespace { | 135 namespace { |
| 134 | 136 |
| 135 class TabEventHandler : public browser_sync::LocalSessionEventHandler { | 137 class TabEventHandler : public sync_sessions::LocalSessionEventHandler { |
| 136 public: | 138 public: |
| 137 TabEventHandler() : weak_factory_(this) { | 139 TabEventHandler() : weak_factory_(this) { |
| 138 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 140 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 139 FROM_HERE, | 141 FROM_HERE, |
| 140 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()), | 142 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()), |
| 141 TestTimeouts::action_max_timeout()); | 143 TestTimeouts::action_max_timeout()); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void OnLocalTabModified( | 146 void OnLocalTabModified( |
| 145 browser_sync::SyncedTabDelegate* modified_tab) override { | 147 sync_sessions::SyncedTabDelegate* modified_tab) override { |
| 146 // Unwind to ensure SessionsSyncManager has processed the event. | 148 // Unwind to ensure SessionsSyncManager has processed the event. |
| 147 base::ThreadTaskRunnerHandle::Get()->PostTask( | 149 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 148 FROM_HERE, | 150 FROM_HERE, |
| 149 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr())); | 151 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr())); |
| 150 } | 152 } |
| 151 | 153 |
| 152 void OnFaviconsChanged(const std::set<GURL>& /* page_urls */, | 154 void OnFaviconsChanged(const std::set<GURL>& /* page_urls */, |
| 153 const GURL& /* icon_url */) override { | 155 const GURL& /* icon_url */) override { |
| 154 // Unwind to ensure SessionsSyncManager has processed the event. | 156 // Unwind to ensure SessionsSyncManager has processed the event. |
| 155 base::ThreadTaskRunnerHandle::Get()->PostTask( | 157 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 176 while (!found) { | 178 while (!found) { |
| 177 found = ModelAssociatorHasTabWithUrl(index, *it); | 179 found = ModelAssociatorHasTabWithUrl(index, *it); |
| 178 if (base::TimeTicks::Now() >= end_time) { | 180 if (base::TimeTicks::Now() >= end_time) { |
| 179 LOG(ERROR) << "Failed to find all tabs after " | 181 LOG(ERROR) << "Failed to find all tabs after " |
| 180 << TestTimeouts::action_max_timeout().InSecondsF() | 182 << TestTimeouts::action_max_timeout().InSecondsF() |
| 181 << " seconds."; | 183 << " seconds."; |
| 182 return false; | 184 return false; |
| 183 } | 185 } |
| 184 if (!found) { | 186 if (!found) { |
| 185 TabEventHandler handler; | 187 TabEventHandler handler; |
| 186 browser_sync::NotificationServiceSessionsRouter router( | 188 sync_sessions::NotificationServiceSessionsRouter router( |
| 187 test()->GetProfile(index), | 189 test()->GetProfile(index), |
| 188 ProfileSyncServiceFactory::GetInstance() | 190 ProfileSyncServiceFactory::GetInstance() |
| 189 ->GetForProfile(test()->GetProfile(index)) | 191 ->GetForProfile(test()->GetProfile(index)) |
| 190 ->GetSyncClient() | 192 ->GetSyncClient() |
| 191 ->GetSyncSessionsClient(), | 193 ->GetSyncSessionsClient(), |
| 192 syncer::SyncableService::StartSyncFlare()); | 194 syncer::SyncableService::StartSyncFlare()); |
| 193 router.StartRoutingTo(&handler); | 195 router.StartRoutingTo(&handler); |
| 194 content::RunMessageLoop(); | 196 content::RunMessageLoop(); |
| 195 } | 197 } |
| 196 } | 198 } |
| 197 } | 199 } |
| 198 return true; | 200 return true; |
| 199 } | 201 } |
| 200 | 202 |
| 201 bool GetLocalWindows(int index, SessionWindowMap* local_windows) { | 203 bool GetLocalWindows(int index, SessionWindowMap* local_windows) { |
| 202 // The local session provided by GetLocalSession is owned, and has lifetime | 204 // The local session provided by GetLocalSession is owned, and has lifetime |
| 203 // controlled, by the model associator, so we must make our own copy. | 205 // controlled, by the model associator, so we must make our own copy. |
| 204 const sync_driver::SyncedSession* local_session; | 206 const sync_sessions::SyncedSession* local_session; |
| 205 if (!GetLocalSession(index, &local_session)) { | 207 if (!GetLocalSession(index, &local_session)) { |
| 206 return false; | 208 return false; |
| 207 } | 209 } |
| 208 for (SessionWindowMap::const_iterator w = local_session->windows.begin(); | 210 for (SessionWindowMap::const_iterator w = local_session->windows.begin(); |
| 209 w != local_session->windows.end(); ++w) { | 211 w != local_session->windows.end(); ++w) { |
| 210 const sessions::SessionWindow& window = *(w->second); | 212 const sessions::SessionWindow& window = *(w->second); |
| 211 sessions::SessionWindow* new_window = new sessions::SessionWindow(); | 213 sessions::SessionWindow* new_window = new sessions::SessionWindow(); |
| 212 new_window->window_id.set_id(window.window_id.id()); | 214 new_window->window_id.set_id(window.window_id.id()); |
| 213 for (size_t t = 0; t < window.tabs.size(); ++t) { | 215 for (size_t t = 0; t < window.tabs.size(); ++t) { |
| 214 const sessions::SessionTab& tab = *window.tabs.at(t); | 216 const sessions::SessionTab& tab = *window.tabs.at(t); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 235 | 237 |
| 236 bool CheckInitialState(int index) { | 238 bool CheckInitialState(int index) { |
| 237 if (0 != GetNumWindows(index)) | 239 if (0 != GetNumWindows(index)) |
| 238 return false; | 240 return false; |
| 239 if (0 != GetNumForeignSessions(index)) | 241 if (0 != GetNumForeignSessions(index)) |
| 240 return false; | 242 return false; |
| 241 return true; | 243 return true; |
| 242 } | 244 } |
| 243 | 245 |
| 244 int GetNumWindows(int index) { | 246 int GetNumWindows(int index) { |
| 245 const sync_driver::SyncedSession* local_session; | 247 const sync_sessions::SyncedSession* local_session; |
| 246 if (!GetLocalSession(index, &local_session)) { | 248 if (!GetLocalSession(index, &local_session)) { |
| 247 return 0; | 249 return 0; |
| 248 } | 250 } |
| 249 return local_session->windows.size(); | 251 return local_session->windows.size(); |
| 250 } | 252 } |
| 251 | 253 |
| 252 int GetNumForeignSessions(int index) { | 254 int GetNumForeignSessions(int index) { |
| 253 SyncedSessionVector sessions; | 255 SyncedSessionVector sessions; |
| 254 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 256 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 255 test()->GetProfile(index))-> | 257 test()->GetProfile(index))-> |
| 256 GetOpenTabsUIDelegate()->GetAllForeignSessions( | 258 GetOpenTabsUIDelegate()->GetAllForeignSessions( |
| 257 &sessions)) { | 259 &sessions)) { |
| 258 return 0; | 260 return 0; |
| 259 } | 261 } |
| 260 return sessions.size(); | 262 return sessions.size(); |
| 261 } | 263 } |
| 262 | 264 |
| 263 bool GetSessionData(int index, SyncedSessionVector* sessions) { | 265 bool GetSessionData(int index, SyncedSessionVector* sessions) { |
| 264 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 266 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 265 test()->GetProfile(index))-> | 267 test()->GetProfile(index))-> |
| 266 GetOpenTabsUIDelegate()->GetAllForeignSessions( | 268 GetOpenTabsUIDelegate()->GetAllForeignSessions( |
| 267 sessions)) { | 269 sessions)) { |
| 268 return false; | 270 return false; |
| 269 } | 271 } |
| 270 SortSyncedSessions(sessions); | 272 SortSyncedSessions(sessions); |
| 271 return true; | 273 return true; |
| 272 } | 274 } |
| 273 | 275 |
| 274 bool CompareSyncedSessions(const sync_driver::SyncedSession* lhs, | 276 bool CompareSyncedSessions(const sync_sessions::SyncedSession* lhs, |
| 275 const sync_driver::SyncedSession* rhs) { | 277 const sync_sessions::SyncedSession* rhs) { |
| 276 if (!lhs || | 278 if (!lhs || |
| 277 !rhs || | 279 !rhs || |
| 278 lhs->windows.size() < 1 || | 280 lhs->windows.size() < 1 || |
| 279 rhs->windows.size() < 1) { | 281 rhs->windows.size() < 1) { |
| 280 // Catchall for uncomparable data. | 282 // Catchall for uncomparable data. |
| 281 return false; | 283 return false; |
| 282 } | 284 } |
| 283 | 285 |
| 284 return lhs->windows < rhs->windows; | 286 return lhs->windows < rhs->windows; |
| 285 } | 287 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 return !checker.TimedOut(); | 435 return !checker.TimedOut(); |
| 434 } | 436 } |
| 435 | 437 |
| 436 void DeleteForeignSession(int index, std::string session_tag) { | 438 void DeleteForeignSession(int index, std::string session_tag) { |
| 437 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 439 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 438 test()->GetProfile(index))-> | 440 test()->GetProfile(index))-> |
| 439 GetOpenTabsUIDelegate()->DeleteForeignSession(session_tag); | 441 GetOpenTabsUIDelegate()->DeleteForeignSession(session_tag); |
| 440 } | 442 } |
| 441 | 443 |
| 442 } // namespace sessions_helper | 444 } // namespace sessions_helper |
| OLD | NEW |