Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / single_client_sessions_sync_test.cc
blob06aeee36710b9b28c79a4d3f1f9438ca39107f9a
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.
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/test/integration/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"
15 using sessions_helper::CheckInitialState;
16 using sessions_helper::GetLocalWindows;
17 using sessions_helper::GetSessionData;
18 using sessions_helper::OpenTabAndGetLocalWindows;
19 using sessions_helper::ScopedWindowMap;
20 using sessions_helper::SessionWindowMap;
21 using sessions_helper::SyncedSessionVector;
22 using sessions_helper::WindowsMatch;
23 using typed_urls_helper::GetUrlFromClient;
25 class SingleClientSessionsSyncTest : public SyncTest {
26 public:
27 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
28 virtual ~SingleClientSessionsSyncTest() {}
30 private:
31 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
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
41 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, MAYBE_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 ASSERT_TRUE(OpenTabAndGetLocalWindows(0,
49 GURL("http://127.0.0.1/bubba"),
50 old_windows.GetMutable()));
51 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
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()));
64 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
67 ASSERT_TRUE(CheckInitialState(0));
69 // We want a URL that doesn't 404 and has a non-empty title.
70 // about:version is simple to render, too.
71 const GURL url("about:version");
73 ScopedWindowMap windows;
74 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
76 int found_navigations = 0;
77 for (SessionWindowMap::const_iterator it = windows.Get()->begin();
78 it != windows.Get()->end(); ++it) {
79 for (std::vector<SessionTab*>::const_iterator it2 =
80 it->second->tabs.begin(); it2 != it->second->tabs.end(); ++it2) {
81 for (std::vector<sessions::SerializedNavigationEntry>::const_iterator
82 it3 = (*it2)->navigations.begin();
83 it3 != (*it2)->navigations.end(); ++it3) {
84 const base::Time timestamp = it3->timestamp();
86 history::URLRow virtual_row;
87 ASSERT_TRUE(GetUrlFromClient(0, it3->virtual_url(), &virtual_row));
88 const base::Time history_timestamp = virtual_row.last_visit();
90 ASSERT_EQ(timestamp, history_timestamp);
91 ++found_navigations;
95 ASSERT_EQ(1, found_navigations);
98 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
99 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
101 ASSERT_TRUE(CheckInitialState(0));
103 // We want a URL that doesn't 404 and has a non-empty title.
104 // about:version is simple to render, too.
105 const GURL url("about:version");
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<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());
119 ++found_navigations;
123 ASSERT_EQ(1, found_navigations);