Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Side by Side Diff: components/sync_driver/revisit/sessions_page_revisit_observer_unittest.cc

Issue 1387253004: [Sync] Creating sync_sessions component, moving revisit logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing test_support target. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/sync_driver/revisit/sessions_page_revisit_observer.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/test/histogram_tester.h"
9 #include "components/sessions/core/serialized_navigation_entry.h"
10 #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
11 #include "components/sessions/core/session_types.h"
12 #include "components/sync_driver/glue/synced_session.h"
13 #include "components/sync_driver/revisit/page_visit_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h"
16
17 using sessions::SessionTab;
18 using sessions::SessionWindow;
19
20 namespace sync_driver {
21
22 namespace {
23
24 static const std::string kExampleUrl = "http://www.example.com";
25 static const std::string kDifferentUrl = "http://www.different.com";
26
27 class TestForeignSessionsProvider : public ForeignSessionsProvider {
28 public:
29 TestForeignSessionsProvider(const std::vector<const SyncedSession*>& sessions,
30 bool return_value)
31 : sessions_(sessions), return_value_(return_value) {}
32 ~TestForeignSessionsProvider() override{};
33
34 bool GetAllForeignSessions(
35 std::vector<const SyncedSession*>* sessions) override {
36 sessions->clear();
37 *sessions = sessions_;
38 return return_value_;
39 }
40
41 private:
42 const std::vector<const SyncedSession*>& sessions_;
43 const bool return_value_;
44 };
45
46 } // namespace
47
48 class SessionsPageRevisitObserverTest : public ::testing::Test {
49 protected:
50 void CheckAndExpect(SessionsPageRevisitObserver& observer,
51 const GURL& url,
52 const bool current_match,
53 const bool offset_match) {
54 base::HistogramTester histogram_tester;
55 observer.CheckForRevisit(url, PageVisitObserver::kTransitionPage);
56
57 histogram_tester.ExpectTotalCount("Sync.PageRevisitTabMatchTransition",
58 current_match ? 1 : 0);
59 histogram_tester.ExpectTotalCount("Sync.PageRevisitTabMissTransition",
60 current_match ? 0 : 1);
61 histogram_tester.ExpectTotalCount(
62 "Sync.PageRevisitNavigationMatchTransition", offset_match ? 1 : 0);
63 histogram_tester.ExpectTotalCount(
64 "Sync.PageRevisitNavigationMissTransition", offset_match ? 0 : 1);
65 histogram_tester.ExpectTotalCount("Sync.PageRevisitSessionDuration", 1);
66 }
67
68 void CheckAndExpect(const SyncedSession* session,
69 const GURL& url,
70 const bool current_match,
71 const bool offset_match) {
72 std::vector<const SyncedSession*> sessions;
73 sessions.push_back(session);
74 SessionsPageRevisitObserver observer(
75 make_scoped_ptr(new TestForeignSessionsProvider(sessions, true)));
76 CheckAndExpect(observer, url, current_match, offset_match);
77 }
78 };
79
80 TEST_F(SessionsPageRevisitObserverTest, RunMatchersNoSessions) {
81 std::vector<const SyncedSession*> sessions;
82 SessionsPageRevisitObserver observer(
83 make_scoped_ptr(new TestForeignSessionsProvider(sessions, true)));
84 CheckAndExpect(observer, GURL(kExampleUrl), false, false);
85 }
86
87 TEST_F(SessionsPageRevisitObserverTest, RunMatchersNoWindows) {
88 scoped_ptr<SyncedSession> session(new SyncedSession());
89 CheckAndExpect(session.get(), GURL(kExampleUrl), false, false);
90 }
91
92 TEST_F(SessionsPageRevisitObserverTest, RunMatchersNoTabs) {
93 scoped_ptr<SyncedSession> session(new SyncedSession());
94 session->windows[0] = new SessionWindow();
95 CheckAndExpect(session.get(), GURL(kExampleUrl), false, false);
96 }
97
98 TEST_F(SessionsPageRevisitObserverTest, RunMatchersNoEntries) {
99 scoped_ptr<SessionWindow> window(new SessionWindow());
100 window->tabs.push_back(new SessionTab());
101 scoped_ptr<SyncedSession> session(new SyncedSession());
102 session->windows[0] = window.release();
103 CheckAndExpect(session.get(), GURL(kExampleUrl), false, false);
104 }
105
106 TEST_F(SessionsPageRevisitObserverTest, RunMatchersSingle) {
107 scoped_ptr<SessionTab> tab(new SessionTab());
108 tab->navigations.push_back(
109 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
110 kExampleUrl, ""));
111 tab->current_navigation_index = 0;
112 scoped_ptr<SessionWindow> window(new SessionWindow());
113 window->tabs.push_back(tab.release());
114 scoped_ptr<SyncedSession> session(new SyncedSession());
115 session->windows[0] = window.release();
116 CheckAndExpect(session.get(), GURL(kExampleUrl), true, false);
117 }
118
119 TEST_F(SessionsPageRevisitObserverTest, RunMatchersFalseProvider) {
120 scoped_ptr<SessionTab> tab(new SessionTab());
121 tab->navigations.push_back(
122 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
123 kExampleUrl, ""));
124 tab->navigations.push_back(
125 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
126 kExampleUrl, ""));
127 tab->current_navigation_index = 1;
128 scoped_ptr<SessionWindow> window(new SessionWindow());
129 window->tabs.push_back(tab.release());
130 scoped_ptr<SyncedSession> session(new SyncedSession());
131 session->windows[0] = window.release();
132
133 // The provider returns false when asked for foreign sessions, even though
134 // it has has a valid tab.
135 std::vector<const SyncedSession*> sessions;
136 sessions.push_back(session.get());
137 SessionsPageRevisitObserver observer(
138 make_scoped_ptr(new TestForeignSessionsProvider(sessions, false)));
139 CheckAndExpect(observer, GURL(kExampleUrl), false, false);
140 }
141
142 TEST_F(SessionsPageRevisitObserverTest, RunMatchersMany) {
143 scoped_ptr<SessionTab> tab1(new SessionTab());
144 tab1->navigations.push_back(
145 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
146 kExampleUrl, ""));
147 tab1->current_navigation_index = 0;
148
149 scoped_ptr<SessionTab> tab2(new SessionTab());
150 tab2->navigations.push_back(
151 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
152 kDifferentUrl, ""));
153 tab2->current_navigation_index = 0;
154
155 scoped_ptr<SessionTab> tab3(new SessionTab());
156 tab3->navigations.push_back(
157 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
158 kDifferentUrl, ""));
159 tab3->current_navigation_index = 0;
160
161 scoped_ptr<SessionTab> tab4(new SessionTab());
162 tab4->navigations.push_back(
163 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
164 kExampleUrl, ""));
165 tab4->navigations.push_back(
166 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
167 kDifferentUrl, ""));
168 tab4->current_navigation_index = 1;
169
170 scoped_ptr<SessionWindow> window1(new SessionWindow());
171 window1->tabs.push_back(tab1.release());
172 scoped_ptr<SessionWindow> window2(new SessionWindow());
173 window2->tabs.push_back(tab2.release());
174 scoped_ptr<SessionWindow> window3(new SessionWindow());
175 window3->tabs.push_back(tab3.release());
176 window3->tabs.push_back(tab4.release());
177
178 scoped_ptr<SyncedSession> session1(new SyncedSession());
179 session1->windows[1] = window1.release();
180 scoped_ptr<SyncedSession> session2(new SyncedSession());
181 session2->windows[2] = window2.release();
182 session2->windows[3] = window3.release();
183
184 std::vector<const SyncedSession*> sessions;
185 sessions.push_back(session1.get());
186 sessions.push_back(session2.get());
187 SessionsPageRevisitObserver observer(
188 make_scoped_ptr(new TestForeignSessionsProvider(sessions, true)));
189
190 base::HistogramTester histogram_tester;
191 CheckAndExpect(observer, GURL(kExampleUrl), true, true);
192 }
193
194 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync_driver/revisit/sessions_page_revisit_observer.cc ('k') | components/sync_sessions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698