| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
| 6 #include "chrome/browser/sessions/session_service.h" | 6 #include "chrome/browser/sessions/session_service.h" |
| 7 #include "chrome/browser/sync/profile_sync_service_harness.h" | 7 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 8 #include "chrome/browser/sync/sessions/session_state.h" | 8 #include "chrome/browser/sync/sessions/session_state.h" |
| 9 #include "chrome/browser/sync/test/integration/sync_test.h" | 9 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 10 #include "chrome/browser/sync/test/integration/sessions_helper.h" | 10 #include "chrome/browser/sync/test/integration/sessions_helper.h" |
| 11 | 11 |
| 12 using sessions_helper::CheckInitialState; | 12 using sessions_helper::CheckInitialState; |
| 13 using sessions_helper::GetLocalWindows; | 13 using sessions_helper::GetLocalWindows; |
| 14 using sessions_helper::GetSessionData; | 14 using sessions_helper::GetSessionData; |
| 15 using sessions_helper::OpenTabAndGetLocalWindows; | 15 using sessions_helper::OpenTabAndGetLocalWindows; |
| 16 using sessions_helper::ScopedWindowMap; |
| 17 using sessions_helper::SyncedSessionVector; |
| 16 using sessions_helper::WindowsMatch; | 18 using sessions_helper::WindowsMatch; |
| 17 | 19 |
| 18 class TwoClientSessionsSyncTest : public SyncTest { | 20 class TwoClientSessionsSyncTest : public SyncTest { |
| 19 public: | 21 public: |
| 20 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} | 22 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} |
| 21 virtual ~TwoClientSessionsSyncTest() {} | 23 virtual ~TwoClientSessionsSyncTest() {} |
| 22 | 24 |
| 23 private: | 25 private: |
| 24 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); | 26 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 static const char* kValidPassphrase = "passphrase!"; | 29 static const char* kValidPassphrase = "passphrase!"; |
| 28 static const char* kURL1 = "chrome://sync"; | 30 static const char* kURL1 = "chrome://sync"; |
| 29 static const char* kURL2 = "chrome://version"; | 31 static const char* kURL2 = "chrome://version"; |
| 30 | 32 |
| 31 // TODO(zea): Test each individual session command we care about separately. | 33 // TODO(zea): Test each individual session command we care about separately. |
| 32 // (as well as multi-window). We're currently only checking basic single-window/ | 34 // (as well as multi-window). We're currently only checking basic single-window/ |
| 33 // single-tab functionality. | 35 // single-tab functionality. |
| 34 | 36 |
| 35 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, SingleClientChanged) { | 37 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, SingleClientChanged) { |
| 36 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 38 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 37 | 39 |
| 38 ASSERT_TRUE(CheckInitialState(0)); | 40 ASSERT_TRUE(CheckInitialState(0)); |
| 39 ASSERT_TRUE(CheckInitialState(1)); | 41 ASSERT_TRUE(CheckInitialState(1)); |
| 40 | 42 |
| 41 ScopedVector<SessionWindow> client0_windows; | 43 ScopedWindowMap client0_windows; |
| 42 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | 44 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), |
| 45 client0_windows.GetMutable())); |
| 43 | 46 |
| 44 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 47 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 45 | 48 |
| 46 // Get foreign session data from client 1. | 49 // Get foreign session data from client 1. |
| 47 SyncedSessionVector sessions1; | 50 SyncedSessionVector sessions1; |
| 48 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 51 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 49 | 52 |
| 50 // Verify client 1's foreign session matches client 0 current window. | 53 // Verify client 1's foreign session matches client 0 current window. |
| 51 ASSERT_EQ(1U, sessions1.size()); | 54 ASSERT_EQ(1U, sessions1.size()); |
| 52 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 55 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 53 } | 56 } |
| 54 | 57 |
| 55 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 58 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 56 SingleClientEnabledEncryption) { | 59 SingleClientEnabledEncryption) { |
| 57 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 60 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 58 | 61 |
| 59 ASSERT_TRUE(CheckInitialState(0)); | 62 ASSERT_TRUE(CheckInitialState(0)); |
| 60 ASSERT_TRUE(CheckInitialState(1)); | 63 ASSERT_TRUE(CheckInitialState(1)); |
| 61 | 64 |
| 62 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 65 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 63 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 66 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 64 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 67 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 65 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 68 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 66 | 69 |
| 67 // Should enable encryption for all other types as well. Just check a subset. | 70 // Should enable encryption for all other types as well. Just check a subset. |
| 68 ASSERT_TRUE(IsEncrypted(1, syncable::PREFERENCES)); | 71 ASSERT_TRUE(IsEncrypted(1, syncable::PREFERENCES)); |
| 69 ASSERT_TRUE(IsEncrypted(1, syncable::BOOKMARKS)); | 72 ASSERT_TRUE(IsEncrypted(1, syncable::BOOKMARKS)); |
| 70 ASSERT_TRUE(IsEncrypted(1, syncable::APPS)); | 73 ASSERT_TRUE(IsEncrypted(1, syncable::APPS)); |
| 71 } | 74 } |
| 72 | 75 |
| 73 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 76 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 74 SingleClientEnabledEncryptionAndChanged) { | 77 SingleClientEnabledEncryptionAndChanged) { |
| 75 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 78 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 76 | 79 |
| 77 ASSERT_TRUE(CheckInitialState(0)); | 80 ASSERT_TRUE(CheckInitialState(0)); |
| 78 ASSERT_TRUE(CheckInitialState(1)); | 81 ASSERT_TRUE(CheckInitialState(1)); |
| 79 | 82 |
| 80 ScopedVector<SessionWindow> client0_windows; | 83 ScopedWindowMap client0_windows; |
| 81 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | 84 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), |
| 85 client0_windows.GetMutable())); |
| 82 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 86 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 83 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 87 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 84 | 88 |
| 85 // Get foreign session data from client 1. | 89 // Get foreign session data from client 1. |
| 86 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 90 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 87 SyncedSessionVector sessions1; | 91 SyncedSessionVector sessions1; |
| 88 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 92 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 89 | 93 |
| 90 // Verify client 1's foreign session matches client 0 current window. | 94 // Verify client 1's foreign session matches client 0 current window. |
| 91 ASSERT_EQ(1U, sessions1.size()); | 95 ASSERT_EQ(1U, sessions1.size()); |
| 92 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 96 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 93 } | 97 } |
| 94 | 98 |
| 95 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 99 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 96 BothClientsEnabledEncryption) { | 100 BothClientsEnabledEncryption) { |
| 97 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 101 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 98 | 102 |
| 99 ASSERT_TRUE(CheckInitialState(0)); | 103 ASSERT_TRUE(CheckInitialState(0)); |
| 100 ASSERT_TRUE(CheckInitialState(1)); | 104 ASSERT_TRUE(CheckInitialState(1)); |
| 101 | 105 |
| 102 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 106 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 103 ASSERT_TRUE(EnableEncryption(1, syncable::SESSIONS)); | 107 ASSERT_TRUE(EnableEncryption(1, syncable::SESSIONS)); |
| 104 ASSERT_TRUE(AwaitQuiescence()); | 108 ASSERT_TRUE(AwaitQuiescence()); |
| 105 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 109 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 106 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 110 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 107 } | 111 } |
| 108 | 112 |
| 109 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { | 113 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { |
| 110 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 111 | 115 |
| 112 ASSERT_TRUE(CheckInitialState(0)); | 116 ASSERT_TRUE(CheckInitialState(0)); |
| 113 ASSERT_TRUE(CheckInitialState(1)); | 117 ASSERT_TRUE(CheckInitialState(1)); |
| 114 | 118 |
| 115 // Open tabs on both clients and retain window information. | 119 // Open tabs on both clients and retain window information. |
| 116 ScopedVector<SessionWindow> client0_windows; | 120 ScopedWindowMap client0_windows; |
| 117 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), client0_windows.get())); | 121 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), |
| 118 ScopedVector<SessionWindow> client1_windows; | 122 client0_windows.GetMutable())); |
| 119 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | 123 ScopedWindowMap client1_windows; |
| 124 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), |
| 125 client1_windows.GetMutable())); |
| 120 | 126 |
| 121 // Wait for sync. | 127 // Wait for sync. |
| 122 ASSERT_TRUE(AwaitQuiescence()); | 128 ASSERT_TRUE(AwaitQuiescence()); |
| 123 | 129 |
| 124 // Get foreign session data from client 0 and 1. | 130 // Get foreign session data from client 0 and 1. |
| 125 SyncedSessionVector sessions0; | 131 SyncedSessionVector sessions0; |
| 126 SyncedSessionVector sessions1; | 132 SyncedSessionVector sessions1; |
| 127 ASSERT_TRUE(GetSessionData(0, &sessions0)); | 133 ASSERT_TRUE(GetSessionData(0, &sessions0)); |
| 128 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 134 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 129 | 135 |
| 130 // Verify client 1's foreign session matches client 0's current window and | 136 // Verify client 1's foreign session matches client 0's current window and |
| 131 // vice versa. | 137 // vice versa. |
| 132 ASSERT_EQ(1U, sessions0.size()); | 138 ASSERT_EQ(1U, sessions0.size()); |
| 133 ASSERT_EQ(1U, sessions1.size()); | 139 ASSERT_EQ(1U, sessions1.size()); |
| 134 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 140 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 135 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | 141 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, *client1_windows.Get())); |
| 136 } | 142 } |
| 137 | 143 |
| 138 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 144 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 139 FirstChangesAndSetsPassphrase) { | 145 FirstChangesAndSetsPassphrase) { |
| 140 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 146 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 141 | 147 |
| 142 ASSERT_TRUE(CheckInitialState(0)); | 148 ASSERT_TRUE(CheckInitialState(0)); |
| 143 ASSERT_TRUE(CheckInitialState(1)); | 149 ASSERT_TRUE(CheckInitialState(1)); |
| 144 | 150 |
| 145 ScopedVector<SessionWindow> client0_windows; | 151 ScopedWindowMap client0_windows; |
| 146 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | 152 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), |
| 153 client0_windows.GetMutable())); |
| 147 | 154 |
| 148 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 155 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 149 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); | 156 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); |
| 150 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | 157 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); |
| 151 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 158 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 152 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | 159 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); |
| 153 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 160 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 154 num_blocking_conflicting_updates); | 161 num_blocking_conflicting_updates); |
| 155 // We have 6 non-blocking conflicts due to the two meta nodes (one for each | 162 // We have 6 non-blocking conflicts due to the two meta nodes (one for each |
| 156 // client), the one tab node, and the six basic preference/themes/search | 163 // client), the one tab node, and the six basic preference/themes/search |
| 157 // engines. | 164 // engines. |
| 158 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> | 165 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> |
| 159 num_conflicting_updates); // The encrypted nodes. | 166 num_conflicting_updates); // The encrypted nodes. |
| 160 | 167 |
| 161 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); | 168 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); |
| 162 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | 169 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); |
| 163 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | 170 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); |
| 164 | 171 |
| 165 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 172 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 166 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 173 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 167 // Get foreign session data from client 0 and 1. | 174 // Get foreign session data from client 0 and 1. |
| 168 SyncedSessionVector sessions1; | 175 SyncedSessionVector sessions1; |
| 169 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 176 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 170 | 177 |
| 171 // Verify client 1's foreign session matches client 0's current window and | 178 // Verify client 1's foreign session matches client 0's current window and |
| 172 // vice versa. | 179 // vice versa. |
| 173 ASSERT_EQ(1U, sessions1.size()); | 180 ASSERT_EQ(1U, sessions1.size()); |
| 174 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 181 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 175 } | 182 } |
| 176 | 183 |
| 177 // Flaky (number of conflicting nodes is off). http://crbug.com/89604. | 184 // Flaky (number of conflicting nodes is off). http://crbug.com/89604. |
| 178 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 185 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 179 FLAKY_FirstChangesWhileSecondWaitingForPassphrase) { | 186 FLAKY_FirstChangesWhileSecondWaitingForPassphrase) { |
| 180 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 187 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 181 | 188 |
| 182 ASSERT_TRUE(CheckInitialState(0)); | 189 ASSERT_TRUE(CheckInitialState(0)); |
| 183 ASSERT_TRUE(CheckInitialState(1)); | 190 ASSERT_TRUE(CheckInitialState(1)); |
| 184 | 191 |
| 185 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 192 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 186 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); | 193 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); |
| 187 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | 194 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); |
| 188 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 195 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 189 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | 196 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); |
| 190 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 197 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 191 num_blocking_conflicting_updates); | 198 num_blocking_conflicting_updates); |
| 192 // We have eight non-blocking conflicts due to the two meta nodes (one for | 199 // We have eight non-blocking conflicts due to the two meta nodes (one for |
| 193 // each client), and the 6 basic preference/themes/search engines nodes. | 200 // each client), and the 6 basic preference/themes/search engines nodes. |
| 194 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> | 201 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> |
| 195 num_conflicting_updates); // The encrypted nodes. | 202 num_conflicting_updates); // The encrypted nodes. |
| 196 | 203 |
| 197 ScopedVector<SessionWindow> client0_windows; | 204 ScopedWindowMap client0_windows; |
| 198 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | 205 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), |
| 206 client0_windows.GetMutable())); |
| 199 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 207 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 200 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 208 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 201 num_blocking_conflicting_updates); | 209 num_blocking_conflicting_updates); |
| 202 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> | 210 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> |
| 203 num_conflicting_updates); // The encrypted nodes. | 211 num_conflicting_updates); // The encrypted nodes. |
| 204 | 212 |
| 205 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); | 213 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); |
| 206 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | 214 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); |
| 207 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | 215 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); |
| 208 | 216 |
| 209 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 217 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 210 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 218 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 211 // Get foreign session data from client 0 and 1. | 219 // Get foreign session data from client 0 and 1. |
| 212 SyncedSessionVector sessions1; | 220 SyncedSessionVector sessions1; |
| 213 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 221 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 214 | 222 |
| 215 // Verify client 1's foreign session matches client 0's current window and | 223 // Verify client 1's foreign session matches client 0's current window and |
| 216 // vice versa. | 224 // vice versa. |
| 217 ASSERT_EQ(1U, sessions1.size()); | 225 ASSERT_EQ(1U, sessions1.size()); |
| 218 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 226 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 219 } | 227 } |
| 220 | 228 |
| 221 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 229 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 222 SecondChangesAfterEncrAndPassphraseChange) { | 230 SecondChangesAfterEncrAndPassphraseChange) { |
| 223 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 231 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 224 | 232 |
| 225 ASSERT_TRUE(CheckInitialState(0)); | 233 ASSERT_TRUE(CheckInitialState(0)); |
| 226 ASSERT_TRUE(CheckInitialState(1)); | 234 ASSERT_TRUE(CheckInitialState(1)); |
| 227 | 235 |
| 228 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 236 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 229 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); | 237 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); |
| 230 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | 238 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); |
| 231 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 239 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 232 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | 240 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); |
| 233 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 241 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 234 num_blocking_conflicting_updates); | 242 num_blocking_conflicting_updates); |
| 235 // We have two non-blocking conflicts due to the two meta nodes (one for each | 243 // We have two non-blocking conflicts due to the two meta nodes (one for each |
| 236 // client), and the 6 basic preference/themes/search engines nodes. | 244 // client), and the 6 basic preference/themes/search engines nodes. |
| 237 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> | 245 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> |
| 238 num_conflicting_updates); // The encrypted nodes. | 246 num_conflicting_updates); // The encrypted nodes. |
| 239 | 247 |
| 240 // These changes are either made with the old passphrase or not encrypted at | 248 // These changes are either made with the old passphrase or not encrypted at |
| 241 // all depending on when client 0's changes are propagated. | 249 // all depending on when client 0's changes are propagated. |
| 242 ScopedVector<SessionWindow> client1_windows; | 250 ScopedWindowMap client1_windows; |
| 243 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | 251 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), |
| 252 client1_windows.GetMutable())); |
| 244 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 253 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| 245 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 254 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 246 num_blocking_conflicting_updates); | 255 num_blocking_conflicting_updates); |
| 247 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> | 256 ASSERT_EQ(8, GetClient(1)->GetLastSessionSnapshot()-> |
| 248 num_conflicting_updates); // The same encrypted nodes. | 257 num_conflicting_updates); // The same encrypted nodes. |
| 249 | 258 |
| 250 // At this point we enter the passphrase, triggering a resync, in which the | 259 // At this point we enter the passphrase, triggering a resync, in which the |
| 251 // local changes of client 1 get overwritten for now. | 260 // local changes of client 1 get overwritten for now. |
| 252 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); | 261 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); |
| 253 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | 262 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 265 | 274 |
| 266 // Flaky. http://crbug.com/85294 | 275 // Flaky. http://crbug.com/85294 |
| 267 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 276 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 268 FLAKY_SecondChangesBeforeEncrAndPassphraseChange) { | 277 FLAKY_SecondChangesBeforeEncrAndPassphraseChange) { |
| 269 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 278 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 270 | 279 |
| 271 ASSERT_TRUE(CheckInitialState(0)); | 280 ASSERT_TRUE(CheckInitialState(0)); |
| 272 ASSERT_TRUE(CheckInitialState(1)); | 281 ASSERT_TRUE(CheckInitialState(1)); |
| 273 | 282 |
| 274 // These changes are either made on client 1 without encryption. | 283 // These changes are either made on client 1 without encryption. |
| 275 ScopedVector<SessionWindow> client1_windows; | 284 ScopedWindowMap client1_windows; |
| 276 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | 285 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), |
| 286 client1_windows.GetMutable())); |
| 277 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 287 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| 278 | 288 |
| 279 // Turn encryption on client 0. Client 1's foreign will be encrypted with the | 289 // Turn encryption on client 0. Client 1's foreign will be encrypted with the |
| 280 // new passphrase and synced back. It will be unable to decrypt it yet. | 290 // new passphrase and synced back. It will be unable to decrypt it yet. |
| 281 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 291 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 282 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); | 292 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); |
| 283 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | 293 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); |
| 284 ASSERT_TRUE(AwaitQuiescence()); | 294 ASSERT_TRUE(AwaitQuiescence()); |
| 285 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | 295 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); |
| 286 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 296 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 298 | 308 |
| 299 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 309 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 300 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 310 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 301 // Client 0's foreign data should match client 1's local data. Client 1's | 311 // Client 0's foreign data should match client 1's local data. Client 1's |
| 302 // foreign data is empty because client 0 did not open any tabs. | 312 // foreign data is empty because client 0 did not open any tabs. |
| 303 SyncedSessionVector sessions0; | 313 SyncedSessionVector sessions0; |
| 304 SyncedSessionVector sessions1; | 314 SyncedSessionVector sessions1; |
| 305 ASSERT_TRUE(GetSessionData(0, &sessions0)); | 315 ASSERT_TRUE(GetSessionData(0, &sessions0)); |
| 306 ASSERT_FALSE(GetSessionData(1, &sessions1)); | 316 ASSERT_FALSE(GetSessionData(1, &sessions1)); |
| 307 ASSERT_EQ(1U, sessions0.size()); | 317 ASSERT_EQ(1U, sessions0.size()); |
| 308 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | 318 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, *client1_windows.Get())); |
| 309 } | 319 } |
| 310 | 320 |
| 311 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 321 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 312 BothChangeWithEncryptionAndPassphrase) { | 322 BothChangeWithEncryptionAndPassphrase) { |
| 313 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 323 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 314 | 324 |
| 315 ASSERT_TRUE(CheckInitialState(0)); | 325 ASSERT_TRUE(CheckInitialState(0)); |
| 316 ASSERT_TRUE(CheckInitialState(1)); | 326 ASSERT_TRUE(CheckInitialState(1)); |
| 317 | 327 |
| 318 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); | 328 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true); |
| 319 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | 329 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); |
| 320 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 330 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 321 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | 331 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); |
| 322 | 332 |
| 323 // These changes will sync over to client 1, who will be unable to decrypt | 333 // These changes will sync over to client 1, who will be unable to decrypt |
| 324 // them due to the missing passphrase. | 334 // them due to the missing passphrase. |
| 325 ScopedVector<SessionWindow> client0_windows; | 335 ScopedWindowMap client0_windows; |
| 326 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | 336 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), |
| 337 client0_windows.GetMutable())); |
| 327 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | 338 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); |
| 328 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 339 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 329 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 340 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
| 330 num_blocking_conflicting_updates); | 341 num_blocking_conflicting_updates); |
| 331 // We have three non-blocking conflicts due to the two meta nodes (one for | 342 // We have three non-blocking conflicts due to the two meta nodes (one for |
| 332 // each client), the one tab node, and the 6 basic preference/themes/search | 343 // each client), the one tab node, and the 6 basic preference/themes/search |
| 333 // engines nodes. | 344 // engines nodes. |
| 334 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> | 345 ASSERT_EQ(9, GetClient(1)->GetLastSessionSnapshot()-> |
| 335 num_conflicting_updates); // The encrypted nodes. | 346 num_conflicting_updates); // The encrypted nodes. |
| 336 | 347 |
| 337 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); | 348 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true); |
| 338 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | 349 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); |
| 339 ASSERT_FALSE(GetClient(1)->service()->IsPassphraseRequired()); | 350 ASSERT_FALSE(GetClient(1)->service()->IsPassphraseRequired()); |
| 340 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | 351 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); |
| 341 | 352 |
| 342 // Open windows on client 1, which should automatically be encrypted. | 353 // Open windows on client 1, which should automatically be encrypted. |
| 343 ScopedVector<SessionWindow> client1_windows; | 354 ScopedWindowMap client1_windows; |
| 344 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL2), client1_windows.get())); | 355 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL2), |
| 356 client1_windows.GetMutable())); |
| 345 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 357 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| 346 | 358 |
| 347 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | 359 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); |
| 348 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | 360 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); |
| 349 // Get foreign session data from client 0 and 1. | 361 // Get foreign session data from client 0 and 1. |
| 350 SyncedSessionVector sessions0; | 362 SyncedSessionVector sessions0; |
| 351 SyncedSessionVector sessions1; | 363 SyncedSessionVector sessions1; |
| 352 ASSERT_TRUE(GetSessionData(0, &sessions0)); | 364 ASSERT_TRUE(GetSessionData(0, &sessions0)); |
| 353 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 365 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 354 | 366 |
| 355 // Verify client 1's foreign session matches client 0's current window and | 367 // Verify client 1's foreign session matches client 0's current window and |
| 356 // vice versa. | 368 // vice versa. |
| 357 ASSERT_EQ(1U, sessions0.size()); | 369 ASSERT_EQ(1U, sessions0.size()); |
| 358 ASSERT_EQ(1U, sessions1.size()); | 370 ASSERT_EQ(1U, sessions1.size()); |
| 359 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | 371 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, *client0_windows.Get())); |
| 360 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | 372 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, *client1_windows.Get())); |
| 361 } | 373 } |
| OLD | NEW |