| 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/live_sessions_sync_test.h" | 5 #include "chrome/test/live_sync/live_sessions_sync_test.h" |
| 6 | 6 |
| 7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Go through and make the Browsers. | 33 // Go through and make the Browsers. |
| 34 for (int i = 0; i < num_clients(); ++i) { | 34 for (int i = 0; i < num_clients(); ++i) { |
| 35 browsers_.push_back(Browser::Create(GetProfile(i))); | 35 browsers_.push_back(Browser::Create(GetProfile(i))); |
| 36 } | 36 } |
| 37 | 37 |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool LiveSessionsSyncTest::GetLocalSession(int index, |
| 42 const SyncedSession** session) { |
| 43 return GetProfile(index)->GetProfileSyncService()-> |
| 44 GetSessionModelAssociator()->GetLocalSession(session); |
| 45 } |
| 46 |
| 41 bool LiveSessionsSyncTest::ModelAssociatorHasTabWithUrl(int index, | 47 bool LiveSessionsSyncTest::ModelAssociatorHasTabWithUrl(int index, |
| 42 const GURL& url) { | 48 const GURL& url) { |
| 43 ui_test_utils::RunAllPendingInMessageLoop(); | 49 ui_test_utils::RunAllPendingInMessageLoop(); |
| 44 const SyncedSession* local_session; | 50 const SyncedSession* local_session; |
| 45 if (!GetProfile(index)->GetProfileSyncService()-> | 51 if (!GetLocalSession(index, &local_session)) { |
| 46 GetSessionModelAssociator()->GetLocalSession(&local_session)) { | |
| 47 return false; | |
| 48 } | |
| 49 if (local_session->windows.size() == 0 || | |
| 50 local_session->windows[0]->tabs.size() == 0 || | |
| 51 local_session->windows[0]->tabs[0]->navigations.size() == 0) { | |
| 52 VLOG(1) << "Bad vectors!"; | |
| 53 return false; | 52 return false; |
| 54 } | 53 } |
| 55 | 54 |
| 56 int nav_index = | 55 if (local_session->windows.size() == 0) { |
| 57 local_session->windows[0]->tabs[0]->current_navigation_index; | 56 VLOG(1) << "Empty windows vector"; |
| 58 TabNavigation nav = | |
| 59 local_session->windows[0]->tabs[0]->navigations[nav_index]; | |
| 60 if (nav.virtual_url() != url) { | |
| 61 VLOG(1) << "Bad url!"; | |
| 62 return false; | 57 return false; |
| 63 } | 58 } |
| 64 if (nav.title().empty()) { | 59 |
| 65 VLOG(1) << "No title!"; | 60 int nav_index; |
| 66 return false; | 61 TabNavigation nav; |
| 62 for (std::vector<SessionWindow*>::const_iterator it = |
| 63 local_session->windows.begin(); it != local_session->windows.end(); |
| 64 ++it) { |
| 65 if ((*it)->tabs.size() == 0) { |
| 66 VLOG(1) << "Empty tabs vector"; |
| 67 continue; |
| 68 } |
| 69 for (std::vector<SessionTab*>::const_iterator tab_it = |
| 70 (*it)->tabs.begin(); tab_it != (*it)->tabs.end(); ++tab_it) { |
| 71 if ((*tab_it)->navigations.size() == 0) { |
| 72 VLOG(1) << "Empty navigations vector"; |
| 73 continue; |
| 74 } |
| 75 nav_index = (*tab_it)->current_navigation_index; |
| 76 nav = (*tab_it)->navigations[nav_index]; |
| 77 if (nav.virtual_url() == url) { |
| 78 VLOG(1) << "Found tab with url " << url.spec(); |
| 79 if (nav.title().empty()) { |
| 80 VLOG(1) << "No title!"; |
| 81 continue; |
| 82 } |
| 83 return true; |
| 84 } |
| 85 } |
| 67 } | 86 } |
| 68 VLOG(1) << "Found tab with url " << url.spec(); | 87 VLOG(1) << "Could not find tab with url " << url.spec(); |
| 69 return true; | 88 return false; |
| 70 } | 89 } |
| 71 | 90 |
| 72 bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) { | 91 bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) { |
| 73 static const int timeout_milli = TestTimeouts::action_max_timeout_ms(); | 92 static const int timeout_milli = TestTimeouts::action_max_timeout_ms(); |
| 74 VLOG(1) << "Opening tab: " << url.spec(); | 93 VLOG(1) << "Opening tab: " << url.spec(); |
| 75 GetBrowser(index)->ShowSingletonTab(url); | 94 GetBrowser(index)->ShowSingletonTab(url); |
| 76 VLOG(1) << "Waiting for session to propagate to associator."; | 95 VLOG(1) << "Waiting for session to propagate to associator."; |
| 77 base::TimeTicks start_time = base::TimeTicks::Now(); | 96 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 78 base::TimeTicks end_time = start_time + | 97 base::TimeTicks end_time = start_time + |
| 79 base::TimeDelta::FromMilliseconds(timeout_milli); | 98 base::TimeDelta::FromMilliseconds(timeout_milli); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 90 | 109 |
| 91 LOG(ERROR) << "Failed to find tab after " << timeout_milli/1000.0 | 110 LOG(ERROR) << "Failed to find tab after " << timeout_milli/1000.0 |
| 92 << " seconds."; | 111 << " seconds."; |
| 93 return false; | 112 return false; |
| 94 } | 113 } |
| 95 | 114 |
| 96 std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) { | 115 std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) { |
| 97 // The local session provided by GetLocalSession is owned, and has lifetime | 116 // The local session provided by GetLocalSession is owned, and has lifetime |
| 98 // controlled, by the model associator, so we must make our own copy. | 117 // controlled, by the model associator, so we must make our own copy. |
| 99 const SyncedSession* local_session; | 118 const SyncedSession* local_session; |
| 100 if (!GetProfile(index)->GetProfileSyncService()->GetSessionModelAssociator()-> | 119 if (!GetLocalSession(index, &local_session)) { |
| 101 GetLocalSession(&local_session)) { | |
| 102 return NULL; | 120 return NULL; |
| 103 } | 121 } |
| 104 scoped_ptr<SyncedSession> session_copy(new SyncedSession()); | 122 scoped_ptr<SyncedSession> session_copy(new SyncedSession()); |
| 105 for (size_t w = 0; w < local_session->windows.size(); ++w) { | 123 for (size_t w = 0; w < local_session->windows.size(); ++w) { |
| 106 const SessionWindow& window = *local_session->windows.at(w); | 124 const SessionWindow& window = *local_session->windows.at(w); |
| 107 scoped_ptr<SessionWindow> new_window(new SessionWindow()); | 125 scoped_ptr<SessionWindow> new_window(new SessionWindow()); |
| 108 for (size_t t = 0; t < window.tabs.size(); ++t) { | 126 for (size_t t = 0; t < window.tabs.size(); ++t) { |
| 109 const SessionTab& tab = *window.tabs.at(t); | 127 const SessionTab& tab = *window.tabs.at(t); |
| 110 scoped_ptr<SessionTab> new_tab(new SessionTab()); | 128 scoped_ptr<SessionTab> new_tab(new SessionTab()); |
| 111 new_tab->navigations.resize(tab.navigations.size()); | 129 new_tab->navigations.resize(tab.navigations.size()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 135 bool LiveSessionsSyncTest::CheckInitialState(int index) { | 153 bool LiveSessionsSyncTest::CheckInitialState(int index) { |
| 136 if (0 != GetNumWindows(index)) | 154 if (0 != GetNumWindows(index)) |
| 137 return false; | 155 return false; |
| 138 if (0 != GetNumForeignSessions(index)) | 156 if (0 != GetNumForeignSessions(index)) |
| 139 return false; | 157 return false; |
| 140 return true; | 158 return true; |
| 141 } | 159 } |
| 142 | 160 |
| 143 int LiveSessionsSyncTest::GetNumWindows(int index) { | 161 int LiveSessionsSyncTest::GetNumWindows(int index) { |
| 144 const SyncedSession* local_session; | 162 const SyncedSession* local_session; |
| 145 if (!GetProfile(index)->GetProfileSyncService()->GetSessionModelAssociator()-> | 163 if (!GetLocalSession(index, &local_session)) { |
| 146 GetLocalSession(&local_session)) { | |
| 147 return 0; | 164 return 0; |
| 148 } | 165 } |
| 149 return local_session->windows.size(); | 166 return local_session->windows.size(); |
| 150 } | 167 } |
| 151 | 168 |
| 152 int LiveSessionsSyncTest::GetNumForeignSessions(int index) { | 169 int LiveSessionsSyncTest::GetNumForeignSessions(int index) { |
| 153 std::vector<const SyncedSession*> sessions; | 170 std::vector<const SyncedSession*> sessions; |
| 154 if (!GetProfile(index)->GetProfileSyncService()-> | 171 if (!GetProfile(index)->GetProfileSyncService()-> |
| 155 GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) | 172 GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) |
| 156 return 0; | 173 return 0; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // sync profile. | 304 // sync profile. |
| 288 BrowserList::CloseAllBrowsers(); | 305 BrowserList::CloseAllBrowsers(); |
| 289 ui_test_utils::RunAllPendingInMessageLoop(); | 306 ui_test_utils::RunAllPendingInMessageLoop(); |
| 290 | 307 |
| 291 // All browsers should be closed at this point, else when the framework | 308 // All browsers should be closed at this point, else when the framework |
| 292 // calls QuitBrowsers() we could see memory corruption. | 309 // calls QuitBrowsers() we could see memory corruption. |
| 293 ASSERT_EQ(0U, BrowserList::size()); | 310 ASSERT_EQ(0U, BrowserList::size()); |
| 294 | 311 |
| 295 LiveSyncTest::CleanUpOnMainThread(); | 312 LiveSyncTest::CleanUpOnMainThread(); |
| 296 } | 313 } |
| OLD | NEW |