| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "components/ntp_snippets/category.h" | 13 #include "components/ntp_snippets/category.h" |
| 14 #include "components/ntp_snippets/content_suggestions_provider.h" | 14 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 15 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" | 15 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" |
| 16 #include "components/prefs/testing_pref_service.h" | 16 #include "components/prefs/testing_pref_service.h" |
| 17 #include "components/sessions/core/serialized_navigation_entry.h" | 17 #include "components/sessions/core/serialized_navigation_entry.h" |
| 18 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 18 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
| 19 #include "components/sessions/core/session_types.h" | 19 #include "components/sessions/core/session_types.h" |
| 20 #include "components/sync_sessions/synced_session.h" | 20 #include "components/sync_sessions/synced_session.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using base::Time; | 24 using base::Time; |
| 25 using base::TimeDelta; | 25 using base::TimeDelta; |
| 26 using sessions::SerializedNavigationEntry; | 26 using sessions::SerializedNavigationEntry; |
| 27 using sessions::SessionTab; | 27 using sessions::SessionTab; |
| 28 using sessions::SessionWindow; | 28 using sessions::SessionWindow; |
| 29 using sync_sessions::SyncedSession; | 29 using sync_sessions::SyncedSession; |
| 30 using sync_sessions::SyncedSessionWindow; |
| 30 using testing::ElementsAre; | 31 using testing::ElementsAre; |
| 31 using testing::IsEmpty; | 32 using testing::IsEmpty; |
| 32 using testing::Property; | 33 using testing::Property; |
| 33 using testing::Test; | 34 using testing::Test; |
| 34 using testing::_; | 35 using testing::_; |
| 35 | 36 |
| 36 namespace ntp_snippets { | 37 namespace ntp_snippets { |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 const char kUrl1[] = "http://www.fake1.com/"; | 40 const char kUrl1[] = "http://www.fake1.com/"; |
| 40 const char kUrl2[] = "http://www.fake2.com/"; | 41 const char kUrl2[] = "http://www.fake2.com/"; |
| 41 const char kUrl3[] = "http://www.fake3.com/"; | 42 const char kUrl3[] = "http://www.fake3.com/"; |
| 42 const char kUrl4[] = "http://www.fake4.com/"; | 43 const char kUrl4[] = "http://www.fake4.com/"; |
| 43 const char kUrl5[] = "http://www.fake5.com/"; | 44 const char kUrl5[] = "http://www.fake5.com/"; |
| 44 const char kUrl6[] = "http://www.fake6.com/"; | 45 const char kUrl6[] = "http://www.fake6.com/"; |
| 45 const char kUrl7[] = "http://www.fake7.com/"; | 46 const char kUrl7[] = "http://www.fake7.com/"; |
| 46 const char kUrl8[] = "http://www.fake8.com/"; | 47 const char kUrl8[] = "http://www.fake8.com/"; |
| 47 const char kUrl9[] = "http://www.fake9.com/"; | 48 const char kUrl9[] = "http://www.fake9.com/"; |
| 48 const char kUrl10[] = "http://www.fake10.com/"; | 49 const char kUrl10[] = "http://www.fake10.com/"; |
| 49 const char kUrl11[] = "http://www.fake11.com/"; | 50 const char kUrl11[] = "http://www.fake11.com/"; |
| 50 const char kTitle[] = "title is ignored"; | 51 const char kTitle[] = "title is ignored"; |
| 51 | 52 |
| 52 SessionWindow* GetOrCreateWindow(SyncedSession* session, int window_id) { | 53 SessionWindow* GetOrCreateWindow(SyncedSession* session, int window_id) { |
| 53 if (session->windows.find(window_id) == session->windows.end()) { | 54 if (session->windows.find(window_id) == session->windows.end()) { |
| 54 session->windows[window_id] = base::MakeUnique<SessionWindow>(); | 55 session->windows[window_id] = base::MakeUnique<SyncedSessionWindow>(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 return session->windows[window_id].get(); | 58 return &session->windows[window_id]->wrapped_window; |
| 58 } | 59 } |
| 59 | 60 |
| 60 void AddTabToSession(SyncedSession* session, | 61 void AddTabToSession(SyncedSession* session, |
| 61 int window_id, | 62 int window_id, |
| 62 const std::string& url, | 63 const std::string& url, |
| 63 TimeDelta age) { | 64 TimeDelta age) { |
| 64 SerializedNavigationEntry navigation = | 65 SerializedNavigationEntry navigation = |
| 65 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url, | 66 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url, |
| 66 kTitle); | 67 kTitle); |
| 67 | 68 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 EXPECT_CALL(*observer(), | 367 EXPECT_CALL(*observer(), |
| 367 OnNewSuggestions( | 368 OnNewSuggestions( |
| 368 _, category(), | 369 _, category(), |
| 369 ElementsAre(Property(&ContentSuggestion::url, GURL(kUrl1)), | 370 ElementsAre(Property(&ContentSuggestion::url, GURL(kUrl1)), |
| 370 Property(&ContentSuggestion::url, GURL(kUrl2))))); | 371 Property(&ContentSuggestion::url, GURL(kUrl2))))); |
| 371 AddTab(0, 0, kUrl2, TimeDelta::FromMinutes(2)); | 372 AddTab(0, 0, kUrl2, TimeDelta::FromMinutes(2)); |
| 372 TriggerOnChange(); | 373 TriggerOnChange(); |
| 373 } | 374 } |
| 374 | 375 |
| 375 } // namespace ntp_snippets | 376 } // namespace ntp_snippets |
| OLD | NEW |