OLD | NEW |
(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 "components/payments/payment_manifest_downloader.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "net/url_request/test_url_fetcher_factory.h" |
| 11 #include "net/url_request/url_fetcher.h" |
| 12 #include "net/url_request/url_request_test_util.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace payments { |
| 17 namespace { |
| 18 |
| 19 class PaymentManifestDownloaderTest |
| 20 : public testing::Test, |
| 21 public PaymentManifestDownloader::Delegate { |
| 22 public: |
| 23 PaymentManifestDownloaderTest() |
| 24 : context_(new net::TestURLRequestContextGetter( |
| 25 base::ThreadTaskRunnerHandle::Get())), |
| 26 downloader_(context_, "https://bobpay.com", this) { |
| 27 downloader_.Download(); |
| 28 } |
| 29 |
| 30 ~PaymentManifestDownloaderTest() override {} |
| 31 |
| 32 // PaymentManifestDownloader::Delegate |
| 33 MOCK_METHOD1(OnManifestDownloadSuccess, void(const std::string& content)); |
| 34 MOCK_METHOD0(OnManifestDownloadFailure, void()); |
| 35 |
| 36 net::TestURLFetcher* fetcher() { |
| 37 return factory_.GetFetcherByID(0); |
| 38 } |
| 39 |
| 40 private: |
| 41 content::TestBrowserThreadBundle thread_bundle_; |
| 42 net::TestURLFetcherFactory factory_; |
| 43 scoped_refptr<net::TestURLRequestContextGetter> context_; |
| 44 PaymentManifestDownloader downloader_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloaderTest); |
| 47 }; |
| 48 |
| 49 TEST_F(PaymentManifestDownloaderTest, HttpHeadResponse404IsFailure) { |
| 50 EXPECT_CALL(*this, OnManifestDownloadFailure()); |
| 51 |
| 52 fetcher()->set_response_code(404); |
| 53 fetcher()->delegate()->OnURLFetchComplete(fetcher()); |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 } // namespace payments |
OLD | NEW |