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

Side by Side Diff: http_fetcher_unittest.cc

Issue 4004004: AU: Restrict to HTTPS for official builds. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | libcurl_http_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ret->SetConnectionAsExpensive(false);
139 ret->SetBuildType(false);
139 return ret; 140 return ret;
140 } 141 }
141 HttpFetcher* NewSmallFetcher() { 142 HttpFetcher* NewSmallFetcher() {
142 return NewLargeFetcher(); 143 return NewLargeFetcher();
143 } 144 }
144 string BigUrl() const { 145 string BigUrl() const {
145 return LocalServerUrlForPath("/big"); 146 return LocalServerUrlForPath("/big");
146 } 147 }
147 string SmallUrl() const { 148 string SmallUrl() const {
148 return LocalServerUrlForPath("/foo"); 149 return LocalServerUrlForPath("/foo");
(...skipping 13 matching lines...) Expand all
162 public: 163 public:
163 HttpFetcher* NewLargeFetcher() { 164 HttpFetcher* NewLargeFetcher() {
164 MultiHttpFetcher<LibcurlHttpFetcher> *ret = 165 MultiHttpFetcher<LibcurlHttpFetcher> *ret =
165 new MultiHttpFetcher<LibcurlHttpFetcher>; 166 new MultiHttpFetcher<LibcurlHttpFetcher>;
166 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect 167 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect
167 ranges(1, make_pair(0, -1)); 168 ranges(1, make_pair(0, -1));
168 ret->set_ranges(ranges); 169 ret->set_ranges(ranges);
169 // Speed up test execution. 170 // Speed up test execution.
170 ret->set_idle_seconds(1); 171 ret->set_idle_seconds(1);
171 ret->set_retry_seconds(1); 172 ret->set_retry_seconds(1);
173 ret->SetConnectionAsExpensive(false);
174 ret->SetBuildType(false);
172 return ret; 175 return ret;
173 } 176 }
174 bool IsMulti() const { return true; } 177 bool IsMulti() const { return true; }
175 }; 178 };
176 179
177 typedef ::testing::Types<LibcurlHttpFetcher, 180 typedef ::testing::Types<LibcurlHttpFetcher,
178 MockHttpFetcher, 181 MockHttpFetcher,
179 MultiHttpFetcher<LibcurlHttpFetcher> > 182 MultiHttpFetcher<LibcurlHttpFetcher> >
180 HttpFetcherTestTypes; 183 HttpFetcherTestTypes;
181 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes); 184 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes);
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 int expected_response_code) { 609 int expected_response_code) {
607 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 610 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
608 { 611 {
609 MultiHttpFetcherTestDelegate delegate(expected_response_code); 612 MultiHttpFetcherTestDelegate delegate(expected_response_code);
610 delegate.loop_ = loop; 613 delegate.loop_ = loop;
611 scoped_ptr<HttpFetcher> fetcher(fetcher_in); 614 scoped_ptr<HttpFetcher> fetcher(fetcher_in);
612 MultiHttpFetcher<LibcurlHttpFetcher>* multi_fetcher = 615 MultiHttpFetcher<LibcurlHttpFetcher>* multi_fetcher =
613 dynamic_cast<MultiHttpFetcher<LibcurlHttpFetcher>*>(fetcher.get()); 616 dynamic_cast<MultiHttpFetcher<LibcurlHttpFetcher>*>(fetcher.get());
614 ASSERT_TRUE(multi_fetcher); 617 ASSERT_TRUE(multi_fetcher);
615 multi_fetcher->set_ranges(ranges); 618 multi_fetcher->set_ranges(ranges);
619 multi_fetcher->SetConnectionAsExpensive(false);
620 multi_fetcher->SetBuildType(false);
616 fetcher->set_delegate(&delegate); 621 fetcher->set_delegate(&delegate);
617 622
618 StartTransferArgs start_xfer_args = {fetcher.get(), url}; 623 StartTransferArgs start_xfer_args = {fetcher.get(), url};
619 624
620 g_timeout_add(0, StartTransfer, &start_xfer_args); 625 g_timeout_add(0, StartTransfer, &start_xfer_args);
621 g_main_loop_run(loop); 626 g_main_loop_run(loop);
622 627
623 EXPECT_EQ(expected_size, delegate.data.size()); 628 EXPECT_EQ(expected_size, delegate.data.size());
624 EXPECT_EQ(expected_prefix, 629 EXPECT_EQ(expected_prefix,
625 string(delegate.data.data(), expected_prefix.size())); 630 string(delegate.data.data(), expected_prefix.size()));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 this->BigUrl(), 696 this->BigUrl(),
692 ranges, 697 ranges,
693 "ij", 698 "ij",
694 2, 699 2,
695 0); 700 0);
696 ranges.push_back(make_pair(0, 5)); 701 ranges.push_back(make_pair(0, 5));
697 } 702 }
698 } 703 }
699 704
700 namespace { 705 namespace {
701 class ExpensiveConnectionTestDelegate : public HttpFetcherDelegate { 706 class BlockedTransferTestDelegate : public HttpFetcherDelegate {
702 public: 707 public:
703 virtual void ReceivedBytes(HttpFetcher* fetcher, 708 virtual void ReceivedBytes(HttpFetcher* fetcher,
704 const char* bytes, int length) { 709 const char* bytes, int length) {
705 ADD_FAILURE(); 710 ADD_FAILURE();
706 } 711 }
707 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) { 712 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) {
708 EXPECT_FALSE(successful); 713 EXPECT_FALSE(successful);
709 g_main_loop_quit(loop_); 714 g_main_loop_quit(loop_);
710 } 715 }
711 GMainLoop* loop_; 716 GMainLoop* loop_;
712 }; 717 };
713 718
714 } // namespace 719 } // namespace
715 720
716 TYPED_TEST(HttpFetcherTest, ExpensiveConnectionTest) { 721 TYPED_TEST(HttpFetcherTest, BlockedTransferTest) {
717 if (this->IsMock() || this->IsMulti()) 722 if (this->IsMock() || this->IsMulti())
718 return; 723 return;
719 typename TestFixture::HttpServer server;
720
721 ASSERT_TRUE(server.started_);
722 724
723 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 725 for (int i = 0; i < 2; i++) {
724 ExpensiveConnectionTestDelegate delegate; 726 typename TestFixture::HttpServer server;
725 delegate.loop_ = loop;
726 727
727 scoped_ptr<HttpFetcher> fetcher(this->NewLargeFetcher()); 728 ASSERT_TRUE(server.started_);
728 dynamic_cast<LibcurlHttpFetcher*>(
729 fetcher.get())->SetConnectionAsExpensive(true);
730 fetcher->set_delegate(&delegate);
731 729
732 StartTransferArgs start_xfer_args = 730 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
733 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) }; 731 BlockedTransferTestDelegate delegate;
732 delegate.loop_ = loop;
734 733
735 g_timeout_add(0, StartTransfer, &start_xfer_args); 734 scoped_ptr<HttpFetcher> fetcher(this->NewLargeFetcher());
736 g_main_loop_run(loop); 735 LibcurlHttpFetcher* curl_fetcher =
737 g_main_loop_unref(loop); 736 dynamic_cast<LibcurlHttpFetcher*>(fetcher.get());
737 bool is_expensive_connection = (i == 0);
738 bool is_official_build = (i == 1);
739 LOG(INFO) << "is_expensive_connection: " << is_expensive_connection;
740 LOG(INFO) << "is_official_build: " << is_official_build;
741 curl_fetcher->SetConnectionAsExpensive(is_expensive_connection);
742 curl_fetcher->SetBuildType(is_official_build);
743 fetcher->set_delegate(&delegate);
744
745 StartTransferArgs start_xfer_args =
746 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) };
747
748 g_timeout_add(0, StartTransfer, &start_xfer_args);
749 g_main_loop_run(loop);
750 g_main_loop_unref(loop);
751 }
738 } 752 }
739 753
740 } // namespace chromeos_update_engine 754 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « no previous file | libcurl_http_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698