Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3484)

Unified Diff: chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc

Issue 2725813003: reland of [sync] Add Sessions integration tests (Closed)
Patch Set: Switch back to WaitForURLOnServer, make everything a constant Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..483c49528e9b7bc093244b7fabf3e6a711c0413c 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,28 @@ class TwoClientSessionsSyncTest : public SyncTest {
TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientSessionsSyncTest() override {}
+ void WaitForWindowsInForeignSession(int index, ScopedWindowMap windows) {
+ std::vector<ScopedWindowMap> expected_windows;
+ expected_windows.push_back(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";
-static const char* kURL2 = "http://127.0.0.1/bubba2";
+static const char* kURL1 = "data:text/html,<html><title>Test</title></html>";
+static const char* kURL2 = "data:text/html,<html><title>Test2</title></html>";
+static const char* kURL3 = "data:text/html,<html><title>Test3</title></html>";
+static const char* kURL4 = "data:text/html,<html><title>Test4</title></html>";
+static const char* kURLTemplate =
+ "data:text/html,<html><title>Test%s</title></html>";
// TODO(zea): Test each individual session command we care about separately.
// (as well as multi-window). We're currently only checking basic single-window/
@@ -48,16 +66,11 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
// Open tab and access a url on client 0
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);
+ std::string url =
+ base::StringPrintf(kURLTemplate, base::GenerateGUID().c_str());
- // 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,
@@ -68,9 +81,10 @@ IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
std::vector<ScopedWindowMap> client_windows(num_clients());
for (int i = 0; i < num_clients(); ++i) {
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));
+ std::string url =
+ base::StringPrintf(kURLTemplate, base::GenerateGUID().c_str());
+ ASSERT_TRUE(OpenTab(i, GURL(url)));
+ ASSERT_TRUE(GetLocalWindows(i, &windows));
client_windows[i] = std::move(windows);
}
@@ -104,19 +118,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 +143,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 +161,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 +183,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 +196,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));
+
+ EXPECT_TRUE(OpenTab(0, GURL(kURL1)));
+ EXPECT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2)));
+
+ // Add a second browser for profile 0. This browser ends up in index 2.
+ AddBrowser(0);
+ EXPECT_TRUE(OpenTab(2, GURL(kURL3)));
+ EXPECT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4)));
+
+ WaitForForeignSessionsToSync(0, 1);
}
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698