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

Side by Side Diff: net/ssl/server_bound_cert_service_unittest.cc

Issue 67923002: Fixes for -Wunused-function on Linux, Android and ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase for realz Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/tests/gl_virtual_contexts_unittests.cc ('k') | net/test/python_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/ssl/server_bound_cert_service.h" 5 #include "net/ssl/server_bound_cert_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/task_runner.h" 14 #include "base/task_runner.h"
15 #include "crypto/ec_private_key.h" 15 #include "crypto/ec_private_key.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
18 #include "net/cert/asn1_util.h" 18 #include "net/cert/asn1_util.h"
19 #include "net/cert/x509_certificate.h" 19 #include "net/cert/x509_certificate.h"
20 #include "net/ssl/default_server_bound_cert_store.h" 20 #include "net/ssl/default_server_bound_cert_store.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace net { 23 namespace net {
24 24
25 namespace { 25 namespace {
26 26
27 #if !defined(USE_OPENSSL)
27 void FailTest(int /* result */) { 28 void FailTest(int /* result */) {
28 FAIL(); 29 FAIL();
29 } 30 }
30 31
31 // Simple task runner that refuses to actually post any tasks. This simulates 32 // Simple task runner that refuses to actually post any tasks. This simulates
32 // a TaskRunner that has been shutdown, by returning false for any attempt to 33 // a TaskRunner that has been shutdown, by returning false for any attempt to
33 // add new tasks. 34 // add new tasks.
34 class FailingTaskRunner : public base::TaskRunner { 35 class FailingTaskRunner : public base::TaskRunner {
35 public: 36 public:
36 FailingTaskRunner() {} 37 FailingTaskRunner() {}
37 38
38 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, 39 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
39 const base::Closure& task, 40 const base::Closure& task,
40 base::TimeDelta delay) OVERRIDE { 41 base::TimeDelta delay) OVERRIDE {
41 return false; 42 return false;
42 } 43 }
43 44
44 virtual bool RunsTasksOnCurrentThread() const OVERRIDE { return true; } 45 virtual bool RunsTasksOnCurrentThread() const OVERRIDE { return true; }
45 46
46 protected: 47 protected:
47 virtual ~FailingTaskRunner() {} 48 virtual ~FailingTaskRunner() {}
48 49
49 private: 50 private:
50 DISALLOW_COPY_AND_ASSIGN(FailingTaskRunner); 51 DISALLOW_COPY_AND_ASSIGN(FailingTaskRunner);
51 }; 52 };
52 53
53 class ServerBoundCertServiceTest : public testing::Test {
54 public:
55 ServerBoundCertServiceTest()
56 : service_(new ServerBoundCertService(
57 new DefaultServerBoundCertStore(NULL),
58 base::MessageLoopProxy::current())) {
59 }
60
61 protected:
62 scoped_ptr<ServerBoundCertService> service_;
63 };
64
65 class MockServerBoundCertStoreWithAsyncGet 54 class MockServerBoundCertStoreWithAsyncGet
66 : public DefaultServerBoundCertStore { 55 : public DefaultServerBoundCertStore {
67 public: 56 public:
68 MockServerBoundCertStoreWithAsyncGet() 57 MockServerBoundCertStoreWithAsyncGet()
69 : DefaultServerBoundCertStore(NULL), cert_count_(0) {} 58 : DefaultServerBoundCertStore(NULL), cert_count_(0) {}
70 59
71 virtual int GetServerBoundCert(const std::string& server_identifier, 60 virtual int GetServerBoundCert(const std::string& server_identifier,
72 base::Time* expiration_time, 61 base::Time* expiration_time,
73 std::string* private_key_result, 62 std::string* private_key_result,
74 std::string* cert_result, 63 std::string* cert_result,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 cert_count_ = 1; 110 cert_count_ = 1;
122 base::MessageLoop::current()->PostTask(FROM_HERE, 111 base::MessageLoop::current()->PostTask(FROM_HERE,
123 base::Bind(callback_, 112 base::Bind(callback_,
124 err, 113 err,
125 server_identifier_, 114 server_identifier_,
126 expiration_time, 115 expiration_time,
127 private_key, 116 private_key,
128 cert)); 117 cert));
129 } 118 }
130 119
120 #endif // !defined(USE_OPENSSL)
121
122 class ServerBoundCertServiceTest : public testing::Test {
123 public:
124 ServerBoundCertServiceTest()
125 : service_(new ServerBoundCertService(
126 new DefaultServerBoundCertStore(NULL),
127 base::MessageLoopProxy::current())) {
128 }
129
130 protected:
131 scoped_ptr<ServerBoundCertService> service_;
132 };
133
131 TEST_F(ServerBoundCertServiceTest, GetDomainForHost) { 134 TEST_F(ServerBoundCertServiceTest, GetDomainForHost) {
132 EXPECT_EQ("google.com", 135 EXPECT_EQ("google.com",
133 ServerBoundCertService::GetDomainForHost("google.com")); 136 ServerBoundCertService::GetDomainForHost("google.com"));
134 EXPECT_EQ("google.com", 137 EXPECT_EQ("google.com",
135 ServerBoundCertService::GetDomainForHost("www.google.com")); 138 ServerBoundCertService::GetDomainForHost("www.google.com"));
136 EXPECT_EQ("foo.appspot.com", 139 EXPECT_EQ("foo.appspot.com",
137 ServerBoundCertService::GetDomainForHost("foo.appspot.com")); 140 ServerBoundCertService::GetDomainForHost("foo.appspot.com"));
138 EXPECT_EQ("bar.appspot.com", 141 EXPECT_EQ("bar.appspot.com",
139 ServerBoundCertService::GetDomainForHost("foo.bar.appspot.com")); 142 ServerBoundCertService::GetDomainForHost("foo.bar.appspot.com"));
140 EXPECT_EQ("appspot.com", 143 EXPECT_EQ("appspot.com",
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 EXPECT_EQ(private_key1, private_key2); 773 EXPECT_EQ(private_key1, private_key2);
771 EXPECT_FALSE(request_handle1.is_active()); 774 EXPECT_FALSE(request_handle1.is_active());
772 EXPECT_FALSE(request_handle2.is_active()); 775 EXPECT_FALSE(request_handle2.is_active());
773 } 776 }
774 777
775 #endif // !defined(USE_OPENSSL) 778 #endif // !defined(USE_OPENSSL)
776 779
777 } // namespace 780 } // namespace
778 781
779 } // namespace net 782 } // namespace net
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_virtual_contexts_unittests.cc ('k') | net/test/python_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698