Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_sessions_sync_test.cc
blob5a913bbd07d6dab8446de7abd452689835d88c9a
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/guid.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sync/test/integration/passwords_helper.h"
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
11 #include "chrome/browser/sync/test/integration/sessions_helper.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
15 using passwords_helper::SetDecryptionPassphrase;
16 using passwords_helper::SetEncryptionPassphrase;
17 using sessions_helper::CheckInitialState;
18 using sessions_helper::DeleteForeignSession;
19 using sessions_helper::GetLocalWindows;
20 using sessions_helper::GetSessionData;
21 using sessions_helper::OpenTabAndGetLocalWindows;
22 using sessions_helper::ScopedWindowMap;
23 using sessions_helper::SessionWindowMap;
24 using sessions_helper::SyncedSessionVector;
25 using sessions_helper::WindowsMatch;
27 class TwoClientSessionsSyncTest : public SyncTest {
28 public:
29 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
30 ~TwoClientSessionsSyncTest() override {}
32 private:
33 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
36 static const char* kURL1 = "http://127.0.0.1/bubba1";
37 static const char* kURL2 = "http://127.0.0.1/bubba2";
39 // TODO(zea): Test each individual session command we care about separately.
40 // (as well as multi-window). We're currently only checking basic single-window/
41 // single-tab functionality.
43 // Fails on Win, see http://crbug.com/232313
44 #if defined(OS_WIN)
45 #define MAYBE_E2ETest_SingleClientChanged DISABLED_E2ETest_SingleClientChanged
46 #define MAYBE_BothChanged DISABLED_BothChanged
47 #define MAYBE_DeleteIdleSession DISABLED_DeleteIdleSession
48 #else
49 #define MAYBE_E2ETest_SingleClientChanged E2ETest_SingleClientChanged
50 #define MAYBE_BothChanged BothChanged
51 #define MAYBE_DeleteIdleSession DeleteIdleSession
52 #endif
55 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
56 MAYBE_E2ETest_SingleClientChanged) {
57 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
59 // Open tab and access a url on client 0
60 SessionWindowMap client0_windows;
61 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s",
62 base::GenerateGUID().c_str());
63 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows));
65 // Retain the window information on client 0
66 std::vector<ScopedWindowMap> expected_windows(1);
67 expected_windows[0].Reset(&client0_windows);
69 // Check the foreign windows on client 1
70 ASSERT_TRUE(AwaitCheckForeignSessionsAgainst(1, expected_windows));
73 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
74 SingleClientEnabledEncryption) {
75 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
77 ASSERT_TRUE(CheckInitialState(0));
78 ASSERT_TRUE(CheckInitialState(1));
80 ASSERT_TRUE(EnableEncryption(0));
81 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
82 ASSERT_TRUE(IsEncryptionComplete(0));
83 ASSERT_TRUE(IsEncryptionComplete(1));
86 // This test is flaky on several platforms:
87 // http://crbug.com/420979
88 // http://crbug.com/421167
89 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
90 DISABLED_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()));