Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: chrome/browser/sync/test/integration/sessions_helper.cc

Issue 2722953002: Revert of [sync] Add Sessions integration tests (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/test/test_timeouts.h" 18 #include "base/test/test_timeouts.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
23 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" 23 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
24 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 24 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
25 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 25 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_tabstrip.h"
28 #include "chrome/browser/ui/singleton_tabs.h" 26 #include "chrome/browser/ui/singleton_tabs.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/ui_test_utils.h"
32 #include "components/browser_sync/profile_sync_service.h" 28 #include "components/browser_sync/profile_sync_service.h"
33 #include "components/sync/driver/sync_client.h" 29 #include "components/sync/driver/sync_client.h"
34 #include "components/sync/test/fake_server/fake_server.h"
35 #include "components/sync/test/fake_server/sessions_hierarchy.h"
36 #include "components/sync_sessions/open_tabs_ui_delegate.h" 30 #include "components/sync_sessions/open_tabs_ui_delegate.h"
37 #include "content/public/browser/navigation_entry.h"
38 #include "content/public/browser/web_contents.h"
39 #include "content/public/test/test_utils.h" 31 #include "content/public/test/test_utils.h"
40 #include "url/gurl.h" 32 #include "url/gurl.h"
41 33
42 using sync_datatype_helper::test; 34 using sync_datatype_helper::test;
43 35
44 namespace sessions_helper { 36 namespace sessions_helper {
45 37
46 bool GetLocalSession(int index, const sync_sessions::SyncedSession** session) { 38 bool GetLocalSession(int index, const sync_sessions::SyncedSession** session) {
47 return ProfileSyncServiceFactory::GetInstance() 39 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(
48 ->GetForProfile(test()->GetProfile(index)) 40 test()->GetProfile(index))->GetOpenTabsUIDelegate()->
49 ->GetOpenTabsUIDelegate() 41 GetLocalSession(session);
50 ->GetLocalSession(session);
51 } 42 }
52 43
53 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { 44 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) {
54 content::RunAllPendingInMessageLoop(); 45 content::RunAllPendingInMessageLoop();
55 const sync_sessions::SyncedSession* local_session; 46 const sync_sessions::SyncedSession* local_session;
56 if (!GetLocalSession(index, &local_session)) { 47 if (!GetLocalSession(index, &local_session)) {
57 return false; 48 return false;
58 } 49 }
59 50
60 if (local_session->windows.size() == 0) { 51 if (local_session->windows.size() == 0) {
(...skipping 26 matching lines...) Expand all
87 } 78 }
88 return true; 79 return true;
89 } 80 }
90 } 81 }
91 } 82 }
92 DVLOG(1) << "Could not find tab with url " << url.spec(); 83 DVLOG(1) << "Could not find tab with url " << url.spec();
93 return false; 84 return false;
94 } 85 }
95 86
96 bool OpenTab(int index, const GURL& url) { 87 bool OpenTab(int index, const GURL& url) {
97 DVLOG(1) << "Opening tab: " << url.spec() << " using browser " << index 88 DVLOG(1) << "Opening tab: " << url.spec() << " using profile "
98 << "."; 89 << index << ".";
99 return OpenTabAtIndex(index, 0, url); 90 chrome::ShowSingletonTab(test()->GetBrowser(index), url);
100 } 91 return WaitForTabsToLoad(index, std::vector<GURL>(1, url));
101
102 bool OpenTabAtIndex(int index, int tab_index, const GURL& url) {
103 chrome::AddTabAt(test()->GetBrowser(index), url, tab_index, true);
104 return WaitForTabsToLoad(index, {url});
105 } 92 }
106 93
107 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls) { 94 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls) {
108 Browser* browser = test()->GetBrowser(index); 95 Browser* browser = test()->GetBrowser(index);
109 for (std::vector<GURL>::const_iterator it = urls.begin(); 96 for (std::vector<GURL>::const_iterator it = urls.begin();
110 it != urls.end(); ++it) { 97 it != urls.end(); ++it) {
111 DVLOG(1) << "Opening tab: " << it->spec() << " using browser " << index 98 DVLOG(1) << "Opening tab: " << it->spec() << " using profile " << index
112 << "."; 99 << ".";
113 chrome::ShowSingletonTab(browser, *it); 100 chrome::ShowSingletonTab(browser, *it);
114 } 101 }
115 return WaitForTabsToLoad(index, urls); 102 return WaitForTabsToLoad(index, urls);
116 } 103 }
117 104
118 void MoveTab(int from_index, int to_index, int tab_index) {
119 content::WebContents* detached_contents =
120 test()
121 ->GetBrowser(from_index)
122 ->tab_strip_model()
123 ->DetachWebContentsAt(tab_index);
124
125 TabStripModel* target_strip = test()->GetBrowser(to_index)->tab_strip_model();
126 target_strip->InsertWebContentsAt(target_strip->count(), detached_contents,
127 TabStripModel::ADD_ACTIVE);
128 }
129
130 bool NavigateTab(int index, const GURL& url) {
131 chrome::NavigateParams params(test()->GetBrowser(index), url,
132 ui::PAGE_TRANSITION_LINK);
133 params.disposition = WindowOpenDisposition::CURRENT_TAB;
134
135 ui_test_utils::NavigateToURL(&params);
136 return WaitForTabsToLoad(index, {url});
137 }
138
139 void NavigateTabBack(int index) {
140 test()
141 ->GetBrowser(index)
142 ->tab_strip_model()
143 ->GetWebContentsAt(0)
144 ->GetController()
145 .GoBack();
146 }
147
148 void NavigateTabForward(int index) {
149 test()
150 ->GetBrowser(index)
151 ->tab_strip_model()
152 ->GetWebContentsAt(0)
153 ->GetController()
154 .GoForward();
155 }
156
157 namespace { 105 namespace {
158 106
159 class TabEventHandler : public sync_sessions::LocalSessionEventHandler { 107 class TabEventHandler : public sync_sessions::LocalSessionEventHandler {
160 public: 108 public:
161 TabEventHandler() : weak_factory_(this) { 109 TabEventHandler() : weak_factory_(this) {
162 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
163 FROM_HERE, 111 FROM_HERE,
164 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()), 112 base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()),
165 TestTimeouts::action_max_timeout()); 113 TestTimeouts::action_max_timeout());
166 } 114 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 new_tab->navigations.begin()); 192 new_tab->navigations.begin());
245 new_window->tabs.push_back(std::move(new_tab)); 193 new_window->tabs.push_back(std::move(new_tab));
246 } 194 }
247 auto id = new_window->window_id.id(); 195 auto id = new_window->window_id.id();
248 (*local_windows)[id] = std::move(new_window); 196 (*local_windows)[id] = std::move(new_window);
249 } 197 }
250 198
251 return true; 199 return true;
252 } 200 }
253 201
202 bool OpenTabAndGetLocalWindows(int index,
203 const GURL& url,
204 ScopedWindowMap* local_windows) {
205 if (!OpenTab(index, url)) {
206 return false;
207 }
208 return GetLocalWindows(index, local_windows);
209 }
210
254 bool CheckInitialState(int index) { 211 bool CheckInitialState(int index) {
255 if (0 != GetNumWindows(index)) 212 if (0 != GetNumWindows(index))
256 return false; 213 return false;
257 if (0 != GetNumForeignSessions(index)) 214 if (0 != GetNumForeignSessions(index))
258 return false; 215 return false;
259 return true; 216 return true;
260 } 217 }
261 218
262 int GetNumWindows(int index) { 219 int GetNumWindows(int index) {
263 const sync_sessions::SyncedSession* local_session; 220 const sync_sessions::SyncedSession* local_session;
264 if (!GetLocalSession(index, &local_session)) { 221 if (!GetLocalSession(index, &local_session)) {
265 return 0; 222 return 0;
266 } 223 }
267 return local_session->windows.size(); 224 return local_session->windows.size();
268 } 225 }
269 226
270 int GetNumForeignSessions(int index) { 227 int GetNumForeignSessions(int index) {
271 SyncedSessionVector sessions; 228 SyncedSessionVector sessions;
272 if (!ProfileSyncServiceFactory::GetInstance() 229 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile(
273 ->GetForProfile(test()->GetProfile(index)) 230 test()->GetProfile(index))->
274 ->GetOpenTabsUIDelegate() 231 GetOpenTabsUIDelegate()->GetAllForeignSessions(
275 ->GetAllForeignSessions(&sessions)) { 232 &sessions)) {
276 return 0; 233 return 0;
277 } 234 }
278 return sessions.size(); 235 return sessions.size();
279 } 236 }
280 237
281 bool GetSessionData(int index, SyncedSessionVector* sessions) { 238 bool GetSessionData(int index, SyncedSessionVector* sessions) {
282 if (!ProfileSyncServiceFactory::GetInstance() 239 if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile(
283 ->GetForProfile(test()->GetProfile(index)) 240 test()->GetProfile(index))->
284 ->GetOpenTabsUIDelegate() 241 GetOpenTabsUIDelegate()->GetAllForeignSessions(
285 ->GetAllForeignSessions(sessions)) { 242 sessions)) {
286 return false; 243 return false;
287 } 244 }
288 SortSyncedSessions(sessions); 245 SortSyncedSessions(sessions);
289 return true; 246 return true;
290 } 247 }
291 248
292 bool CompareSyncedSessions(const sync_sessions::SyncedSession* lhs, 249 bool CompareSyncedSessions(const sync_sessions::SyncedSession* lhs,
293 const sync_sessions::SyncedSession* rhs) { 250 const sync_sessions::SyncedSession* rhs) {
294 if (!lhs || 251 if (!lhs ||
295 !rhs || 252 !rhs ||
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } // namespace 338 } // namespace
382 339
383 bool WindowsMatch(const ScopedWindowMap& win1, const ScopedWindowMap& win2) { 340 bool WindowsMatch(const ScopedWindowMap& win1, const ScopedWindowMap& win2) {
384 return WindowsMatchImpl(win1, win2); 341 return WindowsMatchImpl(win1, win2);
385 } 342 }
386 343
387 bool WindowsMatch(const SessionWindowMap& win1, const ScopedWindowMap& win2) { 344 bool WindowsMatch(const SessionWindowMap& win1, const ScopedWindowMap& win2) {
388 return WindowsMatchImpl(win1, win2); 345 return WindowsMatchImpl(win1, win2);
389 } 346 }
390 347
391 bool CheckForeignSessionsAgainst(int index, 348 bool CheckForeignSessionsAgainst(
392 const std::vector<ScopedWindowMap>& windows) { 349 int index,
350 const std::vector<ScopedWindowMap>& windows) {
393 SyncedSessionVector sessions; 351 SyncedSessionVector sessions;
394 352
395 if (!GetSessionData(index, &sessions)) { 353 if (!GetSessionData(index, &sessions)) {
396 LOG(ERROR) << "Cannot get session data"; 354 LOG(ERROR) << "Cannot get session data";
397 return false; 355 return false;
398 } 356 }
399 357
400 for (size_t w_index = 0; w_index < windows.size(); ++w_index) { 358 for (size_t w_index = 0; w_index < windows.size(); ++w_index) {
401 // Skip the client's local window 359 // Skip the client's local window
402 if (static_cast<int>(w_index) == index) { 360 if (static_cast<int>(w_index) == index)
403 continue; 361 continue;
404 }
405 362
406 size_t s_index = 0; 363 size_t s_index = 0;
407 364
408 for (; s_index < sessions.size(); ++s_index) { 365 for (; s_index < sessions.size(); ++s_index) {
409 if (WindowsMatch(sessions[s_index]->windows, windows[w_index])) 366 if (WindowsMatch(sessions[s_index]->windows, windows[w_index]))
410 break; 367 break;
411 } 368 }
412 369
413 if (s_index == sessions.size()) { 370 if (s_index == sessions.size()) {
414 LOG(ERROR) << "Cannot find window #" << w_index; 371 LOG(ERROR) << "Cannot find window #" << w_index;
(...skipping 21 matching lines...) Expand all
436 index_(index), 393 index_(index),
437 windows_(windows) {} 394 windows_(windows) {}
438 395
439 bool ForeignSessionsMatchChecker::IsExitConditionSatisfied() { 396 bool ForeignSessionsMatchChecker::IsExitConditionSatisfied() {
440 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_); 397 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_);
441 } 398 }
442 399
443 std::string ForeignSessionsMatchChecker::GetDebugMessage() const { 400 std::string ForeignSessionsMatchChecker::GetDebugMessage() const {
444 return "Waiting for matching foreign sessions"; 401 return "Waiting for matching foreign sessions";
445 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698