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

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

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Fixing another ChromeOS test. Created 4 years, 2 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 <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/test/test_timeouts.h" 19 #include "base/test/test_timeouts.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" 24 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
25 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h"
26 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 25 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
27 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 26 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
28 #include "chrome/browser/sync/test/integration/sync_test.h" 27 #include "chrome/browser/sync/test/integration/sync_test.h"
29 #include "chrome/browser/ui/singleton_tabs.h" 28 #include "chrome/browser/ui/singleton_tabs.h"
30 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
31 #include "components/browser_sync/profile_sync_service.h" 30 #include "components/browser_sync/profile_sync_service.h"
32 #include "components/sync/driver/sync_client.h" 31 #include "components/sync/driver/sync_client.h"
33 #include "components/sync_sessions/open_tabs_ui_delegate.h" 32 #include "components/sync_sessions/open_tabs_ui_delegate.h"
34 #include "content/public/test/test_utils.h" 33 #include "content/public/test/test_utils.h"
35 #include "url/gurl.h" 34 #include "url/gurl.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 371
373 if (s_index == sessions.size()) { 372 if (s_index == sessions.size()) {
374 LOG(ERROR) << "Cannot find window #" << w_index; 373 LOG(ERROR) << "Cannot find window #" << w_index;
375 return false; 374 return false;
376 } 375 }
377 } 376 }
378 377
379 return true; 378 return true;
380 } 379 }
381 380
382 namespace { 381 void DeleteForeignSession(int index, std::string session_tag) {
382 ProfileSyncServiceFactory::GetInstance()
383 ->GetForProfile(test()->GetProfile(index))
384 ->GetOpenTabsUIDelegate()
385 ->DeleteForeignSession(session_tag);
386 }
383 387
384 // Helper class used in the implementation of AwaitCheckForeignSessionsAgainst. 388 } // namespace sessions_helper
385 class CheckForeignSessionsChecker : public MultiClientStatusChangeChecker {
386 public:
387 CheckForeignSessionsChecker(int index,
388 const std::vector<ScopedWindowMap>& windows);
389 ~CheckForeignSessionsChecker() override;
390
391 bool IsExitConditionSatisfied() override;
392 std::string GetDebugMessage() const override;
393
394 private:
395 int index_;
396 const std::vector<ScopedWindowMap>& windows_;
397 };
398 389
399 CheckForeignSessionsChecker::CheckForeignSessionsChecker( 390 CheckForeignSessionsChecker::CheckForeignSessionsChecker(
400 int index, const std::vector<ScopedWindowMap>& windows) 391 int index,
392 const std::vector<sessions_helper::ScopedWindowMap>& windows)
401 : MultiClientStatusChangeChecker( 393 : MultiClientStatusChangeChecker(
402 sync_datatype_helper::test()->GetSyncServices()), 394 sync_datatype_helper::test()->GetSyncServices()),
403 index_(index), 395 index_(index),
404 windows_(windows) {} 396 windows_(windows) {}
405 397
406 CheckForeignSessionsChecker::~CheckForeignSessionsChecker() {}
407
408 bool CheckForeignSessionsChecker::IsExitConditionSatisfied() { 398 bool CheckForeignSessionsChecker::IsExitConditionSatisfied() {
409 return CheckForeignSessionsAgainst(index_, windows_); 399 return sessions_helper::CheckForeignSessionsAgainst(index_, windows_);
410 } 400 }
411 401
412 std::string CheckForeignSessionsChecker::GetDebugMessage() const { 402 std::string CheckForeignSessionsChecker::GetDebugMessage() const {
413 return "Waiting for matching foreign sessions"; 403 return "Waiting for matching foreign sessions";
414 } 404 }
415
416 } // namespace
417
418 bool AwaitCheckForeignSessionsAgainst(
419 int index, const std::vector<ScopedWindowMap>& windows) {
420 CheckForeignSessionsChecker checker(index, windows);
421 checker.Wait();
422 return !checker.TimedOut();
423 }
424
425 void DeleteForeignSession(int index, std::string session_tag) {
426 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
427 test()->GetProfile(index))->
428 GetOpenTabsUIDelegate()->DeleteForeignSession(session_tag);
429 }
430
431 } // namespace sessions_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698