Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/browser/ssl/ssl_severity_date_invalid_browsertest.cc

Issue 376663002: Calculate severity score for date_invalid error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test cases Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_severity_date_invalid.h"
6
7 #include "base/files/file_path.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "components/network_time/network_time_tracker.h"
14 #include "net/base/test_data_directory.h"
15 #include "net/cert/x509_certificate.h"
16 #include "net/test/cert_test_util.h"
17 #include "net/test/spawned_test_server/spawned_test_server.h"
18 #include "net/test/test_certificate_data.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using base::Time;
22 using base::TimeDelta;
23 using base::TimeTicks;
24
25 const base::FilePath::CharType kDocRoot[] =
26 FILE_PATH_LITERAL("chrome/test/data");
27
28 const int64 kLatency1 = 50;
29 const int64 kResolution1 = 17;
30
31 class SSLSeverityDateInvalidTest : public InProcessBrowserTest {
32 protected:
33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
34 https_server_.reset(
35 new net::SpawnedTestServer(
36 net::SpawnedTestServer::TYPE_HTTPS,
37 net::SpawnedTestServer::SSLOptions(
38 net::SpawnedTestServer::SSLOptions::CERT_OK),
39 base::FilePath(kDocRoot)));
40 ASSERT_TRUE(https_server_->Start());
41
42 }
43 scoped_ptr<net::SpawnedTestServer> https_server_;
44 };
45
46 IN_PROC_BROWSER_TEST_F(SSLSeverityDateInvalidTest, IsUserClockWrongTest) {
47 GURL url(https_server_->GetURL("files/ssl/google.html"));
48 ui_test_utils::NavigateToURL(browser(), url);
49 base::FilePath certs_dir = net::GetTestCertsDirectory();
50 scoped_refptr<net::X509Certificate> ok_cert =
51 net::ImportCertFromFile(certs_dir, "ok_cert.pem");
52 base::Time time;
53 base::Time network_time;
54 base::TimeDelta uncertainty;
55 ASSERT_FALSE(g_browser_process->network_time_tracker()->
56 GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty));
57 g_browser_process->network_time_tracker()->
58 UpdateNetworkTime(base::Time::Now(),
59 base::TimeDelta::FromMilliseconds(kResolution1),
60 base::TimeDelta::FromMilliseconds(kLatency1),
61 base::TimeTicks());
62 ASSERT_TRUE(g_browser_process->network_time_tracker()->
63 GetNetworkTime(base::TimeTicks(), &network_time, &uncertainty));
64
65 {
66 EXPECT_TRUE(base::Time::FromString("Wed, 03 Jan 2007 12:00:00 GMT",
67 &time));
68 SSLSeverityDateInvalid ssl_severity(time, ok_cert);
69 EXPECT_FLOAT_EQ(0.1, ssl_severity.IsUserClockWrong());
70 }
71
72 {
73 EXPECT_TRUE(base::Time::FromString("Thu, 03 Jul 2014 12:00:00 GMT",
74 &time));
75 SSLSeverityDateInvalid ssl_severity(time, ok_cert);
76 EXPECT_FLOAT_EQ(0.1, ssl_severity.IsUserClockWrong());
77 }
78
79 {
80 SSLSeverityDateInvalid ssl_severity(base::Time::NowFromSystemTime(),
81 ok_cert);
82 EXPECT_FLOAT_EQ(0.9, ssl_severity.IsUserClockWrong());
83 }
84
85 {
86 EXPECT_TRUE(base::Time::FromString("Wed, 08 Jul 2020 12:00:00 GMT",
87 &time));
88 SSLSeverityDateInvalid ssl_severity(time, ok_cert);
89 EXPECT_FLOAT_EQ(0.1, ssl_severity.IsUserClockWrong());
90 }
91
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698