Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / single_client_sessions_sync_test.cc
blobe8086bb0a92041215ba35c1c5469f251537ba06b
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_vector.h"
6 #include "chrome/browser/sessions/session_service.h"
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/test/integration/sessions_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/history/core/browser/history_types.h"
14 #include "components/sessions/session_types.h"
15 #include "sync/test/fake_server/fake_server_verifier.h"
16 #include "sync/test/fake_server/sessions_hierarchy.h"
17 #include "sync/util/time.h"
19 using fake_server::SessionsHierarchy;
20 using sessions_helper::CheckInitialState;
21 using sessions_helper::GetLocalWindows;
22 using sessions_helper::GetSessionData;
23 using sessions_helper::ModelAssociatorHasTabWithUrl;
24 using sessions_helper::OpenTabAndGetLocalWindows;
25 using sessions_helper::ScopedWindowMap;
26 using sessions_helper::SessionWindowMap;
27 using sessions_helper::SyncedSessionVector;
28 using sessions_helper::WaitForTabsToLoad;
29 using sessions_helper::WindowsMatch;
30 using sync_integration_test_util::AwaitCommitActivityCompletion;
31 using typed_urls_helper::GetUrlFromClient;
33 class SingleClientSessionsSyncTest : public SyncTest {
34 public:
35 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
36 ~SingleClientSessionsSyncTest() override {}
38 private:
39 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
42 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) {
43 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
45 ASSERT_TRUE(CheckInitialState(0));
47 // Add a new session to client 0 and wait for it to sync.
48 ScopedWindowMap old_windows;
49 GURL url = GURL("http://127.0.0.1/bubba");
50 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, old_windows.GetMutable()));
51 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
53 // Get foreign session data from client 0.
54 SyncedSessionVector sessions;
55 ASSERT_FALSE(GetSessionData(0, &sessions));
56 ASSERT_EQ(0U, sessions.size());
58 // Verify client didn't change.
59 ScopedWindowMap new_windows;
60 ASSERT_TRUE(GetLocalWindows(0, new_windows.GetMutable()));
61 ASSERT_TRUE(WindowsMatch(*old_windows.Get(), *new_windows.Get()));
63 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer());
64 SessionsHierarchy expected_sessions;
65 expected_sessions.AddWindow(url.spec());
66 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
69 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) {
70 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
72 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer());
73 SessionsHierarchy expected_sessions;
74 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
77 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) {
78 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
80 ASSERT_TRUE(CheckInitialState(0));
82 // Add a new session to client 0 and wait for it to sync.
83 ScopedWindowMap old_windows;
84 ASSERT_TRUE(OpenTabAndGetLocalWindows(0,
85 GURL(chrome::kChromeUIHistoryURL),
86 old_windows.GetMutable()));
87 std::vector<GURL> urls;
88 urls.push_back(GURL(chrome::kChromeUIHistoryURL));
89 ASSERT_TRUE(WaitForTabsToLoad(0, urls));
91 // Verify the chrome history page synced.
92 ASSERT_TRUE(ModelAssociatorHasTabWithUrl(0,
93 GURL(chrome::kChromeUIHistoryURL)));
96 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
97 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
99 ASSERT_TRUE(CheckInitialState(0));
101 // We want a URL that doesn't 404 and has a non-empty title.
102 const GURL url("data:text/html,<html><title>Test</title></html>");
104 ScopedWindowMap windows;
105 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
107 int found_navigations = 0;
108 for (SessionWindowMap::const_iterator it = windows.Get()->begin();
109 it != windows.Get()->end(); ++it) {
110 for (std::vector<sessions::SessionTab*>::const_iterator it2 =
111 it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
112 for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
113 it3 = (*it2)->navigations.begin();
114 it3 != (*it2)->navigations.end(); ++it3) {
115 const base::Time timestamp = it3->timestamp();
117 history::URLRow virtual_row;
118 ASSERT_TRUE(GetUrlFromClient(0, it3->virtual_url(), &virtual_row));
119 const base::Time history_timestamp = virtual_row.last_visit();
121 ASSERT_EQ(timestamp, history_timestamp);
122 ++found_navigations;
126 ASSERT_EQ(1, found_navigations);
129 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
130 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
132 ASSERT_TRUE(CheckInitialState(0));
134 // We want a URL that doesn't 404 and has a non-empty title.
135 const GURL url("data:text/html,<html><title>Test</title></html>");
137 ScopedWindowMap windows;
138 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
140 int found_navigations = 0;
141 for (SessionWindowMap::const_iterator it = windows.Get()->begin();
142 it != windows.Get()->end(); ++it) {
143 for (std::vector<sessions::SessionTab*>::const_iterator it2 =
144 it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
145 for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
146 it3 = (*it2)->navigations.begin();
147 it3 != (*it2)->navigations.end(); ++it3) {
148 EXPECT_EQ(200, it3->http_status_code());
149 ++found_navigations;
153 ASSERT_EQ(1, found_navigations);