| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/offline_pages/core/prefetch/suggested_articles_observer.h" | 5 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "components/offline_pages/core/client_namespace_constants.h" | 10 #include "components/offline_pages/core/client_namespace_constants.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 observer()->GetTestingArticles()->push_back( | 69 observer()->GetTestingArticles()->push_back( |
| 70 ContentSuggestionFromTestURL(test_url_1)); | 70 ContentSuggestionFromTestURL(test_url_1)); |
| 71 | 71 |
| 72 observer()->OnCategoryStatusChanged(category, | 72 observer()->OnCategoryStatusChanged(category, |
| 73 ntp_snippets::CategoryStatus::AVAILABLE); | 73 ntp_snippets::CategoryStatus::AVAILABLE); |
| 74 observer()->OnNewSuggestions(category); | 74 observer()->OnNewSuggestions(category); |
| 75 EXPECT_EQ(1, test_prefetch_dispatcher()->new_suggestions_count); | 75 EXPECT_EQ(1, test_prefetch_dispatcher()->new_suggestions_count); |
| 76 EXPECT_EQ(1U, test_prefetch_dispatcher()->latest_prefetch_urls.size()); | 76 EXPECT_EQ(1U, test_prefetch_dispatcher()->latest_prefetch_urls.size()); |
| 77 EXPECT_EQ(test_url_1, | 77 EXPECT_EQ(test_url_1, |
| 78 test_prefetch_dispatcher()->latest_prefetch_urls[0].url); | 78 test_prefetch_dispatcher()->latest_prefetch_urls[0].url); |
| 79 EXPECT_EQ( | 79 EXPECT_EQ(kSuggestedArticlesNamespace, |
| 80 kSuggestedArticlesNamespace, | 80 test_prefetch_dispatcher()->latest_name_space); |
| 81 test_prefetch_dispatcher()->latest_prefetch_urls[0].client_id.name_space); | |
| 82 } | 81 } |
| 83 | 82 |
| 84 TEST_F(OfflinePageSuggestedArticlesObserverTest, RemovesAllOnBadStatus) { | 83 TEST_F(OfflinePageSuggestedArticlesObserverTest, RemovesAllOnBadStatus) { |
| 85 const GURL test_url_1("https://www.example.com/1"); | 84 const GURL test_url_1("https://www.example.com/1"); |
| 86 const GURL test_url_2("https://www.example.com/2"); | 85 const GURL test_url_2("https://www.example.com/2"); |
| 87 observer()->GetTestingArticles()->push_back( | 86 observer()->GetTestingArticles()->push_back( |
| 88 ContentSuggestionFromTestURL(test_url_1)); | 87 ContentSuggestionFromTestURL(test_url_1)); |
| 89 observer()->GetTestingArticles()->push_back( | 88 observer()->GetTestingArticles()->push_back( |
| 90 ContentSuggestionFromTestURL(test_url_2)); | 89 ContentSuggestionFromTestURL(test_url_2)); |
| 91 | 90 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 112 observer()->OnNewSuggestions(category); | 111 observer()->OnNewSuggestions(category); |
| 113 ASSERT_EQ(1U, test_prefetch_dispatcher()->latest_prefetch_urls.size()); | 112 ASSERT_EQ(1U, test_prefetch_dispatcher()->latest_prefetch_urls.size()); |
| 114 | 113 |
| 115 observer()->OnSuggestionInvalidated( | 114 observer()->OnSuggestionInvalidated( |
| 116 ntp_snippets::ContentSuggestion::ID(category, test_url_1.spec())); | 115 ntp_snippets::ContentSuggestion::ID(category, test_url_1.spec())); |
| 117 | 116 |
| 118 EXPECT_EQ(1, test_prefetch_dispatcher()->remove_by_client_id_count); | 117 EXPECT_EQ(1, test_prefetch_dispatcher()->remove_by_client_id_count); |
| 119 EXPECT_NE(nullptr, test_prefetch_dispatcher()->last_removed_client_id.get()); | 118 EXPECT_NE(nullptr, test_prefetch_dispatcher()->last_removed_client_id.get()); |
| 120 EXPECT_EQ(test_url_1.spec(), | 119 EXPECT_EQ(test_url_1.spec(), |
| 121 test_prefetch_dispatcher()->last_removed_client_id->id); | 120 test_prefetch_dispatcher()->last_removed_client_id->id); |
| 122 EXPECT_EQ( | 121 EXPECT_EQ(kSuggestedArticlesNamespace, |
| 123 kSuggestedArticlesNamespace, | 122 test_prefetch_dispatcher()->latest_name_space); |
| 124 test_prefetch_dispatcher()->latest_prefetch_urls[0].client_id.name_space); | |
| 125 } | 123 } |
| 126 | 124 |
| 127 } // namespace offline_pages | 125 } // namespace offline_pages |
| OLD | NEW |