Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / single_client_sessions_sync_test.cc
blob9ecf4f2191460cc32b72b2db0b541d57dbd2688e
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 "chrome/browser/sessions/session_service.h"
6 #include "chrome/browser/sync/profile_sync_service.h"
7 #include "chrome/browser/sync/test/integration/sessions_helper.h"
8 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
10 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
11 #include "chrome/common/url_constants.h"
12 #include "components/history/core/browser/history_types.h"
13 #include "components/sessions/session_types.h"
14 #include "sync/test/fake_server/fake_server_verifier.h"
15 #include "sync/test/fake_server/sessions_hierarchy.h"
16 #include "sync/util/time.h"
18 using fake_server::SessionsHierarchy;
19 using sessions_helper::CheckInitialState;
20 using sessions_helper::GetLocalWindows;
21 using sessions_helper::GetSessionData;
22 using sessions_helper::ModelAssociatorHasTabWithUrl;
23 using sessions_helper::OpenTabAndGetLocalWindows;
24 using sessions_helper::ScopedWindowMap;
25 using sessions_helper::SessionWindowMap;
26 using sessions_helper::SyncedSessionVector;
27 using sessions_helper::WaitForTabsToLoad;
28 using sessions_helper::WindowsMatch;
29 using sync_integration_test_util::AwaitCommitActivityCompletion;
30 using typed_urls_helper::GetUrlFromClient;
32 class SingleClientSessionsSyncTest : public SyncTest {
33 public:
34 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
35 ~SingleClientSessionsSyncTest() override {}
37 private:
38 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
41 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) {
42 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
44 ASSERT_TRUE(CheckInitialState(0));
46 // Add a new session to client 0 and wait for it to sync.
47 ScopedWindowMap old_windows;
48 GURL url = GURL("http://127.0.0.1/bubba");
49 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, old_windows.GetMutable()));
50 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
52 // Get foreign session data from client 0.
53 SyncedSessionVector sessions;
54 ASSERT_FALSE(GetSessionData(0, &sessions));
55 ASSERT_EQ(0U, sessions.size());
57 // Verify client didn't change.
58 ScopedWindowMap new_windows;
59 ASSERT_TRUE(GetLocalWindows(0, new_windows.GetMutable()));
60 ASSERT_TRUE(WindowsMatch(*old_windows.Get(), *new_windows.Get()));
62 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer());
63 SessionsHierarchy expected_sessions;
64 expected_sessions.AddWindow(url.spec());
65 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
68 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) {
69 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
71 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer());
72 SessionsHierarchy expected_sessions;
73 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
76 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) {
77 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
79 ASSERT_TRUE(CheckInitialState(0));
81 // Add a new session to client 0 and wait for it to sync.
82 ScopedWindowMap old_windows;
83 ASSERT_TRUE(OpenTabAndGetLocalWindows(0,
84 GURL(chrome::kChromeUIHistoryURL),
85 old_windows.GetMutable()));
86 std::vector<GURL> urls;
87 urls.push_back(GURL(chrome::kChromeUIHistoryURL));
88 ASSERT_TRUE(WaitForTabsToLoad(0, urls));
90 // Verify the chrome history page synced.
91 ASSERT_TRUE(ModelAssociatorHasTabWithUrl(0,
92 GURL(chrome::kChromeUIHistoryURL)));
95 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
96 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
98 ASSERT_TRUE(CheckInitialState(0));
100 // We want a URL that doesn't 404 and has a non-empty title.
101 const GURL url("data:text/html,<html><title>Test</title></html>");
103 ScopedWindowMap windows;
104 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
106 int found_navigations = 0;
107 for (SessionWindowMap::const_iterator it = windows.Get()->begin();
108 it != windows.Get()->end(); ++it) {
109 for (std::vector<sessions::SessionTab*>::const_iterator it2 =
110 it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
111 for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
112 it3 = (*it2)->navigations.begin();
113 it3 != (*it2)->navigations.end(); ++it3) {
114 const base::Time timestamp = it3->timestamp();
116 history::URLRow virtual_row;
117 ASSERT_TRUE(GetUrlFromClient(0, it3->virtual_url(), &virtual_row));
118 const base::Time history_timestamp = virtual_row.last_visit();
120 ASSERT_EQ(timestamp, history_timestamp);
121 ++found_navigations;
125 ASSERT_EQ(1, found_navigations);
128 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
129 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
131 ASSERT_TRUE(CheckInitialState(0));
133 // We want a URL that doesn't 404 and has a non-empty title.
134 const GURL url("data:text/html,<html><title>Test</title></html>");
136 ScopedWindowMap windows;
137 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
139 int found_navigations = 0;
140 for (SessionWindowMap::const_iterator it = windows.Get()->begin();
141 it != windows.Get()->end(); ++it) {
142 for (std::vector<sessions::SessionTab*>::const_iterator it2 =
143 it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
144 for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
145 it3 = (*it2)->navigations.begin();
146 it3 != (*it2)->navigations.end(); ++it3) {
147 EXPECT_EQ(200, it3->http_status_code());
148 ++found_navigations;
152 ASSERT_EQ(1, found_navigations);