Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_sessions_sync_test.cc
blob31843afb0602f8efa73a8beecc6146f3300c4baa
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/strings/stringprintf.h"
7 #include "chrome/browser/sessions/session_service.h"
8 #include "chrome/browser/sync/test/integration/passwords_helper.h"
9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
10 #include "chrome/browser/sync/test/integration/sessions_helper.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
14 using passwords_helper::SetDecryptionPassphrase;
15 using passwords_helper::SetEncryptionPassphrase;
16 using sessions_helper::CheckInitialState;
17 using sessions_helper::DeleteForeignSession;
18 using sessions_helper::GetLocalWindows;
19 using sessions_helper::GetSessionData;
20 using sessions_helper::OpenTabAndGetLocalWindows;
21 using sessions_helper::ScopedWindowMap;
22 using sessions_helper::SessionWindowMap;
23 using sessions_helper::SyncedSessionVector;
24 using sessions_helper::WindowsMatch;
26 class TwoClientSessionsSyncTest : public SyncTest {
27 public:
28 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
29 ~TwoClientSessionsSyncTest() override {}
31 private:
32 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
35 static const char* kURL1 = "http://127.0.0.1/bubba1";
36 static const char* kURL2 = "http://127.0.0.1/bubba2";
38 // TODO(zea): Test each individual session command we care about separately.
39 // (as well as multi-window). We're currently only checking basic single-window/
40 // single-tab functionality.
42 // Fails on Win, see http://crbug.com/232313
43 #if defined(OS_WIN)
44 #define MAYBE_E2ETest_SingleClientChanged DISABLED_E2ETest_SingleClientChanged
45 #define MAYBE_BothChanged DISABLED_BothChanged
46 #define MAYBE_DeleteIdleSession DISABLED_DeleteIdleSession
47 #else
48 #define MAYBE_E2ETest_SingleClientChanged E2ETest_SingleClientChanged
49 #define MAYBE_BothChanged BothChanged
50 #define MAYBE_DeleteIdleSession DeleteIdleSession
51 #endif
54 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
55 MAYBE_E2ETest_SingleClientChanged) {
56 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
58 // Open tab and access a url on client 0
59 SessionWindowMap client0_windows;
60 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s",
61 base::GenerateGUID().c_str());
62 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows));
64 // Retain the window information on client 0
65 std::vector<ScopedWindowMap> expected_windows(1);
66 expected_windows[0].Reset(&client0_windows);
68 // Check the foreign windows on client 1
69 ASSERT_TRUE(AwaitCheckForeignSessionsAgainst(1, expected_windows));
72 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
73 SingleClientEnabledEncryption) {
74 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
76 ASSERT_TRUE(CheckInitialState(0));
77 ASSERT_TRUE(CheckInitialState(1));
79 ASSERT_TRUE(EnableEncryption(0));
80 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
81 ASSERT_TRUE(IsEncryptionComplete(0));
82 ASSERT_TRUE(IsEncryptionComplete(1));
85 // This test is flaky on several platforms:
86 // http://crbug.com/420979
87 // http://crbug.com/421167
88 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
89 DISABLED_SingleClientEnabledEncryptionAndChanged) {
90 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
92 ASSERT_TRUE(CheckInitialState(0));
93 ASSERT_TRUE(CheckInitialState(1));
95 ScopedWindowMap client0_windows;
96 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
97 client0_windows.GetMutable()));
98 ASSERT_TRUE(EnableEncryption(0));
99 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
101 // Get foreign session data from client 1.
102 ASSERT_TRUE(IsEncryptionComplete(1));
103 SyncedSessionVector sessions1;
104 ASSERT_TRUE(GetSessionData(1, &sessions1));
106 // Verify client 1's foreign session matches client 0 current window.
107 ASSERT_EQ(1U, sessions1.size());
108 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
111 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
112 BothClientsEnabledEncryption) {
113 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
115 ASSERT_TRUE(CheckInitialState(0));
116 ASSERT_TRUE(CheckInitialState(1));
118 ASSERT_TRUE(EnableEncryption(0));
119 ASSERT_TRUE(EnableEncryption(1));
120 ASSERT_TRUE(AwaitQuiescence());
121 ASSERT_TRUE(IsEncryptionComplete(0));
122 ASSERT_TRUE(IsEncryptionComplete(1));
125 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_BothChanged) {
126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
128 ASSERT_TRUE(CheckInitialState(0));
129 ASSERT_TRUE(CheckInitialState(1));
131 // Open tabs on both clients and retain window information.
132 ScopedWindowMap client0_windows;
133 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2),
134 client0_windows.GetMutable()));
135 ScopedWindowMap client1_windows;
136 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1),
137 client1_windows.GetMutable()));
139 // Wait for sync.
140 ASSERT_TRUE(AwaitQuiescence());
142 // Get foreign session data from client 0 and 1.
143 SyncedSessionVector sessions0;
144 SyncedSessionVector sessions1;
145 ASSERT_TRUE(GetSessionData(0, &sessions0));
146 ASSERT_TRUE(GetSessionData(1, &sessions1));
148 // Verify client 1's foreign session matches client 0's current window and
149 // vice versa.
150 ASSERT_EQ(1U, sessions0.size());
151 ASSERT_EQ(1U, sessions1.size());
152 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
153 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, *client1_windows.Get()));
156 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MAYBE_DeleteIdleSession) {
157 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
159 ASSERT_TRUE(CheckInitialState(0));
160 ASSERT_TRUE(CheckInitialState(1));
162 // Client 0 opened some tabs then went idle.
163 ScopedWindowMap client0_windows;
164 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
165 client0_windows.GetMutable()));
167 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
169 // Get foreign session data from client 1.
170 SyncedSessionVector sessions1;
171 ASSERT_TRUE(GetSessionData(1, &sessions1));
173 // Verify client 1's foreign session matches client 0 current window.
174 ASSERT_EQ(1U, sessions1.size());
175 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
177 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
178 DeleteForeignSession(1, sessions1[0]->session_tag);
179 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
180 ASSERT_FALSE(GetSessionData(1, &sessions1));
183 // Fails all release trybots. crbug.com/263369.
184 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
185 DISABLED_DeleteActiveSession) {
186 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
188 ASSERT_TRUE(CheckInitialState(0));
189 ASSERT_TRUE(CheckInitialState(1));
191 // Client 0 opened some tabs then went idle.
192 ScopedWindowMap client0_windows;
193 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1),
194 client0_windows.GetMutable()));
196 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
197 SyncedSessionVector sessions1;
198 ASSERT_TRUE(GetSessionData(1, &sessions1));
199 ASSERT_EQ(1U, sessions1.size());
200 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));
202 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
203 DeleteForeignSession(1, sessions1[0]->session_tag);
204 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
205 ASSERT_FALSE(GetSessionData(1, &sessions1));
207 // Client 0 becomes active again with a new tab.
208 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2),
209 client0_windows.GetMutable()));
210 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
211 ASSERT_TRUE(GetSessionData(1, &sessions1));
212 ASSERT_EQ(1U, sessions1.size());
213 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get()));