| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 "components/certificate_transparency/log_proof_fetcher.h" | 5 #include "components/certificate_transparency/log_proof_fetcher.h" | 
| 6 | 6 | 
|  | 7 #include <memory> | 
| 7 #include <string> | 8 #include <string> | 
| 8 #include <utility> | 9 #include <utility> | 
| 9 | 10 | 
| 10 #include "base/format_macros.h" | 11 #include "base/format_macros.h" | 
| 11 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" | 
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" | 
| 14 #include "components/safe_json/testing_json_parser.h" | 15 #include "components/safe_json/testing_json_parser.h" | 
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" | 
| 16 #include "net/base/network_delegate.h" | 17 #include "net/base/network_delegate.h" | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 215   std::vector<std::string> consistency_proof_; | 216   std::vector<std::string> consistency_proof_; | 
| 216 }; | 217 }; | 
| 217 | 218 | 
| 218 class LogProofFetcherTest : public ::testing::Test { | 219 class LogProofFetcherTest : public ::testing::Test { | 
| 219  public: | 220  public: | 
| 220   LogProofFetcherTest() | 221   LogProofFetcherTest() | 
| 221       : log_url_(base::StringPrintf("%s://%s/%s/", | 222       : log_url_(base::StringPrintf("%s://%s/%s/", | 
| 222                                     kLogSchema, | 223                                     kLogSchema, | 
| 223                                     kLogHost, | 224                                     kLogHost, | 
| 224                                     kLogPathPrefix)) { | 225                                     kLogPathPrefix)) { | 
| 225     scoped_ptr<LogGetResponseHandler> handler(new LogGetResponseHandler()); | 226     std::unique_ptr<LogGetResponseHandler> handler(new LogGetResponseHandler()); | 
| 226     handler_ = handler.get(); | 227     handler_ = handler.get(); | 
| 227 | 228 | 
| 228     net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 229     net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 
| 229         kLogSchema, kLogHost, std::move(handler)); | 230         kLogSchema, kLogHost, std::move(handler)); | 
| 230 | 231 | 
| 231     fetcher_.reset(new LogProofFetcher(&context_)); | 232     fetcher_.reset(new LogProofFetcher(&context_)); | 
| 232   } | 233   } | 
| 233 | 234 | 
| 234   ~LogProofFetcherTest() override { | 235   ~LogProofFetcherTest() override { | 
| 235     net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(kLogSchema, | 236     net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(kLogSchema, | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 299     } | 300     } | 
| 300   } | 301   } | 
| 301 | 302 | 
| 302   // The |message_loop_|, while seemingly unused, is necessary | 303   // The |message_loop_|, while seemingly unused, is necessary | 
| 303   // for URL request interception. That is the message loop that | 304   // for URL request interception. That is the message loop that | 
| 304   // will be used by the RunLoop. | 305   // will be used by the RunLoop. | 
| 305   base::MessageLoopForIO message_loop_; | 306   base::MessageLoopForIO message_loop_; | 
| 306   base::RunLoop run_loop_; | 307   base::RunLoop run_loop_; | 
| 307   net::TestURLRequestContext context_; | 308   net::TestURLRequestContext context_; | 
| 308   safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; | 309   safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; | 
| 309   scoped_ptr<LogProofFetcher> fetcher_; | 310   std::unique_ptr<LogProofFetcher> fetcher_; | 
| 310   const GURL log_url_; | 311   const GURL log_url_; | 
| 311   LogGetResponseHandler* handler_; | 312   LogGetResponseHandler* handler_; | 
| 312 }; | 313 }; | 
| 313 | 314 | 
| 314 TEST_F(LogProofFetcherTest, TestValidGetReply) { | 315 TEST_F(LogProofFetcherTest, TestValidGetReply) { | 
| 315   SetValidSTHJSONResponse(); | 316   SetValidSTHJSONResponse(); | 
| 316 | 317 | 
| 317   RecordFetchCallbackInvocations callback(true); | 318   RecordFetchCallbackInvocations callback(true); | 
| 318 | 319 | 
| 319   RunFetcherWithCallback(&callback); | 320   RunFetcherWithCallback(&callback); | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 431   RunGetConsistencyFetcherWithCallback(&callback); | 432   RunGetConsistencyFetcherWithCallback(&callback); | 
| 432 | 433 | 
| 433   ASSERT_EQ(FAILURE, callback.intercepted_result_type()); | 434   ASSERT_EQ(FAILURE, callback.intercepted_result_type()); | 
| 434   EXPECT_EQ(net::ERR_CT_CONSISTENCY_PROOF_PARSING_FAILED, callback.net_error()); | 435   EXPECT_EQ(net::ERR_CT_CONSISTENCY_PROOF_PARSING_FAILED, callback.net_error()); | 
| 435   EXPECT_EQ(net::HTTP_OK, callback.http_response_code()); | 436   EXPECT_EQ(net::HTTP_OK, callback.http_response_code()); | 
| 436 } | 437 } | 
| 437 | 438 | 
| 438 }  // namespace | 439 }  // namespace | 
| 439 | 440 | 
| 440 }  // namespace certificate_transparency | 441 }  // namespace certificate_transparency | 
| OLD | NEW | 
|---|