Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / two_client_sessions_sync_test.cc
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 "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"
12
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;
23
24 class TwoClientSessionsSyncTest : public SyncTest {
25  public:
26   TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
27   ~TwoClientSessionsSyncTest() override {}
28
29  private:
30   DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
31 };
32
33 static const char* kURL1 = "http://127.0.0.1/bubba1";
34 static const char* kURL2 = "http://127.0.0.1/bubba2";
35
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.
39
40 // Fails on Win, see http://crbug.com/232313
41 #if defined(OS_WIN)
42 #define MAYBE_SingleClientChanged DISABLED_SingleClientChanged
43 #define MAYBE_BothChanged DISABLED_BothChanged
44 #define MAYBE_DeleteIdleSession DISABLED_DeleteIdleSession
45 #else
46 #define MAYBE_SingleClientChanged SingleClientChanged
47 #define MAYBE_BothChanged BothChanged
48 #define MAYBE_DeleteIdleSession DeleteIdleSession
49 #endif
50
51
52 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
53                        MAYBE_SingleClientChanged) {
54   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
55
56   ASSERT_TRUE(CheckInitialState(0));
57   ASSERT_TRUE(CheckInitialState(1));
58
59   ScopedWindowMap client0_windows;
60   ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
61       client0_windows.GetMutable()));
62
63   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
64
65   // Get foreign session data from client 1.
66   SyncedSessionVector sessions1;
67   ASSERT_TRUE(GetSessionData(1, &sessions1));
68
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()));
72 }
73
74 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
75                        SingleClientEnabledEncryption) {
76   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
77
78   ASSERT_TRUE(CheckInitialState(0));
79   ASSERT_TRUE(CheckInitialState(1));
80
81   ASSERT_TRUE(EnableEncryption(0));
82   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
83   ASSERT_TRUE(IsEncryptionComplete(0));
84   ASSERT_TRUE(IsEncryptionComplete(1));
85 }
86
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.";
93
94   ASSERT_TRUE(CheckInitialState(0));
95   ASSERT_TRUE(CheckInitialState(1));
96
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)));
102
103   // Get foreign session data from client 1.
104   ASSERT_TRUE(IsEncryptionComplete(1));
105   SyncedSessionVector sessions1;
106   ASSERT_TRUE(GetSessionData(1, &sessions1));
107
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()));
111 }
112
113 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
114                        BothClientsEnabledEncryption) {
115   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
116
117   ASSERT_TRUE(CheckInitialState(0));
118   ASSERT_TRUE(CheckInitialState(1));
119
120   ASSERT_TRUE(EnableEncryption(0));
121   ASSERT_TRUE(EnableEncryption(1));
122   ASSERT_TRUE(AwaitQuiescence());
123   ASSERT_TRUE(IsEncryptionComplete(0));
124   ASSERT_TRUE(IsEncryptionComplete(1));
125 }
126
127 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_BothChanged) {
128   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
129
130   ASSERT_TRUE(CheckInitialState(0));
131   ASSERT_TRUE(CheckInitialState(1));
132
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()));
140
141   // Wait for sync.
142   ASSERT_TRUE(AwaitQuiescence());
143
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));
149
150   // Verify client 1's foreign session matches client 0's current window and
151   // vice versa.
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()));
156 }
157
158 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_DeleteIdleSession) {
159   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
160
161   ASSERT_TRUE(CheckInitialState(0));
162   ASSERT_TRUE(CheckInitialState(1));
163
164   // Client 0 opened some tabs then went idle.
165   ScopedWindowMap client0_windows;
166   ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
167       client0_windows.GetMutable()));
168
169   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
170
171   // Get foreign session data from client 1.
172   SyncedSessionVector sessions1;
173   ASSERT_TRUE(GetSessionData(1, &sessions1));
174
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()));
178
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));
183 }
184
185 // Fails all release trybots. crbug.com/263369.
186 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
187                        DISABLED_DeleteActiveSession) {
188   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
189
190   ASSERT_TRUE(CheckInitialState(0));
191   ASSERT_TRUE(CheckInitialState(1));
192
193   // Client 0 opened some tabs then went idle.
194   ScopedWindowMap client0_windows;
195   ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
196       client0_windows.GetMutable()));
197
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()));
203
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));
208
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()));
216 }