| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync_sessions/sync_sessions_metrics.h" | 5 #include "components/sync_sessions/sync_sessions_metrics.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
| 8 | 9 |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "components/sessions/core/session_types.h" | 13 #include "components/sessions/core/session_types.h" |
| 13 #include "components/sync_sessions/fake_sync_sessions_client.h" | 14 #include "components/sync_sessions/fake_sync_sessions_client.h" |
| 14 #include "components/sync_sessions/sessions_sync_manager.h" | 15 #include "components/sync_sessions/sessions_sync_manager.h" |
| 15 #include "components/sync_sessions/synced_session.h" | 16 #include "components/sync_sessions/synced_session.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using sync_driver::SyncedSession; | |
| 19 using sessions::SessionWindow; | 19 using sessions::SessionWindow; |
| 20 using sessions::SessionTab; | 20 using sessions::SessionTab; |
| 21 using base::Time; | 21 using base::Time; |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace sync_sessions { | 24 namespace sync_sessions { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class FakeSessionsSyncManager : public browser_sync::SessionsSyncManager { | 28 class FakeSessionsSyncManager : public SessionsSyncManager { |
| 29 public: | 29 public: |
| 30 FakeSessionsSyncManager(SyncSessionsClient* sessions_client, | 30 FakeSessionsSyncManager(SyncSessionsClient* sessions_client, |
| 31 std::vector<std::unique_ptr<SyncedSession>>* sessions) | 31 std::vector<std::unique_ptr<SyncedSession>>* sessions) |
| 32 : browser_sync::SessionsSyncManager(sessions_client, | 32 : SessionsSyncManager(sessions_client, |
| 33 nullptr, | 33 nullptr, |
| 34 nullptr, | 34 nullptr, |
| 35 nullptr, | 35 nullptr, |
| 36 base::Closure(), | 36 base::Closure(), |
| 37 base::Closure()), | 37 base::Closure()), |
| 38 sessions_(sessions) {} | 38 sessions_(sessions) {} |
| 39 | 39 |
| 40 bool GetAllForeignSessions( | 40 bool GetAllForeignSessions( |
| 41 std::vector<const sync_driver::SyncedSession*>* sessions) override { | 41 std::vector<const SyncedSession*>* sessions) override { |
| 42 for (auto& session : *sessions_) { | 42 for (auto& session : *sessions_) { |
| 43 sessions->push_back(session.get()); | 43 sessions->push_back(session.get()); |
| 44 } | 44 } |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 std::vector<std::unique_ptr<SyncedSession>>* sessions_; | 49 std::vector<std::unique_ptr<SyncedSession>>* sessions_; |
| 50 }; | 50 }; |
| 51 | 51 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 // Runs MaxTabTimestamp on the current sessions data. | 96 // Runs MaxTabTimestamp on the current sessions data. |
| 97 Time MaxTabTimestamp() { | 97 Time MaxTabTimestamp() { |
| 98 std::vector<const SyncedSession*> typed_sessions; | 98 std::vector<const SyncedSession*> typed_sessions; |
| 99 for (auto& session : sessions_) { | 99 for (auto& session : sessions_) { |
| 100 typed_sessions.push_back(session.get()); | 100 typed_sessions.push_back(session.get()); |
| 101 } | 101 } |
| 102 return SyncSessionsMetrics::MaxTabTimestamp(typed_sessions); | 102 return SyncSessionsMetrics::MaxTabTimestamp(typed_sessions); |
| 103 } | 103 } |
| 104 | 104 |
| 105 browser_sync::SessionsSyncManager* get_sessions_sync_manager() { | 105 SessionsSyncManager* get_sessions_sync_manager() { return &fake_manager_; } |
| 106 return &fake_manager_; | |
| 107 } | |
| 108 | 106 |
| 109 private: | 107 private: |
| 110 std::vector<std::unique_ptr<SyncedSession>> sessions_; | 108 std::vector<std::unique_ptr<SyncedSession>> sessions_; |
| 111 FakeSyncSessionsClient fake_client_; | 109 FakeSyncSessionsClient fake_client_; |
| 112 FakeSessionsSyncManager fake_manager_; | 110 FakeSessionsSyncManager fake_manager_; |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 TEST_F(SyncSessionsMetricsTest, NoWindows) { | 113 TEST_F(SyncSessionsMetricsTest, NoWindows) { |
| 116 ASSERT_EQ(Time::UnixEpoch(), MaxTabTimestamp()); | 114 ASSERT_EQ(Time::UnixEpoch(), MaxTabTimestamp()); |
| 117 } | 115 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 194 |
| 197 TEST_F(SyncSessionsMetricsTest, EmitNormalCase) { | 195 TEST_F(SyncSessionsMetricsTest, EmitNormalCase) { |
| 198 base::HistogramTester histogram_tester; | 196 base::HistogramTester histogram_tester; |
| 199 PushTab(0, 0, Time::Now() - TimeDelta::FromHours(1)); | 197 PushTab(0, 0, Time::Now() - TimeDelta::FromHours(1)); |
| 200 SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | 198 SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 201 get_sessions_sync_manager()); | 199 get_sessions_sync_manager()); |
| 202 histogram_tester.ExpectTotalCount("Sync.YoungestForeignTabAgeOnNTP", 1); | 200 histogram_tester.ExpectTotalCount("Sync.YoungestForeignTabAgeOnNTP", 1); |
| 203 } | 201 } |
| 204 | 202 |
| 205 } // namespace sync_sessions | 203 } // namespace sync_sessions |
| OLD | NEW |