Index: chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
diff --git a/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc b/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a5537eebea91866814acb924ef2e3c9d56fc439f |
--- /dev/null |
+++ b/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
@@ -0,0 +1,99 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/background_fetch/background_fetch_client_impl.h" |
+ |
+#include "base/macros.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "chrome/browser/background_fetch/background_fetch_client_factory.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "components/offline_items_collection/core/offline_item.h" |
+#include "content/public/browser/background_fetch_client.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+const char kRegistrationId[] = "1234:www.example.com:game_data"; |
+const char kNamespace[] = "BackgroundFetchNamespace"; |
+ |
+class FakeBackgroundFetchDelegate |
+ : public content::BackgroundFetchClient::Delegate { |
+ public: |
+ explicit FakeBackgroundFetchDelegate(const std::string& id) |
+ : expected_id_(id) {} |
+ |
+ void CleanupAllTasks() override {} |
+ |
+ void CancelDownload(const std::string& registration_id) override { |
+ ASSERT_EQ(registration_id, expected_id_); |
+ } |
+ |
+ void PauseDownload(const std::string& registration_id) override { |
+ ASSERT_EQ(registration_id, expected_id_); |
+ } |
+ |
+ void ResumeDownload(const std::string& registration_id) override { |
+ ASSERT_EQ(registration_id, expected_id_); |
+ } |
+ |
+ private: |
+ std::string expected_id_; |
+}; |
+ |
+} // namespace |
+ |
+class BackgroundFetchClientTest : public ::testing::Test { |
+ public: |
+ BackgroundFetchClientTest() {} |
+ ~BackgroundFetchClientTest() override {} |
+ |
+ protected: |
+ content::TestBrowserThreadBundle thread_bundle_; |
+ |
+ TestingProfile profile_; |
+}; |
+ |
+TEST_F(BackgroundFetchClientTest, CancelDownloadTest) { |
+ BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>( |
+ profile_.GetBackgroundFetchClient()); |
+ FakeBackgroundFetchDelegate delegate(kRegistrationId); |
+ client->SetDelegate(&delegate); |
+ |
+ offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
+ ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id)); |
+ |
+ client->SetDelegate(nullptr); |
+ ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id)); |
+} |
+ |
+TEST_F(BackgroundFetchClientTest, PauseDownloadTest) { |
+ BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>( |
+ profile_.GetBackgroundFetchClient()); |
+ // content::BackgroundFetchClient* client = |
+ // 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.
|
+ FakeBackgroundFetchDelegate delegate(kRegistrationId); |
+ client->SetDelegate(&delegate); |
+ |
+ offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
+ ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); |
+ |
+ client->SetDelegate(nullptr); |
+ ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); |
+} |
+ |
+TEST_F(BackgroundFetchClientTest, ResumeDownloadTest) { |
+ BackgroundFetchClientImpl* client = static_cast<BackgroundFetchClientImpl*>( |
+ profile_.GetBackgroundFetchClient()); |
+ // content::BackgroundFetchClient* client = |
+ // profile_.GetBackgroundFetchClient(); |
+ FakeBackgroundFetchDelegate delegate(kRegistrationId); |
+ client->SetDelegate(&delegate); |
+ |
+ offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
+ ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id)); |
+ |
+ client->SetDelegate(nullptr); |
+ ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id)); |
+} |