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