single_client_sessions_sync_test.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
1// Copyright (c) 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.
4
5#include "base/memory/scoped_vector.h"
6#include "chrome/browser/history/history_types.h"
7#include "chrome/browser/sessions/session_service.h"
8#include "chrome/browser/sessions/session_types.h"
9#include "chrome/browser/sync/profile_sync_service_harness.h"
10#include "chrome/browser/sync/test/integration/sessions_helper.h"
11#include "chrome/browser/sync/test/integration/sync_test.h"
12#include "chrome/browser/sync/test/integration/typed_urls_helper.h"
13#include "sync/util/time.h"
14
15using sessions_helper::CheckInitialState;
16using sessions_helper::GetLocalWindows;
17using sessions_helper::GetSessionData;
18using sessions_helper::OpenTabAndGetLocalWindows;
19using sessions_helper::ScopedWindowMap;
20using sessions_helper::SessionWindowMap;
21using sessions_helper::SyncedSessionVector;
22using sessions_helper::WindowsMatch;
23using typed_urls_helper::GetUrlFromClient;
24
25class SingleClientSessionsSyncTest : public SyncTest {
26 public:
27  SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
28  virtual ~SingleClientSessionsSyncTest() {}
29
30 private:
31  DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
32};
33
34// Timeout on Windows, see http://crbug.com/99819
35#if defined(OS_WIN)
36#define MAYBE_Sanity DISABLED_Sanity
37#else
38#define MAYBE_Sanity Sanity
39#endif
40
41IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, MAYBE_Sanity) {
42  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
43
44  ASSERT_TRUE(CheckInitialState(0));
45
46  ScopedWindowMap old_windows;
47  ASSERT_TRUE(OpenTabAndGetLocalWindows(0,
48                                        GURL("http://127.0.0.1/bubba"),
49                                        old_windows.GetMutable()));
50
51  ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion(
52      "Waiting for session change."));
53
54  // Get foreign session data from client 0.
55  SyncedSessionVector sessions;
56  ASSERT_FALSE(GetSessionData(0, &sessions));
57  ASSERT_EQ(0U, sessions.size());
58
59  // Verify client didn't change.
60  ScopedWindowMap new_windows;
61  ASSERT_TRUE(GetLocalWindows(0, new_windows.GetMutable()));
62  ASSERT_TRUE(WindowsMatch(*old_windows.Get(), *new_windows.Get()));
63}
64
65IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
66  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
67
68  ASSERT_TRUE(CheckInitialState(0));
69
70  // We want a URL that doesn't 404 and has a non-empty title.
71  // about:version is simple to render, too.
72  const GURL url("about:version");
73
74  ScopedWindowMap windows;
75  ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
76
77  int found_navigations = 0;
78  for (SessionWindowMap::const_iterator it = windows.Get()->begin();
79       it != windows.Get()->end(); ++it) {
80    for (std::vector<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();
86
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();
90
91        ASSERT_EQ(timestamp, history_timestamp);
92        ++found_navigations;
93      }
94    }
95  }
96  ASSERT_EQ(1, found_navigations);
97}
98
99IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
100  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
101
102  ASSERT_TRUE(CheckInitialState(0));
103
104  // We want a URL that doesn't 404 and has a non-empty title.
105  // about:version is simple to render, too.
106  const GURL url("about:version");
107
108  ScopedWindowMap windows;
109  ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
110
111  int found_navigations = 0;
112  for (SessionWindowMap::const_iterator it = windows.Get()->begin();
113       it != windows.Get()->end(); ++it) {
114    for (std::vector<SessionTab*>::const_iterator it2 =
115             it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
116      for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
117               it3 = (*it2)->navigations.begin();
118           it3 != (*it2)->navigations.end(); ++it3) {
119        EXPECT_EQ(200, it3->http_status_code());
120        ++found_navigations;
121      }
122    }
123  }
124  ASSERT_EQ(1, found_navigations);
125}
126