[email protected] | dca629c | 2012-03-22 03:40:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d82abb9 | 2010-05-04 17:21:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 4 | |
eroman | ada22007 | 2016-11-23 21:49:31 | [diff] [blame] | 5 | #include "base/build_time.h" |
[email protected] | 567d30e | 2012-07-13 21:48:29 | [diff] [blame] | 6 | #include "base/metrics/statistics_recorder.h" |
[email protected] | ee881f40 | 2013-10-04 21:51:50 | [diff] [blame] | 7 | #include "base/test/launcher/unit_test_launcher.h" |
[email protected] | 331c251 | 2010-05-04 18:15:56 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 9 | #include "crypto/nss_util.h" |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 10 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | 8efa4ba4 | 2013-03-18 21:14:14 | [diff] [blame] | 11 | #include "net/test/net_test_suite.h" |
kapishnikov | abe280e | 2016-04-14 19:07:16 | [diff] [blame] | 12 | #include "url/url_features.h" |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 13 | |
mmenke | e2ad992 | 2017-06-08 20:27:36 | [diff] [blame] | 14 | #if !defined(OS_IOS) |
brettw | 25ca892 | 2016-03-18 22:59:58 | [diff] [blame] | 15 | #include "mojo/edk/embedder/embedder.h" // nogncheck |
amistry | 7e6ebfdc8 | 2015-02-13 04:19:11 | [diff] [blame] | 16 | #endif |
| 17 | |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 18 | using net::internal::ClientSocketPoolBaseHelper; |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 19 | |
eroman | ada22007 | 2016-11-23 21:49:31 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | bool VerifyBuildIsTimely() { |
| 23 | // This lines up with various //net security features, like Certificate |
| 24 | // Transparency or HPKP, in that they require the build time be less than 70 |
| 25 | // days old. Moreover, operating on the assumption that tests are run against |
| 26 | // recently compiled builds, this also serves as a sanity check for the |
| 27 | // system clock, which should be close to the build date. |
| 28 | base::TimeDelta kMaxAge = base::TimeDelta::FromDays(70); |
| 29 | |
| 30 | base::Time build_time = base::GetBuildTime(); |
| 31 | base::Time now = base::Time::Now(); |
| 32 | |
| 33 | if ((now - build_time).magnitude() <= kMaxAge) |
| 34 | return true; |
| 35 | |
| 36 | std::cerr |
| 37 | << "ERROR: This build is more than " << kMaxAge.InDays() |
| 38 | << " days out of date.\n" |
| 39 | "This could indicate a problem with the device's clock, or the build " |
| 40 | "is simply too old.\n" |
| 41 | "See crbug.com/666821 for why this is a problem\n" |
| 42 | << " base::Time::Now() --> " << now << " (" << now.ToInternalValue() |
| 43 | << ")\n" |
| 44 | << " base::GetBuildTime() --> " << build_time << " (" |
| 45 | << build_time.ToInternalValue() << ")\n"; |
| 46 | |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | } // namespace |
| 51 | |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 52 | int main(int argc, char** argv) { |
[email protected] | 26a6459 | 2009-12-15 08:04:40 | [diff] [blame] | 53 | // Record histograms, so we can get histograms data in tests. |
[email protected] | fce44c1 | 2012-07-19 19:17:32 | [diff] [blame] | 54 | base::StatisticsRecorder::Initialize(); |
[email protected] | 6e4cc8f | 2012-06-27 02:21:02 | [diff] [blame] | 55 | |
eroman | ada22007 | 2016-11-23 21:49:31 | [diff] [blame] | 56 | if (!VerifyBuildIsTimely()) |
| 57 | return 1; |
| 58 | |
[email protected] | 47c196b | 2009-12-02 20:04:27 | [diff] [blame] | 59 | NetTestSuite test_suite(argc, argv); |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 60 | ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
[email protected] | d82abb9 | 2010-05-04 17:21:32 | [diff] [blame] | 61 | |
mmenke | e2ad992 | 2017-06-08 20:27:36 | [diff] [blame] | 62 | #if !defined(OS_IOS) |
rockot | c637caf9b | 2016-02-10 09:57:08 | [diff] [blame] | 63 | mojo::edk::Init(); |
amistry | 7e6ebfdc8 | 2015-02-13 04:19:11 | [diff] [blame] | 64 | #endif |
| 65 | |
[email protected] | d85fe1e | 2013-09-05 18:20:36 | [diff] [blame] | 66 | return base::LaunchUnitTests( |
| 67 | argc, argv, base::Bind(&NetTestSuite::Run, |
| 68 | base::Unretained(&test_suite))); |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 69 | } |