Chromium Code Reviews| 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 = "data:text/html,<html><title>Test</title></html>"; |
|
skym
2017/03/02 22:59:43
Same, move up please.
| |
| 38 static const char* kURL2 = "http://127.0.0.1/bubba2"; | 52 static const char* kURL2 = "data:text/html,<html><title>Test2</title></html>"; |
| 53 static const char* kURL3 = "data:text/html,<html><title>Test3</title></html>"; | |
| 54 static const char* kURL4 = "data:text/html,<html><title>Test4</title></html>"; | |
| 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 = |
| 52 base::GenerateGUID().c_str()); | 68 base::StringPrintf("data:text/html,<html><title>Test%s</title></html>", |
|
skym
2017/03/02 22:59:43
How about this literal is a constant as well?
Patrick Noland
2017/03/02 23:32:48
Done.
| |
| 53 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows)); | 69 base::GenerateGUID().c_str()); |
| 54 | 70 |
| 55 // Retain the window information on client 0 | 71 ASSERT_TRUE(OpenTab(0, GURL(url))); |
| 56 std::vector<ScopedWindowMap> expected_windows(1); | 72 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 } | 73 } |
| 62 | 74 |
| 63 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 75 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 64 E2E_ENABLED(AllChanged)) { | 76 E2E_ENABLED(AllChanged)) { |
| 65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 77 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 66 | 78 |
| 67 // Open tabs on all clients and retain window information. | 79 // Open tabs on all clients and retain window information. |
| 68 std::vector<ScopedWindowMap> client_windows(num_clients()); | 80 std::vector<ScopedWindowMap> client_windows(num_clients()); |
| 69 for (int i = 0; i < num_clients(); ++i) { | 81 for (int i = 0; i < num_clients(); ++i) { |
| 70 ScopedWindowMap windows; | 82 ScopedWindowMap windows; |
| 71 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", | 83 std::string url = |
| 72 base::GenerateGUID().c_str()); | 84 base::StringPrintf("data:text/html,<html><title>Test%s</title></html>", |
|
skym
2017/03/02 22:59:43
constant
Patrick Noland
2017/03/02 23:32:48
Done.
| |
| 73 ASSERT_TRUE(OpenTabAndGetLocalWindows(i, GURL(url), &windows)); | 85 base::GenerateGUID().c_str()); |
| 86 ASSERT_TRUE(OpenTab(i, GURL(url))); | |
| 87 ASSERT_TRUE(GetLocalWindows(i, &windows)); | |
| 74 client_windows[i] = std::move(windows); | 88 client_windows[i] = std::move(windows); |
| 75 } | 89 } |
| 76 | 90 |
| 77 // Get foreign session data from all clients and check it against all | 91 // Get foreign session data from all clients and check it against all |
| 78 // client_windows. | 92 // client_windows. |
| 79 for (int i = 0; i < num_clients(); ++i) { | 93 for (int i = 0; i < num_clients(); ++i) { |
| 80 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait()); | 94 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait()); |
| 81 } | 95 } |
| 82 } | 96 } |
| 83 | 97 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 97 // This test is flaky on several platforms: | 111 // This test is flaky on several platforms: |
| 98 // http://crbug.com/420979 | 112 // http://crbug.com/420979 |
| 99 // http://crbug.com/421167 | 113 // http://crbug.com/421167 |
| 100 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 114 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 101 DISABLED_SingleClientEnabledEncryptionAndChanged) { | 115 DISABLED_SingleClientEnabledEncryptionAndChanged) { |
| 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 116 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 103 | 117 |
| 104 ASSERT_TRUE(CheckInitialState(0)); | 118 ASSERT_TRUE(CheckInitialState(0)); |
| 105 ASSERT_TRUE(CheckInitialState(1)); | 119 ASSERT_TRUE(CheckInitialState(1)); |
| 106 | 120 |
| 107 ScopedWindowMap client0_windows; | 121 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| 108 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | |
| 109 ASSERT_TRUE(EnableEncryption(0)); | 122 ASSERT_TRUE(EnableEncryption(0)); |
| 110 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 123 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 } | 124 } |
| 121 | 125 |
| 122 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 126 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 123 BothClientsEnabledEncryption) { | 127 BothClientsEnabledEncryption) { |
| 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 128 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 125 | 129 |
| 126 ASSERT_TRUE(CheckInitialState(0)); | 130 ASSERT_TRUE(CheckInitialState(0)); |
| 127 ASSERT_TRUE(CheckInitialState(1)); | 131 ASSERT_TRUE(CheckInitialState(1)); |
| 128 | 132 |
| 129 ASSERT_TRUE(EnableEncryption(0)); | 133 ASSERT_TRUE(EnableEncryption(0)); |
| 130 ASSERT_TRUE(EnableEncryption(1)); | 134 ASSERT_TRUE(EnableEncryption(1)); |
| 131 ASSERT_TRUE(AwaitQuiescence()); | 135 ASSERT_TRUE(AwaitQuiescence()); |
| 132 ASSERT_TRUE(IsEncryptionComplete(0)); | 136 ASSERT_TRUE(IsEncryptionComplete(0)); |
| 133 ASSERT_TRUE(IsEncryptionComplete(1)); | 137 ASSERT_TRUE(IsEncryptionComplete(1)); |
| 134 } | 138 } |
| 135 | 139 |
| 136 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { | 140 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { |
| 137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 141 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 138 | 142 |
| 139 ASSERT_TRUE(CheckInitialState(0)); | 143 ASSERT_TRUE(CheckInitialState(0)); |
| 140 ASSERT_TRUE(CheckInitialState(1)); | 144 ASSERT_TRUE(CheckInitialState(1)); |
| 141 | 145 |
| 142 // Open tabs on both clients and retain window information. | 146 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| 143 ScopedWindowMap client0_windows; | 147 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 | 148 |
| 148 // Wait for sync. | 149 WaitForForeignSessionsToSync(0, 1); |
| 149 ASSERT_TRUE(AwaitQuiescence()); | 150 WaitForForeignSessionsToSync(1, 0); |
| 150 | 151 |
| 151 // Get foreign session data from client 0 and 1. | 152 // Check that a navigation in client 0 is reflected on client 1. |
| 152 SyncedSessionVector sessions0; | 153 NavigateTab(0, GURL(kURL3)); |
| 153 SyncedSessionVector sessions1; | 154 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 } | 155 } |
| 164 | 156 |
| 165 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { | 157 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { |
| 166 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 158 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 167 | 159 |
| 168 ASSERT_TRUE(CheckInitialState(0)); | 160 ASSERT_TRUE(CheckInitialState(0)); |
| 169 ASSERT_TRUE(CheckInitialState(1)); | 161 ASSERT_TRUE(CheckInitialState(1)); |
| 170 | 162 |
| 171 // Client 0 opened some tabs then went idle. | 163 // Client 0 opened some tabs then went idle. |
| 172 ScopedWindowMap client0_windows; | 164 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| 173 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | 165 WaitForForeignSessionsToSync(0, 1); |
| 174 | |
| 175 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 176 | 166 |
| 177 // Get foreign session data from client 1. | 167 // Get foreign session data from client 1. |
| 178 SyncedSessionVector sessions1; | 168 SyncedSessionVector sessions1; |
| 179 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 169 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 180 | 170 |
| 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. | 171 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
| 186 DeleteForeignSession(1, sessions1[0]->session_tag); | 172 DeleteForeignSession(1, sessions1[0]->session_tag); |
| 187 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 173 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| 188 ASSERT_FALSE(GetSessionData(1, &sessions1)); | 174 ASSERT_FALSE(GetSessionData(1, &sessions1)); |
| 189 } | 175 } |
| 190 | 176 |
| 191 // Fails all release trybots. crbug.com/263369. | 177 // Fails all release trybots. crbug.com/263369. |
| 192 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | 178 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| 193 DeleteActiveSession) { | 179 DeleteActiveSession) { |
| 194 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 180 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 195 | 181 |
| 196 ASSERT_TRUE(CheckInitialState(0)); | 182 ASSERT_TRUE(CheckInitialState(0)); |
| 197 ASSERT_TRUE(CheckInitialState(1)); | 183 ASSERT_TRUE(CheckInitialState(1)); |
| 198 | 184 |
| 199 // Client 0 opened some tabs then went idle. | 185 // Client 0 opened some tabs then went idle. |
| 200 ScopedWindowMap client0_windows; | 186 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| 201 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); | 187 WaitForForeignSessionsToSync(0, 1); |
| 202 | 188 |
| 203 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 204 SyncedSessionVector sessions1; | 189 SyncedSessionVector sessions1; |
| 205 ASSERT_TRUE(GetSessionData(1, &sessions1)); | 190 ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| 206 ASSERT_EQ(1U, sessions1.size()); | 191 ASSERT_EQ(1U, sessions1.size()); |
| 207 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); | |
| 208 | 192 |
| 209 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. | 193 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
| 210 DeleteForeignSession(1, sessions1[0]->session_tag); | 194 DeleteForeignSession(1, sessions1[0]->session_tag); |
| 211 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 195 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| 212 ASSERT_FALSE(GetSessionData(1, &sessions1)); | 196 ASSERT_FALSE(GetSessionData(1, &sessions1)); |
| 213 | 197 |
| 214 // Client 0 becomes active again with a new tab. | 198 // Client 0 becomes active again with a new tab. |
| 215 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); | 199 ASSERT_TRUE(OpenTab(0, GURL(kURL2))); |
| 216 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 200 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 } | 201 } |
| 202 | |
| 203 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MultipleWindowsMultipleTabs) { | |
| 204 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 205 | |
| 206 ASSERT_TRUE(CheckInitialState(0)); | |
| 207 ASSERT_TRUE(CheckInitialState(1)); | |
| 208 | |
| 209 EXPECT_TRUE(OpenTab(0, GURL(kURL1))); | |
| 210 EXPECT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2))); | |
| 211 | |
| 212 // Add a second browser for profile 0. This browser ends up in index 2. | |
| 213 AddBrowser(0); | |
| 214 EXPECT_TRUE(OpenTab(2, GURL(kURL3))); | |
| 215 EXPECT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4))); | |
| 216 | |
| 217 WaitForForeignSessionsToSync(0, 1); | |
| 218 } | |
| OLD | NEW |