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 "components/history/core/browser/history_types.h"
13 #include "components/sessions/session_types.h"
14 #include "sync/util/time.h"
16 using sessions_helper::CheckInitialState
;
17 using sessions_helper::GetLocalWindows
;
18 using sessions_helper::GetSessionData
;
19 using sessions_helper::OpenTabAndGetLocalWindows
;
20 using sessions_helper::ScopedWindowMap
;
21 using sessions_helper::SessionWindowMap
;
22 using sessions_helper::SyncedSessionVector
;
23 using sessions_helper::WindowsMatch
;
24 using sync_integration_test_util::AwaitCommitActivityCompletion
;
25 using typed_urls_helper::GetUrlFromClient
;
27 class SingleClientSessionsSyncTest
: public SyncTest
{
29 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT
) {}
30 ~SingleClientSessionsSyncTest() override
{}
33 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest
);
36 // Timeout on Windows, see http://crbug.com/99819
38 #define MAYBE_Sanity DISABLED_Sanity
40 #define MAYBE_Sanity Sanity
43 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest
, MAYBE_Sanity
) {
44 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
46 ASSERT_TRUE(CheckInitialState(0));
48 // Add a new session to client 0 and wait for it to sync.
49 ScopedWindowMap old_windows
;
50 ASSERT_TRUE(OpenTabAndGetLocalWindows(0,
51 GURL("http://127.0.0.1/bubba"),
52 old_windows
.GetMutable()));
53 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
55 // Get foreign session data from client 0.
56 SyncedSessionVector sessions
;
57 ASSERT_FALSE(GetSessionData(0, &sessions
));
58 ASSERT_EQ(0U, sessions
.size());
60 // Verify client didn't change.
61 ScopedWindowMap new_windows
;
62 ASSERT_TRUE(GetLocalWindows(0, new_windows
.GetMutable()));
63 ASSERT_TRUE(WindowsMatch(*old_windows
.Get(), *new_windows
.Get()));
66 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest
, TimestampMatchesHistory
) {
67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
69 ASSERT_TRUE(CheckInitialState(0));
71 // We want a URL that doesn't 404 and has a non-empty title.
72 const GURL
url("data:text/html,<html><title>Test</title></html>");
74 ScopedWindowMap windows
;
75 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url
, windows
.GetMutable()));
77 int found_navigations
= 0;
78 for (SessionWindowMap::const_iterator it
= windows
.Get()->begin();
79 it
!= windows
.Get()->end(); ++it
) {
80 for (std::vector
<sessions::SessionTab
*>::const_iterator it2
=
81 it
->second
->tabs
.begin(); it2
!= it
->second
->tabs
.end(); ++it2
) {
82 for (std::vector
<sessions::SerializedNavigationEntry
>::const_iterator
83 it3
= (*it2
)->navigations
.begin();
84 it3
!= (*it2
)->navigations
.end(); ++it3
) {
85 const base::Time timestamp
= it3
->timestamp();
87 history::URLRow virtual_row
;
88 ASSERT_TRUE(GetUrlFromClient(0, it3
->virtual_url(), &virtual_row
));
89 const base::Time history_timestamp
= virtual_row
.last_visit();
91 ASSERT_EQ(timestamp
, history_timestamp
);
96 ASSERT_EQ(1, found_navigations
);
99 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest
, ResponseCodeIsPreserved
) {
100 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
102 ASSERT_TRUE(CheckInitialState(0));
104 // We want a URL that doesn't 404 and has a non-empty title.
105 const GURL
url("data:text/html,<html><title>Test</title></html>");
107 ScopedWindowMap windows
;
108 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url
, windows
.GetMutable()));
110 int found_navigations
= 0;
111 for (SessionWindowMap::const_iterator it
= windows
.Get()->begin();
112 it
!= windows
.Get()->end(); ++it
) {
113 for (std::vector
<sessions::SessionTab
*>::const_iterator it2
=
114 it
->second
->tabs
.begin(); it2
!= it
->second
->tabs
.end(); ++it2
) {
115 for (std::vector
<sessions::SerializedNavigationEntry
>::const_iterator
116 it3
= (*it2
)->navigations
.begin();
117 it3
!= (*it2
)->navigations
.end(); ++it3
) {
118 EXPECT_EQ(200, it3
->http_status_code());
123 ASSERT_EQ(1, found_navigations
);