Chromium Code Reviews| Index: chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc |
| diff --git a/chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc b/chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc |
| index da1f810df7a63d3c650b7f075a315d86e4dc50b8..842fd6638b98a180c552640a5eb10fb22fb4a339 100644 |
| --- a/chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc |
| +++ b/chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc |
| @@ -19,7 +19,9 @@ using sessions_helper::CheckInitialState; |
| using sessions_helper::DeleteForeignSession; |
| using sessions_helper::GetLocalWindows; |
| using sessions_helper::GetSessionData; |
| -using sessions_helper::OpenTabAndGetLocalWindows; |
| +using sessions_helper::NavigateTab; |
| +using sessions_helper::OpenTab; |
| +using sessions_helper::OpenTabAtIndex; |
| using sessions_helper::ScopedWindowMap; |
| using sessions_helper::SessionWindowMap; |
| using sessions_helper::SyncedSessionVector; |
| @@ -30,12 +32,26 @@ class TwoClientSessionsSyncTest : public SyncTest { |
| TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} |
| ~TwoClientSessionsSyncTest() override {} |
| + void WaitForWindowsInForeignSession(int index, ScopedWindowMap windows) { |
| + std::vector<ScopedWindowMap> expected_windows(1); |
|
skym
2017/02/27 19:42:50
I think still push_back is more clean than this pa
Patrick Noland
2017/02/27 23:37:07
Done.
|
| + expected_windows[0] = std::move(windows); |
| + EXPECT_TRUE(ForeignSessionsMatchChecker(index, expected_windows).Wait()); |
| + } |
| + |
| + void WaitForForeignSessionsToSync(int local_index, int non_local_index) { |
| + ScopedWindowMap client_windows; |
| + ASSERT_TRUE(GetLocalWindows(local_index, &client_windows)); |
| + WaitForWindowsInForeignSession(non_local_index, std::move(client_windows)); |
| + } |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); |
| }; |
| static const char* kURL1 = "http://127.0.0.1/bubba1"; |
|
skym
2017/02/27 19:42:50
kinda odd how the one client test doesn't use cons
Patrick Noland
2017/02/27 23:37:08
Agreed
|
| static const char* kURL2 = "http://127.0.0.1/bubba2"; |
| +static const char* kURL3 = "http://127.0.0.1/foobar"; |
| +static const char* kURL4 = "http://127.0.0.1/barbaz"; |
| // TODO(zea): Test each individual session command we care about separately. |
| // (as well as multi-window). We're currently only checking basic single-window/ |
| @@ -50,14 +66,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| ScopedWindowMap client0_windows; |
| std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", |
| base::GenerateGUID().c_str()); |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows)); |
| - |
| - // Retain the window information on client 0 |
| - std::vector<ScopedWindowMap> expected_windows(1); |
| - expected_windows[0] = std::move(client0_windows); |
| - // Check the foreign windows on client 1 |
| - ASSERT_TRUE(ForeignSessionsMatchChecker(1, expected_windows).Wait()); |
| + ASSERT_TRUE(OpenTab(0, GURL(url))); |
| + WaitForForeignSessionsToSync(0, 1); |
| } |
| IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| @@ -70,7 +81,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| ScopedWindowMap windows; |
| std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", |
| base::GenerateGUID().c_str()); |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(i, GURL(url), &windows)); |
| + ASSERT_TRUE(OpenTab(i, GURL(url))); |
| + ASSERT_TRUE(GetLocalWindows(i, &windows)); |
| client_windows[i] = std::move(windows); |
| } |
| @@ -104,19 +116,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| ASSERT_TRUE(CheckInitialState(0)); |
| ASSERT_TRUE(CheckInitialState(1)); |
| - ScopedWindowMap client0_windows; |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| ASSERT_TRUE(EnableEncryption(0)); |
| - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| - |
| - // Get foreign session data from client 1. |
| - ASSERT_TRUE(IsEncryptionComplete(1)); |
| - SyncedSessionVector sessions1; |
| - ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| - |
| - // Verify client 1's foreign session matches client 0 current window. |
| - ASSERT_EQ(1U, sessions1.size()); |
| - ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); |
| + WaitForForeignSessionsToSync(0, 1); |
| } |
| IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| @@ -139,27 +141,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { |
| ASSERT_TRUE(CheckInitialState(0)); |
| ASSERT_TRUE(CheckInitialState(1)); |
| - // Open tabs on both clients and retain window information. |
| - ScopedWindowMap client0_windows; |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); |
| - ScopedWindowMap client1_windows; |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), &client1_windows)); |
| - |
| - // Wait for sync. |
| - ASSERT_TRUE(AwaitQuiescence()); |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| + ASSERT_TRUE(OpenTab(1, GURL(kURL2))); |
| - // Get foreign session data from client 0 and 1. |
| - SyncedSessionVector sessions0; |
| - SyncedSessionVector sessions1; |
| - ASSERT_TRUE(GetSessionData(0, &sessions0)); |
| - ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| + WaitForForeignSessionsToSync(0, 1); |
| + WaitForForeignSessionsToSync(1, 0); |
| - // Verify client 1's foreign session matches client 0's current window and |
| - // vice versa. |
| - ASSERT_EQ(1U, sessions0.size()); |
| - ASSERT_EQ(1U, sessions1.size()); |
| - ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); |
| - ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows)); |
| + // Check that a navigation in client 0 is reflected on client 1. |
| + NavigateTab(0, GURL(kURL3)); |
| + WaitForForeignSessionsToSync(0, 1); |
| } |
| IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { |
| @@ -169,19 +159,13 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { |
| ASSERT_TRUE(CheckInitialState(1)); |
| // Client 0 opened some tabs then went idle. |
| - ScopedWindowMap client0_windows; |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); |
| - |
| - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| + WaitForForeignSessionsToSync(0, 1); |
| // Get foreign session data from client 1. |
| SyncedSessionVector sessions1; |
| ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| - // Verify client 1's foreign session matches client 0 current window. |
| - ASSERT_EQ(1U, sessions1.size()); |
| - ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); |
| - |
| // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
| DeleteForeignSession(1, sessions1[0]->session_tag); |
| ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
| @@ -197,14 +181,12 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| ASSERT_TRUE(CheckInitialState(1)); |
| // Client 0 opened some tabs then went idle. |
| - ScopedWindowMap client0_windows; |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| + WaitForForeignSessionsToSync(0, 1); |
| - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| SyncedSessionVector sessions1; |
| ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| ASSERT_EQ(1U, sessions1.size()); |
| - ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); |
| // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. |
| DeleteForeignSession(1, sessions1[0]->session_tag); |
| @@ -212,9 +194,23 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, |
| ASSERT_FALSE(GetSessionData(1, &sessions1)); |
| // Client 0 becomes active again with a new tab. |
| - ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); |
| - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| - ASSERT_TRUE(GetSessionData(1, &sessions1)); |
| - ASSERT_EQ(1U, sessions1.size()); |
| - ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows)); |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL2))); |
| + WaitForForeignSessionsToSync(0, 1); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MultipleWindowsMultipleTabs) { |
| + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| + |
| + ASSERT_TRUE(CheckInitialState(0)); |
| + ASSERT_TRUE(CheckInitialState(1)); |
| + |
| + ASSERT_TRUE(OpenTab(0, GURL(kURL1))); |
| + ASSERT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2))); |
| + |
| + // Add a second browser for profile 0. This browser ends up in index 2. |
| + AddBrowser(0); |
| + ASSERT_TRUE(OpenTab(2, GURL(kURL3))); |
| + ASSERT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4))); |
|
skym
2017/02/27 19:42:50
Still feels like a lot of assert that could be exp
Patrick Noland
2017/02/27 23:37:07
Sometimes yes, although there are cases where if t
|
| + |
| + WaitForForeignSessionsToSync(0, 1); |
| } |