OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/sessions/session_service.h" | 11 #include "chrome/browser/sessions/session_service.h" |
12 #include "chrome/browser/sync/test/integration/passwords_helper.h" | 12 #include "chrome/browser/sync/test/integration/passwords_helper.h" |
13 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 13 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
14 #include "chrome/browser/sync/test/integration/sessions_helper.h" | 14 #include "chrome/browser/sync/test/integration/sessions_helper.h" |
15 #include "chrome/browser/sync/test/integration/sync_test.h" | 15 #include "chrome/browser/sync/test/integration/sync_test.h" |
16 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 16 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
17 | 17 |
18 using sessions_helper::CheckInitialState; | 18 using sessions_helper::CheckInitialState; |
19 using sessions_helper::DeleteForeignSession; | 19 using sessions_helper::DeleteForeignSession; |
20 using sessions_helper::GetLocalWindows; | 20 using sessions_helper::GetLocalWindows; |
21 using sessions_helper::GetSessionData; | 21 using sessions_helper::GetSessionData; |
22 using sessions_helper::OpenTabAndGetLocalWindows; | 22 using sessions_helper::NavigateTab; |
| 23 using sessions_helper::OpenTab; |
| 24 using sessions_helper::OpenTabAtIndex; |
23 using sessions_helper::ScopedWindowMap; | 25 using sessions_helper::ScopedWindowMap; |
24 using sessions_helper::SessionWindowMap; | 26 using sessions_helper::SessionWindowMap; |
25 using sessions_helper::SyncedSessionVector; | 27 using sessions_helper::SyncedSessionVector; |
26 using sessions_helper::WindowsMatch; | 28 using sessions_helper::WindowsMatch; |
27 | 29 |
28 class TwoClientSessionsSyncTest : public SyncTest { | 30 class TwoClientSessionsSyncTest : public SyncTest { |
29 public: | 31 public: |
30 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} | 32 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} |
31 ~TwoClientSessionsSyncTest() override {} | 33 ~TwoClientSessionsSyncTest() override {} |
32 | 34 |
| 35 void WaitForWindowsInForeignSession(int index, ScopedWindowMap windows) { |
| 36 std::vector<ScopedWindowMap> expected_windows; |
| 37 expected_windows.push_back(std::move(windows)); |
| 38 EXPECT_TRUE(ForeignSessionsMatchChecker(index, expected_windows).Wait()); |
| 39 } |
| 40 |
| 41 void WaitForForeignSessionsToSync(int local_index, int non_local_index) { |
| 42 ScopedWindowMap client_windows; |
| 43 ASSERT_TRUE(GetLocalWindows(local_index, &client_windows)); |
| 44 WaitForWindowsInForeignSession(non_local_index, std::move(client_windows)); |
| 45 } |
| 46 |
33 private: | 47 private: |
34 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); | 48 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); |
35 }; | 49 }; |
36 | 50 |
37 static const char* kURL1 = "http://127.0.0.1/bubba1"; | 51 static const char* kURL1 = "http://127.0.0.1/bubba1"; |
38 static const char* kURL2 = "http://127.0.0.1/bubba2"; | 52 static const char* kURL2 = "http://127.0.0.1/bubba2"; |
| 53 static const char* kURL3 = "http://127.0.0.1/foobar"; |
| 54 static const char* kURL4 = "http://127.0.0.1/barbaz"; |
39 | 55 |
40 // TODO(zea): Test each individual session command we care about separately. | 56 // TODO(zea): Test each individual session command we care about separately. |
41 // (as well as multi-window). We're currently only checking basic single-window/ | 57 // (as well as multi-window). We're currently only checking basic single-window/ |
42 // single-tab functionality. | 58 // single-tab functionality. |
43 | 59 |
44 | 60 |
45 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 61 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
46 E2E_ENABLED(SingleClientChanged)) { | 62 E2E_ENABLED(SingleClientChanged)) { |
47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 63 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
48 | 64 |
49 // Open tab and access a url on client 0 | 65 // Open tab and access a url on client 0 |
50 ScopedWindowMap client0_windows; | 66 ScopedWindowMap client0_windows; |
51 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", | 67 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", |
52 base::GenerateGUID().c_str()); | 68 base::GenerateGUID().c_str()); |
53 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows)); | |
54 | 69 |
55 // Retain the window information on client 0 | 70 ASSERT_TRUE(OpenTab(0, GURL(url))); |
56 std::vector<ScopedWindowMap> expected_windows(1); | 71 WaitForForeignSessionsToSync(0, 1); |
57 expected_windows[0] = std::move(client0_windows); | |
58 | |
59 // Check the foreign windows on client 1 | |
60 ASSERT_TRUE(ForeignSessionsMatchChecker(1, expected_windows).Wait()); | |
61 } | 72 } |
62 | 73 |
63 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 74 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
64 E2E_ENABLED(AllChanged)) { | 75 E2E_ENABLED(AllChanged)) { |
65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 76 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
66 | 77 |
67 // Open tabs on all clients and retain window information. | 78 // Open tabs on all clients and retain window information. |
68 std::vector<ScopedWindowMap> client_windows(num_clients()); | 79 std::vector<ScopedWindowMap> client_windows(num_clients()); |
69 for (int i = 0; i < num_clients(); ++i) { | 80 for (int i = 0; i < num_clients(); ++i) { |
70 ScopedWindowMap windows; | 81 ScopedWindowMap windows; |
71 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", | 82 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", |
72 base::GenerateGUID().c_str()); | 83 base::GenerateGUID().c_str()); |
73 ASSERT_TRUE(OpenTabAndGetLocalWindows(i, GURL(url), &windows)); | 84 ASSERT_TRUE(OpenTab(i, GURL(url))); |
| 85 ASSERT_TRUE(GetLocalWindows(i, &windows)); |
74 client_windows[i] = std::move(windows); | 86 client_windows[i] = std::move(windows); |
75 } | 87 } |
76 | 88 |
77 // Get foreign session data from all clients and check it against all | 89 // Get foreign session data from all clients and check it against all |
78 // client_windows. | 90 // client_windows. |
79 for (int i = 0; i < num_clients(); ++i) { | 91 for (int i = 0; i < num_clients(); ++i) { |
80 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait()); | 92 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait()); |
81 } | 93 } |
82 } | 94 } |
83 | 95 |
(...skipping 13 matching lines...) Expand all Loading... |
97 // This test is flaky on several platforms: | 109 // This test is flaky on several platforms: |
98 // http://crbug.com/420979 | 110 // http://crbug.com/420979 |
99 // http://crbug.com/421167 | 111 // http://crbug.com/421167 |
100 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 112 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
101 DISABLED_SingleClientEnabledEncryptionAndChanged) { | 113 DISABLED_SingleClientEnabledEncryptionAndChanged) { |
102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
103 | 115 |
104 ASSERT_TRUE(CheckInitialState(0)); | 116 ASSERT_TRUE(CheckInitialState(0)); |
105 ASSERT_TRUE(CheckInitialState(1)); | 117 ASSERT_TRUE(CheckInitialState(1)); |
106 | 118 |
107 ScopedWindowMap client0_windows; | 119 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
108 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | |
109 ASSERT_TRUE(EnableEncryption(0)); | 120 ASSERT_TRUE(EnableEncryption(0)); |
110 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 121 WaitForForeignSessionsToSync(0, 1); |
111 | |
112 // Get foreign session data from client 1. | |
113 ASSERT_TRUE(IsEncryptionComplete(1)); | |
114 SyncedSessionVector sessions1; | |
115 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
116 | |
117 // Verify client 1's foreign session matches client 0 current window. | |
118 ASSERT_EQ(1U, sessions1.size()); | |
119 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
120 } | 122 } |
121 | 123 |
122 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 124 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
123 BothClientsEnabledEncryption) { | 125 BothClientsEnabledEncryption) { |
124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
125 | 127 |
126 ASSERT_TRUE(CheckInitialState(0)); | 128 ASSERT_TRUE(CheckInitialState(0)); |
127 ASSERT_TRUE(CheckInitialState(1)); | 129 ASSERT_TRUE(CheckInitialState(1)); |
128 | 130 |
129 ASSERT_TRUE(EnableEncryption(0)); | 131 ASSERT_TRUE(EnableEncryption(0)); |
130 ASSERT_TRUE(EnableEncryption(1)); | 132 ASSERT_TRUE(EnableEncryption(1)); |
131 ASSERT_TRUE(AwaitQuiescence()); | 133 ASSERT_TRUE(AwaitQuiescence()); |
132 ASSERT_TRUE(IsEncryptionComplete(0)); | 134 ASSERT_TRUE(IsEncryptionComplete(0)); |
133 ASSERT_TRUE(IsEncryptionComplete(1)); | 135 ASSERT_TRUE(IsEncryptionComplete(1)); |
134 } | 136 } |
135 | 137 |
136 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { | 138 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { |
137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 139 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
138 | 140 |
139 ASSERT_TRUE(CheckInitialState(0)); | 141 ASSERT_TRUE(CheckInitialState(0)); |
140 ASSERT_TRUE(CheckInitialState(1)); | 142 ASSERT_TRUE(CheckInitialState(1)); |
141 | 143 |
142 // Open tabs on both clients and retain window information. | 144 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
143 ScopedWindowMap client0_windows; | 145 ASSERT_TRUE(OpenTab(1, GURL(kURL2))); |
144 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); | |
145 ScopedWindowMap client1_windows; | |
146 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), &client1_windows)); | |
147 | 146 |
148 // Wait for sync. | 147 WaitForForeignSessionsToSync(0, 1); |
149 ASSERT_TRUE(AwaitQuiescence()); | 148 WaitForForeignSessionsToSync(1, 0); |
150 | 149 |
151 // Get foreign session data from client 0 and 1. | 150 // Check that a navigation in client 0 is reflected on client 1. |
152 SyncedSessionVector sessions0; | 151 NavigateTab(0, GURL(kURL3)); |
153 SyncedSessionVector sessions1; | 152 WaitForForeignSessionsToSync(0, 1); |
154 ASSERT_TRUE(GetSessionData(0, &sessions0)); | |
155 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
156 | |
157 // Verify client 1's foreign session matches client 0's current window and | |
158 // vice versa. | |
159 ASSERT_EQ(1U, sessions0.size()); | |
160 ASSERT_EQ(1U, sessions1.size()); | |
161 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
162 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows)); | |
163 } | 153 } |
164 | 154 |
165 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { | 155 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { |
166 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 156 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
167 | 157 |
168 ASSERT_TRUE(CheckInitialState(0)); | 158 ASSERT_TRUE(CheckInitialState(0)); |
169 ASSERT_TRUE(CheckInitialState(1)); | 159 ASSERT_TRUE(CheckInitialState(1)); |
170 | 160 |
171 // Client 0 opened some tabs then went idle. | 161 // Client 0 opened some tabs then went idle. |
172 ScopedWindowMap client0_windows; | 162 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
173 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | 163 WaitForForeignSessionsToSync(0, 1); |
174 | |
175 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
176 | 164 |
177 // Get foreign session data from client 1. | 165 // Get foreign session data from client 1. |
178 SyncedSessionVector sessions1; | 166 SyncedSessionVector sessions1; |
179 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 167 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
180 | 168 |
181 // Verify client 1's foreign session matches client 0 current window. | |
182 ASSERT_EQ(1U, sessions1.size()); | |
183 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
184 | |
185 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. | 169 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
186 DeleteForeignSession(1, sessions1[0]->session_tag); | 170 DeleteForeignSession(1, sessions1[0]->session_tag); |
187 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 171 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
188 ASSERT_FALSE(GetSessionData(1, &sessions1)); | 172 ASSERT_FALSE(GetSessionData(1, &sessions1)); |
189 } | 173 } |
190 | 174 |
191 // Fails all release trybots. crbug.com/263369. | 175 // Fails all release trybots. crbug.com/263369. |
192 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 176 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
193 DeleteActiveSession) { | 177 DeleteActiveSession) { |
194 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 178 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
195 | 179 |
196 ASSERT_TRUE(CheckInitialState(0)); | 180 ASSERT_TRUE(CheckInitialState(0)); |
197 ASSERT_TRUE(CheckInitialState(1)); | 181 ASSERT_TRUE(CheckInitialState(1)); |
198 | 182 |
199 // Client 0 opened some tabs then went idle. | 183 // Client 0 opened some tabs then went idle. |
200 ScopedWindowMap client0_windows; | 184 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
201 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | 185 WaitForForeignSessionsToSync(0, 1); |
202 | 186 |
203 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
204 SyncedSessionVector sessions1; | 187 SyncedSessionVector sessions1; |
205 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 188 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
206 ASSERT_EQ(1U, sessions1.size()); | 189 ASSERT_EQ(1U, sessions1.size()); |
207 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
208 | 190 |
209 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. | 191 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
210 DeleteForeignSession(1, sessions1[0]->session_tag); | 192 DeleteForeignSession(1, sessions1[0]->session_tag); |
211 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 193 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
212 ASSERT_FALSE(GetSessionData(1, &sessions1)); | 194 ASSERT_FALSE(GetSessionData(1, &sessions1)); |
213 | 195 |
214 // Client 0 becomes active again with a new tab. | 196 // Client 0 becomes active again with a new tab. |
215 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); | 197 ASSERT_TRUE(OpenTab(0, GURL(kURL2))); |
216 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 198 WaitForForeignSessionsToSync(0, 1); |
217 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
218 ASSERT_EQ(1U, sessions1.size()); | |
219 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
220 } | 199 } |
| 200 |
| 201 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MultipleWindowsMultipleTabs) { |
| 202 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 203 |
| 204 ASSERT_TRUE(CheckInitialState(0)); |
| 205 ASSERT_TRUE(CheckInitialState(1)); |
| 206 |
| 207 EXPECT_TRUE(OpenTab(0, GURL(kURL1))); |
| 208 EXPECT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2))); |
| 209 |
| 210 // Add a second browser for profile 0. This browser ends up in index 2. |
| 211 AddBrowser(0); |
| 212 EXPECT_TRUE(OpenTab(2, GURL(kURL3))); |
| 213 EXPECT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4))); |
| 214 |
| 215 WaitForForeignSessionsToSync(0, 1); |
| 216 } |
OLD | NEW |