OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 }; | 128 }; |
129 | 129 |
130 template <> | 130 template <> |
131 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { | 131 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { |
132 public: | 132 public: |
133 virtual HttpFetcher* NewLargeFetcher() { | 133 virtual HttpFetcher* NewLargeFetcher() { |
134 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher; | 134 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher; |
135 // Speed up test execution. | 135 // Speed up test execution. |
136 ret->set_idle_seconds(1); | 136 ret->set_idle_seconds(1); |
137 ret->set_retry_seconds(1); | 137 ret->set_retry_seconds(1); |
| 138 ret->SetConnectionAsExpensive(false); |
138 return ret; | 139 return ret; |
139 } | 140 } |
140 HttpFetcher* NewSmallFetcher() { | 141 HttpFetcher* NewSmallFetcher() { |
141 return NewLargeFetcher(); | 142 return NewLargeFetcher(); |
142 } | 143 } |
143 string BigUrl() const { | 144 string BigUrl() const { |
144 return LocalServerUrlForPath("/big"); | 145 return LocalServerUrlForPath("/big"); |
145 } | 146 } |
146 string SmallUrl() const { | 147 string SmallUrl() const { |
147 return LocalServerUrlForPath("/foo"); | 148 return LocalServerUrlForPath("/foo"); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 MultiTest(this->NewLargeFetcher(), | 690 MultiTest(this->NewLargeFetcher(), |
690 this->BigUrl(), | 691 this->BigUrl(), |
691 ranges, | 692 ranges, |
692 "ij", | 693 "ij", |
693 2, | 694 2, |
694 0); | 695 0); |
695 ranges.push_back(make_pair(0, 5)); | 696 ranges.push_back(make_pair(0, 5)); |
696 } | 697 } |
697 } | 698 } |
698 | 699 |
| 700 namespace { |
| 701 class ExpensiveConnectionTestDelegate : public HttpFetcherDelegate { |
| 702 public: |
| 703 virtual void ReceivedBytes(HttpFetcher* fetcher, |
| 704 const char* bytes, int length) { |
| 705 ADD_FAILURE(); |
| 706 } |
| 707 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) { |
| 708 EXPECT_FALSE(successful); |
| 709 g_main_loop_quit(loop_); |
| 710 } |
| 711 GMainLoop* loop_; |
| 712 }; |
| 713 |
| 714 } // namespace |
| 715 |
| 716 TYPED_TEST(HttpFetcherTest, ExpensiveConnectionTest) { |
| 717 if (this->IsMock() || this->IsMulti()) |
| 718 return; |
| 719 typename TestFixture::HttpServer server; |
| 720 |
| 721 ASSERT_TRUE(server.started_); |
| 722 |
| 723 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 724 ExpensiveConnectionTestDelegate delegate; |
| 725 delegate.loop_ = loop; |
| 726 |
| 727 scoped_ptr<HttpFetcher> fetcher(this->NewLargeFetcher()); |
| 728 dynamic_cast<LibcurlHttpFetcher*>( |
| 729 fetcher.get())->SetConnectionAsExpensive(true); |
| 730 fetcher->set_delegate(&delegate); |
| 731 |
| 732 StartTransferArgs start_xfer_args = |
| 733 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) }; |
| 734 |
| 735 g_timeout_add(0, StartTransfer, &start_xfer_args); |
| 736 g_main_loop_run(loop); |
| 737 g_main_loop_unref(loop); |
| 738 } |
| 739 |
699 } // namespace chromeos_update_engine | 740 } // namespace chromeos_update_engine |
OLD | NEW |