Index: chrome/browser/sync/test/integration/single_client_sessions_sync_test.cc |
diff --git a/chrome/browser/sync/test/integration/single_client_sessions_sync_test.cc b/chrome/browser/sync/test/integration/single_client_sessions_sync_test.cc |
index 69c51bc0f108aa593ab06e87307ff52c5bd97e41..cd7e3e3b818ccba8139a185bd611f5ae4099f299 100644 |
--- a/chrome/browser/sync/test/integration/single_client_sessions_sync_test.cc |
+++ b/chrome/browser/sync/test/integration/single_client_sessions_sync_test.cc |
@@ -17,7 +17,6 @@ |
#include "components/sessions/core/session_types.h" |
#include "components/sync/base/time.h" |
#include "components/sync/driver/sync_driver_switches.h" |
-#include "components/sync/test/fake_server/fake_server_verifier.h" |
#include "components/sync/test/fake_server/sessions_hierarchy.h" |
#if defined(OS_CHROMEOS) |
@@ -32,7 +31,13 @@ using sessions_helper::CheckInitialState; |
using sessions_helper::GetLocalWindows; |
using sessions_helper::GetSessionData; |
using sessions_helper::ModelAssociatorHasTabWithUrl; |
+using sessions_helper::MoveTab; |
+using sessions_helper::NavigateTab; |
+using sessions_helper::NavigateTabBack; |
+using sessions_helper::NavigateTabForward; |
using sessions_helper::OpenTabAndGetLocalWindows; |
+using sessions_helper::OpenTab; |
+using sessions_helper::OpenTabAtIndex; |
using sessions_helper::ScopedWindowMap; |
using sessions_helper::SessionWindowMap; |
using sessions_helper::SyncedSessionVector; |
@@ -81,6 +86,38 @@ class SingleClientSessionsSyncTest : public SyncTest { |
#endif |
} |
+ void ExpectNavigationChain(int browser_index, const std::vector<GURL> urls) { |
+ ScopedWindowMap windows; |
+ ASSERT_TRUE(GetLocalWindows(browser_index, &windows)); |
skym
2017/02/24 00:14:09
GetLocalWindows takes a profile_index. This doesn'
Patrick Noland
2017/02/24 01:00:40
Good catch. This works in practice for reasons exp
Patrick Noland
2017/02/27 18:53:26
I ended up just removing this parameter, which is
|
+ ASSERT_EQ(windows.begin()->second->tabs.size(), 1u); |
+ sessions::SessionTab* tab = windows.begin()->second->tabs[0].get(); |
+ |
+ int index = 0; |
+ EXPECT_EQ(urls.size(), tab->navigations.size()); |
+ for (auto it = tab->navigations.begin(); it != tab->navigations.end(); |
+ ++it, ++index) { |
+ EXPECT_EQ(urls[index], it->virtual_url()); |
+ } |
+ } |
+ |
+ // Block until the expected hierarchy is recorded on the FakeServer for the |
+ // profile at |profile_index|. This will time out if the hierarchy is never |
+ // recorded. |
+ void WaitForHierarchyOnServer( |
+ const fake_server::SessionsHierarchy& hierarchy) { |
+ SessionHierarchyMatchChecker checker(GetSyncService(0), hierarchy, |
+ GetFakeServer()); |
+ EXPECT_TRUE(checker.Wait()); |
+ } |
+ |
+ // Shortcut to call WaitForHierarchyOnServer for only |url| in a single |
+ // window. |
+ void WaitForURLOnServer(const GURL& url) { |
+ fake_server::SessionsHierarchy expected_hierarchy; |
+ expected_hierarchy.AddWindow(url.spec()); |
+ WaitForHierarchyOnServer(expected_hierarchy); |
+ } |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest); |
}; |
@@ -106,18 +143,13 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) { |
ASSERT_TRUE(GetLocalWindows(0, &new_windows)); |
ASSERT_TRUE(WindowsMatch(old_windows, new_windows)); |
- fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); |
- SessionsHierarchy expected_sessions; |
- expected_sessions.AddWindow(url.spec()); |
- ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions)); |
+ WaitForURLOnServer(url); |
} |
IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) { |
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
- fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); |
- SessionsHierarchy expected_sessions; |
- ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions)); |
+ WaitForHierarchyOnServer(SessionsHierarchy()); |
} |
IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) { |
@@ -129,8 +161,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) { |
ScopedWindowMap old_windows; |
ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(chrome::kChromeUIHistoryURL), |
&old_windows)); |
- std::vector<GURL> urls; |
- urls.push_back(GURL(chrome::kChromeUIHistoryURL)); |
+ std::vector<GURL> urls({GURL(chrome::kChromeUIHistoryURL)}); |
ASSERT_TRUE(WaitForTabsToLoad(0, urls)); |
skym
2017/02/24 00:14:09
Inline the whole thing!
Patrick Noland
2017/02/27 18:53:26
Done.
|
// Verify the chrome history page synced. |
@@ -194,6 +225,149 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) { |
ASSERT_EQ(1, found_navigations); |
} |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, FragmentURLNavigation) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ ScopedWindowMap windows; |
+ GURL url = GURL("http://127.0.0.1/bubba"); |
+ ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &windows)); |
+ WaitForURLOnServer(url); |
+ |
+ GURL fragment_url = GURL("http://127.0.0.1/bubba#fragment"); |
+ NavigateTab(0, fragment_url); |
+ WaitForURLOnServer(fragment_url); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, |
+ NavigationChainForwardBack) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ ScopedWindowMap windows; |
+ GURL first_url = GURL("http://127.0.0.1/foobar"); |
+ ASSERT_TRUE(OpenTabAndGetLocalWindows(0, first_url, &windows)); |
+ WaitForURLOnServer(first_url); |
+ |
+ GURL second_url = GURL("http://127.0.0.1/barbaz"); |
+ NavigateTab(0, second_url); |
+ WaitForURLOnServer(second_url); |
+ |
+ NavigateTabBack(0); |
+ WaitForURLOnServer(first_url); |
+ |
+ ExpectNavigationChain(0, {first_url, second_url}); |
+ |
+ NavigateTabForward(0); |
+ WaitForURLOnServer(second_url); |
+ |
+ ExpectNavigationChain(0, {first_url, second_url}); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, |
+ NavigationChainAlteredDestructively) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ ScopedWindowMap windows; |
+ GURL base_url = GURL("http://127.0.0.1/bubba"); |
+ ASSERT_TRUE(OpenTabAndGetLocalWindows(0, base_url, &windows)); |
+ WaitForURLOnServer(base_url); |
+ |
+ GURL first_url = GURL("http://127.0.0.1/foobar"); |
+ ASSERT_TRUE(NavigateTab(0, first_url)); |
+ WaitForURLOnServer(first_url); |
+ |
+ // Check that the navigation chain matches the above sequence of {base_url, |
+ // first_url}. |
+ ExpectNavigationChain(0, {base_url, first_url}); |
+ |
+ NavigateTabBack(0); |
+ WaitForURLOnServer(base_url); |
+ |
+ GURL second_url = GURL("http://127.0.0.1/barbaz"); |
+ NavigateTab(0, second_url); |
+ WaitForURLOnServer(second_url); |
+ |
+ NavigateTabBack(0); |
+ WaitForURLOnServer(base_url); |
+ |
+ // Check that the navigation chain contains second_url where first_url was |
+ // before. |
+ ExpectNavigationChain(0, {base_url, second_url}); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewTab) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ GURL base_url = GURL("http://127.0.0.1/bubba"); |
+ ASSERT_TRUE(OpenTabAtIndex(0, 0, base_url)); |
+ |
+ SessionsHierarchy hierarchy; |
+ hierarchy.AddWindow(base_url.spec()); |
+ WaitForHierarchyOnServer(hierarchy); |
+ |
+ GURL new_tab_url = GURL("http://127.0.0.1/foobar"); |
+ ASSERT_TRUE(OpenTabAtIndex(0, 1, new_tab_url)); |
+ |
+ SessionsHierarchy new_hierarchy; |
+ new_hierarchy.AddWindow( |
+ std::multiset<std::string>({base_url.spec(), new_tab_url.spec()})); |
skym
2017/02/24 00:14:09
Do you need to specify std::multiset<std::string>
Patrick Noland
2017/02/24 01:00:40
The compiler complains if you don't :/
skym
2017/02/24 16:20:17
But, why? Also, I don't think you need () and {} e
Patrick Noland
2017/02/27 18:53:26
This is replaced with the initializer_list now, al
|
+ WaitForHierarchyOnServer(new_hierarchy); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewWindow) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ GURL base_url = GURL("http://127.0.0.1/bubba"); |
+ ASSERT_TRUE(OpenTab(0, base_url)); |
+ |
+ SessionsHierarchy hierarchy; |
+ hierarchy.AddWindow(base_url.spec()); |
+ WaitForHierarchyOnServer(hierarchy); |
+ |
+ GURL new_window_url = GURL("http://127.0.0.1/foobar"); |
+ AddBrowser(0); |
+ ASSERT_TRUE(OpenTab(1, new_window_url)); |
+ |
+ SessionsHierarchy new_hierarchy; |
+ new_hierarchy.AddWindow({base_url.spec()}); |
skym
2017/02/24 00:14:09
Why the {}? It seems like it should do the same th
Patrick Noland
2017/02/27 18:53:26
Done.
|
+ new_hierarchy.AddWindow({new_window_url.spec()}); |
+ WaitForHierarchyOnServer(new_hierarchy); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TabMovedToOtherWindow) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ ASSERT_TRUE(CheckInitialState(0)); |
+ |
+ GURL base_url = GURL("http://127.0.0.1/bubba"); |
+ GURL moved_tab_url = GURL("http://127.0.0.1/foobar"); |
+ |
+ ASSERT_TRUE(OpenTab(0, base_url)); |
+ ASSERT_TRUE(OpenTabAtIndex(0, 1, moved_tab_url)); |
+ |
+ GURL new_window_url = GURL("http://127.0.0.1/barbaz"); |
+ AddBrowser(0); |
+ ASSERT_TRUE(OpenTab(1, new_window_url)); |
+ |
+ SessionsHierarchy hierarchy; |
+ hierarchy.AddWindow( |
+ std::multiset<std::string>({base_url.spec(), moved_tab_url.spec()})); |
+ hierarchy.AddWindow({new_window_url.spec()}); |
+ WaitForHierarchyOnServer(hierarchy); |
+ |
+ // Move tab 1 in browser 0 to browser 1. |
+ MoveTab(0, 1, 1); |
+ |
+ SessionsHierarchy changed_hierarchy; |
skym
2017/02/24 00:14:09
Doesn't this make you want to have a constructor f
Patrick Noland
2017/02/24 01:00:40
Yes it does, I'll just add that
skym
2017/02/24 16:20:17
Bonus points for making a fancy one that can take
Patrick Noland
2017/02/27 18:53:26
That requires a variadic template, which should be
|
+ changed_hierarchy.AddWindow({base_url.spec()}); |
+ changed_hierarchy.AddWindow(std::multiset<std::string>( |
+ {new_window_url.spec(), moved_tab_url.spec()})); |
+ WaitForHierarchyOnServer(changed_hierarchy); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) { |
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |