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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 } | 82 } |
83 return true; | 83 return true; |
84 } | 84 } |
85 } | 85 } |
86 } | 86 } |
87 VLOG(1) << "Could not find tab with url " << url.spec(); | 87 VLOG(1) << "Could not find tab with url " << url.spec(); |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
91 bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) { | 91 bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) { |
92 static const int timeout_milli = TestTimeouts::action_max_timeout_ms(); | |
93 VLOG(1) << "Opening tab: " << url.spec(); | 92 VLOG(1) << "Opening tab: " << url.spec(); |
94 GetBrowser(index)->ShowSingletonTab(url); | 93 GetBrowser(index)->ShowSingletonTab(url); |
94 return AwaitSessionPropagation(index, std::vector<GURL>(1, url)); | |
95 } | |
96 | |
97 bool LiveSessionsSyncTest::OpenMultipleTabs(int index, | |
98 const std::vector<GURL>& urls) { | |
99 Browser* browser = GetBrowser(index); | |
100 for (std::vector<GURL>::const_iterator it = urls.begin(); | |
101 it != urls.end(); ++it) { | |
102 VLOG(1) << "Opening tab: " << it->spec(); | |
103 browser->ShowSingletonTab(*it); | |
104 } | |
105 return AwaitSessionPropagation(index, urls); | |
106 } | |
107 | |
108 bool LiveSessionsSyncTest::AwaitSessionPropagation( | |
109 int index, const std::vector<GURL>& urls) { | |
95 VLOG(1) << "Waiting for session to propagate to associator."; | 110 VLOG(1) << "Waiting for session to propagate to associator."; |
111 static const int timeout_milli = TestTimeouts::action_max_timeout_ms(); | |
96 base::TimeTicks start_time = base::TimeTicks::Now(); | 112 base::TimeTicks start_time = base::TimeTicks::Now(); |
97 base::TimeTicks end_time = start_time + | 113 base::TimeTicks end_time = start_time + |
98 base::TimeDelta::FromMilliseconds(timeout_milli); | 114 base::TimeDelta::FromMilliseconds(timeout_milli); |
99 do { | 115 bool found; |
100 if (ModelAssociatorHasTabWithUrl(index, url)) | 116 for (std::vector<GURL>::const_iterator it = urls.begin(); |
101 return true; | 117 it != urls.end(); ++it) { |
102 GetProfile(index)->GetProfileSyncService()->GetSessionModelAssociator()-> | 118 found = false; |
braffert
2011/08/04 23:47:34
Using a flag here to avoid calling ModelAssociator
| |
103 BlockUntilLocalChangeForTest(timeout_milli); | 119 do { |
104 ui_test_utils::RunMessageLoop(); | 120 if (base::TimeTicks::Now() >= end_time) { |
105 } while (base::TimeTicks::Now() < end_time); | 121 LOG(ERROR) << "Failed to find all tabs after " << timeout_milli/1000.0 |
106 | 122 << " seconds."; |
107 if (ModelAssociatorHasTabWithUrl(index, url)) | 123 return false; |
108 return true; | 124 } |
109 | 125 found = ModelAssociatorHasTabWithUrl(index, *it); |
Nicolas Zea
2011/08/05 00:40:02
May as well put this before the timeout check.
braffert
2011/08/05 00:47:38
I'm not seeing why one way is better than the othe
| |
110 LOG(ERROR) << "Failed to find tab after " << timeout_milli/1000.0 | 126 if (!found) { |
111 << " seconds."; | 127 GetProfile(index)->GetProfileSyncService()-> |
112 return false; | 128 GetSessionModelAssociator()-> |
129 BlockUntilLocalChangeForTest(timeout_milli); | |
130 ui_test_utils::RunMessageLoop(); | |
131 } | |
132 } while (!found); | |
133 } | |
134 return true; | |
113 } | 135 } |
114 | 136 |
115 std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) { | 137 std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) { |
116 // The local session provided by GetLocalSession is owned, and has lifetime | 138 // The local session provided by GetLocalSession is owned, and has lifetime |
117 // controlled, by the model associator, so we must make our own copy. | 139 // controlled, by the model associator, so we must make our own copy. |
118 const SyncedSession* local_session; | 140 const SyncedSession* local_session; |
119 if (!GetLocalSession(index, &local_session)) { | 141 if (!GetLocalSession(index, &local_session)) { |
120 return NULL; | 142 return NULL; |
121 } | 143 } |
122 scoped_ptr<SyncedSession> session_copy(new SyncedSession()); | 144 scoped_ptr<SyncedSession> session_copy(new SyncedSession()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 // sync profile. | 326 // sync profile. |
305 BrowserList::CloseAllBrowsers(); | 327 BrowserList::CloseAllBrowsers(); |
306 ui_test_utils::RunAllPendingInMessageLoop(); | 328 ui_test_utils::RunAllPendingInMessageLoop(); |
307 | 329 |
308 // All browsers should be closed at this point, else when the framework | 330 // All browsers should be closed at this point, else when the framework |
309 // calls QuitBrowsers() we could see memory corruption. | 331 // calls QuitBrowsers() we could see memory corruption. |
310 ASSERT_EQ(0U, BrowserList::size()); | 332 ASSERT_EQ(0U, BrowserList::size()); |
311 | 333 |
312 LiveSyncTest::CleanUpOnMainThread(); | 334 LiveSyncTest::CleanUpOnMainThread(); |
313 } | 335 } |
OLD | NEW |