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

Side by Side Diff: chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Add GetVisualsForItem support Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/background_fetch/background_fetch_client_impl.h"
6
7 #include "base/macros.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/background_fetch/background_fetch_client_factory.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "components/offline_items_collection/core/offline_item.h"
12 #include "content/public/browser/background_fetch_client.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 const char kRegistrationId[] = "1234:www.example.com:game_data";
19 const char kNamespace[] = "BackgroundFetchNamespace";
20
21 class FakeBackgroundFetchDelegate
22 : public content::BackgroundFetchClient::Delegate {
23 public:
24 explicit FakeBackgroundFetchDelegate(const std::string& id)
25 : expected_id_(id) {}
26
27 void CleanupAllTasks() override {}
28
29 void CancelDownload(const std::string& registration_id) override {
30 ASSERT_EQ(registration_id, expected_id_);
31 }
32
33 void PauseDownload(const std::string& registration_id) override {
34 ASSERT_EQ(registration_id, expected_id_);
35 }
36
37 void ResumeDownload(const std::string& registration_id) override {
38 ASSERT_EQ(registration_id, expected_id_);
39 }
40
41 private:
42 std::string expected_id_;
43 };
44
45 } // namespace
46
47 class BackgroundFetchClientTest : public ::testing::Test {
48 public:
49 BackgroundFetchClientTest() {}
50 ~BackgroundFetchClientTest() override {}
51
52 protected:
53 content::TestBrowserThreadBundle thread_bundle_;
54
55 TestingProfile profile_;
56 };
57
58 TEST_F(BackgroundFetchClientTest, CancelDownloadTest) {
59 BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>(
60 profile_.GetBackgroundFetchClient());
61 FakeBackgroundFetchDelegate delegate(kRegistrationId);
62 client->SetDelegate(&delegate);
63
64 offline_items_collection::ContentId id(kNamespace, kRegistrationId);
65 ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id));
66
67 client->SetDelegate(nullptr);
68 ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id));
69 }
70
71 TEST_F(BackgroundFetchClientTest, PauseDownloadTest) {
72 BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>(
73 profile_.GetBackgroundFetchClient());
74 // content::BackgroundFetchClient* client =
75 // profile_.GetBackgroundFetchClient();
Peter Beverloo 2017/04/18 23:12:08 Here any below - please remove the commented out c
harkness 2017/04/19 09:03:41 oops, thanks.
76 FakeBackgroundFetchDelegate delegate(kRegistrationId);
77 client->SetDelegate(&delegate);
78
79 offline_items_collection::ContentId id(kNamespace, kRegistrationId);
80 ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id));
81
82 client->SetDelegate(nullptr);
83 ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id));
84 }
85
86 TEST_F(BackgroundFetchClientTest, ResumeDownloadTest) {
87 BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>(
88 profile_.GetBackgroundFetchClient());
89 // content::BackgroundFetchClient* client =
90 // profile_.GetBackgroundFetchClient();
91 FakeBackgroundFetchDelegate delegate(kRegistrationId);
92 client->SetDelegate(&delegate);
93
94 offline_items_collection::ContentId id(kNamespace, kRegistrationId);
95 ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id));
96
97 client->SetDelegate(nullptr);
98 ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id));
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698