Index: chrome/browser/ssl/ssl_error_classification_browsertest.cc |
diff --git a/chrome/browser/ssl/ssl_error_classification_browsertest.cc b/chrome/browser/ssl/ssl_error_classification_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c2bc04f21bdebee5241493a5e70d25730800e452 |
--- /dev/null |
+++ b/chrome/browser/ssl/ssl_error_classification_browsertest.cc |
@@ -0,0 +1,95 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ssl/ssl_error_classification.h" |
+ |
+#include "base/files/file_path.h" |
+#include "base/i18n/time_formatting.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/time/time.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+#include "components/network_time/network_time_tracker.h" |
+#include "net/base/test_data_directory.h" |
+#include "net/cert/x509_certificate.h" |
+#include "net/test/cert_test_util.h" |
+#include "net/test/spawned_test_server/spawned_test_server.h" |
+#include "net/test/test_certificate_data.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using base::Time; |
+using base::TimeDelta; |
+using base::TimeTicks; |
+ |
+const base::FilePath::CharType kDocRoot[] = |
+ FILE_PATH_LITERAL("chrome/test/data"); |
+ |
+const int64 kLatency1 = 50; |
+const int64 kResolution1 = 17; |
+ |
+class SSLErrorClassificationTest : public InProcessBrowserTest { |
+ protected: |
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
+ https_server_.reset( |
+ new net::SpawnedTestServer( |
+ net::SpawnedTestServer::TYPE_HTTPS, |
+ net::SpawnedTestServer::SSLOptions( |
+ net::SpawnedTestServer::SSLOptions::CERT_OK), |
+ base::FilePath(kDocRoot))); |
+ ASSERT_TRUE(https_server_->Start()); |
+ |
+ } |
+ scoped_ptr<net::SpawnedTestServer> https_server_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(SSLErrorClassificationTest, IsUserClockWrongTest) { |
+ GURL url(https_server_->GetURL("files/ssl/google.html")); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ base::FilePath certs_dir = net::GetTestCertsDirectory(); |
+ scoped_refptr<net::X509Certificate> ok_cert = |
+ net::ImportCertFromFile(certs_dir, "ok_cert.pem"); |
+ base::Time time; |
+ base::Time network_time; |
+ base::TimeDelta uncertainty; |
+ ASSERT_FALSE(g_browser_process->network_time_tracker()-> |
+ GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty)); |
+ g_browser_process->network_time_tracker()->UpdateNetworkTime( |
+ base::Time::NowFromSystemTime(), |
+ base::TimeDelta::FromMilliseconds(kResolution1), |
+ base::TimeDelta::FromMilliseconds(kLatency1), |
+ base::TimeTicks()); |
+ ASSERT_TRUE(g_browser_process->network_time_tracker()-> |
+ GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty)); |
+ |
+ { |
+ EXPECT_TRUE(base::Time::FromString("Wed, 03 Jan 2007 12:00:00 GMT", |
+ &time)); |
+ EXPECT_TRUE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
+ EXPECT_FALSE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
+ } |
+ |
+ { |
+ EXPECT_TRUE(base::Time::FromString("Thu, 03 Jul 2014 12:00:00 GMT", |
+ &time)); |
+ EXPECT_TRUE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
+ EXPECT_FALSE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
+ } |
+ |
+ { |
+ EXPECT_FALSE(SSLErrorClassification:: |
+ IsUserClockInThePast(true, base::Time::NowFromSystemTime())); |
+ EXPECT_FALSE(SSLErrorClassification:: |
+ IsUserClockInTheFuture(true, |
+ base::Time::NowFromSystemTime())); |
+ } |
+ |
+ { |
+ EXPECT_TRUE(base::Time::FromString("Wed, 08 Jul 2020 12:00:00 GMT", |
+ &time)); |
+ EXPECT_FALSE(SSLErrorClassification::IsUserClockInThePast(true, time)); |
+ EXPECT_TRUE(SSLErrorClassification::IsUserClockInTheFuture(true, time)); |
+ } |
+} |