| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" | 5 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "net/base/request_priority.h" |
| 17 #include "net/base/test_data_directory.h" | 18 #include "net/base/test_data_directory.h" |
| 18 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 19 #include "net/http/transport_security_state.h" | 20 #include "net/http/transport_security_state.h" |
| 20 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
| 21 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
| 22 #include "net/url_request/fraudulent_certificate_reporter.h" | 23 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 // For the first version of the feature, sending reports is "fire and forget". | 118 // For the first version of the feature, sending reports is "fire and forget". |
| 118 // Therefore, we test only that the Reporter tried to send a request at all. | 119 // Therefore, we test only that the Reporter tried to send a request at all. |
| 119 // In the future, when we have more sophisticated (i.e., any) error handling | 120 // In the future, when we have more sophisticated (i.e., any) error handling |
| 120 // and re-tries, we will need more sopisticated tests as well. | 121 // and re-tries, we will need more sopisticated tests as well. |
| 121 // | 122 // |
| 122 // This class doesn't do anything now, but in near future versions it will. | 123 // This class doesn't do anything now, but in near future versions it will. |
| 123 class MockURLRequest : public net::URLRequest { | 124 class MockURLRequest : public net::URLRequest { |
| 124 public: | 125 public: |
| 125 explicit MockURLRequest(net::URLRequestContext* context) | 126 explicit MockURLRequest(net::URLRequestContext* context) |
| 126 : net::URLRequest(GURL(std::string()), NULL, context) {} | 127 : net::URLRequest(GURL(std::string()), |
| 128 net::DEFAULT_PRIORITY, |
| 129 NULL, |
| 130 context, |
| 131 context->network_delegate()) {} |
| 127 | 132 |
| 128 private: | 133 private: |
| 129 }; | 134 }; |
| 130 | 135 |
| 131 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 136 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is |
| 132 // otherwise normal: reports are constructed and sent in the usual way. | 137 // otherwise normal: reports are constructed and sent in the usual way. |
| 133 class MockReporter : public ChromeFraudulentCertificateReporter { | 138 class MockReporter : public ChromeFraudulentCertificateReporter { |
| 134 public: | 139 public: |
| 135 explicit MockReporter(net::URLRequestContext* request_context) | 140 explicit MockReporter(net::URLRequestContext* request_context) |
| 136 : ChromeFraudulentCertificateReporter(request_context) {} | 141 : ChromeFraudulentCertificateReporter(request_context) {} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 203 } |
| 199 | 204 |
| 200 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 205 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
| 201 base::MessageLoop loop(base::MessageLoop::TYPE_IO); | 206 base::MessageLoop loop(base::MessageLoop::TYPE_IO); |
| 202 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 207 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
| 203 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 208 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
| 204 loop.RunUntilIdle(); | 209 loop.RunUntilIdle(); |
| 205 } | 210 } |
| 206 | 211 |
| 207 } // namespace chrome_browser_net | 212 } // namespace chrome_browser_net |
| OLD | NEW |