Chromium Code Reviews| 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_reporting/error_report.h" | 5 #include "components/certificate_reporting/error_report.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/time/default_clock.h" | 16 #include "base/time/default_clock.h" |
| 17 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 18 #include "components/certificate_reporting/cert_logger.pb.h" | 18 #include "components/certificate_reporting/cert_logger.pb.h" |
| 19 #include "components/network_time/network_time_test_utils.h" | 19 #include "components/network_time/network_time_test_utils.h" |
| 20 #include "components/prefs/testing_pref_service.h" | 20 #include "components/prefs/testing_pref_service.h" |
| 21 #include "components/version_info/version_info.h" | |
| 21 #include "net/cert/cert_status_flags.h" | 22 #include "net/cert/cert_status_flags.h" |
| 22 #include "net/ssl/ssl_info.h" | 23 #include "net/ssl/ssl_info.h" |
| 23 #include "net/test/cert_test_util.h" | 24 #include "net/test/cert_test_util.h" |
| 24 #include "net/test/test_data_directory.h" | 25 #include "net/test/test_data_directory.h" |
| 25 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
| 30 #include "base/test/scoped_feature_list.h" | 31 #include "base/test/scoped_feature_list.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 EXPECT_TRUE(parsed.features_info() | 241 EXPECT_TRUE(parsed.features_info() |
| 241 .network_time_querying_info() | 242 .network_time_querying_info() |
| 242 .network_time_queries_enabled()); | 243 .network_time_queries_enabled()); |
| 243 EXPECT_EQ(CertLoggerFeaturesInfo::NetworkTimeQueryingInfo:: | 244 EXPECT_EQ(CertLoggerFeaturesInfo::NetworkTimeQueryingInfo:: |
| 244 NETWORK_TIME_FETCHES_ON_DEMAND_ONLY, | 245 NETWORK_TIME_FETCHES_ON_DEMAND_ONLY, |
| 245 parsed.features_info() | 246 parsed.features_info() |
| 246 .network_time_querying_info() | 247 .network_time_querying_info() |
| 247 .network_time_query_behavior()); | 248 .network_time_query_behavior()); |
| 248 } | 249 } |
| 249 | 250 |
| 251 TEST(ErrorReportTest, TestChromeChannelIncluded) { | |
| 252 base::Thread io_thread("IO thread"); | |
|
Lei Zhang
2017/06/30 22:32:06
Does your test case need an IO thread?
sperigo
2017/06/30 23:37:28
Done.
sperigo
2017/06/30 23:37:29
I guess not! Thanks.
| |
| 253 base::Thread::Options thread_options; | |
| 254 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | |
| 255 EXPECT_TRUE(io_thread.StartWithOptions(thread_options)); | |
| 256 | |
| 257 SSLInfo ssl_info; | |
| 258 ASSERT_NO_FATAL_FAILURE( | |
| 259 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); | |
| 260 ErrorReport report(kDummyHostname, ssl_info); | |
| 261 | |
| 262 // Add a chrome channel to the report. | |
| 263 report.AddChromeChannel(version_info::Channel::DEV); | |
| 264 std::string serialized_report; | |
| 265 ASSERT_TRUE(report.Serialize(&serialized_report)); | |
| 266 | |
| 267 // Check that the parsed report contains the chrome channel information. | |
| 268 CertLoggerRequest parsed; | |
| 269 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); | |
| 270 EXPECT_TRUE(parsed.chrome_channel()); | |
|
Lei Zhang
2017/06/30 22:32:06
It is a bit weird to check chrome_channel() twice.
sperigo
2017/06/30 23:37:29
Done.
| |
| 271 EXPECT_EQ(CertLoggerRequest::DEV, parsed.chrome_channel()); | |
|
meacer
2017/06/30 22:24:46
A bit of an overkill but you might want to test al
sperigo
2017/06/30 23:37:29
Done.
sperigo
2017/06/30 23:37:29
I like this! I'm a fan of over testing over under
| |
| 272 } | |
| 273 | |
| 250 #if defined(OS_ANDROID) | 274 #if defined(OS_ANDROID) |
| 251 // Tests that information about the Android AIA fetching feature is included in | 275 // Tests that information about the Android AIA fetching feature is included in |
| 252 // the report. | 276 // the report. |
| 253 TEST(ErrorReportTest, AndroidAIAFetchingFeatureEnabled) { | 277 TEST(ErrorReportTest, AndroidAIAFetchingFeatureEnabled) { |
| 254 SSLInfo ssl_info; | 278 SSLInfo ssl_info; |
| 255 ASSERT_NO_FATAL_FAILURE( | 279 ASSERT_NO_FATAL_FAILURE( |
| 256 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); | 280 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); |
| 257 ErrorReport report(kDummyHostname, ssl_info); | 281 ErrorReport report(kDummyHostname, ssl_info); |
| 258 std::string serialized_report; | 282 std::string serialized_report; |
| 259 ASSERT_TRUE(report.Serialize(&serialized_report)); | 283 ASSERT_TRUE(report.Serialize(&serialized_report)); |
| 260 CertLoggerRequest parsed; | 284 CertLoggerRequest parsed; |
| 261 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); | 285 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); |
| 262 EXPECT_EQ(CertLoggerFeaturesInfo::ANDROID_AIA_FETCHING_ENABLED, | 286 EXPECT_EQ(CertLoggerFeaturesInfo::ANDROID_AIA_FETCHING_ENABLED, |
| 263 parsed.features_info().android_aia_fetching_status()); | 287 parsed.features_info().android_aia_fetching_status()); |
| 264 } | 288 } |
| 265 #endif | 289 #endif |
| 266 | 290 |
| 267 } // namespace | 291 } // namespace |
| 268 | 292 |
| 269 } // namespace certificate_reporting | 293 } // namespace certificate_reporting |
| OLD | NEW |