OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ssl/ssl_error_classification.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/network_time/network_time_tracker.h" |
| 16 #include "net/base/test_data_directory.h" |
| 17 #include "net/cert/x509_certificate.h" |
| 18 #include "net/test/cert_test_util.h" |
| 19 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 20 #include "net/test/test_certificate_data.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 |
| 23 using base::Time; |
| 24 using base::TimeDelta; |
| 25 using base::TimeTicks; |
| 26 |
| 27 const base::FilePath::CharType kDocRoot[] = |
| 28 FILE_PATH_LITERAL("chrome/test/data"); |
| 29 |
| 30 const int64 kLatency1 = 50; |
| 31 const int64 kResolution1 = 17; |
| 32 |
| 33 class SSLErrorClassificationTest : public InProcessBrowserTest { |
| 34 protected: |
| 35 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 36 https_server_.reset( |
| 37 new net::SpawnedTestServer( |
| 38 net::SpawnedTestServer::TYPE_HTTPS, |
| 39 net::SpawnedTestServer::SSLOptions( |
| 40 net::SpawnedTestServer::SSLOptions::CERT_OK), |
| 41 base::FilePath(kDocRoot))); |
| 42 ASSERT_TRUE(https_server_->Start()); |
| 43 |
| 44 } |
| 45 scoped_ptr<net::SpawnedTestServer> https_server_; |
| 46 }; |
| 47 |
| 48 IN_PROC_BROWSER_TEST_F(SSLErrorClassificationTest, IsUserClockWrongTest) { |
| 49 GURL url(https_server_->GetURL("files/ssl/google.html")); |
| 50 ui_test_utils::NavigateToURL(browser(), url); |
| 51 base::FilePath certs_dir = net::GetTestCertsDirectory(); |
| 52 scoped_refptr<net::X509Certificate> ok_cert = |
| 53 net::ImportCertFromFile(certs_dir, "ok_cert.pem"); |
| 54 base::Time time; |
| 55 base::Time network_time; |
| 56 base::TimeDelta uncertainty; |
| 57 ASSERT_FALSE(g_browser_process->network_time_tracker()-> |
| 58 GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty)); |
| 59 g_browser_process->network_time_tracker()->UpdateNetworkTime( |
| 60 base::Time::NowFromSystemTime(), |
| 61 base::TimeDelta::FromMilliseconds(kResolution1), |
| 62 base::TimeDelta::FromMilliseconds(kLatency1), |
| 63 base::TimeTicks()); |
| 64 ASSERT_TRUE(g_browser_process->network_time_tracker()-> |
| 65 GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty)); |
| 66 |
| 67 { |
| 68 EXPECT_TRUE(base::Time::FromString("Wed, 03 Jan 2007 12:00:00 GMT", |
| 69 &time)); |
| 70 EXPECT_TRUE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
| 71 EXPECT_FALSE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
| 72 } |
| 73 |
| 74 { |
| 75 EXPECT_TRUE(base::Time::FromString("Thu, 03 Jul 2014 12:00:00 GMT", |
| 76 &time)); |
| 77 EXPECT_TRUE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
| 78 EXPECT_FALSE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
| 79 } |
| 80 |
| 81 { |
| 82 EXPECT_FALSE(SSLErrorClassification:: |
| 83 IsUserClockInThePast(true, base::Time::NowFromSystemTime())); |
| 84 EXPECT_FALSE(SSLErrorClassification:: |
| 85 IsUserClockInTheFuture(true, |
| 86 base::Time::NowFromSystemTime())); |
| 87 } |
| 88 |
| 89 { |
| 90 EXPECT_TRUE(base::Time::FromString("Wed, 08 Jul 2020 12:00:00 GMT", |
| 91 &time)); |
| 92 EXPECT_FALSE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
| 93 EXPECT_TRUE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
| 94 } |
| 95 } |
OLD | NEW |