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 <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/multi_client_status_change_checke
r.h" | |
25 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 24 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
26 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 25 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
27 #include "chrome/browser/ui/singleton_tabs.h" | 26 #include "chrome/browser/ui/singleton_tabs.h" |
28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
29 #include "components/browser_sync/profile_sync_service.h" | 28 #include "components/browser_sync/profile_sync_service.h" |
30 #include "components/sync/driver/sync_client.h" | 29 #include "components/sync/driver/sync_client.h" |
31 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 30 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
32 #include "content/public/test/test_utils.h" | 31 #include "content/public/test/test_utils.h" |
33 #include "url/gurl.h" | 32 #include "url/gurl.h" |
34 | 33 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 369 |
371 if (s_index == sessions.size()) { | 370 if (s_index == sessions.size()) { |
372 LOG(ERROR) << "Cannot find window #" << w_index; | 371 LOG(ERROR) << "Cannot find window #" << w_index; |
373 return false; | 372 return false; |
374 } | 373 } |
375 } | 374 } |
376 | 375 |
377 return true; | 376 return true; |
378 } | 377 } |
379 | 378 |
380 namespace { | 379 void DeleteForeignSession(int index, std::string session_tag) { |
| 380 ProfileSyncServiceFactory::GetInstance() |
| 381 ->GetForProfile(test()->GetProfile(index)) |
| 382 ->GetOpenTabsUIDelegate() |
| 383 ->DeleteForeignSession(session_tag); |
| 384 } |
381 | 385 |
382 // Helper class used in the implementation of AwaitCheckForeignSessionsAgainst. | 386 } // namespace sessions_helper |
383 class CheckForeignSessionsChecker : public MultiClientStatusChangeChecker { | |
384 public: | |
385 CheckForeignSessionsChecker(int index, | |
386 const std::vector<ScopedWindowMap>& windows); | |
387 ~CheckForeignSessionsChecker() override; | |
388 | 387 |
389 bool IsExitConditionSatisfied() override; | 388 ForeignSessionsMatchChecker::ForeignSessionsMatchChecker( |
390 std::string GetDebugMessage() const override; | 389 int index, |
391 | 390 const std::vector<sessions_helper::ScopedWindowMap>& windows) |
392 private: | |
393 int index_; | |
394 const std::vector<ScopedWindowMap>& windows_; | |
395 }; | |
396 | |
397 CheckForeignSessionsChecker::CheckForeignSessionsChecker( | |
398 int index, const std::vector<ScopedWindowMap>& windows) | |
399 : MultiClientStatusChangeChecker( | 391 : MultiClientStatusChangeChecker( |
400 sync_datatype_helper::test()->GetSyncServices()), | 392 sync_datatype_helper::test()->GetSyncServices()), |
401 index_(index), | 393 index_(index), |
402 windows_(windows) {} | 394 windows_(windows) {} |
403 | 395 |
404 CheckForeignSessionsChecker::~CheckForeignSessionsChecker() {} | 396 bool ForeignSessionsMatchChecker::IsExitConditionSatisfied() { |
405 | 397 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_); |
406 bool CheckForeignSessionsChecker::IsExitConditionSatisfied() { | |
407 return CheckForeignSessionsAgainst(index_, windows_); | |
408 } | 398 } |
409 | 399 |
410 std::string CheckForeignSessionsChecker::GetDebugMessage() const { | 400 std::string ForeignSessionsMatchChecker::GetDebugMessage() const { |
411 return "Waiting for matching foreign sessions"; | 401 return "Waiting for matching foreign sessions"; |
412 } | 402 } |
413 | |
414 } // namespace | |
415 | |
416 bool AwaitCheckForeignSessionsAgainst( | |
417 int index, const std::vector<ScopedWindowMap>& windows) { | |
418 CheckForeignSessionsChecker checker(index, windows); | |
419 checker.Wait(); | |
420 return !checker.TimedOut(); | |
421 } | |
422 | |
423 void DeleteForeignSession(int index, std::string session_tag) { | |
424 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
425 test()->GetProfile(index))-> | |
426 GetOpenTabsUIDelegate()->DeleteForeignSession(session_tag); | |
427 } | |
428 | |
429 } // namespace sessions_helper | |
OLD | NEW |