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

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

Issue 400323002: Refactor the captive portal code to move from the ssl_blocking_page class to the ssl_error_classific (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Comments 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_classification.h" 5 #include "chrome/browser/ssl/ssl_error_classification.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "content/public/browser/web_contents.h"
9 #include "net/base/test_data_directory.h" 11 #include "net/base/test_data_directory.h"
10 #include "net/cert/x509_certificate.h" 12 #include "net/cert/x509_certificate.h"
11 #include "net/test/cert_test_util.h" 13 #include "net/test/cert_test_util.h"
12 #include "net/test/test_certificate_data.h" 14 #include "net/test/test_certificate_data.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using base::Time; 17 using base::Time;
18 using content::WebContents;
16 19
17 TEST(SSLErrorClassification, TestDateInvalidScore) { 20 class SSLErrorClassificationTest : public ChromeRenderViewHostTestHarness {
21 public:
22 SSLErrorClassificationTest() {
23 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
24 }
25
26 virtual void SetUp() OVERRIDE {
27 ChromeRenderViewHostTestHarness::SetUp();
28 web_contents_.reset(CreateTestWebContents());
29 }
30
31 virtual void TearDown() OVERRIDE {
32 web_contents_.reset(NULL);
33 ChromeRenderViewHostTestHarness::TearDown();
34 }
35
36 WebContents* GetWebContents() {
37 return web_contents_.get();
38 }
39
40 private:
41 scoped_ptr<WebContents> web_contents_;
42 };
43
44 TEST_F(SSLErrorClassificationTest, TestDateInvalidScore) {
18 base::FilePath certs_dir = net::GetTestCertsDirectory(); 45 base::FilePath certs_dir = net::GetTestCertsDirectory();
19 scoped_refptr<net::X509Certificate> expired_cert = 46 scoped_refptr<net::X509Certificate> expired_cert =
20 net::ImportCertFromFile(certs_dir, "expired_cert.pem"); 47 net::ImportCertFromFile(certs_dir, "expired_cert.pem");
21 base::Time time; 48 base::Time time;
49 WebContents* contents = GetWebContents();
22 50
23 { 51 {
24 EXPECT_TRUE(base::Time::FromString("Wed, 03 Jan 2007 12:00:00 GMT", &time)); 52 EXPECT_TRUE(base::Time::FromString("Wed, 03 Jan 2007 12:00:00 GMT", &time));
25 SSLErrorClassification ssl_error(time, *expired_cert); 53 SSLErrorClassification ssl_error(contents, time, *expired_cert);
26 EXPECT_FLOAT_EQ(0.2f, ssl_error.CalculateScoreTimePassedSinceExpiry()); 54 EXPECT_FLOAT_EQ(0.2f, ssl_error.CalculateScoreTimePassedSinceExpiry());
27 } 55 }
28 56
29 { 57 {
30 EXPECT_TRUE(base::Time::FromString("Sat, 06 Jan 2007 12:00:00 GMT", &time)); 58 EXPECT_TRUE(base::Time::FromString("Sat, 06 Jan 2007 12:00:00 GMT", &time));
31 SSLErrorClassification ssl_error(time, *expired_cert); 59 SSLErrorClassification ssl_error(contents, time, *expired_cert);
32 EXPECT_FLOAT_EQ(0.3f, ssl_error.CalculateScoreTimePassedSinceExpiry()); 60 EXPECT_FLOAT_EQ(0.3f, ssl_error.CalculateScoreTimePassedSinceExpiry());
33 } 61 }
34 62
35 { 63 {
36 EXPECT_TRUE(base::Time::FromString("Mon, 08 Jan 2007 12:00:00 GMT", &time)); 64 EXPECT_TRUE(base::Time::FromString("Mon, 08 Jan 2007 12:00:00 GMT", &time));
37 SSLErrorClassification ssl_error(time, *expired_cert); 65 SSLErrorClassification ssl_error(contents, time, *expired_cert);
38 EXPECT_FLOAT_EQ(0.4f, ssl_error.CalculateScoreTimePassedSinceExpiry()); 66 EXPECT_FLOAT_EQ(0.4f, ssl_error.CalculateScoreTimePassedSinceExpiry());
39 } 67 }
40
41 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698