multiple_client_sessions_sync_test.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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
3// found in the LICENSE file.
4
5#include "base/memory/scoped_vector.h"
6#include "base/strings/stringprintf.h"
7#include "chrome/browser/sessions/session_service.h"
8#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
9#include "chrome/browser/sync/test/integration/sessions_helper.h"
10#include "chrome/browser/sync/test/integration/sync_test.h"
11
12using sessions_helper::AwaitCheckForeignSessionsAgainst;
13using sessions_helper::CheckInitialState;
14using sessions_helper::OpenTabAndGetLocalWindows;
15using sessions_helper::ScopedWindowMap;
16using sessions_helper::SessionWindowMap;
17using sessions_helper::SyncedSessionVector;
18
19class MultipleClientSessionsSyncTest : public SyncTest {
20 public:
21  MultipleClientSessionsSyncTest() : SyncTest(MULTIPLE_CLIENT) {}
22  virtual ~MultipleClientSessionsSyncTest() {}
23
24 private:
25  DISALLOW_COPY_AND_ASSIGN(MultipleClientSessionsSyncTest);
26};
27
28// Timeout on Windows, see http://crbug.com/99819
29#if defined(OS_WIN)
30#define MAYBE_AllChanged DISABLED_AllChanged
31#define MAYBE_EncryptedAndChanged DISABLED_EncryptedAndChanged
32#else
33#define MAYBE_AllChanged AllChanged
34#define MAYBE_EncryptedAndChanged EncryptedAndChanged
35#endif
36
37IN_PROC_BROWSER_TEST_F(MultipleClientSessionsSyncTest, MAYBE_AllChanged) {
38  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
39  std::vector<ScopedWindowMap> client_windows(num_clients());
40
41  for (int i = 0; i < num_clients(); ++i) {
42    ASSERT_TRUE(CheckInitialState(i));
43  }
44
45  // Open tabs on all clients and retain window information.
46  for (int i = 0; i < num_clients(); ++i) {
47    SessionWindowMap windows;
48    ASSERT_TRUE(OpenTabAndGetLocalWindows(
49        i, GURL(base::StringPrintf("http://127.0.0.1/bubba%i", i)), &windows));
50    client_windows[i].Reset(&windows);
51  }
52
53  // Get foreign session data from all clients and check it against all
54  // client_windows.
55  for (int i = 0; i < num_clients(); ++i) {
56    ASSERT_TRUE(AwaitCheckForeignSessionsAgainst(i, client_windows));
57  }
58}
59
60IN_PROC_BROWSER_TEST_F(MultipleClientSessionsSyncTest,
61                       MAYBE_EncryptedAndChanged) {
62  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
63  std::vector<ScopedWindowMap> client_windows(num_clients());
64
65  for (int i = 0; i < num_clients(); ++i) {
66    ASSERT_TRUE(CheckInitialState(i));
67  }
68
69  // Enable encryption on client 0, should propagate to all other clients.
70  ASSERT_TRUE(EnableEncryption(0));
71
72  // Wait for sync.
73  // TODO(zea): Fix sync completion detection so we don't need this. For now,
74  // the profile sync service harness detects completion before all encryption
75  // changes are propagated.
76  ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
77
78  // Open tabs on all clients and retain window information.
79  for (int i = 0; i < num_clients(); ++i) {
80    SessionWindowMap windows;
81    ASSERT_TRUE(OpenTabAndGetLocalWindows(
82        i, GURL(base::StringPrintf("http://127.0.0.1/bubba%i", i)), &windows));
83    client_windows[i].Reset(&windows);
84  }
85
86  // Get foreign session data from all clients and check it against all
87  // client_windows.
88  for (int i = 0; i < num_clients(); ++i) {
89    ASSERT_TRUE(AwaitCheckForeignSessionsAgainst(i, client_windows));
90    ASSERT_TRUE(IsEncryptionComplete(i));
91  }
92}
93