Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / single_client_sessions_sync_test.cc
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/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"
14
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;
24
25 class 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
41 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, MAYBE_Sanity) {
42   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
43
44   ASSERT_TRUE(CheckInitialState(0));
45
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)->AwaitCommitActivityCompletion());
52
53   // Get foreign session data from client 0.
54   SyncedSessionVector sessions;
55   ASSERT_FALSE(GetSessionData(0, &sessions));
56   ASSERT_EQ(0U, sessions.size());
57
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()));
62 }
63
64 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
65   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
66
67   ASSERT_TRUE(CheckInitialState(0));
68
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");
72
73   ScopedWindowMap windows;
74   ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
75
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();
85
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();
89
90         ASSERT_EQ(timestamp, history_timestamp);
91         ++found_navigations;
92       }
93     }
94   }
95   ASSERT_EQ(1, found_navigations);
96 }
97
98 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
99   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
100
101   ASSERT_TRUE(CheckInitialState(0));
102
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");
106
107   ScopedWindowMap windows;
108   ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, windows.GetMutable()));
109
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;
120       }
121     }
122   }
123   ASSERT_EQ(1, found_navigations);
124 }