Chromium Code Reviews| 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 "base/build_time.h" | |
| 5 #include "base/metrics/statistics_recorder.h" | 6 #include "base/metrics/statistics_recorder.h" |
| 6 #include "base/test/launcher/unit_test_launcher.h" | 7 #include "base/test/launcher/unit_test_launcher.h" |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "crypto/nss_util.h" | 9 #include "crypto/nss_util.h" |
| 9 #include "net/socket/client_socket_pool_base.h" | 10 #include "net/socket/client_socket_pool_base.h" |
| 10 #include "net/test/net_test_suite.h" | 11 #include "net/test/net_test_suite.h" |
| 11 #include "url/url_features.h" | 12 #include "url/url_features.h" |
| 12 | 13 |
| 13 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 14 #include "base/android/jni_android.h" | 15 #include "base/android/jni_android.h" |
| 15 #include "base/android/jni_registrar.h" | 16 #include "base/android/jni_registrar.h" |
| 16 #include "net/android/dummy_spnego_authenticator.h" | 17 #include "net/android/dummy_spnego_authenticator.h" |
| 17 #include "net/android/net_jni_registrar.h" | 18 #include "net/android/net_jni_registrar.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 21 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 21 #include "mojo/edk/embedder/embedder.h" // nogncheck | 22 #include "mojo/edk/embedder/embedder.h" // nogncheck |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 using net::internal::ClientSocketPoolBaseHelper; | 25 using net::internal::ClientSocketPoolBaseHelper; |
| 25 | 26 |
| 27 namespace { | |
| 28 | |
| 29 bool VerifyBuildIsTimely() { | |
| 30 // This (currently) lines up with the policy used by CTPolicyEnforcer, which | |
| 31 // requires the build be less than 70 days old. Moreover, operating on the | |
| 32 // assumption that tests are run on recently compiled builds, this also | |
| 33 // serves as a sanity check for the system clock (it should be close to the | |
| 34 // build date). | |
| 35 base::TimeDelta kMaxAge = base::TimeDelta::FromDays(70); | |
| 36 | |
| 37 base::Time build_time = base::GetBuildTime(); | |
| 38 base::Time now = base::Time::Now(); | |
| 39 | |
| 40 if ((now - build_time) <= kMaxAge) | |
|
jbudorick
2016/11/22 15:59:53
This only works if now is >70 days ahead of build
eroman
2016/11/22 22:49:46
Good point! Fixed.
(Should probably apply somethi
eroman
2016/11/22 22:56:03
Also oddly, the opposite seems to be the case on t
eroman
2016/11/22 22:59:16
Actually Ryan pointed out I am an idiot. Current t
| |
| 41 return true; | |
| 42 | |
| 43 std::cerr | |
| 44 << "ERROR: This build is more than " << kMaxAge.InDays() | |
| 45 << " days out of date.\n" | |
| 46 "This could indicate a problem with the device's clock, or the build " | |
| 47 "is simply too old.\n" | |
| 48 "See crbug.com/666821 for why this is a problem\n" | |
| 49 << " base::Time::Now() --> " << now << " (" << now.ToInternalValue() | |
| 50 << ")\n" | |
| 51 << " base::GetBuildTime() --> " << build_time << " (" | |
| 52 << build_time.ToInternalValue() << ")\n"; | |
| 53 | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 26 int main(int argc, char** argv) { | 59 int main(int argc, char** argv) { |
| 27 // Record histograms, so we can get histograms data in tests. | 60 // Record histograms, so we can get histograms data in tests. |
| 28 base::StatisticsRecorder::Initialize(); | 61 base::StatisticsRecorder::Initialize(); |
| 29 | 62 |
| 30 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
| 31 const base::android::RegistrationMethod kNetTestRegisteredMethods[] = { | 64 const base::android::RegistrationMethod kNetTestRegisteredMethods[] = { |
| 32 {"DummySpnegoAuthenticator", | 65 {"DummySpnegoAuthenticator", |
| 33 net::android::DummySpnegoAuthenticator::RegisterJni}, | 66 net::android::DummySpnegoAuthenticator::RegisterJni}, |
| 34 {"NetAndroid", net::android::RegisterJni}, | 67 {"NetAndroid", net::android::RegisterJni}, |
| 35 }; | 68 }; |
| 36 | 69 |
| 37 // Register JNI bindings for android. Doing it early as the test suite setup | 70 // Register JNI bindings for android. Doing it early as the test suite setup |
| 38 // may initiate a call to Java. | 71 // may initiate a call to Java. |
| 39 base::android::RegisterNativeMethods( | 72 base::android::RegisterNativeMethods( |
| 40 base::android::AttachCurrentThread(), | 73 base::android::AttachCurrentThread(), |
| 41 kNetTestRegisteredMethods, | 74 kNetTestRegisteredMethods, |
| 42 arraysize(kNetTestRegisteredMethods)); | 75 arraysize(kNetTestRegisteredMethods)); |
| 43 #endif | 76 #endif |
| 44 | 77 |
| 78 if (!VerifyBuildIsTimely()) | |
| 79 return 1; | |
| 80 | |
| 45 NetTestSuite test_suite(argc, argv); | 81 NetTestSuite test_suite(argc, argv); |
| 46 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 82 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
| 47 | 83 |
| 48 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 84 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 49 mojo::edk::Init(); | 85 mojo::edk::Init(); |
| 50 #endif | 86 #endif |
| 51 | 87 |
| 52 return base::LaunchUnitTests( | 88 return base::LaunchUnitTests( |
| 53 argc, argv, base::Bind(&NetTestSuite::Run, | 89 argc, argv, base::Bind(&NetTestSuite::Run, |
| 54 base::Unretained(&test_suite))); | 90 base::Unretained(&test_suite))); |
| 55 } | 91 } |
| OLD | NEW |