Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_sessions_sync_test.cc
blobe5b3d00bc61f5a4ded70a8e6c13cd33a90076712
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.
5 #include "base/memory/scoped_vector.h"
6 #include "chrome/browser/sessions/session_service.h"
7 #include "chrome/browser/sync/test/integration/passwords_helper.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 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
13 using passwords_helper::SetDecryptionPassphrase;
14 using passwords_helper::SetEncryptionPassphrase;
15 using sessions_helper::CheckInitialState;
16 using sessions_helper::DeleteForeignSession;
17 using sessions_helper::GetLocalWindows;
18 using sessions_helper::GetSessionData;
19 using sessions_helper::OpenTabAndGetLocalWindows;
20 using sessions_helper::ScopedWindowMap;
21 using sessions_helper::SyncedSessionVector;
22 using sessions_helper::WindowsMatch;
24 class TwoClientSessionsSyncTest : public SyncTest {
25 public:
26 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
27 virtual ~TwoClientSessionsSyncTest() {}
29 private:
30 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
33 static const char* kURL1 = "http://127.0.0.1/bubba1";
34 static const char* kURL2 = "http://127.0.0.1/bubba2";
36 // TODO(zea): Test each individual session command we care about separately.
37 // (as well as multi-window). We're currently only checking basic single-window/
38 // single-tab functionality.
40 // Fails on Win, see http://crbug.com/232313
41 #if defined(OS_WIN)
42 #define MAYBE_SingleClientChanged DISABLED_SingleClientChanged
43 #define MAYBE_SingleClientEnabledEncryptionAndChanged DISABLED_SingleClientEnabledEncryptionAndChanged
44 #define MAYBE_BothChanged DISABLED_BothChanged
45 #define MAYBE_DeleteIdleSession DISABLED_DeleteIdleSession
46 #else
47 #define MAYBE_SingleClientChanged SingleClientChanged
48 #define MAYBE_SingleClientEnabledEncryptionAndChanged SingleClientEnabledEncryptionAndChanged
49 #define MAYBE_BothChanged BothChanged
50 #define MAYBE_DeleteIdleSession DeleteIdleSession
51 #endif
54 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
55 MAYBE_SingleClientChanged) {
56 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
58 ASSERT_TRUE(CheckInitialState(0));
59 ASSERT_TRUE(CheckInitialState(1));
61 ScopedWindowMap client0_windows;
62 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
63 client0_windows.GetMutable()));
65 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
67 // Get foreign session data from client 1.
68 SyncedSessionVector sessions1;
69 ASSERT_TRUE(GetSessionData(1, &sessions1));
71 // Verify client 1's foreign session matches client 0 current window.
72 ASSERT_EQ(1U, sessions1.size());
73 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
76 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
77 SingleClientEnabledEncryption) {
78 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
80 ASSERT_TRUE(CheckInitialState(0));
81 ASSERT_TRUE(CheckInitialState(1));
83 ASSERT_TRUE(EnableEncryption(0));
84 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
85 ASSERT_TRUE(IsEncryptionComplete(0));
86 ASSERT_TRUE(IsEncryptionComplete(1));
89 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
90 MAYBE_SingleClientEnabledEncryptionAndChanged) {
91 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
93 ASSERT_TRUE(CheckInitialState(0));
94 ASSERT_TRUE(CheckInitialState(1));
96 ScopedWindowMap client0_windows;
97 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
98 client0_windows.GetMutable()));
99 ASSERT_TRUE(EnableEncryption(0));
100 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
102 // Get foreign session data from client 1.
103 ASSERT_TRUE(IsEncryptionComplete(1));
104 SyncedSessionVector sessions1;
105 ASSERT_TRUE(GetSessionData(1, &sessions1));
107 // Verify client 1's foreign session matches client 0 current window.
108 ASSERT_EQ(1U, sessions1.size());
109 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
112 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
113 BothClientsEnabledEncryption) {
114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
116 ASSERT_TRUE(CheckInitialState(0));
117 ASSERT_TRUE(CheckInitialState(1));
119 ASSERT_TRUE(EnableEncryption(0));
120 ASSERT_TRUE(EnableEncryption(1));
121 ASSERT_TRUE(AwaitQuiescence());
122 ASSERT_TRUE(IsEncryptionComplete(0));
123 ASSERT_TRUE(IsEncryptionComplete(1));
126 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_BothChanged) {
127 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
129 ASSERT_TRUE(CheckInitialState(0));
130 ASSERT_TRUE(CheckInitialState(1));
132 // Open tabs on both clients and retain window information.
133 ScopedWindowMap client0_windows;
134 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2),
135 client0_windows.GetMutable()));
136 ScopedWindowMap client1_windows;
137 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1),
138 client1_windows.GetMutable()));
140 // Wait for sync.
141 ASSERT_TRUE(AwaitQuiescence());
143 // Get foreign session data from client 0 and 1.
144 SyncedSessionVector sessions0;
145 SyncedSessionVector sessions1;
146 ASSERT_TRUE(GetSessionData(0, &sessions0));
147 ASSERT_TRUE(GetSessionData(1, &sessions1));
149 // Verify client 1's foreign session matches client 0's current window and
150 // vice versa.
151 ASSERT_EQ(1U, sessions0.size());
152 ASSERT_EQ(1U, sessions1.size());
153 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
154 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, *client1_windows.Get()));
157 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_DeleteIdleSession) {
158 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
160 ASSERT_TRUE(CheckInitialState(0));
161 ASSERT_TRUE(CheckInitialState(1));
163 // Client 0 opened some tabs then went idle.
164 ScopedWindowMap client0_windows;
165 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
166 client0_windows.GetMutable()));
168 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
170 // Get foreign session data from client 1.
171 SyncedSessionVector sessions1;
172 ASSERT_TRUE(GetSessionData(1, &sessions1));
174 // Verify client 1's foreign session matches client 0 current window.
175 ASSERT_EQ(1U, sessions1.size());
176 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
178 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
179 DeleteForeignSession(1, sessions1[0]->session_tag);
180 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
181 ASSERT_FALSE(GetSessionData(1, &sessions1));
184 // Fails all release trybots. crbug.com/263369.
185 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
186 DISABLED_DeleteActiveSession) {
187 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
189 ASSERT_TRUE(CheckInitialState(0));
190 ASSERT_TRUE(CheckInitialState(1));
192 // Client 0 opened some tabs then went idle.
193 ScopedWindowMap client0_windows;
194 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
195 client0_windows.GetMutable()));
197 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
198 SyncedSessionVector sessions1;
199 ASSERT_TRUE(GetSessionData(1, &sessions1));
200 ASSERT_EQ(1U, sessions1.size());
201 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
203 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
204 DeleteForeignSession(1, sessions1[0]->session_tag);
205 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
206 ASSERT_FALSE(GetSessionData(1, &sessions1));
208 // Client 0 becomes active again with a new tab.
209 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2),
210 client0_windows.GetMutable()));
211 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
212 ASSERT_TRUE(GetSessionData(1, &sessions1));
213 ASSERT_EQ(1U, sessions1.size());
214 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));