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/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" | 5 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using base::Time; | 25 using base::Time; |
26 using base::TimeDelta; | 26 using base::TimeDelta; |
27 using sessions::SerializedNavigationEntry; | 27 using sessions::SerializedNavigationEntry; |
28 using sessions::SessionTab; | 28 using sessions::SessionTab; |
29 using sessions::SessionWindow; | 29 using sessions::SessionWindow; |
30 using sync_sessions::SyncedSession; | 30 using sync_sessions::SyncedSession; |
31 using testing::ElementsAre; | 31 using testing::ElementsAre; |
32 using testing::IsEmpty; | 32 using testing::IsEmpty; |
33 using testing::Property; | 33 using testing::Property; |
34 using testing::Test; | 34 using testing::Test; |
35 using testing::UnorderedElementsAre; | |
36 using testing::_; | 35 using testing::_; |
37 | 36 |
38 namespace ntp_snippets { | 37 namespace ntp_snippets { |
39 namespace { | 38 namespace { |
40 | 39 |
41 const char kUrl1[] = "http://www.fake1.com/"; | 40 const char kUrl1[] = "http://www.fake1.com/"; |
42 const char kUrl2[] = "http://www.fake2.com/"; | 41 const char kUrl2[] = "http://www.fake2.com/"; |
43 const char kUrl3[] = "http://www.fake3.com/"; | 42 const char kUrl3[] = "http://www.fake3.com/"; |
44 const char kUrl4[] = "http://www.fake4.com/"; | 43 const char kUrl4[] = "http://www.fake4.com/"; |
45 const char kUrl5[] = "http://www.fake5.com/"; | 44 const char kUrl5[] = "http://www.fake5.com/"; |
(...skipping 24 matching lines...) Expand all Loading... |
70 tab->timestamp = Time::Now() - age; | 69 tab->timestamp = Time::Now() - age; |
71 tab->navigations.push_back(navigation); | 70 tab->navigations.push_back(navigation); |
72 | 71 |
73 SessionWindow* window = GetOrCreateWindow(session, window_id); | 72 SessionWindow* window = GetOrCreateWindow(session, window_id); |
74 // The window deletes the tabs it points at upon destruction. | 73 // The window deletes the tabs it points at upon destruction. |
75 window->tabs.push_back(std::move(tab)); | 74 window->tabs.push_back(std::move(tab)); |
76 } | 75 } |
77 | 76 |
78 class FakeForeignSessionsProvider : public ForeignSessionsProvider { | 77 class FakeForeignSessionsProvider : public ForeignSessionsProvider { |
79 public: | 78 public: |
80 ~FakeForeignSessionsProvider() override {} | 79 ~FakeForeignSessionsProvider() override = default; |
81 void SetAllForeignSessions(std::vector<const SyncedSession*> sessions) { | 80 void SetAllForeignSessions(std::vector<const SyncedSession*> sessions) { |
82 sessions_ = sessions; | 81 sessions_ = std::move(sessions); |
83 change_callback_.Run(); | 82 change_callback_.Run(); |
84 } | 83 } |
85 | 84 |
86 // ForeignSessionsProvider implementation. | 85 // ForeignSessionsProvider implementation. |
87 void SubscribeForForeignTabChange( | 86 void SubscribeForForeignTabChange( |
88 const base::Closure& change_callback) override { | 87 const base::Closure& change_callback) override { |
89 change_callback_ = change_callback; | 88 change_callback_ = change_callback; |
90 } | 89 } |
91 bool HasSessionsData() override { return true; } | 90 bool HasSessionsData() override { return true; } |
92 std::vector<const sync_sessions::SyncedSession*> GetAllForeignSessions() | 91 std::vector<const sync_sessions::SyncedSession*> GetAllForeignSessions() |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const std::string& url, | 138 const std::string& url, |
140 TimeDelta age) { | 139 TimeDelta age) { |
141 AddTabToSession(GetOrCreateSession(session_id), window_id, url, age); | 140 AddTabToSession(GetOrCreateSession(session_id), window_id, url, age); |
142 } | 141 } |
143 | 142 |
144 void TriggerOnChange() { | 143 void TriggerOnChange() { |
145 std::vector<const SyncedSession*> sessions; | 144 std::vector<const SyncedSession*> sessions; |
146 for (const auto& kv : sessions_map_) { | 145 for (const auto& kv : sessions_map_) { |
147 sessions.push_back(kv.second.get()); | 146 sessions.push_back(kv.second.get()); |
148 } | 147 } |
149 fake_foreign_sessions_provider_->SetAllForeignSessions(sessions); | 148 fake_foreign_sessions_provider_->SetAllForeignSessions(std::move(sessions)); |
150 } | 149 } |
151 | 150 |
152 void Dismiss(const std::string& url) { | 151 void Dismiss(const std::string& url) { |
153 // The url of a given suggestion is used as the |within_category_id|. | 152 // The url of a given suggestion is used as the |within_category_id|. |
154 provider_->DismissSuggestion(provider_->MakeUniqueID(category(), url)); | 153 provider_->DismissSuggestion(provider_->MakeUniqueID(category(), url)); |
155 } | 154 } |
156 | 155 |
157 Category category() { | 156 Category category() { |
158 return category_factory_.FromKnownCategory(KnownCategories::FOREIGN_TABS); | 157 return category_factory_.FromKnownCategory(KnownCategories::FOREIGN_TABS); |
159 } | 158 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 AddTab(0, 0, kUrl1, TimeDelta::FromMinutes(1)); | 317 AddTab(0, 0, kUrl1, TimeDelta::FromMinutes(1)); |
319 AddTab(0, 0, kUrl2, TimeDelta::FromMinutes(2)); | 318 AddTab(0, 0, kUrl2, TimeDelta::FromMinutes(2)); |
320 AddTab(0, 0, kUrl3, TimeDelta::FromMinutes(3)); | 319 AddTab(0, 0, kUrl3, TimeDelta::FromMinutes(3)); |
321 AddTab(0, 0, kUrl4, TimeDelta::FromMinutes(4)); | 320 AddTab(0, 0, kUrl4, TimeDelta::FromMinutes(4)); |
322 AddTab(0, 0, kUrl5, TimeDelta::FromMinutes(5)); | 321 AddTab(0, 0, kUrl5, TimeDelta::FromMinutes(5)); |
323 AddTab(0, 0, kUrl6, TimeDelta::FromMinutes(6)); | 322 AddTab(0, 0, kUrl6, TimeDelta::FromMinutes(6)); |
324 TriggerOnChange(); | 323 TriggerOnChange(); |
325 } | 324 } |
326 | 325 |
327 } // namespace ntp_snippets | 326 } // namespace ntp_snippets |
OLD | NEW |