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
{
26 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT
) {}
27 ~TwoClientSessionsSyncTest() override
{}
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
42 #define MAYBE_SingleClientChanged DISABLED_SingleClientChanged
43 #define MAYBE_BothChanged DISABLED_BothChanged
44 #define MAYBE_DeleteIdleSession DISABLED_DeleteIdleSession
46 #define MAYBE_SingleClientChanged SingleClientChanged
47 #define MAYBE_BothChanged BothChanged
48 #define MAYBE_DeleteIdleSession DeleteIdleSession
52 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
,
53 MAYBE_SingleClientChanged
) {
54 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
56 ASSERT_TRUE(CheckInitialState(0));
57 ASSERT_TRUE(CheckInitialState(1));
59 ScopedWindowMap client0_windows
;
60 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1
),
61 client0_windows
.GetMutable()));
63 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
65 // Get foreign session data from client 1.
66 SyncedSessionVector sessions1
;
67 ASSERT_TRUE(GetSessionData(1, &sessions1
));
69 // Verify client 1's foreign session matches client 0 current window.
70 ASSERT_EQ(1U, sessions1
.size());
71 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));
74 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
,
75 SingleClientEnabledEncryption
) {
76 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
78 ASSERT_TRUE(CheckInitialState(0));
79 ASSERT_TRUE(CheckInitialState(1));
81 ASSERT_TRUE(EnableEncryption(0));
82 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
83 ASSERT_TRUE(IsEncryptionComplete(0));
84 ASSERT_TRUE(IsEncryptionComplete(1));
87 // This test is flaky on several platforms:
88 // http://crbug.com/420979
89 // http://crbug.com/421167
90 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
,
91 DISABLED_SingleClientEnabledEncryptionAndChanged
) {
92 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
94 ASSERT_TRUE(CheckInitialState(0));
95 ASSERT_TRUE(CheckInitialState(1));
97 ScopedWindowMap client0_windows
;
98 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1
),
99 client0_windows
.GetMutable()));
100 ASSERT_TRUE(EnableEncryption(0));
101 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
103 // Get foreign session data from client 1.
104 ASSERT_TRUE(IsEncryptionComplete(1));
105 SyncedSessionVector sessions1
;
106 ASSERT_TRUE(GetSessionData(1, &sessions1
));
108 // Verify client 1's foreign session matches client 0 current window.
109 ASSERT_EQ(1U, sessions1
.size());
110 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));
113 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
,
114 BothClientsEnabledEncryption
) {
115 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117 ASSERT_TRUE(CheckInitialState(0));
118 ASSERT_TRUE(CheckInitialState(1));
120 ASSERT_TRUE(EnableEncryption(0));
121 ASSERT_TRUE(EnableEncryption(1));
122 ASSERT_TRUE(AwaitQuiescence());
123 ASSERT_TRUE(IsEncryptionComplete(0));
124 ASSERT_TRUE(IsEncryptionComplete(1));
127 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
, MAYBE_BothChanged
) {
128 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
130 ASSERT_TRUE(CheckInitialState(0));
131 ASSERT_TRUE(CheckInitialState(1));
133 // Open tabs on both clients and retain window information.
134 ScopedWindowMap client0_windows
;
135 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2
),
136 client0_windows
.GetMutable()));
137 ScopedWindowMap client1_windows
;
138 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1
),
139 client1_windows
.GetMutable()));
142 ASSERT_TRUE(AwaitQuiescence());
144 // Get foreign session data from client 0 and 1.
145 SyncedSessionVector sessions0
;
146 SyncedSessionVector sessions1
;
147 ASSERT_TRUE(GetSessionData(0, &sessions0
));
148 ASSERT_TRUE(GetSessionData(1, &sessions1
));
150 // Verify client 1's foreign session matches client 0's current window and
152 ASSERT_EQ(1U, sessions0
.size());
153 ASSERT_EQ(1U, sessions1
.size());
154 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));
155 ASSERT_TRUE(WindowsMatch(sessions0
[0]->windows
, *client1_windows
.Get()));
158 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
, MAYBE_DeleteIdleSession
) {
159 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
161 ASSERT_TRUE(CheckInitialState(0));
162 ASSERT_TRUE(CheckInitialState(1));
164 // Client 0 opened some tabs then went idle.
165 ScopedWindowMap client0_windows
;
166 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1
),
167 client0_windows
.GetMutable()));
169 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
171 // Get foreign session data from client 1.
172 SyncedSessionVector sessions1
;
173 ASSERT_TRUE(GetSessionData(1, &sessions1
));
175 // Verify client 1's foreign session matches client 0 current window.
176 ASSERT_EQ(1U, sessions1
.size());
177 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));
179 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
180 DeleteForeignSession(1, sessions1
[0]->session_tag
);
181 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
182 ASSERT_FALSE(GetSessionData(1, &sessions1
));
185 // Fails all release trybots. crbug.com/263369.
186 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest
,
187 DISABLED_DeleteActiveSession
) {
188 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
190 ASSERT_TRUE(CheckInitialState(0));
191 ASSERT_TRUE(CheckInitialState(1));
193 // Client 0 opened some tabs then went idle.
194 ScopedWindowMap client0_windows
;
195 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1
),
196 client0_windows
.GetMutable()));
198 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
199 SyncedSessionVector sessions1
;
200 ASSERT_TRUE(GetSessionData(1, &sessions1
));
201 ASSERT_EQ(1U, sessions1
.size());
202 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));
204 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
205 DeleteForeignSession(1, sessions1
[0]->session_tag
);
206 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
207 ASSERT_FALSE(GetSessionData(1, &sessions1
));
209 // Client 0 becomes active again with a new tab.
210 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2
),
211 client0_windows
.GetMutable()));
212 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
213 ASSERT_TRUE(GetSessionData(1, &sessions1
));
214 ASSERT_EQ(1U, sessions1
.size());
215 ASSERT_TRUE(WindowsMatch(sessions1
[0]->windows
, *client0_windows
.Get()));