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

Side by Side Diff: components/offline_pages/content/suggested_articles_observer_unittest.cc

Issue 2864293003: [Offline Pages] Add a GCMAppHandler for offline page prefetch. (Closed)
Patch Set: Touch ups. Created 3 years, 7 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
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/content/suggested_articles_observer.h" 5 #include "components/offline_pages/content/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"
11 #include "components/offline_pages/core/stub_offline_page_model.h" 11 #include "components/offline_pages/core/stub_offline_page_model.h"
12 #include "content/public/test/test_browser_context.h" 12 #include "content/public/test/test_browser_context.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 using ntp_snippets::Category; 16 using ntp_snippets::Category;
17 using ntp_snippets::ContentSuggestion; 17 using ntp_snippets::ContentSuggestion;
18 18
19 namespace gcm {
20 class GCMDriver;
21 }
22
19 namespace offline_pages { 23 namespace offline_pages {
20 24
21 namespace { 25 namespace {
22 26
23 ContentSuggestion ContentSuggestionFromTestURL(const GURL& test_url) { 27 ContentSuggestion ContentSuggestionFromTestURL(const GURL& test_url) {
24 auto category = 28 auto category =
25 Category::FromKnownCategory(ntp_snippets::KnownCategories::ARTICLES); 29 Category::FromKnownCategory(ntp_snippets::KnownCategories::ARTICLES);
26 return ContentSuggestion(category, test_url.spec(), test_url); 30 return ContentSuggestion(category, test_url.spec(), test_url);
27 } 31 }
28 32
(...skipping 16 matching lines...) Expand all
45 49
46 void RemovePrefetchURLsByClientId(const ClientId& client_id) override { 50 void RemovePrefetchURLsByClientId(const ClientId& client_id) override {
47 DCHECK_EQ(client_id.name_space, kSuggestedArticlesNamespace); 51 DCHECK_EQ(client_id.name_space, kSuggestedArticlesNamespace);
48 remove_by_client_id_count++; 52 remove_by_client_id_count++;
49 last_removed_client_id = base::MakeUnique<ClientId>(client_id); 53 last_removed_client_id = base::MakeUnique<ClientId>(client_id);
50 } 54 }
51 55
52 void BeginBackgroundTask( 56 void BeginBackgroundTask(
53 std::unique_ptr<ScopedBackgroundTask> task) override {} 57 std::unique_ptr<ScopedBackgroundTask> task) override {}
54 void StopBackgroundTask(ScopedBackgroundTask* task) override {} 58 void StopBackgroundTask(ScopedBackgroundTask* task) override {}
59 void RegisterWithGCMDriver(gcm::GCMDriver* driver) override {}
55 60
56 std::vector<PrefetchURL> latest_prefetch_urls; 61 std::vector<PrefetchURL> latest_prefetch_urls;
57 std::unique_ptr<ClientId> last_removed_client_id; 62 std::unique_ptr<ClientId> last_removed_client_id;
58 63
59 int new_suggestions_count = 0; 64 int new_suggestions_count = 0;
60 int remove_all_suggestions_count = 0; 65 int remove_all_suggestions_count = 0;
61 int remove_by_client_id_count = 0; 66 int remove_by_client_id_count = 0;
62 }; 67 };
63 68
64 class TestDelegate : public SuggestedArticlesObserver::Delegate { 69 class TestDelegate : public SuggestedArticlesObserver::Delegate {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 194
190 observer()->OnSuggestionInvalidated( 195 observer()->OnSuggestionInvalidated(
191 ntp_snippets::ContentSuggestion::ID(category, test_url_1.spec())); 196 ntp_snippets::ContentSuggestion::ID(category, test_url_1.spec()));
192 197
193 EXPECT_EQ(1, test_prefetch_service()->remove_by_client_id_count); 198 EXPECT_EQ(1, test_prefetch_service()->remove_by_client_id_count);
194 EXPECT_EQ(ClientId(kSuggestedArticlesNamespace, test_url_1.spec()), 199 EXPECT_EQ(ClientId(kSuggestedArticlesNamespace, test_url_1.spec()),
195 *test_prefetch_service()->last_removed_client_id); 200 *test_prefetch_service()->last_removed_client_id);
196 } 201 }
197 202
198 } // namespace offline_pages 203 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698